his_api_controller.go 268KB

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