his_api_controller.go 233KB

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