his_api_controller.go 212KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156
  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. //var register_log string
  1567. if config.IsOpen == 1 {
  1568. //service.Gdyb1201("", miConfig.OrgName, "1122", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, 1, "")
  1569. 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))
  1570. saveLog(result, requestLog, "1101")
  1571. //register_log = requestLog + "\r\n" + "\r\n" + "\r\n" + result
  1572. var res ResultTwo
  1573. if err := json.Unmarshal([]byte(result), &res); err != nil {
  1574. utils.ErrorLog("解析失败:%v", err)
  1575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1576. return
  1577. }
  1578. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  1579. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  1580. infoStr := string(Iinfos)
  1581. idetinfoStr := string(Idetinfos)
  1582. if res.Infcode == 0 {
  1583. his := models.VMHisPatient{
  1584. Name: name,
  1585. Gender: gender,
  1586. Birthday: birthUnix,
  1587. MedicalTreatmentType: medical_care,
  1588. IdType: certificates,
  1589. IdCardNo: id_card,
  1590. BalanceAccountsType: settlementValue,
  1591. SocialType: social_type,
  1592. MedicalInsuranceNumber: medical_insurance_card,
  1593. RegisterType: register_type,
  1594. RegisterCost: registration_fee,
  1595. TreatmentCost: medical_expenses,
  1596. Status: 1,
  1597. Ctime: time.Now().Unix(),
  1598. Mtime: time.Now().Unix(),
  1599. PsnNo: res.Output.Baseinfo.PsnNo,
  1600. PsnCertType: res.Output.Baseinfo.PsnCertType,
  1601. Certno: res.Output.Baseinfo.Certno,
  1602. PsnName: res.Output.Baseinfo.PsnName,
  1603. Gend: res.Output.Baseinfo.Gend,
  1604. Naty: res.Output.Baseinfo.Naty,
  1605. Brdy: res.Output.Baseinfo.Brdy,
  1606. Age: res.Output.Baseinfo.Age,
  1607. Iinfo: infoStr,
  1608. Idetinfo: idetinfoStr,
  1609. PatientId: patient.ID,
  1610. RecordDate: theTime.Unix(),
  1611. UserOrgId: adminInfo.CurrentOrgId,
  1612. AdminUserId: admin_user_id,
  1613. IsReturn: 1,
  1614. IdCardType: id_card_type,
  1615. Doctor: doctor,
  1616. Departments: department,
  1617. }
  1618. timestamp := time.Now().Unix()
  1619. tempTime := time.Unix(timestamp, 0)
  1620. timeFormat := tempTime.Format("20060102150405")
  1621. chrgBchno := rand.Intn(100000) + 10000
  1622. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1623. //count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  1624. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1625. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  1626. IdCardNo := ""
  1627. if id_card_type == 1 {
  1628. // IdCardNo = medical_insurance_card
  1629. IdCardNo = patient.IdCardNo
  1630. } else {
  1631. IdCardNo = patient.IdCardNo
  1632. }
  1633. var insutypes []string
  1634. var insutype string
  1635. var is390 int = 0
  1636. var is310 int = 0
  1637. for _, item := range res.Output.Iinfo {
  1638. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1639. insutypes = append(insutypes, item.Insutype)
  1640. }
  1641. }
  1642. if len(insutypes) == 1 {
  1643. insutype = insutypes[0]
  1644. } else {
  1645. for _, i := range insutypes {
  1646. if i == "390" {
  1647. is390 = 1
  1648. }
  1649. if i == "310" {
  1650. is310 = 1
  1651. }
  1652. }
  1653. }
  1654. if is390 == 1 {
  1655. insutype = "390"
  1656. }
  1657. if is310 == 1 {
  1658. insutype = "310"
  1659. }
  1660. if len(insutypes) == 0 {
  1661. insutype = "310"
  1662. }
  1663. //insutype = "390"
  1664. 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)
  1665. saveLog(result, requestLog, "2201")
  1666. //register_log = register_log + requestLog + "\r\n" + "\r\n" + "\r\n" + result + "\r\n" + "\r\n" + "\r\n"
  1667. //saveRegisterLog(register_log)
  1668. var res ResultThree
  1669. if err := json.Unmarshal([]byte(result), &res); err != nil {
  1670. utils.ErrorLog("解析失败:%v", err)
  1671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1672. return
  1673. }
  1674. if res.Infcode != 0 {
  1675. adminUser := c.GetAdminUserInfo()
  1676. errlog := &models.HisOrderError{
  1677. UserOrgId: adminUser.CurrentOrgId,
  1678. Ctime: time.Now().Unix(),
  1679. Mtime: time.Now().Unix(),
  1680. ErrMsg: res.ErrMsg,
  1681. Status: 1,
  1682. PatientId: id,
  1683. RecordTime: recordDateTime,
  1684. Stage: 2,
  1685. }
  1686. service.CreateErrMsgLog(errlog)
  1687. c.ServeSuccessJSON(map[string]interface{}{
  1688. "failed_code": -10,
  1689. "msg": res.ErrMsg,
  1690. })
  1691. return
  1692. }
  1693. his.Number = res.Output.Data.MdtrtID
  1694. his.PsnNo = res.Output.Data.PsnNo
  1695. his.IptOtpNo = res.Output.Data.IptOtpNo
  1696. his.IdCardNo = patient.IdCardNo
  1697. his.PhoneNumber = patient.Phone
  1698. his.UserOrgId = adminInfo.CurrentOrgId
  1699. his.Ctime = time.Now().Unix()
  1700. his.Mtime = time.Now().Unix()
  1701. his.Status = 1
  1702. service.UpdateHisPatientStatus(&his)
  1703. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  1704. c.ServeSuccessJSON(map[string]interface{}{
  1705. "his_info": his,
  1706. })
  1707. } else {
  1708. adminUser := c.GetAdminUserInfo()
  1709. errlog := &models.HisOrderError{
  1710. UserOrgId: adminUser.CurrentOrgId,
  1711. Ctime: time.Now().Unix(),
  1712. Mtime: time.Now().Unix(),
  1713. ErrMsg: res.ErrMsg,
  1714. Status: 1,
  1715. PatientId: id,
  1716. RecordTime: recordDateTime,
  1717. Stage: 1,
  1718. }
  1719. service.CreateErrMsgLog(errlog)
  1720. c.ServeSuccessJSON(map[string]interface{}{
  1721. "failed_code": -10,
  1722. "msg": res.ErrMsg,
  1723. })
  1724. return
  1725. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  1726. }
  1727. }
  1728. }
  1729. //上传明细----预结算----确认订单
  1730. func (c *HisApiController) GetUploadInfo() {
  1731. id, _ := c.GetInt64("id")
  1732. record_time := c.GetString("record_time")
  1733. his_patient_id, _ := c.GetInt64("his_patient_id")
  1734. order_id, _ := c.GetInt64("order_id")
  1735. pay_way, _ := c.GetInt64("pay_way")
  1736. pay_price, _ := c.GetFloat("pay_price")
  1737. pay_card_no := c.GetString("pay_card_no")
  1738. discount_price, _ := c.GetFloat("discount_price")
  1739. preferential_price, _ := c.GetFloat("preferential_price")
  1740. reality_price, _ := c.GetFloat("reality_price")
  1741. found_price, _ := c.GetFloat("found_price")
  1742. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1743. private_price, _ := c.GetFloat("private_price")
  1744. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1745. admin_user_id, _ := c.GetInt64("admin_user_id")
  1746. fapiao_code := c.GetString("fapiao_code")
  1747. fapiao_number := c.GetString("fapiao_number")
  1748. diagnosis_id := c.GetString("diagnosis")
  1749. sick_type, _ := c.GetInt64("sick_type")
  1750. reg_type, _ := c.GetInt64("p_type")
  1751. id_str := c.GetString("ids")
  1752. ids_arr := strings.Split(id_str, ",")
  1753. timeLayout := "2006-01-02"
  1754. loc, _ := time.LoadLocation("Local")
  1755. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1756. if err != nil {
  1757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1758. return
  1759. }
  1760. recordDateTime := theTime.Unix()
  1761. adminUser := c.GetAdminUserInfo()
  1762. var tempOrder models.HisOrder
  1763. tempOrder, _ = service.GetHisOrderByID(order_id)
  1764. var prescriptions []*models.HisPrescription
  1765. var start_time int64
  1766. var end_time int64
  1767. //if adminUser.CurrentOrgId == 10106{
  1768. // if len(fapiao_code) == 0{
  1769. // fapiao_code = "144072080589"
  1770. // }
  1771. // if len(fapiao_number) == 0{
  1772. // order, _ := service.GetLastHisOrder(adminUser.CurrentOrgId)
  1773. // if order.ID == 0{
  1774. // fapiao_number = "00001520"
  1775. // }else{
  1776. // //fapiao_code = "00001520"
  1777. // fpNumber, _ := strconv.Atoi(order.FaPiaoNumber)
  1778. // var zero string
  1779. // if fpNumber >= 1000{
  1780. // zero = "0000" + strconv.Itoa(fpNumber)
  1781. // }else if fpNumber >= 10000{
  1782. // zero = "000" + strconv.Itoa(fpNumber)
  1783. // } else if fpNumber >= 100000{
  1784. // zero = "00" + strconv.Itoa(fpNumber)
  1785. // } else if fpNumber >= 1000000{
  1786. // zero = "0" + strconv.Itoa(fpNumber)
  1787. // }else {
  1788. // zero = strconv.Itoa(fpNumber)
  1789. // }
  1790. // fapiao_number = zero
  1791. // }
  1792. // }
  1793. //}
  1794. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1795. his, _ := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  1796. var patientPrescription models.HisPrescriptionInfo
  1797. patientPrescription, _ = service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  1798. if patientPrescription.ID == 0 {
  1799. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1800. }
  1801. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1802. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1803. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  1804. diagnosis_ids := strings.Split(diagnosis_id, ",")
  1805. var config []*models.HisXtDiagnoseConfig
  1806. for _, item := range diagnosis_ids {
  1807. id, _ := strconv.ParseInt(item, 10, 64)
  1808. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1809. config = append(config, diagnosisConfig)
  1810. }
  1811. sickConfig, _ := service.FindSickById(sick_type)
  1812. if tempOrder.ID == 0 {
  1813. tempOrder, _ = service.GetTodayHisOrder(adminUser.CurrentOrgId, id, recordDateTime, his.Number)
  1814. }
  1815. if tempOrder.ID == 0 {
  1816. var result string
  1817. var requestLog string
  1818. if miConfig.InsuplcAdmdvs == "440781" { //
  1819. 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)
  1820. } else {
  1821. 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)
  1822. }
  1823. saveLog(result, requestLog, "2203")
  1824. var respJSON2 map[string]interface{}
  1825. if err := json.Unmarshal([]byte(string(result)), &respJSON2); err != nil {
  1826. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1828. return
  1829. }
  1830. userJSONBytes2, _ := json.Marshal(respJSON2)
  1831. var res2 ResultSix
  1832. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  1833. utils.ErrorLog("解析失败:%v", err)
  1834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1835. return
  1836. }
  1837. if res2.Infcode != 0 {
  1838. adminUser := c.GetAdminUserInfo()
  1839. errlog := &models.HisOrderError{
  1840. UserOrgId: adminUser.CurrentOrgId,
  1841. Ctime: time.Now().Unix(),
  1842. Mtime: time.Now().Unix(),
  1843. ErrMsg: res2.ErrMsg,
  1844. Status: 1,
  1845. PatientId: id,
  1846. RecordTime: recordDateTime,
  1847. Stage: 3,
  1848. }
  1849. service.CreateErrMsgLog(errlog)
  1850. c.ServeSuccessJSON(map[string]interface{}{
  1851. "failed_code": -10,
  1852. "msg": res2.ErrMsg,
  1853. })
  1854. return
  1855. } else {
  1856. his.Diagnosis = diagnosis_id
  1857. his.SickType = sickConfig.ID
  1858. his.PType = fmt.Sprintf("%d", reg_type)
  1859. service.UpdateHisPatientThree(&his)
  1860. data := make(map[string]interface{})
  1861. if settle_accounts_type == 1 { //日结
  1862. if reg_type == 11 {
  1863. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  1864. } else {
  1865. prescriptions, _ = service.GetNewHisPrescription(adminUser.CurrentOrgId, his_patient_id, recordDateTime, strconv.Itoa(int(reg_type)))
  1866. }
  1867. //prescriptions, _ = service.GetNewHisPrescriptionTwo(adminUser.CurrentOrgId, his_patient_id, recordDateTime, reg_type)
  1868. data["pre"] = prescriptions
  1869. } else { //月结
  1870. start_time_str := c.GetString("start_time")
  1871. end_time_str := c.GetString("end_time")
  1872. timeLayout := "2006-01-02"
  1873. loc, _ := time.LoadLocation("Local")
  1874. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1875. if err != nil {
  1876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1877. return
  1878. }
  1879. recordStartTime := theStartTime.Unix()
  1880. start_time = recordStartTime
  1881. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1882. if err != nil {
  1883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1884. return
  1885. }
  1886. recordEndTime := theEndTime.Unix()
  1887. end_time = recordEndTime
  1888. prescriptions, _ = service.GetMonthHisPrescriptionTwo(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  1889. data["pre"] = prescriptions
  1890. }
  1891. if reg_type == 1111 || reg_type == 1112 {
  1892. reg_type = 11
  1893. }
  1894. timestamp := time.Now().Unix()
  1895. tempTime := time.Unix(timestamp, 0)
  1896. timeFormat := tempTime.Format("20060102150405")
  1897. chrgBchno := rand.Intn(100000) + 10000
  1898. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1899. strconv.FormatInt(his.PatientId, 10)
  1900. client := &http.Client{}
  1901. data["psn_no"] = his.PsnNo
  1902. data["mdtrt_id"] = his.Number
  1903. data["chrg_bchno"] = chrg_bchno
  1904. data["org_name"] = miConfig.OrgName
  1905. data["doctor"] = roles.UserName
  1906. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1907. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  1908. data["fixmedins_code"] = miConfig.Code
  1909. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  1910. data["dept_code"] = "15"
  1911. } else {
  1912. data["dept_code"] = department.Number
  1913. }
  1914. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1915. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1916. data["secret_key"] = miConfig.SecretKey
  1917. data["balance_accounts_type"] = strconv.FormatInt(his.BalanceAccountsType, 10)
  1918. var ids []int64
  1919. for _, item := range prescriptions {
  1920. ids = append(ids, item.ID)
  1921. }
  1922. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1923. if config.IsOpen == 1 { //对接了医保,走医保流程
  1924. bytesData, _ := json.Marshal(data)
  1925. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  1926. resp, _ := client.Do(req)
  1927. defer resp.Body.Close()
  1928. body, ioErr := ioutil.ReadAll(resp.Body)
  1929. if ioErr != nil {
  1930. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1931. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1932. return
  1933. }
  1934. var respJSON map[string]interface{}
  1935. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1936. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1938. return
  1939. }
  1940. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1941. userJSONBytes, _ := json.Marshal(respJSON)
  1942. request_respJSON := respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  1943. requestJSONBytes, _ := json.Marshal(request_respJSON)
  1944. saveLog(string(userJSONBytes), string(requestJSONBytes), "2204")
  1945. var res ResultFour
  1946. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1947. utils.ErrorLog("解析失败:%v", err)
  1948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1949. return
  1950. }
  1951. if res.Infcode == 0 {
  1952. order := &models.HisOrder{
  1953. UserOrgId: adminUser.CurrentOrgId,
  1954. HisPatientId: his.ID,
  1955. PatientId: his.PatientId,
  1956. SettleAccountsDate: recordDateTime,
  1957. Ctime: time.Now().Unix(),
  1958. Mtime: time.Now().Unix(),
  1959. Status: 0,
  1960. Number: chrg_bchno,
  1961. Infcode: res.Infcode,
  1962. WarnMsg: res.WarnMsg,
  1963. Cainfo: res.Cainfo,
  1964. ErrMsg: res.ErrMsg,
  1965. RespondTime: res.RefmsgTime,
  1966. InfRefmsgid: res.InfRefmsgid,
  1967. OrderStatus: 1,
  1968. PayWay: pay_way,
  1969. PayPrice: pay_price,
  1970. PayCardNo: pay_card_no,
  1971. DiscountPrice: discount_price,
  1972. PreferentialPrice: preferential_price,
  1973. RealityPrice: reality_price,
  1974. FoundPrice: found_price,
  1975. MedicalInsurancePrice: medical_insurance_price,
  1976. PrivatePrice: private_price,
  1977. IsMedicineInsurance: 1,
  1978. SettleType: settle_accounts_type,
  1979. SettleStartTime: start_time,
  1980. SettleEndTime: end_time,
  1981. Creator: roles.AdminUserId,
  1982. Modify: roles.AdminUserId,
  1983. FaPiaoNumber: fapiao_number,
  1984. FaPiaoCode: fapiao_code,
  1985. PType: 2,
  1986. Diagnosis: diagnosis_id,
  1987. }
  1988. err = service.CreateOrder(order)
  1989. if err != nil {
  1990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1991. return
  1992. }
  1993. for _, item := range res.Output.Result {
  1994. temp := strings.Split(item.FeedetlSn, "-")
  1995. var advice_id int64 = 0
  1996. var project_id int64 = 0
  1997. var types int64 = 0
  1998. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1999. types, _ = strconv.ParseInt(temp[1], 10, 64)
  2000. if temp[1] == "1" {
  2001. advice_id = id
  2002. project_id = 0
  2003. } else if temp[1] == "2" {
  2004. advice_id = 0
  2005. project_id = id
  2006. }
  2007. info := &models.HisOrderInfo{
  2008. OrderNumber: order.Number,
  2009. FeedetlSn: item.FeedetlSn,
  2010. UploadDate: time.Now().Unix(),
  2011. AdviceId: advice_id,
  2012. DetItemFeeSumamt: item.DetItemFeeSumamt,
  2013. Cnt: item.Cnt,
  2014. Pric: float64(item.Pric),
  2015. PatientId: his.PatientId,
  2016. PricUplmtAmt: item.PricUplmtAmt,
  2017. SelfpayProp: item.SelfpayProp,
  2018. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2019. OverlmtAmt: item.OverlmtAmt,
  2020. PreselfpayAmt: item.PreselfpayAmt,
  2021. BasMednFlag: item.BasMednFlag,
  2022. MedChrgitmType: item.MedChrgitmType,
  2023. HiNegoDrugFlag: item.HiNegoDrugFlag,
  2024. Status: 1,
  2025. Memo: item.Memo,
  2026. Mtime: time.Now().Unix(),
  2027. InscpScpAmt: item.InscpScpAmt,
  2028. DrtReimFlag: item.DrtReimFlag,
  2029. Ctime: time.Now().Unix(),
  2030. ListSpItemFlag: item.ListSpItemFlag,
  2031. ChldMedcFlag: item.ChldMedcFlag,
  2032. LmtUsedFlag: item.LmtUsedFlag,
  2033. ChrgitmLv: item.ChrgitmLv,
  2034. UserOrgId: adminUser.CurrentOrgId,
  2035. HisPatientId: his.ID,
  2036. OrderId: order.ID,
  2037. ProjectId: project_id,
  2038. Type: types,
  2039. }
  2040. service.CreateOrderInfo(info)
  2041. }
  2042. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2043. service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, his_patient_id, chrg_bchno, recordDateTime)
  2044. var total float64
  2045. for _, item := range prescriptions {
  2046. if item.Type == 1 { //药品
  2047. for _, subItem := range item.HisDoctorAdviceInfo {
  2048. total = total + (subItem.Price * subItem.PrescribingNumber)
  2049. }
  2050. }
  2051. if item.Type == 2 { //项目
  2052. for _, subItem := range item.HisPrescriptionProject {
  2053. total = total + (subItem.Price * float64(subItem.Count))
  2054. }
  2055. }
  2056. }
  2057. for _, item := range prescriptions {
  2058. for _, subItem := range item.HisAdditionalCharge {
  2059. total = total + (subItem.Price * float64(subItem.Count))
  2060. }
  2061. }
  2062. allTotal := fmt.Sprintf("%.2f", total)
  2063. if res.Infcode == 0 {
  2064. var rf []*ResultFive
  2065. json.Unmarshal([]byte(his.Iinfo), &rf)
  2066. chrg_bchno := chrg_bchno
  2067. cert_no := his.Certno
  2068. var insutypes []string
  2069. var insutype string
  2070. var is390 int = 0
  2071. var is310 int = 0
  2072. for _, item := range rf {
  2073. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  2074. insutypes = append(insutypes, item.Insutype)
  2075. }
  2076. }
  2077. if len(insutypes) == 1 {
  2078. insutype = insutypes[0]
  2079. } else {
  2080. for _, i := range insutypes {
  2081. if i == "390" {
  2082. is390 = 1
  2083. }
  2084. if i == "310" {
  2085. is310 = 1
  2086. }
  2087. }
  2088. }
  2089. if is390 == 1 {
  2090. insutype = "390"
  2091. }
  2092. if is310 == 1 {
  2093. insutype = "310"
  2094. }
  2095. if len(insutypes) == 0 {
  2096. insutype = "310"
  2097. }
  2098. //insutype = "390"
  2099. if his.IdCardType == 1 {
  2100. // cert_no = his.MedicalInsuranceNumber
  2101. cert_no = his.Certno
  2102. } else {
  2103. cert_no = his.Certno
  2104. }
  2105. 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)
  2106. var dat map[string]interface{}
  2107. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2108. fmt.Println(dat)
  2109. } else {
  2110. fmt.Println(err)
  2111. }
  2112. saveLog(result, src_resquest, "2207")
  2113. userJSONBytes, _ := json.Marshal(dat)
  2114. var res ResultSeven
  2115. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2116. utils.ErrorLog("解析失败:%v", err)
  2117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2118. return
  2119. }
  2120. if res.Infcode != 0 {
  2121. errlog := &models.HisOrderError{
  2122. UserOrgId: adminUser.CurrentOrgId,
  2123. Ctime: time.Now().Unix(),
  2124. Mtime: time.Now().Unix(),
  2125. Number: chrg_bchno,
  2126. ErrMsg: res.ErrMsg,
  2127. Status: 1,
  2128. PatientId: id,
  2129. RecordTime: recordDateTime,
  2130. Stage: 6,
  2131. }
  2132. service.CreateErrMsgLog(errlog)
  2133. c.ServeSuccessJSON(map[string]interface{}{
  2134. "failed_code": -10,
  2135. "msg": res.ErrMsg,
  2136. })
  2137. return
  2138. } else {
  2139. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2140. order.OrderStatus = 2
  2141. order.Status = 1
  2142. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2143. order.SetlId = res.Output.Setlinfo.SetlID
  2144. order.PsnNo = res.Output.Setlinfo.PsnNo
  2145. order.PsnName = res.Output.Setlinfo.PsnName
  2146. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2147. order.Certno = res.Output.Setlinfo.Certno
  2148. order.Gend = res.Output.Setlinfo.Gend
  2149. order.Naty = res.Output.Setlinfo.Naty
  2150. order.Age = res.Output.Setlinfo.Age
  2151. order.Insutype = res.Output.Setlinfo.Insutype
  2152. order.PsnType = res.Output.Setlinfo.PsnType
  2153. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2154. order.SetlTime = res.Output.Setlinfo.SetlTime
  2155. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2156. order.MedType = res.Output.Setlinfo.MedType
  2157. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2158. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2159. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2160. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2161. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2162. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2163. order.HifpPay = res.Output.Setlinfo.HifpPay
  2164. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2165. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2166. order.HifesPay = res.Output.Setlinfo.HifesPay
  2167. order.HifobPay = res.Output.Setlinfo.HifobPay
  2168. order.MafPay = res.Output.Setlinfo.MafPay
  2169. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  2170. order.OthPay = res.Output.Setlinfo.OthPay
  2171. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2172. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2173. order.AcctPay = res.Output.Setlinfo.AcctPay
  2174. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2175. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2176. order.Balc = res.Output.Setlinfo.Balc
  2177. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2178. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2179. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2180. order.ClrWay = res.Output.Setlinfo.ClrWay
  2181. order.Creator = order.Creator
  2182. order.Modify = roles.AdminUserId
  2183. order.RequestLog = src_resquest
  2184. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2185. detailStr := string(setlDetail)
  2186. order.SetlDetail = detailStr
  2187. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2188. err = service.UpDateOrder(order)
  2189. if err == nil {
  2190. c.ServeSuccessJSON(map[string]interface{}{
  2191. "msg": "结算成功",
  2192. })
  2193. } else {
  2194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2195. return
  2196. }
  2197. }
  2198. } else {
  2199. adminUser := c.GetAdminUserInfo()
  2200. errlog := &models.HisOrderError{
  2201. UserOrgId: adminUser.CurrentOrgId,
  2202. Ctime: time.Now().Unix(),
  2203. Mtime: time.Now().Unix(),
  2204. ErrMsg: res.ErrMsg,
  2205. Status: 1,
  2206. PatientId: id,
  2207. RecordTime: recordDateTime,
  2208. Stage: 4,
  2209. }
  2210. service.CreateErrMsgLog(errlog)
  2211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2212. return
  2213. }
  2214. } else {
  2215. adminUser := c.GetAdminUserInfo()
  2216. errlog := &models.HisOrderError{
  2217. UserOrgId: adminUser.CurrentOrgId,
  2218. Ctime: time.Now().Unix(),
  2219. Mtime: time.Now().Unix(),
  2220. ErrMsg: res.ErrMsg,
  2221. Status: 1,
  2222. PatientId: id,
  2223. RecordTime: recordDateTime,
  2224. Stage: 4,
  2225. }
  2226. service.CreateErrMsgLog(errlog)
  2227. c.ServeSuccessJSON(map[string]interface{}{
  2228. "failed_code": -10,
  2229. "msg": res.ErrMsg,
  2230. })
  2231. return
  2232. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  2233. //return
  2234. }
  2235. }
  2236. }
  2237. } else if tempOrder.ID > 0 {
  2238. if tempOrder.IsPre == 1 {
  2239. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  2240. var rf []*ResultFive
  2241. json.Unmarshal([]byte(his.Iinfo), &rf)
  2242. chrg_bchno := tempOrder.Number
  2243. cert_no := his.Certno
  2244. var insutypes []string
  2245. var insutype string
  2246. var is390 int = 0
  2247. var is310 int = 0
  2248. for _, item := range rf {
  2249. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  2250. insutypes = append(insutypes, item.Insutype)
  2251. }
  2252. }
  2253. if len(insutypes) == 1 {
  2254. insutype = insutypes[0]
  2255. } else {
  2256. for _, i := range insutypes {
  2257. if i == "390" {
  2258. is390 = 1
  2259. }
  2260. if i == "310" {
  2261. is310 = 1
  2262. }
  2263. }
  2264. }
  2265. if is390 == 1 {
  2266. insutype = "390"
  2267. }
  2268. if is310 == 1 {
  2269. insutype = "310"
  2270. }
  2271. if len(insutypes) == 0 {
  2272. insutype = "310"
  2273. }
  2274. //insutype = "390"
  2275. if his.IdCardType == 1 {
  2276. // cert_no = his.MedicalInsuranceNumber
  2277. cert_no = his.Certno
  2278. } else {
  2279. cert_no = his.Certno
  2280. }
  2281. 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)
  2282. var dat map[string]interface{}
  2283. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2284. fmt.Println(dat)
  2285. } else {
  2286. fmt.Println(err)
  2287. }
  2288. saveLog(result, src_resquest, "2207")
  2289. userJSONBytes, _ := json.Marshal(dat)
  2290. var res ResultSeven
  2291. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2292. utils.ErrorLog("解析失败:%v", err)
  2293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2294. return
  2295. }
  2296. if res.Infcode != 0 {
  2297. errlog := &models.HisOrderError{
  2298. UserOrgId: adminUser.CurrentOrgId,
  2299. Ctime: time.Now().Unix(),
  2300. Mtime: time.Now().Unix(),
  2301. Number: chrg_bchno,
  2302. ErrMsg: res.ErrMsg,
  2303. Status: 1,
  2304. PatientId: id,
  2305. RecordTime: recordDateTime,
  2306. Stage: 6,
  2307. }
  2308. service.CreateErrMsgLog(errlog)
  2309. c.ServeSuccessJSON(map[string]interface{}{
  2310. "failed_code": -10,
  2311. "msg": res.ErrMsg,
  2312. })
  2313. return
  2314. } else {
  2315. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2316. order.OrderStatus = 2
  2317. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2318. order.SetlId = res.Output.Setlinfo.SetlID
  2319. order.PsnNo = res.Output.Setlinfo.PsnNo
  2320. order.PsnName = res.Output.Setlinfo.PsnName
  2321. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2322. order.Certno = res.Output.Setlinfo.Certno
  2323. order.Gend = res.Output.Setlinfo.Gend
  2324. order.Naty = res.Output.Setlinfo.Naty
  2325. order.Age = res.Output.Setlinfo.Age
  2326. order.Insutype = res.Output.Setlinfo.Insutype
  2327. order.PsnType = res.Output.Setlinfo.PsnType
  2328. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2329. order.SetlTime = res.Output.Setlinfo.SetlTime
  2330. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2331. order.MedType = res.Output.Setlinfo.MedType
  2332. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2333. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2334. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2335. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2336. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2337. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2338. order.HifpPay = res.Output.Setlinfo.HifpPay
  2339. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2340. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2341. order.HifesPay = res.Output.Setlinfo.HifesPay
  2342. order.HifobPay = res.Output.Setlinfo.HifobPay
  2343. order.MafPay = res.Output.Setlinfo.MafPay
  2344. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  2345. order.OthPay = res.Output.Setlinfo.OthPay
  2346. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2347. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2348. order.AcctPay = res.Output.Setlinfo.AcctPay
  2349. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2350. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2351. order.Balc = res.Output.Setlinfo.Balc
  2352. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2353. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2354. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2355. order.ClrWay = res.Output.Setlinfo.ClrWay
  2356. order.Creator = order.Creator
  2357. order.Modify = roles.AdminUserId
  2358. order.RequestLog = src_resquest
  2359. order.Diagnosis = diagnosis_id
  2360. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2361. detailStr := string(setlDetail)
  2362. order.SetlDetail = detailStr
  2363. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2364. err = service.UpDateOrder(order)
  2365. if err == nil {
  2366. c.ServeSuccessJSON(map[string]interface{}{
  2367. "msg": "结算成功",
  2368. })
  2369. } else {
  2370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2371. return
  2372. }
  2373. }
  2374. }
  2375. }
  2376. }
  2377. //func (c *HisApiController) GetPreUploadInfo() {
  2378. // id, _ := c.GetInt64("id")
  2379. // record_time := c.GetString("record_time")
  2380. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2381. // admin_user_id, _ := c.GetInt64("admin_user_id")
  2382. //
  2383. // timeLayout := "2006-01-02"
  2384. // loc, _ := time.LoadLocation("Local")
  2385. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2386. // if err != nil {
  2387. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2388. // return
  2389. // }
  2390. // recordDateTime := theTime.Unix()
  2391. // adminUser := c.GetAdminUserInfo()
  2392. //
  2393. // var prescriptions []*models.HisPrescription
  2394. //
  2395. // var start_time int64
  2396. // var end_time int64
  2397. //
  2398. // data := make(map[string]interface{})
  2399. // if settle_accounts_type == 1 { //日结
  2400. // prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  2401. // data["pre"] = prescriptions
  2402. //
  2403. // } else { //月结
  2404. // start_time_str := c.GetString("start_time")
  2405. // end_time_str := c.GetString("end_time")
  2406. // timeLayout := "2006-01-02"
  2407. // loc, _ := time.LoadLocation("Local")
  2408. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2409. // if err != nil {
  2410. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2411. // return
  2412. // }
  2413. // recordStartTime := theStartTime.Unix()
  2414. // start_time = recordStartTime
  2415. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2416. // if err != nil {
  2417. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2418. // return
  2419. // }
  2420. // recordEndTime := theEndTime.Unix()
  2421. // end_time = recordEndTime
  2422. // prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  2423. // data["pre"] = prescriptions
  2424. //
  2425. // }
  2426. //
  2427. // roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2428. //
  2429. // his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2430. // timestamp := time.Now().Unix()
  2431. // tempTime := time.Unix(timestamp, 0)
  2432. // timeFormat := tempTime.Format("20060102150405")
  2433. // chrgBchno := rand.Intn(100000) + 10000
  2434. // chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  2435. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2436. // patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2437. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  2438. // strconv.FormatInt(his.PatientId, 10)
  2439. // client := &http.Client{}
  2440. // data["psn_no"] = his.PsnNo
  2441. // data["mdtrt_id"] = his.Number
  2442. // data["chrg_bchno"] = chrg_bchno
  2443. // data["org_name"] = miConfig.OrgName
  2444. // data["doctor"] = roles.UserName
  2445. // data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  2446. // data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  2447. // data["fixmedins_code"] = miConfig.Code
  2448. // data["dept_code"] = department.Number
  2449. // data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  2450. // data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  2451. // data["secret_key"] = miConfig.SecretKey
  2452. // var ids []int64
  2453. //
  2454. // for _, item := range prescriptions {
  2455. // ids = append(ids, item.ID)
  2456. // }
  2457. // config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2458. // if config.IsOpen == 1 { //对接了医保,走医保流程
  2459. // bytesData, _ := json.Marshal(data)
  2460. // req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  2461. // resp, _ := client.Do(req)
  2462. // defer resp.Body.Close()
  2463. // body, ioErr := ioutil.ReadAll(resp.Body)
  2464. // if ioErr != nil {
  2465. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2466. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2467. // return
  2468. // }
  2469. // var respJSON map[string]interface{}
  2470. // if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  2471. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2472. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2473. // return
  2474. // }
  2475. //
  2476. // respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2477. // userJSONBytes, _ := json.Marshal(respJSON)
  2478. // var res ResultFour
  2479. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2480. // utils.ErrorLog("解析失败:%v", err)
  2481. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2482. // return
  2483. // }
  2484. //
  2485. // if res.Infcode == 0 {
  2486. // order := &models.HisOrder{
  2487. // UserOrgId: adminUser.CurrentOrgId,
  2488. // HisPatientId: his.ID,
  2489. // PatientId: his.PatientId,
  2490. // SettleAccountsDate: recordDateTime,
  2491. // Ctime: time.Now().Unix(),
  2492. // Mtime: time.Now().Unix(),
  2493. // Status: 1,
  2494. // Number: chrg_bchno,
  2495. // Infcode: res.Infcode,
  2496. // WarnMsg: res.WarnMsg,
  2497. // Cainfo: res.Cainfo,
  2498. // ErrMsg: res.ErrMsg,
  2499. // RespondTime: res.RefmsgTime,
  2500. // InfRefmsgid: res.InfRefmsgid,
  2501. // OrderStatus: 1,
  2502. // IsMedicineInsurance: 1,
  2503. // SettleType: settle_accounts_type,
  2504. // SettleStartTime: start_time,
  2505. // SettleEndTime: end_time,
  2506. // Creator: roles.ID,
  2507. // Modify: roles.ID,
  2508. // PType: 2,
  2509. // }
  2510. // err = service.CreateOrder(order)
  2511. // if err != nil {
  2512. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2513. // return
  2514. // }
  2515. //
  2516. // for _, item := range res.Output.Result {
  2517. // temp := strings.Split(item.FeedetlSn, "-")
  2518. // var advice_id int64 = 0
  2519. // var project_id int64 = 0
  2520. // var types int64 = 0
  2521. //
  2522. // id, _ := strconv.ParseInt(temp[2], 10, 64)
  2523. // types, _ = strconv.ParseInt(temp[1], 10, 64)
  2524. //
  2525. // if temp[1] == "1" {
  2526. // advice_id = id
  2527. // project_id = 0
  2528. // } else if temp[1] == "2" {
  2529. // advice_id = 0
  2530. // project_id = id
  2531. // }
  2532. //
  2533. // info := &models.HisOrderInfo{
  2534. // OrderNumber: order.Number,
  2535. // FeedetlSn: item.FeedetlSn,
  2536. // UploadDate: time.Now().Unix(),
  2537. // AdviceId: advice_id,
  2538. // DetItemFeeSumamt: item.DetItemFeeSumamt,
  2539. // Cnt: item.Cnt,
  2540. // Pric: float64(item.Pric),
  2541. // PatientId: his.PatientId,
  2542. // PricUplmtAmt: item.PricUplmtAmt,
  2543. // SelfpayProp: item.SelfpayProp,
  2544. // FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2545. // OverlmtAmt: item.OverlmtAmt,
  2546. // PreselfpayAmt: item.PreselfpayAmt,
  2547. // BasMednFlag: item.BasMednFlag,
  2548. // MedChrgitmType: item.MedChrgitmType,
  2549. // HiNegoDrugFlag: item.HiNegoDrugFlag,
  2550. // Status: 1,
  2551. // Memo: item.Memo,
  2552. // Mtime: time.Now().Unix(),
  2553. // InscpScpAmt: item.InscpScpAmt,
  2554. // DrtReimFlag: item.DrtReimFlag,
  2555. // Ctime: time.Now().Unix(),
  2556. // ListSpItemFlag: item.ListSpItemFlag,
  2557. // ChldMedcFlag: item.ChldMedcFlag,
  2558. // LmtUsedFlag: item.LmtUsedFlag,
  2559. // ChrgitmLv: item.ChrgitmLv,
  2560. // UserOrgId: adminUser.CurrentOrgId,
  2561. // HisPatientId: his.ID,
  2562. // OrderId: order.ID,
  2563. // ProjectId: project_id,
  2564. // Type: types,
  2565. // }
  2566. // service.CreateOrderInfo(info)
  2567. //
  2568. // }
  2569. // service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2570. // service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  2571. //
  2572. // var total float64
  2573. // for _, item := range prescriptions {
  2574. // if item.Type == 1 { //药品
  2575. // for _, subItem := range item.HisDoctorAdviceInfo {
  2576. // total = total + (subItem.Price * subItem.PrescribingNumber)
  2577. // }
  2578. // }
  2579. // if item.Type == 2 { //项目
  2580. // for _, subItem := range item.HisPrescriptionProject {
  2581. // total = total + (subItem.Price * float64(subItem.Count))
  2582. // }
  2583. // }
  2584. // }
  2585. //
  2586. // for _, item := range prescriptions {
  2587. // for _, subItem := range item.HisAdditionalCharge {
  2588. // total = total + (subItem.Price * float64(subItem.Count))
  2589. // }
  2590. // }
  2591. //
  2592. // allTotal := fmt.Sprintf("%.2f", total)
  2593. // if res.Infcode == 0 {
  2594. // var rf []*ResultFive
  2595. // json.Unmarshal([]byte(his.Iinfo), &rf)
  2596. // psn_no := his.PsnNo
  2597. // mdtrt_id := his.Number
  2598. // chrg_bchno := chrg_bchno
  2599. // cert_no := his.Certno
  2600. // insutype := rf[0].Insutype
  2601. //
  2602. // if his.IdCardType == 1 {
  2603. // cert_no = his.MedicalInsuranceNumber
  2604. //
  2605. // } else {
  2606. //
  2607. // cert_no = his.Certno
  2608. //
  2609. // }
  2610. //
  2611. // api := "http://127.0.0.1:9532/" + "gdyb/seven?cert_no=" + cert_no + "&insutype=" +
  2612. // insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  2613. // "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  2614. // miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10)
  2615. // resp, requestErr := http.Get(api)
  2616. // if requestErr != nil {
  2617. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2618. // return
  2619. // }
  2620. // defer resp.Body.Close()
  2621. // body, ioErr := ioutil.ReadAll(resp.Body)
  2622. // if ioErr != nil {
  2623. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2624. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2625. // return
  2626. // }
  2627. // var respJSON map[string]interface{}
  2628. // if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2629. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2630. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2631. // return
  2632. // }
  2633. // fmt.Println(respJSON)
  2634. // respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2635. // userJSONBytes, _ := json.Marshal(respJSON)
  2636. // var res ResultSeven
  2637. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2638. // utils.ErrorLog("解析失败:%v", err)
  2639. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2640. // return
  2641. // }
  2642. // if res.Infcode != 0 {
  2643. // errlog := &models.HisOrderError{
  2644. // UserOrgId: adminUser.CurrentOrgId,
  2645. // Ctime: time.Now().Unix(),
  2646. // Mtime: time.Now().Unix(),
  2647. // Number: chrg_bchno,
  2648. // ErrMsg: res.ErrMsg,
  2649. // Status: 1,
  2650. // PatientId: id,
  2651. // RecordTime: recordDateTime,
  2652. // Stage: 7,
  2653. // }
  2654. // service.CreateErrMsgLog(errlog)
  2655. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2656. // return
  2657. // } else {
  2658. // order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2659. // order.OrderStatus = 1
  2660. // order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2661. // order.SetlId = res.Output.Setlinfo.SetlID
  2662. // order.PsnNo = res.Output.Setlinfo.PsnNo
  2663. // order.PsnName = res.Output.Setlinfo.PsnName
  2664. // order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2665. // order.Certno = res.Output.Setlinfo.Certno
  2666. // order.Gend = res.Output.Setlinfo.Gend
  2667. // order.Naty = res.Output.Setlinfo.Naty
  2668. // order.Age = res.Output.Setlinfo.Age
  2669. // order.Insutype = res.Output.Setlinfo.Insutype
  2670. // order.PsnType = res.Output.Setlinfo.PsnType
  2671. // order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2672. // order.SetlTime = res.Output.Setlinfo.SetlTime
  2673. // order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2674. // order.MedType = res.Output.Setlinfo.MedType
  2675. // order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2676. // order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2677. // order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2678. // order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2679. // order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2680. // order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2681. // order.HifpPay = res.Output.Setlinfo.HifpPay
  2682. // order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2683. // order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2684. // order.HifesPay = res.Output.Setlinfo.HifesPay
  2685. // order.HifobPay = res.Output.Setlinfo.HifobPay
  2686. // order.MafPay = res.Output.Setlinfo.MafPay
  2687. // order.OthPay = res.Output.Setlinfo.OthPay
  2688. // order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2689. // order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2690. // order.AcctPay = res.Output.Setlinfo.AcctPay
  2691. // order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2692. // order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2693. // order.Balc = res.Output.Setlinfo.Balc
  2694. // order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2695. // order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2696. // order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2697. // order.ClrWay = res.Output.Setlinfo.ClrWay
  2698. // order.Creator = order.Creator
  2699. // order.Modify = roles.ID
  2700. // setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2701. // detailStr := string(setlDetail)
  2702. // order.SetlDetail = detailStr
  2703. // //err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2704. // err = service.UpDateOrder(order)
  2705. // if err == nil {
  2706. // c.ServeSuccessJSON(map[string]interface{}{
  2707. // "msg": "预结算成功",
  2708. // })
  2709. // } else {
  2710. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2711. // return
  2712. // }
  2713. // }
  2714. // } else {
  2715. // adminUser := c.GetAdminUserInfo()
  2716. // errlog := &models.HisOrderError{
  2717. // UserOrgId: adminUser.CurrentOrgId,
  2718. // Ctime: time.Now().Unix(),
  2719. // Mtime: time.Now().Unix(),
  2720. // ErrMsg: res.ErrMsg,
  2721. // Status: 1,
  2722. // PatientId: id,
  2723. // RecordTime: recordDateTime,
  2724. // Stage: 4,
  2725. // }
  2726. // service.CreateErrMsgLog(errlog)
  2727. //
  2728. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2729. // return
  2730. // }
  2731. // } else {
  2732. // adminUser := c.GetAdminUserInfo()
  2733. // errlog := &models.HisOrderError{
  2734. // UserOrgId: adminUser.CurrentOrgId,
  2735. // Ctime: time.Now().Unix(),
  2736. // Mtime: time.Now().Unix(),
  2737. // ErrMsg: res.ErrMsg,
  2738. // Status: 1,
  2739. // PatientId: id,
  2740. // RecordTime: recordDateTime,
  2741. // Stage: 4,
  2742. // }
  2743. // service.CreateErrMsgLog(errlog)
  2744. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  2745. // return
  2746. // }
  2747. //
  2748. // } else {
  2749. // var total float64
  2750. // for _, item := range prescriptions {
  2751. // if item.Type == 1 { //药品
  2752. // for _, subItem := range item.HisDoctorAdviceInfo {
  2753. // total = total + (subItem.Price * subItem.PrescribingNumber)
  2754. // }
  2755. // }
  2756. // if item.Type == 2 { //项目
  2757. // for _, subItem := range item.HisPrescriptionProject {
  2758. // total = total + (subItem.Price * float64(subItem.Count))
  2759. // }
  2760. // }
  2761. //
  2762. // for _, subItem := range item.HisAdditionalCharge {
  2763. // total = total + (subItem.Price * float64(subItem.Count))
  2764. // }
  2765. // }
  2766. //
  2767. // allTotal := fmt.Sprintf("%.2f", total)
  2768. // totals, _ := strconv.ParseFloat(allTotal, 64)
  2769. // order := &models.HisOrder{
  2770. // UserOrgId: adminUser.CurrentOrgId,
  2771. // HisPatientId: his.ID,
  2772. // PatientId: id,
  2773. // SettleAccountsDate: recordDateTime,
  2774. // Ctime: time.Now().Unix(),
  2775. // Mtime: time.Now().Unix(),
  2776. // Status: 1,
  2777. // OrderStatus: 2,
  2778. // Number: chrg_bchno,
  2779. // MedfeeSumamt: totals,
  2780. // }
  2781. // err = service.CreateOrder(order)
  2782. // if err != nil {
  2783. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2784. // return
  2785. // }
  2786. //
  2787. // var customs []*Custom
  2788. // for _, item := range prescriptions {
  2789. //
  2790. // if item.Type == 1 { //药品
  2791. // for _, subItem := range item.HisDoctorAdviceInfo {
  2792. // cus := &Custom{
  2793. // AdviceId: subItem.ID,
  2794. // ProjectId: 0,
  2795. // DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  2796. // Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  2797. // FeedetlSn: subItem.FeedetlSn,
  2798. // Price: fmt.Sprintf("%.2f", subItem.Price),
  2799. // MedListCodg: subItem.MedListCodg,
  2800. // Type: 1,
  2801. // }
  2802. // customs = append(customs, cus)
  2803. // }
  2804. // }
  2805. //
  2806. // if item.Type == 2 { //项目
  2807. // for _, subItem := range item.HisPrescriptionProject {
  2808. //
  2809. // cus := &Custom{
  2810. // AdviceId: 0,
  2811. // ProjectId: subItem.ID,
  2812. // DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  2813. // Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  2814. // FeedetlSn: subItem.FeedetlSn,
  2815. // Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  2816. // MedListCodg: subItem.MedListCodg,
  2817. // Type: 2,
  2818. // }
  2819. //
  2820. // customs = append(customs, cus)
  2821. // }
  2822. // }
  2823. //
  2824. // for _, item := range item.HisAdditionalCharge {
  2825. // cus := &Custom{
  2826. // ItemId: item.ID,
  2827. // AdviceId: 0,
  2828. // ProjectId: 0,
  2829. // DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  2830. // Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  2831. // FeedetlSn: item.FeedetlSn,
  2832. // Price: fmt.Sprintf("%.2f", float64(item.Price)),
  2833. // MedListCodg: item.XtHisAddtionConfig.Code,
  2834. // Type: 3,
  2835. // }
  2836. //
  2837. // customs = append(customs, cus)
  2838. // }
  2839. //
  2840. // }
  2841. //
  2842. // for _, item := range customs {
  2843. // var advice_id int64 = 0
  2844. // var project_id int64 = 0
  2845. // var item_id int64 = 0
  2846. //
  2847. // var types int64 = 0
  2848. //
  2849. // if item.Type == 1 {
  2850. // advice_id = item.AdviceId
  2851. // project_id = 0
  2852. // item_id = 0
  2853. // } else if item.Type == 2 {
  2854. // advice_id = 0
  2855. // item_id = 0
  2856. //
  2857. // project_id = item.ProjectId
  2858. // } else if item.Type == 3 {
  2859. // advice_id = 0
  2860. // item_id = item.ItemId
  2861. // project_id = 0
  2862. // }
  2863. //
  2864. // detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  2865. // cut, _ := strconv.ParseFloat(item.Cut, 32)
  2866. // pric, _ := strconv.ParseFloat(item.Price, 32)
  2867. //
  2868. // info := &models.HisOrderInfo{
  2869. // OrderNumber: order.Number,
  2870. // UploadDate: time.Now().Unix(),
  2871. // AdviceId: advice_id,
  2872. // DetItemFeeSumamt: detItemFeeSumamt,
  2873. // Cnt: cut,
  2874. // Pric: pric,
  2875. // PatientId: id,
  2876. // Status: 1,
  2877. // Mtime: time.Now().Unix(),
  2878. // Ctime: time.Now().Unix(),
  2879. // UserOrgId: adminUser.CurrentOrgId,
  2880. // HisPatientId: his.ID,
  2881. // OrderId: order.ID,
  2882. // ProjectId: project_id,
  2883. // Type: types,
  2884. // ItemId: item_id,
  2885. // }
  2886. // service.CreateOrderInfo(info)
  2887. // }
  2888. // //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2889. // err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2890. // err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  2891. // err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2892. // if err == nil {
  2893. // c.ServeSuccessJSON(map[string]interface{}{
  2894. // "msg": "结算成功",
  2895. // })
  2896. // } else {
  2897. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2898. // return
  2899. // }
  2900. // }
  2901. //}
  2902. //上传明细-预结算-
  2903. func (c *HisApiController) GetPreUploadInfo() {
  2904. id, _ := c.GetInt64("id")
  2905. record_time := c.GetString("record_time")
  2906. his_patient_id, _ := c.GetInt64("his_patient_id")
  2907. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2908. admin_user_id, _ := c.GetInt64("admin_user_id")
  2909. diagnosis_id := c.GetString("diagnosis")
  2910. sick_type, _ := c.GetInt64("sick_type")
  2911. reg_type, _ := c.GetInt64("p_type")
  2912. id_str := c.GetString("ids")
  2913. ids_arr := strings.Split(id_str, ",")
  2914. timeLayout := "2006-01-02"
  2915. loc, _ := time.LoadLocation("Local")
  2916. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2917. if err != nil {
  2918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2919. return
  2920. }
  2921. recordDateTime := theTime.Unix()
  2922. adminUser := c.GetAdminUserInfo()
  2923. diagnosis_ids := strings.Split(diagnosis_id, ",")
  2924. var config []*models.HisXtDiagnoseConfig
  2925. for _, item := range diagnosis_ids {
  2926. id, _ := strconv.ParseInt(item, 10, 64)
  2927. diagnosisConfig, _ := service.FindDiagnoseById(id)
  2928. config = append(config, diagnosisConfig)
  2929. }
  2930. //diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  2931. sickConfig, _ := service.FindSickById(sick_type)
  2932. var prescriptions []*models.HisPrescription
  2933. var start_time int64
  2934. var end_time int64
  2935. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2936. fmt.Println(his_patient_id)
  2937. his, _ := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2938. timestamp := time.Now().Unix()
  2939. tempTime := time.Unix(timestamp, 0)
  2940. timeFormat := tempTime.Format("20060102150405")
  2941. chrgBchno := rand.Intn(100000) + 10000
  2942. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  2943. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2944. var patientPrescription models.HisPrescriptionInfo
  2945. patientPrescription, _ = service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2946. if patientPrescription.ID == 0 {
  2947. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2948. }
  2949. //miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2950. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  2951. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  2952. strconv.FormatInt(his.PatientId, 10)
  2953. var result string
  2954. var requestLog string
  2955. if miConfig.InsuplcAdmdvs == "440781" { //
  2956. 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)
  2957. } else {
  2958. 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)
  2959. }
  2960. saveLog(result, requestLog, "2203")
  2961. var respJSON2 map[string]interface{}
  2962. if err := json.Unmarshal([]byte(string(result)), &respJSON2); err != nil {
  2963. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2965. return
  2966. }
  2967. userJSONBytes2, _ := json.Marshal(respJSON2)
  2968. var res2 ResultSix
  2969. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  2970. utils.ErrorLog("解析失败:%v", err)
  2971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2972. return
  2973. }
  2974. if res2.Infcode != 0 {
  2975. adminUser := c.GetAdminUserInfo()
  2976. errlog := &models.HisOrderError{
  2977. UserOrgId: adminUser.CurrentOrgId,
  2978. Ctime: time.Now().Unix(),
  2979. Mtime: time.Now().Unix(),
  2980. ErrMsg: res2.ErrMsg,
  2981. Status: 1,
  2982. PatientId: id,
  2983. RecordTime: recordDateTime,
  2984. Stage: 3,
  2985. }
  2986. service.CreateErrMsgLog(errlog)
  2987. c.ServeSuccessJSON(map[string]interface{}{
  2988. "failed_code": -10,
  2989. "msg": res2.ErrMsg,
  2990. })
  2991. return
  2992. } else {
  2993. his.Diagnosis = diagnosis_id
  2994. his.SickType = sickConfig.ID
  2995. his.PType = fmt.Sprintf("%d", reg_type)
  2996. service.UpdateHisPatientThree(&his)
  2997. data := make(map[string]interface{})
  2998. if settle_accounts_type == 1 { //日结
  2999. if reg_type == 11 {
  3000. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  3001. } else {
  3002. prescriptions, _ = service.GetNewHisPrescription(adminUser.CurrentOrgId, his_patient_id, recordDateTime, strconv.Itoa(int(reg_type)))
  3003. }
  3004. data["pre"] = prescriptions
  3005. } else { //月结
  3006. start_time_str := c.GetString("start_time")
  3007. end_time_str := c.GetString("end_time")
  3008. timeLayout := "2006-01-02"
  3009. loc, _ := time.LoadLocation("Local")
  3010. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  3011. if err != nil {
  3012. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3013. return
  3014. }
  3015. recordStartTime := theStartTime.Unix()
  3016. start_time = recordStartTime
  3017. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3018. if err != nil {
  3019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3020. return
  3021. }
  3022. recordEndTime := theEndTime.Unix()
  3023. end_time = recordEndTime
  3024. prescriptions, _ = service.GetMonthHisPrescriptionTwo(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  3025. data["pre"] = prescriptions
  3026. }
  3027. if reg_type == 1111 || reg_type == 1112 {
  3028. reg_type = 11
  3029. }
  3030. client := &http.Client{}
  3031. data["psn_no"] = his.PsnNo
  3032. data["mdtrt_id"] = his.Number
  3033. data["chrg_bchno"] = chrg_bchno
  3034. data["org_name"] = miConfig.OrgName
  3035. data["doctor"] = roles.UserName
  3036. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  3037. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  3038. data["fixmedins_code"] = miConfig.Code
  3039. data["balance_accounts_type"] = strconv.FormatInt(his.BalanceAccountsType, 10)
  3040. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  3041. data["dept_code"] = "15"
  3042. } else {
  3043. data["dept_code"] = department.Number
  3044. }
  3045. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  3046. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  3047. data["secret_key"] = miConfig.SecretKey
  3048. var ids []int64
  3049. for _, item := range prescriptions {
  3050. ids = append(ids, item.ID)
  3051. }
  3052. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3053. if config.IsOpen == 1 { //对接了医保,走医保流程
  3054. bytesData, _ := json.Marshal(data)
  3055. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  3056. resp, _ := client.Do(req)
  3057. defer resp.Body.Close()
  3058. body, ioErr := ioutil.ReadAll(resp.Body)
  3059. if ioErr != nil {
  3060. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3062. return
  3063. }
  3064. var respJSON map[string]interface{}
  3065. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  3066. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3068. return
  3069. }
  3070. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3071. userJSONBytes, _ := json.Marshal(respJSON)
  3072. //request_respJSON := respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  3073. //requestJSONBytes, _ := json.Marshal(request_respJSON)
  3074. //saveLog(string(userJSONBytes), string(requestJSONBytes), "2204")
  3075. var res ResultFour
  3076. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3077. utils.ErrorLog("解析失败:%v", err)
  3078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3079. return
  3080. }
  3081. if res.Infcode == 0 {
  3082. order := &models.HisOrder{
  3083. UserOrgId: adminUser.CurrentOrgId,
  3084. HisPatientId: his.ID,
  3085. PatientId: his.PatientId,
  3086. SettleAccountsDate: recordDateTime,
  3087. Ctime: time.Now().Unix(),
  3088. Mtime: time.Now().Unix(),
  3089. Status: 0,
  3090. Number: chrg_bchno,
  3091. Infcode: res.Infcode,
  3092. WarnMsg: res.WarnMsg,
  3093. Cainfo: res.Cainfo,
  3094. ErrMsg: res.ErrMsg,
  3095. RespondTime: res.RefmsgTime,
  3096. InfRefmsgid: res.InfRefmsgid,
  3097. OrderStatus: 1,
  3098. IsMedicineInsurance: 1,
  3099. SettleType: settle_accounts_type,
  3100. SettleStartTime: start_time,
  3101. SettleEndTime: end_time,
  3102. Creator: roles.AdminUserId,
  3103. Modify: roles.AdminUserId,
  3104. PType: 2,
  3105. Diagnosis: diagnosis_id,
  3106. }
  3107. err = service.CreateOrder(order)
  3108. if err != nil {
  3109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  3110. return
  3111. }
  3112. for _, item := range res.Output.Result {
  3113. temp := strings.Split(item.FeedetlSn, "-")
  3114. var advice_id int64 = 0
  3115. var project_id int64 = 0
  3116. var types int64 = 0
  3117. id, _ := strconv.ParseInt(temp[2], 10, 64)
  3118. types, _ = strconv.ParseInt(temp[1], 10, 64)
  3119. if temp[1] == "1" {
  3120. advice_id = id
  3121. project_id = 0
  3122. } else if temp[1] == "2" {
  3123. advice_id = 0
  3124. project_id = id
  3125. }
  3126. info := &models.HisOrderInfo{
  3127. OrderNumber: order.Number,
  3128. FeedetlSn: item.FeedetlSn,
  3129. UploadDate: time.Now().Unix(),
  3130. AdviceId: advice_id,
  3131. DetItemFeeSumamt: item.DetItemFeeSumamt,
  3132. Cnt: item.Cnt,
  3133. Pric: float64(item.Pric),
  3134. PatientId: his.PatientId,
  3135. PricUplmtAmt: item.PricUplmtAmt,
  3136. SelfpayProp: item.SelfpayProp,
  3137. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  3138. OverlmtAmt: item.OverlmtAmt,
  3139. PreselfpayAmt: item.PreselfpayAmt,
  3140. BasMednFlag: item.BasMednFlag,
  3141. MedChrgitmType: item.MedChrgitmType,
  3142. HiNegoDrugFlag: item.HiNegoDrugFlag,
  3143. Status: 1,
  3144. Memo: item.Memo,
  3145. Mtime: time.Now().Unix(),
  3146. InscpScpAmt: item.InscpScpAmt,
  3147. DrtReimFlag: item.DrtReimFlag,
  3148. Ctime: time.Now().Unix(),
  3149. ListSpItemFlag: item.ListSpItemFlag,
  3150. ChldMedcFlag: item.ChldMedcFlag,
  3151. LmtUsedFlag: item.LmtUsedFlag,
  3152. ChrgitmLv: item.ChrgitmLv,
  3153. UserOrgId: adminUser.CurrentOrgId,
  3154. HisPatientId: his.ID,
  3155. OrderId: order.ID,
  3156. ProjectId: project_id,
  3157. Type: types,
  3158. }
  3159. service.CreateOrderInfo(info)
  3160. }
  3161. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  3162. service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, his_patient_id, chrg_bchno, recordDateTime)
  3163. var total float64
  3164. for _, item := range prescriptions {
  3165. if item.Type == 1 { //药品
  3166. for _, subItem := range item.HisDoctorAdviceInfo {
  3167. total = total + (subItem.Price * subItem.PrescribingNumber)
  3168. }
  3169. }
  3170. if item.Type == 2 { //项目
  3171. for _, subItem := range item.HisPrescriptionProject {
  3172. total = total + (subItem.Price * float64(subItem.Count))
  3173. }
  3174. }
  3175. }
  3176. for _, item := range prescriptions {
  3177. for _, subItem := range item.HisAdditionalCharge {
  3178. total = total + (subItem.Price * float64(subItem.Count))
  3179. }
  3180. }
  3181. allTotal := fmt.Sprintf("%.2f", total)
  3182. if res.Infcode == 0 {
  3183. var rf []*ResultFive
  3184. json.Unmarshal([]byte(his.Iinfo), &rf)
  3185. chrg_bchno := chrg_bchno
  3186. cert_no := his.Certno
  3187. var insutypes []string
  3188. var insutype string
  3189. var is390 int = 0
  3190. var is310 int = 0
  3191. for _, item := range rf {
  3192. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  3193. insutypes = append(insutypes, item.Insutype)
  3194. }
  3195. }
  3196. if len(insutypes) == 1 {
  3197. insutype = insutypes[0]
  3198. } else {
  3199. for _, i := range insutypes {
  3200. if i == "390" {
  3201. is390 = 1
  3202. }
  3203. if i == "310" {
  3204. is310 = 1
  3205. }
  3206. }
  3207. }
  3208. if is390 == 1 {
  3209. insutype = "390"
  3210. }
  3211. if is310 == 1 {
  3212. insutype = "310"
  3213. }
  3214. if len(insutypes) == 0 {
  3215. insutype = "310"
  3216. }
  3217. //insutype = "390"
  3218. if his.IdCardType == 1 {
  3219. cert_no = his.MedicalInsuranceNumber
  3220. } else {
  3221. cert_no = his.Certno
  3222. }
  3223. 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)
  3224. var dat map[string]interface{}
  3225. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3226. fmt.Println(dat)
  3227. } else {
  3228. fmt.Println(err)
  3229. }
  3230. saveLog(result, request_log, "2206")
  3231. userJSONBytes, _ := json.Marshal(dat)
  3232. var res ResultSeven
  3233. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3234. utils.ErrorLog("解析失败:%v", err)
  3235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3236. return
  3237. }
  3238. if res.Infcode != 0 {
  3239. errlog := &models.HisOrderError{
  3240. UserOrgId: adminUser.CurrentOrgId,
  3241. Ctime: time.Now().Unix(),
  3242. Mtime: time.Now().Unix(),
  3243. Number: chrg_bchno,
  3244. ErrMsg: res.ErrMsg,
  3245. Status: 1,
  3246. PatientId: id,
  3247. RecordTime: recordDateTime,
  3248. Stage: 20,
  3249. }
  3250. service.CreateErrMsgLog(errlog)
  3251. c.ServeSuccessJSON(map[string]interface{}{
  3252. "failed_code": -10,
  3253. "msg": res.ErrMsg,
  3254. })
  3255. return
  3256. } else {
  3257. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  3258. order.OrderStatus = 1
  3259. order.IsPre = 1
  3260. order.Status = 1
  3261. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  3262. order.SetlId = res.Output.Setlinfo.SetlID
  3263. order.PsnNo = res.Output.Setlinfo.PsnNo
  3264. order.PsnName = res.Output.Setlinfo.PsnName
  3265. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  3266. order.Certno = res.Output.Setlinfo.Certno
  3267. order.Gend = res.Output.Setlinfo.Gend
  3268. order.Naty = res.Output.Setlinfo.Naty
  3269. order.Age = res.Output.Setlinfo.Age
  3270. order.Insutype = res.Output.Setlinfo.Insutype
  3271. order.PsnType = res.Output.Setlinfo.PsnType
  3272. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  3273. order.SetlTime = res.Output.Setlinfo.SetlTime
  3274. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  3275. order.MedType = res.Output.Setlinfo.MedType
  3276. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  3277. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  3278. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  3279. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  3280. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  3281. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  3282. order.HifpPay = res.Output.Setlinfo.HifpPay
  3283. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  3284. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  3285. order.HifesPay = res.Output.Setlinfo.HifesPay
  3286. order.HifobPay = res.Output.Setlinfo.HifobPay
  3287. order.MafPay = res.Output.Setlinfo.MafPay
  3288. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  3289. order.OthPay = res.Output.Setlinfo.OthPay
  3290. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  3291. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  3292. order.AcctPay = res.Output.Setlinfo.AcctPay
  3293. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  3294. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  3295. order.Balc = res.Output.Setlinfo.Balc
  3296. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  3297. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  3298. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  3299. order.ClrWay = res.Output.Setlinfo.ClrWay
  3300. order.Creator = order.Creator
  3301. order.Modify = roles.AdminUserId
  3302. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  3303. detailStr := string(setlDetail)
  3304. order.SetlDetail = detailStr
  3305. //err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  3306. err = service.UpDateOrder(order)
  3307. if err == nil {
  3308. c.ServeSuccessJSON(map[string]interface{}{
  3309. "msg": "预结算成功",
  3310. })
  3311. } else {
  3312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  3313. return
  3314. }
  3315. }
  3316. } else {
  3317. adminUser := c.GetAdminUserInfo()
  3318. errlog := &models.HisOrderError{
  3319. UserOrgId: adminUser.CurrentOrgId,
  3320. Ctime: time.Now().Unix(),
  3321. Mtime: time.Now().Unix(),
  3322. ErrMsg: res.ErrMsg,
  3323. Status: 1,
  3324. PatientId: id,
  3325. RecordTime: recordDateTime,
  3326. Stage: 4,
  3327. }
  3328. service.CreateErrMsgLog(errlog)
  3329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  3330. return
  3331. }
  3332. } else {
  3333. adminUser := c.GetAdminUserInfo()
  3334. errlog := &models.HisOrderError{
  3335. UserOrgId: adminUser.CurrentOrgId,
  3336. Ctime: time.Now().Unix(),
  3337. Mtime: time.Now().Unix(),
  3338. ErrMsg: res.ErrMsg,
  3339. Status: 1,
  3340. PatientId: id,
  3341. RecordTime: recordDateTime,
  3342. Stage: 4,
  3343. }
  3344. service.CreateErrMsgLog(errlog)
  3345. c.ServeSuccessJSON(map[string]interface{}{
  3346. "failed_code": -10,
  3347. "msg": res.ErrMsg,
  3348. })
  3349. return
  3350. }
  3351. }
  3352. }
  3353. }
  3354. //func (c *HisApiController) GetSettleInfo() {
  3355. // id, _ := c.GetInt64("id")
  3356. // order_id, _ := c.GetInt64("order_id")
  3357. //
  3358. // record_time := c.GetString("record_time")
  3359. // pay_way, _ := c.GetInt64("pay_way")
  3360. // pay_price, _ := c.GetFloat("pay_price")
  3361. // pay_card_no := c.GetString("pay_card_no")
  3362. // discount_price, _ := c.GetFloat("discount_price")
  3363. // preferential_price, _ := c.GetFloat("preferential_price")
  3364. // reality_price, _ := c.GetFloat("reality_price")
  3365. // found_price, _ := c.GetFloat("found_price")
  3366. // medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  3367. // private_price, _ := c.GetFloat("private_price")
  3368. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  3369. // admin_user_id, _ := c.GetInt64("admin_user_id")
  3370. //
  3371. // timeLayout := "2006-01-02"
  3372. // loc, _ := time.LoadLocation("Local")
  3373. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3374. // if err != nil {
  3375. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3376. // return
  3377. // }
  3378. // recordDateTime := theTime.Unix()
  3379. // adminUser := c.GetAdminUserInfo()
  3380. //
  3381. // var prescriptions []*models.HisPrescription
  3382. //
  3383. // data := make(map[string]interface{})
  3384. // if settle_accounts_type == 1 { //日结
  3385. // prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  3386. // data["pre"] = prescriptions
  3387. //
  3388. // } else { //月结
  3389. // start_time_str := c.GetString("start_time")
  3390. // end_time_str := c.GetString("end_time")
  3391. // timeLayout := "2006-01-02"
  3392. // loc, _ := time.LoadLocation("Local")
  3393. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  3394. // if err != nil {
  3395. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3396. // return
  3397. // }
  3398. // recordStartTime := theStartTime.Unix()
  3399. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3400. // if err != nil {
  3401. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3402. // return
  3403. // }
  3404. // recordEndTime := theEndTime.Unix()
  3405. // prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  3406. // data["pre"] = prescriptions
  3407. //
  3408. // }
  3409. //
  3410. // roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3411. //
  3412. // his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  3413. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3414. // patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  3415. // strconv.FormatInt(his.PatientId, 10)
  3416. //
  3417. // order_src, _ := service.GetHisOrderByID(order_id)
  3418. //
  3419. // config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3420. // if config.IsOpen == 1 { //对接了医保,走医保流程
  3421. //
  3422. // var total float64
  3423. // for _, item := range prescriptions {
  3424. // if item.Type == 1 { //药品
  3425. // for _, subItem := range item.HisDoctorAdviceInfo {
  3426. // total = total + (subItem.Price * subItem.PrescribingNumber)
  3427. // }
  3428. // }
  3429. // if item.Type == 2 { //项目
  3430. // for _, subItem := range item.HisPrescriptionProject {
  3431. // total = total + (subItem.Price * float64(subItem.Count))
  3432. // }
  3433. // }
  3434. // }
  3435. //
  3436. // for _, item := range prescriptions {
  3437. // for _, subItem := range item.HisAdditionalCharge {
  3438. // total = total + (subItem.Price * float64(subItem.Count))
  3439. // }
  3440. // }
  3441. //
  3442. // allTotal := fmt.Sprintf("%.2f", total)
  3443. // var rf []*ResultFive
  3444. // json.Unmarshal([]byte(his.Iinfo), &rf)
  3445. // psn_no := order_src.PsnNo
  3446. // mdtrt_id := order_src.MdtrtId
  3447. // chrg_bchno := order_src.Number
  3448. // cert_no := order_src.Certno
  3449. // insutype := rf[0].Insutype
  3450. //
  3451. // if his.IdCardType == 1 {
  3452. // cert_no = his.MedicalInsuranceNumber
  3453. // } else {
  3454. // cert_no = his.Certno
  3455. // }
  3456. //
  3457. // 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)
  3458. // var dat map[string]interface{}
  3459. // if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3460. // fmt.Println(dat)
  3461. // } else {
  3462. // fmt.Println(err)
  3463. // }
  3464. //
  3465. // userJSONBytes, _ := json.Marshal(dat)
  3466. //
  3467. //
  3468. //
  3469. // var res ResultSeven
  3470. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3471. // utils.ErrorLog("解析失败:%v", err)
  3472. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3473. // return
  3474. // }
  3475. // if res.Infcode == -1 {
  3476. // errlog := &models.HisOrderError{
  3477. // UserOrgId: adminUser.CurrentOrgId,
  3478. // Ctime: time.Now().Unix(),
  3479. // Mtime: time.Now().Unix(),
  3480. // Number: chrg_bchno,
  3481. // ErrMsg: res.ErrMsg,
  3482. // Status: 1,
  3483. // PatientId: id,
  3484. // RecordTime: recordDateTime,
  3485. // Stage: 6,
  3486. // }
  3487. // service.CreateErrMsgLog(errlog)
  3488. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  3489. // return
  3490. // } else {
  3491. // order_src.OrderStatus = 2
  3492. // order_src.PayWay = pay_way
  3493. // order_src.PayPrice = pay_price
  3494. // order_src.PayCardNo = pay_card_no
  3495. // order_src.DiscountPrice = discount_price
  3496. // order_src.PreferentialPrice = preferential_price
  3497. // order_src.RealityPrice = reality_price
  3498. // order_src.FoundPrice = found_price
  3499. // order_src.MedicalInsurancePrice = medical_insurance_price
  3500. // order_src.PrivatePrice = private_price
  3501. // order_src.MdtrtId = res.Output.Setlinfo.MdtrtID
  3502. // order_src.SetlId = res.Output.Setlinfo.SetlID
  3503. // order_src.PsnNo = res.Output.Setlinfo.PsnNo
  3504. // order_src.PsnName = res.Output.Setlinfo.PsnName
  3505. // order_src.PsnCertType = res.Output.Setlinfo.PsnCertType
  3506. // order_src.Certno = res.Output.Setlinfo.Certno
  3507. // order_src.Gend = res.Output.Setlinfo.Gend
  3508. // order_src.Naty = res.Output.Setlinfo.Naty
  3509. // order_src.Age = res.Output.Setlinfo.Age
  3510. // order_src.Insutype = res.Output.Setlinfo.Insutype
  3511. // order_src.PsnType = res.Output.Setlinfo.PsnType
  3512. // order_src.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  3513. // order_src.SetlTime = res.Output.Setlinfo.SetlTime
  3514. // order_src.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  3515. // order_src.MedType = res.Output.Setlinfo.MedType
  3516. // order_src.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  3517. // order_src.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  3518. // order_src.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  3519. // order_src.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  3520. // order_src.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  3521. // order_src.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  3522. // order_src.HifpPay = res.Output.Setlinfo.HifpPay
  3523. // order_src.CvlservPay = res.Output.Setlinfo.CvlservPay
  3524. // order_src.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  3525. // order_src.HifesPay = res.Output.Setlinfo.HifesPay
  3526. // order_src.HifobPay = res.Output.Setlinfo.HifobPay
  3527. // order_src.MafPay = res.Output.Setlinfo.MafPay
  3528. // order_src.OthPay = res.Output.Setlinfo.OthPay
  3529. // order_src.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  3530. // order_src.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  3531. // order_src.AcctPay = res.Output.Setlinfo.AcctPay
  3532. // order_src.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  3533. // order_src.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  3534. // order_src.Balc = res.Output.Setlinfo.Balc
  3535. // order_src.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  3536. // order_src.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  3537. // order_src.ClrOptins = res.Output.Setlinfo.ClrOptins
  3538. // order_src.ClrWay = res.Output.Setlinfo.ClrWay
  3539. // order_src.Creator = order_src.Creator
  3540. // order_src.Modify = roles.ID
  3541. // order_src.RequestLog = src_resquest
  3542. // setlDetail, _ := json.Marshal(res.Output.Setldetail)
  3543. // detailStr := string(setlDetail)
  3544. // order_src.SetlDetail = detailStr
  3545. // err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  3546. // err = service.UpDateOrder(order_src)
  3547. //
  3548. // if err == nil {
  3549. // c.ServeSuccessJSON(map[string]interface{}{
  3550. // "msg": "结算成功",
  3551. // })
  3552. // } else {
  3553. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  3554. // return
  3555. // }
  3556. // }
  3557. // }
  3558. //}
  3559. //退款
  3560. func (c *HisApiController) Refund() {
  3561. order_id, _ := c.GetInt64("order_id")
  3562. admin_user_id, _ := c.GetInt64("admin_user_id")
  3563. //record_time := c.GetString("record_time")
  3564. //patient_id, _ := c.GetInt64("patient_id")
  3565. //timeLayout := "2006-01-02"
  3566. //loc, _ := time.LoadLocation("Local")
  3567. adminUser := c.GetAdminUserInfo()
  3568. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3569. //if err != nil {
  3570. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3571. // return
  3572. //}
  3573. //recordDateTime := theTime.Unix()
  3574. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3575. var order models.HisOrder
  3576. order, _ = service.GetHisOrderByID(order_id)
  3577. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3578. if order.ID == 0 {
  3579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3580. return
  3581. //order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  3582. }
  3583. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3584. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3585. if config.IsOpen == 1 { //对接了医保,走医保流程
  3586. result, src_resquest := service.Gdyb2208(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  3587. var dat map[string]interface{}
  3588. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3589. fmt.Println(dat)
  3590. } else {
  3591. fmt.Println(err)
  3592. }
  3593. saveLog(result, src_resquest, "2208")
  3594. userJSONBytes, _ := json.Marshal(dat)
  3595. var res ResultSixteen
  3596. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3597. utils.ErrorLog("解析失败:%v", err)
  3598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3599. return
  3600. }
  3601. if res.Infcode == 0 {
  3602. result, src_request := service.Gdyb2205(order.PsnNo, order.MdtrtId, order.Number, miConfig.OrgName, roles.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  3603. var dat map[string]interface{}
  3604. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3605. fmt.Println(dat)
  3606. } else {
  3607. fmt.Println(err)
  3608. }
  3609. saveLog(result, src_request, "2205")
  3610. userJSONBytes, _ := json.Marshal(dat)
  3611. var res2 ResultSix
  3612. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  3613. utils.ErrorLog("解析失败:%v", err)
  3614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3615. return
  3616. }
  3617. if res2.Infcode == 0 {
  3618. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, src_resquest, result)
  3619. if err == nil {
  3620. c.ServeSuccessJSON(map[string]interface{}{
  3621. "msg": "退费成功",
  3622. })
  3623. } else {
  3624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3625. return
  3626. }
  3627. } else {
  3628. c.ServeSuccessJSON(map[string]interface{}{
  3629. "code": -10,
  3630. "msg": res2.ErrMsg,
  3631. })
  3632. }
  3633. } else {
  3634. c.ServeSuccessJSON(map[string]interface{}{
  3635. "code": -10,
  3636. "msg": res.ErrMsg,
  3637. })
  3638. }
  3639. }
  3640. }
  3641. func (c *HisApiController) RefundNumber() {
  3642. record_time := c.GetString("record_time")
  3643. //patient_id, _ := c.GetInt64("patient_id")
  3644. admin_user_id, _ := c.GetInt64("admin_user_id")
  3645. his_patient_id, _ := c.GetInt64("id")
  3646. timeLayout := "2006-01-02"
  3647. loc, _ := time.LoadLocation("Local")
  3648. adminUser := c.GetAdminUserInfo()
  3649. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3650. fmt.Println(err)
  3651. if err != nil {
  3652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3653. return
  3654. }
  3655. recordDateTime := theTime.Unix()
  3656. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3657. his, _ := service.GetHisPatientRecord(adminUser.CurrentOrgId, his_patient_id)
  3658. //patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3659. //order, _ := service.GetHisOrderByID(order_id)
  3660. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3661. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3662. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3663. count, _ := service.GetOrderCountByNumber(adminUser.CurrentOrgId, his.PatientId, recordDateTime, his.Number)
  3664. if count > 0 {
  3665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  3666. return
  3667. }
  3668. if config.IsOpen == 1 { //对接了医保,走医保流程
  3669. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  3670. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + roles.UserName + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  3671. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3672. resp3, requestErr3 := http.Get(api3)
  3673. if requestErr3 != nil {
  3674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3675. return
  3676. }
  3677. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  3678. if ioErr3 != nil {
  3679. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  3680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3681. return
  3682. }
  3683. var respJSON3 map[string]interface{}
  3684. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  3685. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3687. return
  3688. }
  3689. respJSON3 = respJSON3["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3690. userJSONBytes3, _ := json.Marshal(respJSON3)
  3691. var res2 ResultSix
  3692. if err := json.Unmarshal(userJSONBytes3, &res2); err != nil {
  3693. utils.ErrorLog("解析失败:%v", err)
  3694. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3695. return
  3696. }
  3697. if res2.Infcode == 0 {
  3698. if err == nil {
  3699. c.ServeSuccessJSON(map[string]interface{}{
  3700. "msg": "退号成功",
  3701. })
  3702. service.UpdataRegStatusTwo(his_patient_id, recordDateTime, adminUser.CurrentOrgId)
  3703. } else {
  3704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3705. return
  3706. }
  3707. } else {
  3708. c.ServeSuccessJSON(map[string]interface{}{
  3709. "code": -10,
  3710. "msg": res2.ErrMsg,
  3711. })
  3712. }
  3713. } else {
  3714. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  3715. //if err == nil {
  3716. // c.ServeSuccessJSON(map[string]interface{}{
  3717. // "msg": "退费成功",
  3718. // })
  3719. //} else {
  3720. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3721. // return
  3722. //}
  3723. }
  3724. }
  3725. func (c *HisApiController) RefundDetail() {
  3726. order_id, _ := c.GetInt64("order_id")
  3727. his_patient_id, _ := c.GetInt64("his_patient_id")
  3728. number := c.GetString("number")
  3729. record_time := c.GetString("record_time")
  3730. patient_id, _ := c.GetInt64("patient_id")
  3731. timeLayout := "2006-01-02"
  3732. loc, _ := time.LoadLocation("Local")
  3733. adminUser := c.GetAdminUserInfo()
  3734. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3735. fmt.Println(err)
  3736. if err != nil {
  3737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3738. return
  3739. }
  3740. recordDateTime := theTime.Unix()
  3741. his, _ := service.GetNewVMHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  3742. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3743. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3744. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3745. var order models.HisOrder
  3746. order, _ = service.GetHisOrderByID(order_id)
  3747. if order.ID == 0 {
  3748. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  3749. }
  3750. if config.IsOpen == 1 { //对接了医保,走医保流程
  3751. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  3752. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  3753. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3754. resp2, requestErr2 := http.Get(api2)
  3755. if requestErr2 != nil {
  3756. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3757. return
  3758. }
  3759. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  3760. if ioErr2 != nil {
  3761. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  3762. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3763. return
  3764. }
  3765. var respJSON2 map[string]interface{}
  3766. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  3767. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3769. return
  3770. }
  3771. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId, "", "")
  3772. if err == nil {
  3773. c.ServeSuccessJSON(map[string]interface{}{
  3774. "msg": "退费成功",
  3775. })
  3776. } else {
  3777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3778. return
  3779. }
  3780. } else {
  3781. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId, "", "")
  3782. if err == nil {
  3783. c.ServeSuccessJSON(map[string]interface{}{
  3784. "msg": "退费成功",
  3785. })
  3786. } else {
  3787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3788. return
  3789. }
  3790. }
  3791. }
  3792. //对账
  3793. func (c *HisApiController) GetCheckAccount() {
  3794. start_time := c.GetString("start_time")
  3795. end_time := c.GetString("end_time")
  3796. insutype := c.GetString("insutype")
  3797. clr_type := c.GetString("clr_type")
  3798. admin_user_id, _ := c.GetInt64("admin_user_id")
  3799. adminUser := c.GetAdminUserInfo()
  3800. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3801. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3802. timeLayout := "2006-01-02"
  3803. loc, _ := time.LoadLocation("Local")
  3804. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3805. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3806. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  3807. //orders_two, _ := service.GetOrderByTimeThree(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  3808. fixmedins_setl_cnt := int64(len(orders))
  3809. //
  3810. ////撤销的算2条数据为一笔
  3811. //for _, item := range orders_two {
  3812. // if item.OrderStatus == 3 {
  3813. // fixmedins_setl_cnt = fixmedins_setl_cnt + 1
  3814. // }
  3815. //}
  3816. var medfee_sumamt float64
  3817. var acct_pay float64
  3818. var fund_pay_sumamt float64
  3819. for _, item := range orders {
  3820. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  3821. acct_pay = acct_pay + item.AcctPay
  3822. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  3823. }
  3824. var user_name string
  3825. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3826. if role.ID == 0 {
  3827. user_name = "xxx"
  3828. } else {
  3829. user_name = role.UserName
  3830. }
  3831. if config.IsOpen == 1 {
  3832. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  3833. "insutype=" + insutype +
  3834. "&clr_type=" + clr_type +
  3835. "&setl_optins=" + "定点医保中心" +
  3836. "&stmt_begndate=" + start_time +
  3837. "&stm_enddate=" + end_time +
  3838. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  3839. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  3840. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  3841. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  3842. "&fixmedins_code=" + miConfig.Code +
  3843. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  3844. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3845. "&secret_key=" + miConfig.SecretKey +
  3846. "&org_name=" + miConfig.OrgName +
  3847. "&doctor=" + user_name
  3848. fmt.Println(api)
  3849. resp, requestErr := http.Get(api)
  3850. if requestErr != nil {
  3851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3852. return
  3853. }
  3854. body, ioErr := ioutil.ReadAll(resp.Body)
  3855. fmt.Println(body)
  3856. if ioErr != nil {
  3857. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3858. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3859. return
  3860. }
  3861. var respJSON map[string]interface{}
  3862. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3863. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3865. return
  3866. }
  3867. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3868. userJSONBytes, _ := json.Marshal(respJSON)
  3869. var res ResultEight
  3870. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3871. utils.ErrorLog("解析失败:%v", err)
  3872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3873. return
  3874. }
  3875. if res.Infcode == 0 {
  3876. if res.Output.Stmtinfo.StmtRslt == "0" {
  3877. micc := &models.MedicalInsuranceCostCompare{
  3878. StartTime: startime.Unix(),
  3879. EndTime: endtime.Unix(),
  3880. Insutype: insutype,
  3881. CheckType: 1,
  3882. Num: fixmedins_setl_cnt,
  3883. Mtime: time.Now().Unix(),
  3884. Status: 1,
  3885. UserOrgId: adminUser.CurrentOrgId,
  3886. CostTotal: medfee_sumamt,
  3887. FuncTotal: fund_pay_sumamt,
  3888. PsnPay: acct_pay,
  3889. Creator: admin_user_id,
  3890. Ctime: time.Now().Unix(),
  3891. }
  3892. err := service.CreateMedicalInsuranceCostCompareRecord(micc)
  3893. if err == nil {
  3894. c.ServeSuccessJSON(map[string]interface{}{
  3895. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  3896. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  3897. })
  3898. } else {
  3899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3900. }
  3901. } else {
  3902. c.ServeSuccessJSON(map[string]interface{}{
  3903. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  3904. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  3905. })
  3906. }
  3907. } else {
  3908. c.ServeSuccessJSON(map[string]interface{}{
  3909. "code": -10,
  3910. "msg": res.ErrMsg,
  3911. })
  3912. }
  3913. }
  3914. }
  3915. func (c *HisApiController) Check310() {
  3916. adminUser := c.GetAdminUserInfo()
  3917. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3918. var user_name string
  3919. user_name = "xxx"
  3920. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  3921. "insutype=" + "310" +
  3922. "&clr_type=" + "11" +
  3923. "&setl_optins=" + "定点医保中心" +
  3924. "&stmt_begndate=" + "2021-03-01" +
  3925. "&stm_enddate=" + "2021-03-31" +
  3926. "&medfee_sumamt=" + "11521" +
  3927. "&fund_pay_sumamt=" + "10166.66" +
  3928. "&acct_pay=" + "0" +
  3929. "&fixmedins_setl_cnt=" + "7" +
  3930. "&fixmedins_code=" + miConfig.Code +
  3931. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  3932. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3933. "&secret_key=" + miConfig.SecretKey +
  3934. "&org_name=" + miConfig.OrgName +
  3935. "&doctor=" + user_name
  3936. fmt.Println(api)
  3937. resp, requestErr := http.Get(api)
  3938. if requestErr != nil {
  3939. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3940. return
  3941. }
  3942. body, ioErr := ioutil.ReadAll(resp.Body)
  3943. fmt.Println(body)
  3944. if ioErr != nil {
  3945. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3946. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3947. return
  3948. }
  3949. var respJSON map[string]interface{}
  3950. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3951. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3953. return
  3954. }
  3955. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3956. userJSONBytes, _ := json.Marshal(respJSON)
  3957. var res ResultEight
  3958. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3959. utils.ErrorLog("解析失败:%v", err)
  3960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3961. return
  3962. }
  3963. }
  3964. func (c *HisApiController) Check390() {
  3965. adminUser := c.GetAdminUserInfo()
  3966. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3967. var user_name string
  3968. user_name = "张俊杰"
  3969. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  3970. "insutype=" + "390" +
  3971. "&clr_type=" + "11" +
  3972. "&setl_optins=" + "定点医保中心" +
  3973. "&stmt_begndate=" + "2021-03-01" +
  3974. "&stm_enddate=" + "2021-03-31" +
  3975. "&medfee_sumamt=" + "209318.43" +
  3976. "&fund_pay_sumamt=" + "188029.12" +
  3977. "&acct_pay=" + "0" +
  3978. "&fixmedins_setl_cnt=" + "48" +
  3979. "&fixmedins_code=" + miConfig.Code +
  3980. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  3981. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3982. "&secret_key=" + miConfig.SecretKey +
  3983. "&org_name=" + miConfig.OrgName +
  3984. "&doctor=" + user_name
  3985. fmt.Println(api)
  3986. resp, requestErr := http.Get(api)
  3987. if requestErr != nil {
  3988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3989. return
  3990. }
  3991. body, ioErr := ioutil.ReadAll(resp.Body)
  3992. fmt.Println(body)
  3993. if ioErr != nil {
  3994. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3996. return
  3997. }
  3998. var respJSON map[string]interface{}
  3999. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4000. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4002. return
  4003. }
  4004. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4005. userJSONBytes, _ := json.Marshal(respJSON)
  4006. var res ResultEight
  4007. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4008. utils.ErrorLog("解析失败:%v", err)
  4009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4010. return
  4011. }
  4012. }
  4013. //对账明细
  4014. func (c *HisApiController) GetCheckDetailAccount() {
  4015. start_time := c.GetString("start_time")
  4016. end_time := c.GetString("end_time")
  4017. admin_user_id, _ := c.GetInt64("admin_user_id")
  4018. adminUser := c.GetAdminUserInfo()
  4019. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4020. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4021. timeLayout := "2006-01-02"
  4022. loc, _ := time.LoadLocation("Local")
  4023. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4024. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4025. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  4026. Mkdir(miConfig.OrgName)
  4027. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  4028. file_name := file + ".txt"
  4029. zip_name := file + ".zip"
  4030. zip_path := miConfig.OrgName + "/" + zip_name
  4031. file_path := miConfig.OrgName + "/" + file_name
  4032. decimal.DivisionPrecision = 2
  4033. var medfee_sumamt float64
  4034. var psn_cash_pay float64
  4035. var fund_pay_sumamt float64
  4036. fixmedins_setl_cnt := int64(len(orders))
  4037. for _, item := range orders {
  4038. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  4039. psn_cash_pay = psn_cash_pay + item.PsnCashPay
  4040. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  4041. }
  4042. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  4043. defer f.Close()
  4044. if err != nil {
  4045. fmt.Println(err.Error())
  4046. } else {
  4047. for _, item := range orders {
  4048. var refd_setl_flag string
  4049. if item.OrderStatus == 2 {
  4050. refd_setl_flag = "0"
  4051. var str string
  4052. str = item.SetlId + " " +
  4053. item.MdtrtId + " " +
  4054. item.PsnNo + " " +
  4055. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  4056. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  4057. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\r\n"
  4058. _, err = f.Write([]byte(str))
  4059. }
  4060. if item.OrderStatus == 3 {
  4061. var str string
  4062. str = item.SetlId + " " +
  4063. item.MdtrtId + " " +
  4064. item.PsnNo + " " +
  4065. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  4066. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  4067. fmt.Sprintf("%.2f", item.AcctPay) + " " + "1" + "\r\n"
  4068. _, err = f.Write([]byte(str))
  4069. var str2 string
  4070. str2 = item.SetlId + " " +
  4071. item.MdtrtId + " " +
  4072. item.PsnNo + " " +
  4073. fmt.Sprintf("%.2f", 0-item.MedfeeSumamt) + " " +
  4074. fmt.Sprintf("%.2f", 0-item.FundPaySumamt) + " " +
  4075. fmt.Sprintf("%.2f", 0-item.AcctPay) + " " + "1" + "\r\n"
  4076. _, err = f.Write([]byte(str2))
  4077. }
  4078. }
  4079. }
  4080. Zip(file_path, zip_path)
  4081. fmt.Println(ReadFile(zip_path))
  4082. fmt.Println(string(ReadFile(zip_path)))
  4083. if config.IsOpen == 1 {
  4084. var user_name string
  4085. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4086. if role.ID == 0 {
  4087. user_name = "管理员"
  4088. } else {
  4089. user_name = role.UserName
  4090. }
  4091. baseParams := models.BaseParams{
  4092. SecretKey: miConfig.SecretKey,
  4093. FixmedinsCode: miConfig.Code,
  4094. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4095. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4096. OrgName: miConfig.OrgName,
  4097. Doctor: user_name,
  4098. }
  4099. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  4100. var dat map[string]interface{}
  4101. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4102. fmt.Println(dat)
  4103. } else {
  4104. fmt.Println(err)
  4105. }
  4106. userJSONBytes, _ := json.Marshal(dat)
  4107. var res ResultNine
  4108. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4109. utils.ErrorLog("解析失败:%v", err)
  4110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4111. return
  4112. }
  4113. if res.Infcode == 0 {
  4114. fileNo := res.Output.FileQuryNo
  4115. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  4116. "file_qury_no=" + fileNo +
  4117. "&setl_optins=" + "定点医保中心" +
  4118. "&stmt_begndate=" + start_time +
  4119. "&stm_enddate=" + end_time +
  4120. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  4121. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  4122. "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) +
  4123. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  4124. "&fixmedins_code=" + miConfig.Code +
  4125. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  4126. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  4127. "&secret_key=" + miConfig.SecretKey +
  4128. "&org_name=" + miConfig.OrgName +
  4129. "&doctor=" + user_name
  4130. resp, requestErr := http.Get(api)
  4131. if requestErr != nil {
  4132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4133. return
  4134. }
  4135. body, ioErr := ioutil.ReadAll(resp.Body)
  4136. if ioErr != nil {
  4137. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4139. return
  4140. }
  4141. var respJSON map[string]interface{}
  4142. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4143. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4145. return
  4146. }
  4147. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4148. userJSONBytes, _ := json.Marshal(respJSON)
  4149. var res ResultTen
  4150. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4151. utils.ErrorLog("解析失败:%v", err)
  4152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4153. return
  4154. }
  4155. if res.Infcode == 0 {
  4156. service.Gdyb9102(baseParams, zip_name, fileNo)
  4157. micc := &models.MedicalInsuranceCostCompare{
  4158. StartTime: startime.Unix(),
  4159. EndTime: endtime.Unix(),
  4160. Insutype: "0",
  4161. CheckType: 2,
  4162. Num: fixmedins_setl_cnt,
  4163. Mtime: time.Now().Unix(),
  4164. Status: 1,
  4165. UserOrgId: adminUser.CurrentOrgId,
  4166. CostTotal: medfee_sumamt,
  4167. FuncTotal: fund_pay_sumamt,
  4168. PsnPay: psn_cash_pay,
  4169. Creator: admin_user_id,
  4170. Ctime: time.Now().Unix(),
  4171. }
  4172. service.CreateMedicalInsuranceCostCompareRecord(micc)
  4173. c.ServeSuccessJSON(map[string]interface{}{
  4174. "msg": "明细对账成功",
  4175. })
  4176. }
  4177. } else {
  4178. }
  4179. }
  4180. }
  4181. func (c *HisApiController) GetSettleAccounts() {
  4182. //id, _ := c.GetInt64("id")
  4183. //record_time := c.GetString("record_time")
  4184. order_id, _ := c.GetInt64("order_id")
  4185. admin_user_id, _ := c.GetInt64("admin_user_id")
  4186. //timeLayout := "2006-01-02"
  4187. //loc, _ := time.LoadLocation("Local")
  4188. //
  4189. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4190. //if err != nil {
  4191. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4192. // return
  4193. //}
  4194. //recordDateTime := theTime.Unix()
  4195. adminUser := c.GetAdminUserInfo()
  4196. order, _ := service.GetHisOrderByID(order_id)
  4197. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  4198. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  4199. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  4200. orderInfos = append(orderInfos, orderInfos_two...)
  4201. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  4202. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  4203. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  4204. //var config []*models.HisXtDiagnoseConfig
  4205. var name string
  4206. for _, item := range diagnosis_ids {
  4207. id, _ := strconv.ParseInt(item, 10, 64)
  4208. diagnosisConfig, _ := service.FindDiagnoseById(id)
  4209. if len(name) == 0 {
  4210. name = diagnosisConfig.ClassName
  4211. } else {
  4212. name = name + "," + diagnosisConfig.ClassName
  4213. }
  4214. }
  4215. var bedCostTotal float64 = 0 //床位总费
  4216. var bedCostSelfTotal float64 = 0 //床位自费
  4217. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  4218. var operationCostTotal float64 = 0 //手术费
  4219. var operationCostSelfTotal float64 = 0 //手术费
  4220. var operationCostPartSelfTotal float64 = 0 //手术费
  4221. var otherCostTotal float64 = 0 //其他费用
  4222. var otherCostSelfTotal float64 = 0 //其他费用
  4223. var otherCostPartSelfTotal float64 = 0 //其他费用
  4224. var materialCostTotal float64 = 0 //材料费
  4225. var materialCostSelfTotal float64 = 0 //材料费
  4226. var materialCostPartSelfTotal float64 = 0 //材料费
  4227. var westernMedicineCostTotal float64 = 0 //西药费
  4228. var westernMedicineCostSelfTotal float64 = 0 //西药费
  4229. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  4230. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  4231. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  4232. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  4233. var checkCostTotal float64 = 0 //检查费
  4234. var checkCostSelfTotal float64 = 0 //检查费
  4235. var checkCostPartSelfTotal float64 = 0 //检查费
  4236. var laboratoryCostTotal float64 = 0 //化验费
  4237. var laboratoryCostSelfTotal float64 = 0 //化验费
  4238. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  4239. var treatCostTotal float64 = 0 //治疗费用
  4240. var treatCostSelfTotal float64 = 0 //治疗费用
  4241. var treatCostPartSelfTotal float64 = 0 //治疗费用
  4242. decimal.DivisionPrecision = 2
  4243. for _, item := range orderInfos {
  4244. if item.MedChrgitmType == "01" { //床位费
  4245. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4246. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4247. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4248. }
  4249. if item.MedChrgitmType == "03" { //检查费
  4250. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4251. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4252. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4253. }
  4254. if item.MedChrgitmType == "04" { //化验费
  4255. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4256. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4257. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4258. }
  4259. if item.MedChrgitmType == "05" { //治疗费
  4260. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4261. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4262. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4263. }
  4264. if item.MedChrgitmType == "06" { //手术费
  4265. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4266. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4267. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4268. }
  4269. if item.MedChrgitmType == "08" { //材料费
  4270. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4271. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4272. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4273. }
  4274. if item.MedChrgitmType == "09" { //西药费
  4275. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4276. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4277. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4278. }
  4279. if item.MedChrgitmType == "11" { //中成费
  4280. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4281. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4282. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4283. }
  4284. if item.MedChrgitmType == "14" { //其他费
  4285. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4286. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4287. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4288. }
  4289. }
  4290. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4291. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4292. var user_name string
  4293. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4294. if role.ID == 0 {
  4295. user_name = "管理员"
  4296. } else {
  4297. user_name = role.UserName
  4298. }
  4299. baseParams := models.BaseParams{
  4300. SecretKey: miConfig.SecretKey,
  4301. FixmedinsCode: miConfig.Code,
  4302. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4303. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4304. OrgName: miConfig.OrgName,
  4305. Doctor: user_name,
  4306. }
  4307. businessParams := models.BusinessParams{
  4308. PsnNo: order.PsnNo,
  4309. MdtrtId: order.MdtrtId,
  4310. SetlId: order.SetlId,
  4311. }
  4312. if config.IsOpen == 1 {
  4313. result := service.Gdyb5203(baseParams, businessParams)
  4314. var dat map[string]interface{}
  4315. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4316. fmt.Println(dat)
  4317. } else {
  4318. fmt.Println(err)
  4319. }
  4320. userJSONBytes, _ := json.Marshal(dat)
  4321. var res ResultEleven
  4322. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4323. utils.ErrorLog("解析失败:%v", err)
  4324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4325. return
  4326. }
  4327. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4328. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  4329. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, order.PatientId, order.SettleAccountsDate)
  4330. adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  4331. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4332. var doctor_name string
  4333. if roles.ID == 0 {
  4334. doctor_name = "管理员"
  4335. } else {
  4336. doctor_name = roles.UserName
  4337. }
  4338. yiliao_leibie := ""
  4339. switch order.MedType {
  4340. case "11":
  4341. yiliao_leibie = "普通门诊"
  4342. break
  4343. case "12":
  4344. yiliao_leibie = "门诊挂号"
  4345. break
  4346. case "13":
  4347. yiliao_leibie = "急诊"
  4348. break
  4349. case "14":
  4350. yiliao_leibie = "门诊特殊病"
  4351. break
  4352. case "15":
  4353. yiliao_leibie = "门诊统筹"
  4354. break
  4355. case "16":
  4356. yiliao_leibie = "门诊慢性病"
  4357. break
  4358. case "21":
  4359. yiliao_leibie = "普通住院"
  4360. break
  4361. }
  4362. departments, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  4363. if res.Infcode == 0 {
  4364. c.ServeSuccessJSON(map[string]interface{}{
  4365. "diagnosis": name,
  4366. "order_infos": orderInfos,
  4367. "number": order.MdtrtId,
  4368. "date": order.SettleAccountsDate,
  4369. "charge_admin": charge_admin,
  4370. "printor_admin": printor_admin,
  4371. "info": res.Output.Setlinfo,
  4372. "bedCostTotal": bedCostTotal,
  4373. "bedCostSelfTotal": bedCostSelfTotal,
  4374. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  4375. "operationCostTotal": operationCostTotal,
  4376. "operationCostSelfTotal": operationCostSelfTotal,
  4377. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  4378. "otherCostTotal": otherCostTotal,
  4379. "otherCostSelfTotal": otherCostSelfTotal,
  4380. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  4381. "materialCostTotal": materialCostTotal,
  4382. "materialCostSelfTotal": materialCostSelfTotal,
  4383. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  4384. "westernMedicineCostTotal": westernMedicineCostTotal,
  4385. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  4386. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  4387. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  4388. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  4389. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  4390. "checkCostTotal": checkCostTotal,
  4391. "checkCostSelfTotal": checkCostSelfTotal,
  4392. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  4393. "laboratoryCostTotal": laboratoryCostTotal,
  4394. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  4395. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  4396. "treatCostTotal": treatCostTotal,
  4397. "treatCostSelfTotal": treatCostSelfTotal,
  4398. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  4399. "doctor_code": adminRole_two.DoctorCode,
  4400. "doctor_name": doctor_name,
  4401. "health_card_no": order.PsnNo,
  4402. "department": departments.Name,
  4403. "yiliao_leibie": yiliao_leibie,
  4404. "after_money": order.AccountPrice,
  4405. "patient": patient,
  4406. "org_name": miConfig.OrgName,
  4407. "org_code": miConfig.Code,
  4408. "order_number": order.Number,
  4409. })
  4410. }
  4411. }
  4412. }
  4413. func (c *HisApiController) CheckTreatment() {
  4414. patient_id, _ := c.GetInt64("patient_id", 0)
  4415. record_time := c.GetString("record_time")
  4416. insutype := c.GetString("insutype")
  4417. timeLayout := "2006-01-02"
  4418. loc, _ := time.LoadLocation("Local")
  4419. adminUser := c.GetAdminUserInfo()
  4420. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4421. fmt.Println(err)
  4422. if err != nil {
  4423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4424. return
  4425. }
  4426. recordDateTime := theTime.Unix()
  4427. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  4428. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  4429. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4430. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4431. var user_name string
  4432. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  4433. if role.ID == 0 {
  4434. user_name = "xxx"
  4435. } else {
  4436. user_name = role.UserName
  4437. }
  4438. baseParams := models.BaseParams{
  4439. SecretKey: miConfig.SecretKey,
  4440. FixmedinsCode: miConfig.Code,
  4441. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4442. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4443. OrgName: miConfig.OrgName,
  4444. Doctor: user_name,
  4445. }
  4446. if config.IsOpen == 1 {
  4447. result := service.Gdyb2001(baseParams, his.PsnNo, insutype, strconv.FormatInt(patientPrescription.RegisterType, 10))
  4448. var dat map[string]interface{}
  4449. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4450. fmt.Println(dat)
  4451. } else {
  4452. fmt.Println(err)
  4453. }
  4454. }
  4455. }
  4456. func (c *HisApiController) PutRecord() {
  4457. id, _ := c.GetInt64("id")
  4458. record_time := c.GetString("record_time")
  4459. timeLayout := "2006-01-02"
  4460. loc, _ := time.LoadLocation("Local")
  4461. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4462. if err != nil {
  4463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4464. return
  4465. }
  4466. recordDateTime := theTime.Unix()
  4467. adminInfo := c.GetAdminUserInfo()
  4468. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  4469. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  4470. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  4471. fmt.Println(miConfig.SecretKey)
  4472. if patient == nil {
  4473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4474. return
  4475. }
  4476. if len(patient.IdCardNo) == 0 {
  4477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  4478. return
  4479. }
  4480. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  4481. if config.IsOpen == 1 {
  4482. 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
  4483. resp, requestErr := http.Get(api)
  4484. if requestErr != nil {
  4485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4486. return
  4487. }
  4488. defer resp.Body.Close()
  4489. body, ioErr := ioutil.ReadAll(resp.Body)
  4490. if ioErr != nil {
  4491. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4493. return
  4494. }
  4495. var respJSON map[string]interface{}
  4496. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4497. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4499. return
  4500. }
  4501. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4502. userJSONBytes, _ := json.Marshal(userJSON)
  4503. var res ResultTwo
  4504. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4505. utils.ErrorLog("解析失败:%v", err)
  4506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4507. return
  4508. }
  4509. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  4510. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  4511. infoStr := string(Iinfos)
  4512. idetinfoStr := string(Idetinfos)
  4513. if res.Infcode == 0 {
  4514. his := models.VMHisPatient{
  4515. Status: 1,
  4516. Ctime: time.Now().Unix(),
  4517. Mtime: time.Now().Unix(),
  4518. PsnNo: res.Output.Baseinfo.PsnNo,
  4519. PsnCertType: res.Output.Baseinfo.PsnCertType,
  4520. Certno: res.Output.Baseinfo.Certno,
  4521. PsnName: res.Output.Baseinfo.PsnName,
  4522. Gend: res.Output.Baseinfo.Gend,
  4523. Naty: res.Output.Baseinfo.Naty,
  4524. Brdy: res.Output.Baseinfo.Brdy,
  4525. Age: res.Output.Baseinfo.Age,
  4526. Iinfo: infoStr,
  4527. Idetinfo: idetinfoStr,
  4528. PatientId: patient.ID,
  4529. RecordDate: theTime.Unix(),
  4530. UserOrgId: adminInfo.CurrentOrgId,
  4531. AdminUserId: adminInfo.AdminUser.Id,
  4532. IsReturn: 1,
  4533. }
  4534. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  4535. 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")
  4536. 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")
  4537. var dat map[string]interface{}
  4538. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4539. fmt.Println(dat)
  4540. } else {
  4541. fmt.Println(err)
  4542. }
  4543. var dat2 map[string]interface{}
  4544. if err := json.Unmarshal([]byte(result2), &dat2); err == nil {
  4545. fmt.Println(dat2)
  4546. } else {
  4547. fmt.Println(err)
  4548. }
  4549. } else {
  4550. adminUser := c.GetAdminUserInfo()
  4551. errlog := &models.HisOrderError{
  4552. UserOrgId: adminUser.CurrentOrgId,
  4553. Ctime: time.Now().Unix(),
  4554. Mtime: time.Now().Unix(),
  4555. ErrMsg: res.ErrMsg,
  4556. Status: 1,
  4557. PatientId: id,
  4558. RecordTime: recordDateTime,
  4559. Stage: 1,
  4560. }
  4561. service.CreateErrMsgLog(errlog)
  4562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  4563. return
  4564. }
  4565. }
  4566. }
  4567. func (c *HisApiController) GetUploadDiag() {
  4568. id, _ := c.GetInt64("id")
  4569. record_time := c.GetString("record_time")
  4570. diagnosis_id, _ := c.GetInt64("diagnosis")
  4571. sick_type, _ := c.GetInt64("sick_type")
  4572. reg_type, _ := c.GetInt64("reg_type")
  4573. timeLayout := "2006-01-02"
  4574. loc, _ := time.LoadLocation("Local")
  4575. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4576. if err != nil {
  4577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4578. return
  4579. }
  4580. var patientPrescription models.HisPrescriptionInfo
  4581. recordDateTime := theTime.Unix()
  4582. adminInfo := c.GetAdminUserInfo()
  4583. patientPrescription, _ = service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  4584. if patientPrescription.ID == 0 {
  4585. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  4586. }
  4587. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  4588. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  4589. his, _ := service.GetVMHisPatientInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  4590. sickConfig, _ := service.FindSickById(sick_type)
  4591. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  4592. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  4593. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  4594. "&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 +
  4595. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.ContentCode + "&sick_name=" + sickConfig.ClassName
  4596. resp2, requestErr2 := http.Get(api2)
  4597. if requestErr2 != nil {
  4598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4599. return
  4600. }
  4601. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  4602. if ioErr2 != nil {
  4603. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  4604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4605. return
  4606. }
  4607. var respJSON2 map[string]interface{}
  4608. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  4609. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4611. return
  4612. }
  4613. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4614. userJSONBytes2, _ := json.Marshal(respJSON2)
  4615. var res2 ResultSix
  4616. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  4617. utils.ErrorLog("解析失败:%v", err)
  4618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4619. return
  4620. }
  4621. if res2.Infcode != 0 {
  4622. adminUser := c.GetAdminUserInfo()
  4623. errlog := &models.HisOrderError{
  4624. UserOrgId: adminUser.CurrentOrgId,
  4625. Ctime: time.Now().Unix(),
  4626. Mtime: time.Now().Unix(),
  4627. ErrMsg: res2.ErrMsg,
  4628. Status: 1,
  4629. PatientId: id,
  4630. RecordTime: recordDateTime,
  4631. Stage: 3,
  4632. }
  4633. service.CreateErrMsgLog(errlog)
  4634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  4635. return
  4636. }
  4637. c.ServeSuccessJSON(map[string]interface{}{
  4638. "msg": "上传成功",
  4639. })
  4640. }
  4641. type QueryResult struct {
  4642. ID int64
  4643. Name string
  4644. Code string
  4645. List_type_code string
  4646. }
  4647. func (c *HisApiController) GetCheckCode() {
  4648. ids_str := c.GetString("ids")
  4649. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  4650. ids_arr := strings.Split(ids_str, ",")
  4651. var queryResult []QueryResult
  4652. ids := make([]int64, 0)
  4653. for _, item := range ids_arr {
  4654. id, _ := strconv.ParseInt(item, 10, 64)
  4655. ids = append(ids, id)
  4656. }
  4657. if record_type == 1 {
  4658. drugs, _ := service.GetBatchDrugList(ids)
  4659. for _, item := range drugs {
  4660. result := QueryResult{
  4661. ID: item.ID,
  4662. Name: item.DrugName,
  4663. Code: item.MedicalInsuranceNumber,
  4664. List_type_code: "101",
  4665. }
  4666. queryResult = append(queryResult, result)
  4667. }
  4668. } else if record_type == 2 {
  4669. goods, _ := service.GetBatchGoodInformationList(ids)
  4670. for _, item := range goods {
  4671. result := QueryResult{
  4672. ID: item.ID,
  4673. Name: item.GoodName,
  4674. Code: item.MedicalInsuranceNumber,
  4675. List_type_code: "301",
  4676. }
  4677. queryResult = append(queryResult, result)
  4678. }
  4679. } else if record_type == 3 {
  4680. projects, _ := service.GetBathchMyPorjecgList(ids)
  4681. for _, item := range projects {
  4682. result := QueryResult{
  4683. ID: item.ID,
  4684. Name: item.ProjectName,
  4685. Code: item.MedicalCode,
  4686. List_type_code: "201",
  4687. }
  4688. queryResult = append(queryResult, result)
  4689. }
  4690. }
  4691. admin_user_id, _ := c.GetInt64("admin_user_id")
  4692. adminUser := c.GetAdminUserInfo()
  4693. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4694. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4695. var user_name string
  4696. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4697. if role.ID == 0 {
  4698. user_name = "xxx"
  4699. } else {
  4700. user_name = role.UserName
  4701. }
  4702. baseParams := &models.BaseParams{
  4703. SecretKey: miConfig.SecretKey,
  4704. FixmedinsCode: miConfig.Code,
  4705. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4706. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4707. OrgName: miConfig.OrgName,
  4708. Doctor: user_name,
  4709. }
  4710. if config.IsOpen == 1 {
  4711. for _, item := range queryResult {
  4712. var result string
  4713. if record_type == 1 {
  4714. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  4715. } else if record_type == 2 {
  4716. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  4717. } else if record_type == 3 {
  4718. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  4719. }
  4720. var dat map[string]interface{}
  4721. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4722. fmt.Println(dat)
  4723. } else {
  4724. fmt.Println(err)
  4725. }
  4726. userJSONBytes, _ := json.Marshal(dat)
  4727. var res ResultSix
  4728. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4729. utils.ErrorLog("解析失败:%v", err)
  4730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4731. return
  4732. }
  4733. if res.Infcode == 0 {
  4734. if record_type == 1 {
  4735. service.UpdateBaseDrugById(item.ID)
  4736. } else if record_type == 2 {
  4737. service.UpdateGoodInformaitonByDetail(item.ID)
  4738. } else if record_type == 3 {
  4739. service.UpdateProjectById(item.ID)
  4740. }
  4741. c.ServeSuccessJSON(map[string]interface{}{
  4742. "failed_code": 0,
  4743. "msg": "目录对照成功",
  4744. })
  4745. } else {
  4746. c.ServeSuccessJSON(map[string]interface{}{
  4747. "failed_code": -10,
  4748. "msg": res.ErrMsg,
  4749. })
  4750. }
  4751. }
  4752. }
  4753. }
  4754. func (c *HisApiController) UnCheckCode() {
  4755. ids_str := c.GetString("ids")
  4756. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  4757. admin_user_id, _ := c.GetInt64("admin_user_id")
  4758. ids_arr := strings.Split(ids_str, ",")
  4759. var queryResult []QueryResult
  4760. ids := make([]int64, 0)
  4761. for _, item := range ids_arr {
  4762. id, _ := strconv.ParseInt(item, 10, 64)
  4763. ids = append(ids, id)
  4764. }
  4765. if record_type == 1 {
  4766. drugs, _ := service.GetBatchDrugList(ids)
  4767. for _, item := range drugs {
  4768. result := QueryResult{
  4769. ID: item.ID,
  4770. Name: item.DrugName,
  4771. Code: item.MedicalInsuranceNumber,
  4772. List_type_code: "101",
  4773. }
  4774. queryResult = append(queryResult, result)
  4775. }
  4776. } else if record_type == 2 {
  4777. goods, _ := service.GetBatchGoodInformationList(ids)
  4778. for _, item := range goods {
  4779. result := QueryResult{
  4780. ID: item.ID,
  4781. Name: item.GoodName,
  4782. Code: item.MedicalInsuranceNumber,
  4783. List_type_code: "301",
  4784. }
  4785. queryResult = append(queryResult, result)
  4786. }
  4787. } else if record_type == 3 {
  4788. projects, _ := service.GetBathchMyPorjecgList(ids)
  4789. for _, item := range projects {
  4790. result := QueryResult{
  4791. ID: item.ID,
  4792. Name: item.ProjectName,
  4793. Code: item.MedicalCode,
  4794. List_type_code: "201",
  4795. }
  4796. queryResult = append(queryResult, result)
  4797. }
  4798. }
  4799. adminUser := c.GetAdminUserInfo()
  4800. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4801. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4802. var user_name string
  4803. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4804. if role.ID == 0 {
  4805. user_name = "xxx"
  4806. } else {
  4807. user_name = role.UserName
  4808. }
  4809. baseParams := &models.BaseParams{
  4810. SecretKey: miConfig.SecretKey,
  4811. FixmedinsCode: miConfig.Code,
  4812. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4813. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4814. OrgName: miConfig.OrgName,
  4815. Doctor: user_name,
  4816. }
  4817. if config.IsOpen == 1 {
  4818. for _, item := range queryResult {
  4819. var result string
  4820. if record_type == 1 {
  4821. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  4822. } else if record_type == 2 {
  4823. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  4824. } else if record_type == 3 {
  4825. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  4826. }
  4827. var dat2 map[string]interface{}
  4828. if err := json.Unmarshal([]byte(result), &dat2); err == nil {
  4829. fmt.Println(dat2)
  4830. } else {
  4831. fmt.Println(err)
  4832. }
  4833. userJSONBytes, _ := json.Marshal(dat2)
  4834. var res ResultSix
  4835. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4836. utils.ErrorLog("解析失败:%v", err)
  4837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4838. return
  4839. }
  4840. if res.Infcode == 0 {
  4841. if record_type == 1 {
  4842. service.UpdateDrugByIdDetail(item.ID)
  4843. } else if record_type == 2 {
  4844. service.UpdateGoodInfoById(item.ID)
  4845. } else if record_type == 3 {
  4846. service.UpdateMyProjectById(item.ID)
  4847. }
  4848. c.ServeSuccessJSON(map[string]interface{}{
  4849. "failed_code": 0,
  4850. "msg": "撤销目录对照成功",
  4851. })
  4852. } else {
  4853. c.ServeSuccessJSON(map[string]interface{}{
  4854. "failed_code": -10,
  4855. "msg": res.ErrMsg,
  4856. })
  4857. }
  4858. }
  4859. }
  4860. }
  4861. func (c *HisApiController) GetPatientInfo() {
  4862. id_card_no := c.GetString("id_card_no")
  4863. admin_user_id, _ := c.GetInt64("admin_user_id")
  4864. patient, _ := service.GetPatientByIDCard(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  4865. if patient.ID == 0 {
  4866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4867. return
  4868. }
  4869. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  4870. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  4871. config, _ := service.GetMedicalInsuranceConfig(c.GetAdminUserInfo().CurrentOrgId)
  4872. if config.IsOpen == 1 {
  4873. result := service.Gdyb1101A(id_card_no, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  4874. var dat map[string]interface{}
  4875. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4876. fmt.Println(dat)
  4877. } else {
  4878. fmt.Println(err)
  4879. }
  4880. userJSONBytes, _ := json.Marshal(dat)
  4881. var res ResultTwo
  4882. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4883. utils.ErrorLog("解析失败:%v", err)
  4884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4885. return
  4886. }
  4887. if res.Infcode != 0 {
  4888. c.ServeSuccessJSON(map[string]interface{}{
  4889. "failed_code": -10,
  4890. "msg": res.ErrMsg,
  4891. })
  4892. } else {
  4893. c.ServeSuccessJSON(map[string]interface{}{
  4894. "failed_code": 0,
  4895. "info": res,
  4896. })
  4897. }
  4898. }
  4899. }
  4900. func (c *HisApiController) PsnPutOnRecord() {
  4901. record_type, _ := c.GetInt64("type")
  4902. patient_id, _ := c.GetInt64("patient_id")
  4903. admin_user_id, _ := c.GetInt64("admin_user_id")
  4904. start_time := c.GetString("start_time")
  4905. end_time := c.GetString("end_time")
  4906. adminUser := c.GetAdminUserInfo()
  4907. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4908. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4909. var patients []*models.Patients
  4910. if record_type == 1 { //全部备案
  4911. patient, _ := service.GetAllPatient(adminUser.CurrentOrgId)
  4912. patients = append(patients, patient...)
  4913. } else { //单个备案
  4914. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  4915. patients = append(patients, patient)
  4916. }
  4917. var user_name string
  4918. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4919. if role.ID == 0 {
  4920. user_name = "xxx"
  4921. } else {
  4922. user_name = role.UserName
  4923. }
  4924. if config.IsOpen == 1 {
  4925. for _, item := range patients {
  4926. 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
  4927. resp, requestErr := http.Get(api)
  4928. if requestErr != nil {
  4929. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4930. return
  4931. }
  4932. defer resp.Body.Close()
  4933. body, ioErr := ioutil.ReadAll(resp.Body)
  4934. if ioErr != nil {
  4935. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4937. return
  4938. }
  4939. var respJSON map[string]interface{}
  4940. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4941. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4943. return
  4944. }
  4945. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4946. userJSONBytes, _ := json.Marshal(userJSON)
  4947. var res ResultTwo
  4948. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4949. utils.ErrorLog("解析失败:%v", err)
  4950. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4951. return
  4952. }
  4953. if res.Infcode == 0 {
  4954. result := service.Gdyb2505(res.Output.Baseinfo.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, start_time, end_time)
  4955. var dat map[string]interface{}
  4956. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4957. fmt.Println(dat)
  4958. } else {
  4959. fmt.Println(err)
  4960. }
  4961. userJSONBytes, _ := json.Marshal(dat)
  4962. var res2 ResultThirteen
  4963. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  4964. utils.ErrorLog("解析失败:%v", err)
  4965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4966. return
  4967. }
  4968. if res2.Infcode == 0 {
  4969. psnResult := &models.GdybPsnRecord{
  4970. UserOrgId: adminUser.CurrentOrgId,
  4971. PatientId: item.ID,
  4972. PsnNo: res.Output.Baseinfo.PsnNo,
  4973. Ctime: time.Now().Unix(),
  4974. Mtime: time.Now().Unix(),
  4975. Status: 1,
  4976. IsCancel: 1,
  4977. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  4978. }
  4979. service.CreatePsnRecord(psnResult)
  4980. } else {
  4981. c.ServeSuccessJSON(map[string]interface{}{
  4982. "failed_code": -10,
  4983. "msg": res2.ErrMsg,
  4984. })
  4985. return
  4986. }
  4987. }
  4988. }
  4989. }
  4990. }
  4991. func (c *HisApiController) PsnUnPutOnRecord() {
  4992. id, _ := c.GetInt64("id")
  4993. //record_type, _ := c.GetInt64("type")
  4994. admin_user_id, _ := c.GetInt64("admin_user_id")
  4995. adminUser := c.GetAdminUserInfo()
  4996. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4997. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4998. var user_name string
  4999. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  5000. if role.ID == 0 {
  5001. user_name = "xxx"
  5002. } else {
  5003. user_name = role.UserName
  5004. }
  5005. psn_record, _ := service.GetPsnRecordById(id)
  5006. if psn_record.ID == 0 {
  5007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  5008. return
  5009. }
  5010. if config.IsOpen == 1 {
  5011. result := service.Gdyb2506(psn_record.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  5012. var dat map[string]interface{}
  5013. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5014. fmt.Println(dat)
  5015. } else {
  5016. fmt.Println(err)
  5017. }
  5018. userJSONBytes, _ := json.Marshal(dat)
  5019. var res ResultFourteen
  5020. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5021. utils.ErrorLog("解析失败:%v", err)
  5022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5023. return
  5024. }
  5025. if res.Infcode == 0 {
  5026. psn_record.IsCancel = 2
  5027. service.CreatePsnRecord(&psn_record)
  5028. } else {
  5029. c.ServeSuccessJSON(map[string]interface{}{
  5030. "failed_code": -10,
  5031. "msg": res.ErrMsg,
  5032. })
  5033. return
  5034. }
  5035. }
  5036. }
  5037. func (c *HisApiController) PsnPutNCDSOnRecord() {
  5038. patient_id, _ := c.GetInt64("patient_id")
  5039. insutype := c.GetString("insutype")
  5040. psn_no := c.GetString("psn_no")
  5041. doctor_id, _ := c.GetInt64("doctor_id")
  5042. sick_id, _ := c.GetInt64("sick_id")
  5043. department_id, _ := c.GetInt64("department_id")
  5044. adminUser := c.GetAdminUserInfo()
  5045. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  5046. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5047. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5048. sick, _ := service.FindSickById(sick_id)
  5049. doctor, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, doctor_id)
  5050. if config.IsOpen == 1 {
  5051. 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)
  5052. var dat map[string]interface{}
  5053. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5054. fmt.Println(dat)
  5055. } else {
  5056. fmt.Println(err)
  5057. }
  5058. userJSONBytes, _ := json.Marshal(dat)
  5059. var res2 ResultThirteen
  5060. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  5061. utils.ErrorLog("解析失败:%v", err)
  5062. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5063. return
  5064. }
  5065. if res2.Infcode == 0 {
  5066. psnResult := &models.GdybPsnNcdsRecord{
  5067. UserOrgId: adminUser.CurrentOrgId,
  5068. PatientId: patient.ID,
  5069. PsnNo: psn_no,
  5070. DoctorId: doctor.AdminUserId,
  5071. DepartmentId: department_id,
  5072. SickType: sick_id,
  5073. Insutype: insutype,
  5074. Ctime: time.Now().Unix(),
  5075. Mtime: time.Now().Unix(),
  5076. Status: 1,
  5077. IsCancel: 1,
  5078. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  5079. }
  5080. service.CreatePsnNCDSRecord(psnResult)
  5081. c.ServeSuccessJSON(map[string]interface{}{
  5082. "failed_code": 0,
  5083. "msg": "备案成功",
  5084. "result": psnResult,
  5085. })
  5086. } else {
  5087. c.ServeSuccessJSON(map[string]interface{}{
  5088. "failed_code": -10,
  5089. "msg": res2.ErrMsg,
  5090. })
  5091. return
  5092. }
  5093. }
  5094. }
  5095. func (c *HisApiController) PsnPutUnNCDSOnRecord() {
  5096. id, _ := c.GetInt64("id")
  5097. admin_user_id, _ := c.GetInt64("admin_user_id")
  5098. adminUser := c.GetAdminUserInfo()
  5099. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5100. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5101. var user_name string
  5102. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  5103. if role.ID == 0 {
  5104. user_name = "xxx"
  5105. } else {
  5106. user_name = role.UserName
  5107. }
  5108. psn_record, _ := service.GetPsnNCDSRecordById(id)
  5109. if psn_record.ID == 0 {
  5110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  5111. return
  5112. }
  5113. if config.IsOpen == 1 {
  5114. result := service.Gdyb2504(psn_record.PsnNo, miConfig.OrgName, user_name, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  5115. var dat map[string]interface{}
  5116. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5117. fmt.Println(dat)
  5118. } else {
  5119. fmt.Println(err)
  5120. }
  5121. userJSONBytes, _ := json.Marshal(dat)
  5122. var res ResultFourteen
  5123. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5124. utils.ErrorLog("解析失败:%v", err)
  5125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5126. return
  5127. }
  5128. if res.Infcode == 0 {
  5129. psn_record.IsCancel = 2
  5130. service.CreatePsnNCDSRecord(&psn_record)
  5131. c.ServeSuccessJSON(map[string]interface{}{
  5132. "failed_code": 0,
  5133. "msg": "撤销备案成功",
  5134. })
  5135. } else {
  5136. c.ServeSuccessJSON(map[string]interface{}{
  5137. "failed_code": -10,
  5138. "msg": res.ErrMsg,
  5139. })
  5140. return
  5141. }
  5142. }
  5143. }
  5144. func (c *HisApiController) TestTest() {
  5145. patient, _ := service.GetHisPatientInfo(4, 456, 1619712000)
  5146. fmt.Println(patient.Iinfo)
  5147. }
  5148. type CustomData struct {
  5149. MsgId string
  5150. PsnNo string
  5151. Info string
  5152. }
  5153. func (c *HisApiController) ReversalData() {
  5154. var customData []*CustomData
  5155. custom := &CustomData{
  5156. MsgId: "H44022900158202103301714472004",
  5157. PsnNo: "44020000001101329945",
  5158. Info: "2207",
  5159. }
  5160. customData = append(customData, custom)
  5161. custom1 := &CustomData{
  5162. MsgId: "H4402290015820210330172057803",
  5163. PsnNo: "44020000001101161813",
  5164. Info: "2207",
  5165. }
  5166. customData = append(customData, custom1)
  5167. custom2 := &CustomData{
  5168. MsgId: "H44022900158202103301705198813",
  5169. PsnNo: "44190000133097375417",
  5170. Info: "2207",
  5171. }
  5172. customData = append(customData, custom2)
  5173. custom3 := &CustomData{
  5174. MsgId: "H44022900158202103301715524756",
  5175. PsnNo: "44020000001100187221",
  5176. Info: "2207",
  5177. }
  5178. customData = append(customData, custom3)
  5179. custom4 := &CustomData{
  5180. MsgId: "H44022900158202103301730376224",
  5181. PsnNo: "44020000001101959155",
  5182. Info: "2207",
  5183. }
  5184. customData = append(customData, custom4)
  5185. custom5 := &CustomData{
  5186. MsgId: "H44022900158202103301748008725",
  5187. PsnNo: "44020000001104246641",
  5188. Info: "2207",
  5189. }
  5190. customData = append(customData, custom5)
  5191. custom6 := &CustomData{
  5192. MsgId: "H44022900158202103301718096755",
  5193. PsnNo: "44020000001102211860",
  5194. Info: "2207",
  5195. }
  5196. customData = append(customData, custom6)
  5197. custom7 := &CustomData{
  5198. MsgId: "H44022900158202103301736551640",
  5199. PsnNo: "44020000001102687718",
  5200. Info: "2207",
  5201. }
  5202. customData = append(customData, custom7)
  5203. custom8 := &CustomData{
  5204. MsgId: "H44022900158202103301743097676",
  5205. PsnNo: "44020000001102127785",
  5206. Info: "2207",
  5207. }
  5208. customData = append(customData, custom8)
  5209. custom9 := &CustomData{
  5210. MsgId: "H44022900158202103301712304203",
  5211. PsnNo: "44020000001101518097",
  5212. Info: "2207",
  5213. }
  5214. customData = append(customData, custom9)
  5215. custom10 := &CustomData{
  5216. MsgId: "H44022900158202103301738448785",
  5217. PsnNo: "44020000001100500813",
  5218. Info: "2207",
  5219. }
  5220. customData = append(customData, custom10)
  5221. custom11 := &CustomData{
  5222. MsgId: "H44022900158202103301732455843",
  5223. PsnNo: "44020000001102690557",
  5224. Info: "2207",
  5225. }
  5226. customData = append(customData, custom11)
  5227. custom12 := &CustomData{
  5228. MsgId: "H44022900158202103301745421708",
  5229. PsnNo: "44020000001102211928",
  5230. Info: "2207",
  5231. }
  5232. customData = append(customData, custom12)
  5233. custom1212 := &CustomData{
  5234. MsgId: "H440229001582021033017351627",
  5235. PsnNo: "44020000001102481733",
  5236. Info: "2207",
  5237. }
  5238. customData = append(customData, custom1212)
  5239. custom13 := &CustomData{
  5240. MsgId: "H44022900158202103301740327951",
  5241. PsnNo: "44020000001103174866",
  5242. Info: "2207",
  5243. }
  5244. customData = append(customData, custom13)
  5245. custom14 := &CustomData{
  5246. MsgId: "H4402290015820210330174922668",
  5247. PsnNo: "44020000001102927272",
  5248. Info: "2207",
  5249. }
  5250. customData = append(customData, custom14)
  5251. custom15 := &CustomData{
  5252. MsgId: "H44022900158202103301752362273",
  5253. PsnNo: "44020000001102942890",
  5254. Info: "2207",
  5255. }
  5256. customData = append(customData, custom15)
  5257. custom16 := &CustomData{
  5258. MsgId: "H44022900158202103301751082917",
  5259. PsnNo: "44020000001101662162",
  5260. Info: "2207",
  5261. }
  5262. customData = append(customData, custom16)
  5263. custom17 := &CustomData{
  5264. MsgId: "H44022900158202103301754147728",
  5265. PsnNo: "44020000000229014511",
  5266. Info: "2207",
  5267. }
  5268. customData = append(customData, custom17)
  5269. adminUser := c.GetAdminUserInfo()
  5270. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5271. for _, item := range customData {
  5272. result := service.Gdyb2601(item.PsnNo, item.MsgId, item.Info, miConfig.OrgName, "张俊杰", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  5273. fmt.Println(result)
  5274. }
  5275. }
  5276. func (c *HisApiController) ReversalOtherData() {
  5277. var customData []*CustomData
  5278. custom := &CustomData{
  5279. MsgId: "H44022900158202103301714472004",
  5280. PsnNo: "44020000001101329945",
  5281. Info: "2208",
  5282. }
  5283. customData = append(customData, custom)
  5284. custom1 := &CustomData{
  5285. MsgId: "H4402290015820210330172057803",
  5286. PsnNo: "44020000001101161813",
  5287. Info: "2208",
  5288. }
  5289. customData = append(customData, custom1)
  5290. custom2 := &CustomData{
  5291. MsgId: "H44022900158202103301705198813",
  5292. PsnNo: "44190000133097375417",
  5293. Info: "2208",
  5294. }
  5295. customData = append(customData, custom2)
  5296. custom3 := &CustomData{
  5297. MsgId: "H44022900158202103301715524756",
  5298. PsnNo: "44020000001100187221",
  5299. Info: "2208",
  5300. }
  5301. customData = append(customData, custom3)
  5302. custom4 := &CustomData{
  5303. MsgId: "H44022900158202103301730376224",
  5304. PsnNo: "44020000001101959155",
  5305. Info: "2208",
  5306. }
  5307. customData = append(customData, custom4)
  5308. custom5 := &CustomData{
  5309. MsgId: "H44022900158202103301748008725",
  5310. PsnNo: "44020000001104246641",
  5311. Info: "2208",
  5312. }
  5313. customData = append(customData, custom5)
  5314. custom6 := &CustomData{
  5315. MsgId: "H44022900158202103301718096755",
  5316. PsnNo: "44020000001102211860",
  5317. Info: "2208",
  5318. }
  5319. customData = append(customData, custom6)
  5320. custom7 := &CustomData{
  5321. MsgId: "H44022900158202103301736551640",
  5322. PsnNo: "44020000001102687718",
  5323. Info: "2208",
  5324. }
  5325. customData = append(customData, custom7)
  5326. custom8 := &CustomData{
  5327. MsgId: "H44022900158202103301743097676",
  5328. PsnNo: "44020000001102127785",
  5329. Info: "2208",
  5330. }
  5331. customData = append(customData, custom8)
  5332. custom9 := &CustomData{
  5333. MsgId: "H44022900158202103301712304203",
  5334. PsnNo: "44020000001101518097",
  5335. Info: "2208",
  5336. }
  5337. customData = append(customData, custom9)
  5338. custom10 := &CustomData{
  5339. MsgId: "H44022900158202103301738448785",
  5340. PsnNo: "44020000001100500813",
  5341. Info: "2208",
  5342. }
  5343. customData = append(customData, custom10)
  5344. custom11 := &CustomData{
  5345. MsgId: "H44022900158202103301732455843",
  5346. PsnNo: "44020000001102690557",
  5347. Info: "2208",
  5348. }
  5349. customData = append(customData, custom11)
  5350. custom12 := &CustomData{
  5351. MsgId: "H44022900158202103301745421708",
  5352. PsnNo: "44020000001102211928",
  5353. Info: "2208",
  5354. }
  5355. customData = append(customData, custom12)
  5356. custom1212 := &CustomData{
  5357. MsgId: "H440229001582021033017351627",
  5358. PsnNo: "44020000001102481733",
  5359. Info: "2208",
  5360. }
  5361. customData = append(customData, custom1212)
  5362. custom13 := &CustomData{
  5363. MsgId: "H44022900158202103301740327951",
  5364. PsnNo: "44020000001103174866",
  5365. Info: "2208",
  5366. }
  5367. customData = append(customData, custom13)
  5368. custom14 := &CustomData{
  5369. MsgId: "H4402290015820210330174922668",
  5370. PsnNo: "44020000001102927272",
  5371. Info: "2208",
  5372. }
  5373. customData = append(customData, custom14)
  5374. custom15 := &CustomData{
  5375. MsgId: "H44022900158202103301752362273",
  5376. PsnNo: "44020000001102942890",
  5377. Info: "2208",
  5378. }
  5379. customData = append(customData, custom15)
  5380. custom16 := &CustomData{
  5381. MsgId: "H44022900158202103301751082917",
  5382. PsnNo: "44020000001101662162",
  5383. Info: "2208",
  5384. }
  5385. customData = append(customData, custom16)
  5386. custom17 := &CustomData{
  5387. MsgId: "H44022900158202103301754147728",
  5388. PsnNo: "44020000000229014511",
  5389. Info: "2208",
  5390. }
  5391. customData = append(customData, custom17)
  5392. adminUser := c.GetAdminUserInfo()
  5393. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5394. for _, item := range customData {
  5395. result := service.Gdyb2601(item.PsnNo, item.MsgId, item.Info, miConfig.OrgName, "张俊杰", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  5396. fmt.Println(result)
  5397. }
  5398. }
  5399. func PathExists(path string) (bool, error) {
  5400. _, err := os.Stat(path)
  5401. if err == nil {
  5402. return true, nil
  5403. }
  5404. if os.IsNotExist(err) {
  5405. return false, nil
  5406. }
  5407. return false, err
  5408. }
  5409. //创建文件夹
  5410. func Mkdir(dir string) {
  5411. // 创建文件夹
  5412. exist, err := PathExists(dir)
  5413. if err != nil {
  5414. fmt.Println(err.Error())
  5415. } else {
  5416. if exist {
  5417. fmt.Println(dir + "文件夹已存在!")
  5418. } else {
  5419. // 文件夹名称,权限
  5420. err := os.Mkdir(dir, os.ModePerm)
  5421. if err != nil {
  5422. fmt.Println(dir+"文件夹创建失败:", err.Error())
  5423. } else {
  5424. fmt.Println(dir + "文件夹创建成功!")
  5425. }
  5426. }
  5427. }
  5428. }
  5429. //压缩文件
  5430. func Zip(srcFile string, destZip string) error {
  5431. zipfile, err := os.Create(destZip)
  5432. if err != nil {
  5433. return err
  5434. }
  5435. defer zipfile.Close()
  5436. archive := zip.NewWriter(zipfile)
  5437. defer archive.Close()
  5438. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  5439. if err != nil {
  5440. return err
  5441. }
  5442. header, err := zip.FileInfoHeader(info)
  5443. if err != nil {
  5444. return err
  5445. }
  5446. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  5447. // header.Name = path
  5448. if info.IsDir() {
  5449. header.Name += "/"
  5450. } else {
  5451. header.Method = zip.Deflate
  5452. }
  5453. writer, err := archive.CreateHeader(header)
  5454. if err != nil {
  5455. return err
  5456. }
  5457. if !info.IsDir() {
  5458. file, err := os.Open(path)
  5459. if err != nil {
  5460. return err
  5461. }
  5462. defer file.Close()
  5463. _, err = io.Copy(writer, file)
  5464. }
  5465. return err
  5466. })
  5467. return err
  5468. }
  5469. func ReadFile(filePath string) []byte {
  5470. f, err := os.Open(filePath)
  5471. if err != nil {
  5472. fmt.Println("read file fail", err)
  5473. return nil
  5474. }
  5475. defer f.Close()
  5476. fd, err := ioutil.ReadAll(f)
  5477. if err != nil {
  5478. fmt.Println("read to fd fail", err)
  5479. return nil
  5480. }
  5481. return fd
  5482. }
  5483. func RemoveRepeatedCode(arr []string) (newArr []string) {
  5484. newArr = make([]string, 0)
  5485. for i := 0; i < len(arr); i++ {
  5486. repeat := false
  5487. for j := i + 1; j < len(arr); j++ {
  5488. if arr[i] == arr[j] {
  5489. repeat = true
  5490. break
  5491. }
  5492. }
  5493. if !repeat {
  5494. newArr = append(newArr, arr[i])
  5495. }
  5496. }
  5497. return
  5498. }
  5499. func saveRegisterLog(result string) {
  5500. org_id, _ := beego.AppConfig.Int64("org_id")
  5501. miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  5502. dir := miConfig.OrgName + "日志"
  5503. utils.Mkdir(dir)
  5504. month := time.Unix(1557042972, 0).Format("1")
  5505. year := time.Now().Format("2006")
  5506. month = time.Now().Format("01")
  5507. day := time.Now().Format("02")
  5508. file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  5509. file_name := file + ".txt"
  5510. file_path := miConfig.OrgName + "日志" + "/" + file_name
  5511. exist, _ := utils.PathExists(file_path)
  5512. if exist { //存在
  5513. fmt.Println("存在")
  5514. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  5515. if err != nil {
  5516. fmt.Println("read fail")
  5517. }
  5518. content := "\r\n" + result
  5519. n, _ := f.Seek(0, 2)
  5520. _, err = f.WriteAt([]byte(content), n)
  5521. } else { //不存在
  5522. fmt.Println("文件不存在,创建文件")
  5523. f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  5524. defer f.Close()
  5525. if err != nil {
  5526. } else {
  5527. _, err = f.Write([]byte("记录日志"))
  5528. }
  5529. }
  5530. }
  5531. func saveLog(result string, request string, infno string) {
  5532. org_id, _ := beego.AppConfig.Int64("org_id")
  5533. miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  5534. dir := miConfig.OrgName + "日志"
  5535. utils.Mkdir(dir)
  5536. month := time.Unix(1557042972, 0).Format("1")
  5537. year := time.Now().Format("2006")
  5538. month = time.Now().Format("01")
  5539. day := time.Now().Format("02")
  5540. file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  5541. file_name := file + ".txt"
  5542. file_path := miConfig.OrgName + "日志" + "/" + file_name
  5543. exist, _ := utils.PathExists(file_path)
  5544. if exist { //存在
  5545. fmt.Println("存在")
  5546. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  5547. if err != nil {
  5548. fmt.Println("read fail")
  5549. }
  5550. content := infno + "\r\n" + "\r\n" + "\r\n" + "\r\n" + request + "\r\n" + "\r\n" + "\r\n" + "\r\n" + result
  5551. n, _ := f.Seek(0, 2)
  5552. _, err = f.WriteAt([]byte(content), n)
  5553. } else { //不存在
  5554. fmt.Println("文件不存在,创建文件")
  5555. f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  5556. defer f.Close()
  5557. if err != nil {
  5558. } else {
  5559. _, err = f.Write([]byte("记录日志"))
  5560. }
  5561. }
  5562. }