his_api_controller.go 235KB

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