his_api_controller.go 233KB

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