his_api_controller.go 267KB

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