zh_his_api_controller.go 279KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064
  1. package zh
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "fmt"
  6. "gdyb/controllers"
  7. "gdyb/enums"
  8. "gdyb/models"
  9. "gdyb/service"
  10. "gdyb/utils"
  11. "github.com/astaxie/beego"
  12. "github.com/axgle/mahonia"
  13. "github.com/jinzhu/gorm"
  14. "io/ioutil"
  15. "math"
  16. "math/rand"
  17. "net/http"
  18. "os"
  19. "regexp"
  20. "strconv"
  21. "strings"
  22. "syscall"
  23. "time"
  24. "unsafe"
  25. "github.com/gorilla/websocket"
  26. "net/url"
  27. )
  28. type ZHHisApiController struct {
  29. controllers.BaseAuthAPIController
  30. }
  31. type ResultSix struct {
  32. Cainfo interface{} `json:"cainfo"`
  33. ErrMsg string `json:"err_msg"`
  34. InfRefmsgid string `json:"inf_refmsgid"`
  35. Infcode int64 `json:"infcode"`
  36. Output struct {
  37. } `json:"output"`
  38. RefmsgTime string `json:"refmsg_time"`
  39. RespondTime string `json:"respond_time"`
  40. Signtype interface{} `json:"signtype"`
  41. WarnMsg interface{} `json:"warn_msg"`
  42. }
  43. type ResultTwo struct {
  44. ErrMsg string `json:"err_msg"`
  45. InfRefmsgid string `json:"inf_refmsgid"`
  46. Infcode int64 `json:"infcode"`
  47. Output struct {
  48. Baseinfo struct {
  49. Age float64 `json:"age"`
  50. Certno string `json:"certno"`
  51. Gend string `json:"gend"`
  52. //Brdy string `json:"brdy"`
  53. Naty string `json:"naty"`
  54. PsnCertType string `json:"psn_cert_type"`
  55. PsnName string `json:"psn_name"`
  56. PsnNo string `json:"psn_no"`
  57. } `json:"baseinfo"`
  58. Idetinfo []interface{} `json:"idetinfo"`
  59. Iinfo []struct {
  60. Balc float64 `json:"balc"`
  61. CvlservFlag string `json:"cvlserv_flag"`
  62. EmpName string `json:"emp_name"`
  63. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  64. Insutype string `json:"insutype"`
  65. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  66. //PausInsuDate string `json:"paus_insu_date"`
  67. //PsnInsuDate string `json:"psn_insu_date"`
  68. PsnInsuStas string `json:"psn_insu_stas"`
  69. PsnType string `json:"psn_type"`
  70. } `json:"insuinfo"`
  71. } `json:"output"`
  72. RefmsgTime string `json:"refmsg_time"`
  73. RespondTime string `json:"respond_time"`
  74. Signtype interface{} `json:"signtype"`
  75. WarnInfo interface{} `json:"warn_info"`
  76. }
  77. type ResultTwohb struct {
  78. ErrMsg string `json:"err_msg"`
  79. InfRefmsgid string `json:"inf_refmsgid"`
  80. Infcode int64 `json:"infcode"`
  81. Output struct {
  82. Baseinfo struct {
  83. Age float64 `json:"age"`
  84. Certno string `json:"certno"`
  85. Gend string `json:"gend"`
  86. //Brdy string `json:"brdy"`
  87. Naty string `json:"naty"`
  88. PsnCertType string `json:"psn_cert_type"`
  89. PsnName string `json:"psn_name"`
  90. PsnNo string `json:"psn_no"`
  91. ExpContent ExpContent `json:"exp_content"`
  92. } `json:"baseinfo"`
  93. Idetinfo []interface{} `json:"idetinfo"`
  94. Iinfo []struct {
  95. Balc float64 `json:"balc"`
  96. CvlservFlag string `json:"cvlserv_flag"`
  97. EmpName string `json:"emp_name"`
  98. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  99. Insutype string `json:"insutype"`
  100. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  101. //PausInsuDate string `json:"paus_insu_date"`
  102. //PsnInsuDate string `json:"psn_insu_date"`
  103. PsnInsuStas string `json:"psn_insu_stas"`
  104. PsnType string `json:"psn_type"`
  105. } `json:"insuinfo"`
  106. } `json:"output"`
  107. RefmsgTime string `json:"refmsg_time"`
  108. RespondTime string `json:"respond_time"`
  109. Signtype interface{} `json:"signtype"`
  110. WarnInfo interface{} `json:"warn_info"`
  111. }
  112. type ExpContent struct {
  113. MdtrtCertType string `json:"mdtrt_cert_type"`
  114. MdtrtCertNo string `json:"mdtrt_cert_no"`
  115. }
  116. type AHResultTwo struct {
  117. ErrMsg string `json:"err_msg"`
  118. InfRefmsgid string `json:"inf_refmsgid"`
  119. Infcode int64 `json:"infcode"`
  120. Output struct {
  121. Baseinfo struct {
  122. Age float64 `json:"age"`
  123. Certno string `json:"certno"`
  124. Gend string `json:"gend"`
  125. Naty string `json:"naty"`
  126. //Brdy string `json:"brdy"`
  127. PsnCertType string `json:"psn_cert_type"`
  128. PsnName string `json:"psn_name"`
  129. PsnNo string `json:"psn_no"`
  130. } `json:"baseinfo"`
  131. Idetinfo []interface{} `json:"idetinfo"`
  132. Iinfo []struct {
  133. Balc float64 `json:"balc"`
  134. CvlservFlag string `json:"cvlserv_flag"`
  135. EmpName string `json:"emp_name"`
  136. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  137. Insutype string `json:"insutype"`
  138. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  139. PsnInsuStas string `json:"psn_insu_stas"`
  140. PsnType string `json:"psn_type"`
  141. } `json:"insuinfo"`
  142. } `json:"output"`
  143. RefmsgTime string `json:"refmsg_time"`
  144. RespondTime string `json:"respond_time"`
  145. Signtype interface{} `json:"signtype"`
  146. WarnInfo interface{} `json:"warn_info"`
  147. }
  148. type ResultTwo10265 struct {
  149. ErrMsg string `json:"err_msg"`
  150. InfRefmsgid string `json:"inf_refmsgid"`
  151. Infcode string `json:"infcode"`
  152. Output struct {
  153. Baseinfo struct {
  154. Age float64 `json:"age"`
  155. Certno string `json:"certno"`
  156. Gend string `json:"gend"`
  157. //Brdy string `json:"brdy"`
  158. Naty string `json:"naty"`
  159. PsnCertType string `json:"psn_cert_type"`
  160. PsnName string `json:"psn_name"`
  161. PsnNo string `json:"psn_no"`
  162. } `json:"baseinfo"`
  163. Idetinfo []interface{} `json:"idetinfo"`
  164. Iinfo []struct {
  165. Balc float64 `json:"balc"`
  166. CvlservFlag string `json:"cvlserv_flag"`
  167. EmpName string `json:"emp_name"`
  168. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  169. Insutype string `json:"insutype"`
  170. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  171. PsnInsuStas string `json:"psn_insu_stas"`
  172. PsnType string `json:"psn_type"`
  173. } `json:"insuinfo"`
  174. } `json:"output"`
  175. RefmsgTime string `json:"refmsg_time"`
  176. RespondTime string `json:"respond_time"`
  177. Signtype interface{} `json:"signtype"`
  178. WarnInfo interface{} `json:"warn_info"`
  179. }
  180. type ResultThree struct {
  181. Cainfo interface{} `json:"cainfo"`
  182. ErrMsg string `json:"err_msg"`
  183. InfRefmsgid string `json:"inf_refmsgid"`
  184. Infcode int64 `json:"infcode"`
  185. Output struct {
  186. Result struct {
  187. MdtrtID string `json:"mdtrt_id"`
  188. } `json:"result"`
  189. } `json:"output"`
  190. RefmsgTime string `json:"refmsg_time"`
  191. RespondTime string `json:"respond_time"`
  192. Signtype interface{} `json:"signtype"`
  193. WarnMsg interface{} `json:"warn_msg"`
  194. }
  195. type ResultThree10265 struct {
  196. Cainfo interface{} `json:"cainfo"`
  197. ErrMsg string `json:"err_msg"`
  198. InfRefmsgid string `json:"inf_refmsgid"`
  199. Infcode string `json:"infcode"`
  200. Output struct {
  201. Result struct {
  202. MdtrtID string `json:"mdtrt_id"`
  203. } `json:"result"`
  204. } `json:"output"`
  205. RefmsgTime string `json:"refmsg_time"`
  206. RespondTime string `json:"respond_time"`
  207. Signtype interface{} `json:"signtype"`
  208. WarnMsg interface{} `json:"warn_msg"`
  209. }
  210. type ResultFour struct {
  211. Cainfo string `json:"cainfo"`
  212. ErrMsg string `json:"err_msg"`
  213. InfRefmsgid string `json:"inf_refmsgid"`
  214. Infcode int64 `json:"infcode"`
  215. Output struct {
  216. Result []struct {
  217. BasMednFlag string `json:"bas_medn_flag"`
  218. ChldMedcFlag string `json:"chld_medc_flag"`
  219. ChrgitmLv string `json:"chrgitm_lv"`
  220. Cnt float64 `json:"cnt"`
  221. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  222. DrtReimFlag string `json:"drt_reim_flag"`
  223. FeedetlSn string `json:"feedetl_sn"`
  224. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  225. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  226. InscpScpAmt float64 `json:"inscp_scp_amt"`
  227. ListSpItemFlag string `json:"list_sp_item_flag"`
  228. LmtUsedFlag string `json:"lmt_used_flag"`
  229. MedChrgitmType string `json:"med_chrgitm_type"`
  230. Memo string `json:"memo"`
  231. OverlmtAmt float64 `json:"overlmt_amt"`
  232. PreselfpayAmt float64 `json:"preselfpay_amt"`
  233. Pric float64 `json:"pric"`
  234. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  235. SelfpayProp float64 `json:"selfpay_prop"`
  236. } `json:"result"`
  237. } `json:"output"`
  238. RefmsgTime string `json:"refmsg_time"`
  239. RespondTime string `json:"respond_time"`
  240. Signtype string `json:"signtype"`
  241. WarnMsg string `json:"warn_msg"`
  242. }
  243. type ResultFour10265 struct {
  244. Cainfo string `json:"cainfo"`
  245. ErrMsg string `json:"err_msg"`
  246. InfRefmsgid string `json:"inf_refmsgid"`
  247. Infcode string `json:"infcode"`
  248. Output struct {
  249. Result []struct {
  250. BasMednFlag string `json:"bas_medn_flag"`
  251. ChldMedcFlag string `json:"chld_medc_flag"`
  252. ChrgitmLv string `json:"chrgitm_lv"`
  253. Cnt float64 `json:"cnt"`
  254. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  255. DrtReimFlag string `json:"drt_reim_flag"`
  256. FeedetlSn string `json:"feedetl_sn"`
  257. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  258. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  259. InscpScpAmt float64 `json:"inscp_scp_amt"`
  260. ListSpItemFlag string `json:"list_sp_item_flag"`
  261. LmtUsedFlag string `json:"lmt_used_flag"`
  262. MedChrgitmType string `json:"med_chrgitm_type"`
  263. Memo string `json:"memo"`
  264. OverlmtAmt float64 `json:"overlmt_amt"`
  265. PreselfpayAmt float64 `json:"preselfpay_amt"`
  266. Pric float64 `json:"pric"`
  267. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  268. SelfpayProp float64 `json:"selfpay_prop"`
  269. } `json:"result"`
  270. } `json:"output"`
  271. RefmsgTime string `json:"refmsg_time"`
  272. RespondTime string `json:"respond_time"`
  273. Signtype string `json:"signtype"`
  274. WarnMsg string `json:"warn_msg"`
  275. }
  276. type ResultFive struct {
  277. Balc float64 `json:"balc"`
  278. CvlservFlag string `json:"cvlserv_flag"`
  279. EmpName string `json:"emp_name"`
  280. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  281. Insutype string `json:"insutype"`
  282. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  283. PausInsuDate string `json:"paus_insu_date"`
  284. PsnInsuDate string `json:"psn_insu_date"`
  285. PsnInsuStas string `json:"psn_insu_stas"`
  286. PsnType string `json:"psn_type"`
  287. }
  288. type ResultSevenTwo struct {
  289. Cainfo string `json:"cainfo"`
  290. ErrMsg string `json:"err_msg"`
  291. InfRefmsgid string `json:"inf_refmsgid"`
  292. Infcode int64 `json:"infcode"`
  293. Output struct {
  294. Setldetail []interface{} `json:"setldetail"`
  295. Setlinfo struct {
  296. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  297. AcctPay float64 `json:"acct_pay"`
  298. ActPayDedc float64 `json:"act_pay_dedc"`
  299. Age string `json:"age"`
  300. Balc float64 `json:"balc"`
  301. //Brdy string `json:"brdy"`
  302. Certno string `json:"certno"`
  303. ClrOptins string `json:"clr_optins"`
  304. ClrType string `json:"clr_type"`
  305. ClrWay string `json:"clr_way"`
  306. CvlservFlag string `json:"cvlserv_flag"`
  307. CvlservPay float64 `json:"cvlserv_pay"`
  308. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  309. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  310. Gend string `json:"gend"`
  311. HifesPay float64 `json:"hifes_pay"`
  312. HifmiPay float64 `json:"hifmi_pay"`
  313. HifpPay float64 `json:"hifp_pay"`
  314. HospPartAmt float64 `json:"hosp_part_amt"`
  315. InscpScpAmt float64 `json:"inscp_scp_amt"`
  316. Insutype string `json:"insutype"`
  317. MafPay float64 `json:"maf_pay"`
  318. MdtrtCertType string `json:"mdtrt_cert_type"`
  319. HifobPay float64 `json:"hifob_pay"`
  320. MdtrtID string `json:"mdtrt_id"`
  321. MedType string `json:"med_type"`
  322. MedfeeSumamt float64 `json:"medfee_sumamt"`
  323. MedinsSetlID string `json:"medins_setl_id"`
  324. Naty string `json:"naty"`
  325. OthPay float64 `json:"oth_pay"`
  326. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  327. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  328. PreselfpayAmt float64 `json:"preselfpay_amt"`
  329. PsnCashPay float64 `json:"psn_cash_pay"`
  330. PsnCertType string `json:"psn_cert_type"`
  331. PsnName string `json:"psn_name"`
  332. PsnNo string `json:"psn_no"`
  333. PsnPartAmt float64 `json:"psn_part_amt"`
  334. PsnType string `json:"psn_type"`
  335. SetlID string `json:"setl_id"`
  336. SetlTime string `json:"setl_time"`
  337. } `json:"setlinfo"`
  338. } `json:"output"`
  339. RefmsgTime string `json:"refmsg_time"`
  340. RespondTime string `json:"respond_time"`
  341. Signtype interface{} `json:"signtype"`
  342. WarnMsg interface{} `json:"warn_msg"`
  343. }
  344. type ResultSeven struct {
  345. Cainfo string `json:"cainfo"`
  346. ErrMsg string `json:"err_msg"`
  347. InfRefmsgid string `json:"inf_refmsgid"`
  348. Infcode int64 `json:"infcode"`
  349. Output struct {
  350. Setldetail []interface{} `json:"setldetail"`
  351. Setlinfo struct {
  352. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  353. AcctPay float64 `json:"acct_pay"`
  354. ActPayDedc float64 `json:"act_pay_dedc"`
  355. Age float64 `json:"age"`
  356. Balc float64 `json:"balc"`
  357. //Brdy string `json:"brdy"`
  358. Certno string `json:"certno"`
  359. ClrOptins string `json:"clr_optins"`
  360. ClrType string `json:"clr_type"`
  361. ClrWay string `json:"clr_way"`
  362. CvlservFlag string `json:"cvlserv_flag"`
  363. CvlservPay float64 `json:"cvlserv_pay"`
  364. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  365. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  366. Gend string `json:"gend"`
  367. HifesPay float64 `json:"hifes_pay"`
  368. HifmiPay float64 `json:"hifmi_pay"`
  369. HifpPay float64 `json:"hifp_pay"`
  370. HospPartAmt float64 `json:"hosp_part_amt"`
  371. InscpScpAmt float64 `json:"inscp_scp_amt"`
  372. Insutype string `json:"insutype"`
  373. MafPay float64 `json:"maf_pay"`
  374. MdtrtCertType string `json:"mdtrt_cert_type"`
  375. HifobPay float64 `json:"hifob_pay"`
  376. MdtrtID string `json:"mdtrt_id"`
  377. MedType string `json:"med_type"`
  378. MedfeeSumamt float64 `json:"medfee_sumamt"`
  379. MedinsSetlID string `json:"medins_setl_id"`
  380. Naty string `json:"naty"`
  381. OthPay float64 `json:"oth_pay"`
  382. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  383. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  384. PreselfpayAmt float64 `json:"preselfpay_amt"`
  385. PsnCashPay float64 `json:"psn_cash_pay"`
  386. PsnCertType string `json:"psn_cert_type"`
  387. PsnName string `json:"psn_name"`
  388. PsnNo string `json:"psn_no"`
  389. PsnPartAmt float64 `json:"psn_part_amt"`
  390. PsnType string `json:"psn_type"`
  391. SetlID string `json:"setl_id"`
  392. SetlTime string `json:"setl_time"`
  393. } `json:"setlinfo"`
  394. } `json:"output"`
  395. RefmsgTime string `json:"refmsg_time"`
  396. RespondTime string `json:"respond_time"`
  397. Signtype interface{} `json:"signtype"`
  398. WarnMsg interface{} `json:"warn_msg"`
  399. }
  400. type ResultSeven10265 struct {
  401. Cainfo string `json:"cainfo"`
  402. ErrMsg string `json:"err_msg"`
  403. InfRefmsgid string `json:"inf_refmsgid"`
  404. Infcode string `json:"infcode"`
  405. Output struct {
  406. Setldetail []interface{} `json:"setldetail"`
  407. Setlinfo struct {
  408. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  409. AcctPay float64 `json:"acct_pay"`
  410. ActPayDedc float64 `json:"act_pay_dedc"`
  411. Age float64 `json:"age"`
  412. Balc float64 `json:"balc"`
  413. //Brdy string `json:"brdy"`
  414. Certno string `json:"certno"`
  415. ClrOptins string `json:"clr_optins"`
  416. ClrType string `json:"clr_type"`
  417. ClrWay string `json:"clr_way"`
  418. CvlservFlag string `json:"cvlserv_flag"`
  419. CvlservPay float64 `json:"cvlserv_pay"`
  420. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  421. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  422. Gend string `json:"gend"`
  423. HifesPay float64 `json:"hifes_pay"`
  424. HifmiPay float64 `json:"hifmi_pay"`
  425. HifpPay float64 `json:"hifp_pay"`
  426. HospPartAmt float64 `json:"hosp_part_amt"`
  427. InscpScpAmt float64 `json:"inscp_scp_amt"`
  428. Insutype string `json:"insutype"`
  429. MafPay float64 `json:"maf_pay"`
  430. MdtrtCertType string `json:"mdtrt_cert_type"`
  431. HifobPay float64 `json:"hifob_pay"`
  432. MdtrtID string `json:"mdtrt_id"`
  433. MedType string `json:"med_type"`
  434. MedfeeSumamt float64 `json:"medfee_sumamt"`
  435. MedinsSetlID string `json:"medins_setl_id"`
  436. Naty string `json:"naty"`
  437. OthPay float64 `json:"oth_pay"`
  438. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  439. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  440. PreselfpayAmt float64 `json:"preselfpay_amt"`
  441. PsnCashPay float64 `json:"psn_cash_pay"`
  442. PsnCertType string `json:"psn_cert_type"`
  443. PsnName string `json:"psn_name"`
  444. PsnNo string `json:"psn_no"`
  445. PsnPartAmt float64 `json:"psn_part_amt"`
  446. PsnType string `json:"psn_type"`
  447. SetlID string `json:"setl_id"`
  448. SetlTime string `json:"setl_time"`
  449. } `json:"setlinfo"`
  450. } `json:"output"`
  451. RefmsgTime string `json:"refmsg_time"`
  452. RespondTime string `json:"respond_time"`
  453. Signtype interface{} `json:"signtype"`
  454. WarnMsg interface{} `json:"warn_msg"`
  455. }
  456. type ResultSixteen struct {
  457. Cainfo string `json:"cainfo"`
  458. ErrMsg string `json:"err_msg"`
  459. InfRefmsgid string `json:"inf_refmsgid"`
  460. Infcode int64 `json:"infcode"`
  461. Output struct {
  462. Setldetail []interface{} `json:"setldetail"`
  463. Setlinfo struct {
  464. MdtrtID string `json:"mdtrt_id"`
  465. SetlID string `json:"setl_id"`
  466. ClrOptins string `json:"clr_optins"`
  467. SetlTime string `json:"setl_time"`
  468. MedfeeSumamt float64 `json:"medfee_sumamt"`
  469. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  470. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  471. PreselfpayAmt float64 `json:"preselfpay_amt"`
  472. InscpScpAmt float64 `json:"inscp_scp_amt"`
  473. ActPayDedc float64 `json:"act_pay_dedc"`
  474. HifpPay float64 `json:"hifp_pay"`
  475. PoolPropSe float64 `json:"pool_prop_selfpay"`
  476. Lfpay float64 `json:"selfpay"`
  477. CvlservPay float64 `json:"cvlserv_pay"`
  478. HifesPay float64 `json:"hifes_pay"`
  479. HifmiPay float64 `json:"hifmi_pay"`
  480. HifobPay float64 `json:"hifob_pay"`
  481. MafPay float64 `json:"maf_pay"`
  482. OthPay float64 `json:"oth_pay"`
  483. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  484. PsnPartAmt float64 `json:"psn_part_amt"`
  485. AcctPay float64 `json:"acct_pay"`
  486. Balc float64 `json:"balc"`
  487. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  488. HospPartAmt float64 `json:"hosp_part_amt"`
  489. MedinsSetlID string `json:"medins_setl_id"`
  490. PdnCashPay string `json:"pdn_cash_pay"`
  491. } `json:"setlinfo"`
  492. } `json:"output"`
  493. RefmsgTime string `json:"refmsg_time"`
  494. RespondTime string `json:"respond_time"`
  495. Signtype interface{} `json:"signtype"`
  496. WarnMsg interface{} `json:"warn_msg"`
  497. }
  498. type ResultSixteen10265 struct {
  499. Cainfo string `json:"cainfo"`
  500. ErrMsg string `json:"err_msg"`
  501. InfRefmsgid string `json:"inf_refmsgid"`
  502. Infcode string `json:"infcode"`
  503. Output struct {
  504. Setldetail []interface{} `json:"setldetail"`
  505. Setlinfo struct {
  506. MdtrtID string `json:"mdtrt_id"`
  507. SetlID string `json:"setl_id"`
  508. ClrOptins string `json:"clr_optins"`
  509. SetlTime string `json:"setl_time"`
  510. MedfeeSumamt float64 `json:"medfee_sumamt"`
  511. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  512. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  513. PreselfpayAmt float64 `json:"preselfpay_amt"`
  514. InscpScpAmt float64 `json:"inscp_scp_amt"`
  515. ActPayDedc float64 `json:"act_pay_dedc"`
  516. HifpPay float64 `json:"hifp_pay"`
  517. PoolPropSe float64 `json:"pool_prop_selfpay"`
  518. Lfpay float64 `json:"selfpay"`
  519. CvlservPay float64 `json:"cvlserv_pay"`
  520. HifesPay float64 `json:"hifes_pay"`
  521. HifmiPay float64 `json:"hifmi_pay"`
  522. HifobPay float64 `json:"hifob_pay"`
  523. MafPay float64 `json:"maf_pay"`
  524. OthPay float64 `json:"oth_pay"`
  525. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  526. PsnPartAmt float64 `json:"psn_part_amt"`
  527. AcctPay float64 `json:"acct_pay"`
  528. Balc float64 `json:"balc"`
  529. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  530. HospPartAmt float64 `json:"hosp_part_amt"`
  531. MedinsSetlID string `json:"medins_setl_id"`
  532. PdnCashPay string `json:"pdn_cash_pay"`
  533. } `json:"setlinfo"`
  534. } `json:"output"`
  535. RefmsgTime string `json:"refmsg_time"`
  536. RespondTime string `json:"respond_time"`
  537. Signtype interface{} `json:"signtype"`
  538. WarnMsg interface{} `json:"warn_msg"`
  539. }
  540. type Custom struct {
  541. DetItemFeeSumamt string
  542. Cut string
  543. FeedetlSn string
  544. Price string
  545. MedListCodg string
  546. Type int64
  547. AdviceId int64
  548. ProjectId int64
  549. ItemId int64
  550. }
  551. type ResultEmpty struct {
  552. Cainfo interface{} `json:"cainfo"`
  553. ErrMsg string `json:"err_msg"`
  554. InfRefmsgid string `json:"inf_refmsgid"`
  555. Infcode int64 `json:"infcode"`
  556. Output struct {
  557. } `json:"output"`
  558. RefmsgTime string `json:"refmsg_time"`
  559. RespondTime string `json:"respond_time"`
  560. Signtype interface{} `json:"signtype"`
  561. WarnMsg interface{} `json:"warn_msg"`
  562. }
  563. type ResultEmpty10265 struct {
  564. Cainfo interface{} `json:"cainfo"`
  565. ErrMsg string `json:"err_msg"`
  566. InfRefmsgid string `json:"inf_refmsgid"`
  567. Infcode string `json:"infcode"`
  568. Output struct {
  569. } `json:"output"`
  570. RefmsgTime string `json:"refmsg_time"`
  571. RespondTime string `json:"respond_time"`
  572. Signtype interface{} `json:"signtype"`
  573. WarnMsg interface{} `json:"warn_msg"`
  574. }
  575. type CustomResult struct {
  576. BasMednFlag string `json:"bas_medn_flag"`
  577. ChldMedcFlag string `json:"chld_medc_flag"`
  578. ChrgitmLv string `json:"chrgitm_lv"`
  579. Cnt float64 `json:"cnt"`
  580. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  581. DrtReimFlag string `json:"drt_reim_flag"`
  582. FeedetlSn string `json:"feedetl_sn"`
  583. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  584. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  585. InscpScpAmt float64 `json:"inscp_scp_amt"`
  586. ListSpItemFlag string `json:"list_sp_item_flag"`
  587. LmtUsedFlag string `json:"lmt_used_flag"`
  588. MedChrgitmType string `json:"med_chrgitm_type"`
  589. Memo string `json:"memo"`
  590. OverlmtAmt float64 `json:"overlmt_amt"`
  591. PreselfpayAmt float64 `json:"preselfpay_amt"`
  592. Pric float64 `json:"pric"`
  593. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  594. SelfpayProp float64 `json:"selfpay_prop"`
  595. }
  596. func ZHHisManagerApiRegistRouters() {
  597. beego.Router("/zh/api/inhopitalcheck/get", &ZHHisApiController{}, "get:GetZHInHospitalCheck")
  598. beego.Router("/zh/api/outhopitalcheck/get", &ZHHisApiController{}, "get:GetZHOutHospitalCheck")
  599. beego.Router("/zh/api/uploadinfo/get", &ZHHisApiController{}, "get:GetUploadInfo")
  600. beego.Router("/zh/api/presettle/get", &ZHHisApiController{}, "get:GetPreSettleInfo")
  601. beego.Router("/zh/api/settle/get", &ZHHisApiController{}, "get:GetSettleInfo")
  602. beego.Router("/zh/api/inthopitaluncheck/get", &ZHHisApiController{}, "get:GetZHInHospitalUnCheck")
  603. beego.Router("/zh/api/outhopitaluncheck/get", &ZHHisApiController{}, "get:GetZHOutHospitalUnCheck")
  604. beego.Router("/zh/api/refund", &ZHHisApiController{}, "get:ZHRefund")
  605. beego.Router("/zh/api/refunddetail", &ZHHisApiController{}, "get:ZHRefundDetail")
  606. beego.Router("/zh/api/patient/info", &ZHHisApiController{}, "get:GetZHPatientInfo")
  607. beego.Router("/zh/api/readcard", &ZHHisApiController{}, "get:ReadCard")
  608. beego.Router("/zh/api/clearsettle", &ZHHisApiController{}, "get:ClearSettle")
  609. beego.Router("/zh/api/readelecard", &ZHHisApiController{}, "get:ReadEleCard")
  610. beego.Router("/zh/api/deviceinit", &ZHHisApiController{}, "get:ReadEleCardfordevice")
  611. //beego.Router("/zh/api/readelecard", &ZHHisApiController{}, "get:ReadEleCard")
  612. beego.Router("/zh/api/lingbao/upload", &ZHHisApiController{}, "get:UploadLingBao")
  613. beego.Router("/zh/api/lingbao/refund", &ZHHisApiController{}, "get:RefundLingBao")
  614. beego.Router("/zh/api/lingbao/get", &ZHHisApiController{}, "get:GetLingBao")
  615. beego.Router("/api/token/get", &ZHHisApiController{}, "post:GetToken")
  616. beego.Router("/api/ele/info", &ZHHisApiController{}, "post:GetEleInfo")
  617. beego.Router("/api/4102", &ZHHisApiController{}, "get:Get4102")
  618. beego.Router("/api/4103", &ZHHisApiController{}, "get:Get4103")
  619. //beego.Router("/api/4104", &ZHHisApiController{}, "get:Get4104")
  620. beego.Router("/api/cardstatus", &ZHHisApiController{}, "get:GetCardStatus")
  621. //beego.Router("/api/2403", &ZHHisApiController{}, "get:Get2403")
  622. beego.Router("/api/5201", &ZHHisApiController{}, "get:Get5201")
  623. }
  624. func (c *ZHHisApiController) Get5201() {
  625. }
  626. // func (c *ZHHisApiController) Get2403(){
  627. // id, _ := c.GetInt64("order_id")
  628. // order,_ := service.GetHisOrderByID(id)
  629. // hosp,_ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  630. //
  631. //
  632. // med_type := "21"
  633. // id_card_type := hosp.IdCardType
  634. //
  635. //
  636. //
  637. // diagnosis_ids_arr := strings.Split(hosp.Diagnosis, "-")
  638. // adminInfo := c.GetAdminUserInfo()
  639. // var patient service.Patients
  640. // if id == 0 {
  641. // patient, _ = service.GetPatientByIDCard(order.Certno, adminInfo.CurrentOrgId)
  642. // } else {
  643. // patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  644. // }
  645. // diagnosisConfig, _ := service.FindDiagnoseByIds(diagnosis_ids_arr)
  646. //
  647. // doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, hosp.Doctor)
  648. // //deviceNumber, _ := service.GetDeviceNumberByID(adm_bed, adminInfo.CurrentOrgId)
  649. // departmentInfo, _ := service.GetDepartMentDetail(hosp.Departments)
  650. //
  651. //
  652. //
  653. //
  654. // var struct2401 service.Struct2401
  655. // struct2401.Insutype = "390"
  656. // psn_info, _ := service.GetPsnByPatientId(patient.ID)
  657. // if id_card_type == 1 {
  658. // struct2401.MdtrtCertType = "03"
  659. // bas := strings.Split(psn_info.CardInfo, "|")
  660. // cardNumber := bas[2]
  661. // struct2401.MdtrtCertNo = cardNumber
  662. // struct2401.PsnNo = order.PsnNo
  663. // } else if id_card_type == 4 {
  664. // struct2401.MdtrtCertType = "01"
  665. // struct2401.MdtrtCertNo = psn_info.VerifyNumber
  666. // struct2401.PsnNo = psn_info.PsnNo
  667. // } else {
  668. // struct2401.MdtrtCertType = "02"
  669. // struct2401.MdtrtCertNo = hosp.Certno
  670. // struct2401.PsnNo = hosp.PsnNo
  671. // }
  672. //
  673. // struct2401.IptNo = "2023061415103410808113442"
  674. // struct2401.AtddrNo = doctorInfo.DoctorNumber
  675. // struct2401.ChfpdrName = doctorInfo.UserName
  676. // struct2401.AdmDiagDscr = diagnosisConfig[0].ClassName
  677. // struct2401.AdmDeptCodg = strconv.FormatInt(int64(departmentInfo.ID), 10)
  678. // struct2401.AdmDeptName = departmentInfo.Name
  679. // struct2401.AdmBed = ""
  680. // struct2401.AdmBed = "待定"
  681. //
  682. // struct2401.DscgMaindiagName = diagnosisConfig[0].ClassName
  683. // struct2401.DscgMaindiagCode = diagnosisConfig[0].CountryCode
  684. // struct2401.Begntime = "2023"
  685. // struct2401.DiseCodg = sickConfig.CountryCode
  686. // struct2401.DiseName = sickConfig.ClassName
  687. //
  688. // }
  689. func (c *ZHHisApiController) GetCardStatus() {
  690. //patient_id, _ := c.GetInt64("patient_id")
  691. //record_date, _ := c.GetInt64("record_date")
  692. //psn, _ := service.GetPsnByPatientIdtWO(patient_id,record_date)
  693. //if len(psn.VerifyNumber) > 0{
  694. // c.ServeSuccessJSON(map[string]interface{}{
  695. // "msg": "读卡成功",
  696. // })
  697. //} else{
  698. // c.ServeSuccessJSON(map[string]interface{}{
  699. // "msg": "",
  700. // })
  701. //}
  702. }
  703. func (c *ZHHisApiController) GetEleInfo() {
  704. body, _ := ioutil.ReadAll(c.Ctx.Request.Body)
  705. var respJSON map[string]interface{}
  706. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  707. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  708. return
  709. }
  710. token := respJSON["token"].(string)
  711. respJSON = respJSON["result"].(map[string]interface{})
  712. result_byte, _ := json.Marshal(respJSON)
  713. result := string(result_byte)
  714. fmt.Println("token")
  715. fmt.Println(token)
  716. fmt.Println("result")
  717. fmt.Println(result)
  718. var res ResultTwo
  719. var res10265 ResultTwo10265 //1101结果
  720. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  721. utils.ErrorLog("解析失败:%v", err)
  722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  723. return
  724. }
  725. res.ErrMsg = res10265.ErrMsg
  726. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  727. res.Infcode = infocode
  728. res.Output = res10265.Output
  729. res.InfRefmsgid = res10265.InfRefmsgid
  730. if res.Infcode == 0 {
  731. patient, err := service.GetPatientByNumber(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  732. if err == gorm.ErrRecordNotFound {
  733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  734. return
  735. } else if err != nil {
  736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  737. return
  738. } else {
  739. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  740. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  741. infoStr := string(Iinfos)
  742. idetinfoStr := string(Idetinfos)
  743. psn := &models.HisPsn{
  744. PsnNo: res.Output.Baseinfo.PsnNo,
  745. Age: res.Output.Baseinfo.Age,
  746. PatientId: patient.ID,
  747. Certno: res.Output.Baseinfo.Certno,
  748. Gend: res.Output.Baseinfo.Gend,
  749. Naty: res.Output.Baseinfo.Naty,
  750. PsnCertType: res.Output.Baseinfo.PsnCertType,
  751. PsnName: res.Output.Baseinfo.PsnName,
  752. Idetinfo: idetinfoStr,
  753. Insuinfo: infoStr,
  754. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  755. CardInfo: "",
  756. VerifyNumber: token,
  757. }
  758. service.CreateHisPsn(psn)
  759. c.ServeSuccessJSON(map[string]interface{}{
  760. "patient": patient,
  761. "number": token,
  762. })
  763. }
  764. } else {
  765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  766. return
  767. }
  768. }
  769. func (c *ZHHisApiController) GetToken() {
  770. body, _ := ioutil.ReadAll(c.Ctx.Request.Body)
  771. var respJSON map[string]interface{}
  772. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  773. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  774. return
  775. }
  776. token := respJSON["token"].(string)
  777. id_card_no := respJSON["id_card_no"].(string)
  778. fmt.Println("token")
  779. fmt.Println(token)
  780. fmt.Println("result")
  781. fmt.Println(id_card_no)
  782. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  783. patient, _ := service.GetPatientByIDCard(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  784. var api string
  785. api = "http://172.16.13.254:9532/" + "api/eleinfo?" + "fixmedins_code=" + miConfig.Code + "&secret_key=" + miConfig.SecretKey + "&org_name=" + miConfig.OrgName +
  786. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&url=" + miConfig.Url + "&cainfo=" + miConfig.Cainfo + "&token=" + token + "&user_name=" + patient.Name + "&id_card_no=" + patient.IdCardNo
  787. resp, requestErr := http.Get(api)
  788. if requestErr != nil {
  789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  790. return
  791. }
  792. body, ioErr := ioutil.ReadAll(resp.Body)
  793. if ioErr != nil {
  794. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  796. return
  797. }
  798. c.ServeSuccessJSON(map[string]interface{}{
  799. "msg": "读卡成功",
  800. })
  801. }
  802. func (c *ZHHisApiController) UploadLingBao() {
  803. id, _ := c.GetInt64("id")
  804. record_time := c.GetString("record_time")
  805. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  806. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  807. admin_user_id, _ := c.GetInt64("admin_user_id")
  808. timeLayout := "2006-01-02"
  809. loc, _ := time.LoadLocation("Local")
  810. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  811. if err != nil {
  812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  813. return
  814. }
  815. recordDateTime := theTime.Unix()
  816. adminUser := c.GetAdminUserInfo()
  817. var prescriptions []*models.HisPrescription
  818. data := make(map[string]interface{})
  819. if settle_accounts_type == 1 { //日结
  820. prescriptions, _ = service.GetZHHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  821. } else { //月结
  822. start_time_str := c.GetString("start_time")
  823. end_time_str := c.GetString("end_time")
  824. timeLayout := "2006-01-02"
  825. loc, _ := time.LoadLocation("Local")
  826. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  827. if err != nil {
  828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  829. return
  830. }
  831. recordStartTime := theStartTime.Unix()
  832. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  833. if err != nil {
  834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  835. return
  836. }
  837. recordEndTime := theEndTime.Unix()
  838. prescriptions, _ = service.GetZHMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  839. }
  840. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  841. record, _ := service.GetInHospitalRecord(in_hospital_id)
  842. if record.ID == 0 {
  843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  844. return
  845. }
  846. timestamp := time.Now().Unix()
  847. tempTime := time.Unix(timestamp, 0)
  848. timeFormat := tempTime.Format("20060102150405")
  849. chrgBchno := rand.Intn(100000) + 10000
  850. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(record.PatientId, 10)
  851. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  852. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  853. department, _ := service.GetDepartMentDetail(record.Departments)
  854. strconv.FormatInt(record.PatientId, 10)
  855. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, record.Doctor)
  856. //client := &http.Client{}
  857. data["psn_no"] = record.PsnNo
  858. data["mdtrt_id"] = record.Number
  859. data["chrg_bchno"] = chrg_bchno
  860. data["org_name"] = miConfig.OrgName
  861. data["doctor"] = roles.UserName
  862. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  863. data["dept"] = strconv.FormatInt(department.ID, 10)
  864. data["fixmedins_code"] = miConfig.Code
  865. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  866. data["dept_code"] = "15"
  867. } else {
  868. data["dept_code"] = department.Number
  869. }
  870. if miConfig.Code == "H15049901371" {
  871. if record.MedType == 14 {
  872. if record.InsutypeType == "390" {
  873. data["med_type"] = "9933"
  874. } else if record.InsutypeType == "310" {
  875. data["med_type"] = "990502"
  876. }
  877. } else if record.MedType == 11 {
  878. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  879. }
  880. } else {
  881. if record.MedType == 1112 {
  882. data["med_type"] = strconv.FormatInt(11, 10)
  883. } else {
  884. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  885. }
  886. }
  887. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  888. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  889. data["secret_key"] = miConfig.SecretKey
  890. var ids []int64
  891. fmt.Println(data)
  892. for _, item := range prescriptions {
  893. ids = append(ids, item.ID)
  894. }
  895. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  896. if config.IsOpen == 1 { //对接了医保,走医保流程
  897. var pagesize int = 100
  898. var start int = 1
  899. var stop int
  900. var pagecount int
  901. var curpage int
  902. var isSuccess bool = true
  903. var customs []*models.NewCustom
  904. for _, item := range prescriptions {
  905. tm := time.Unix(item.PreTime, 0)
  906. if item.Type == 1 { //药品
  907. for _, subItem := range item.HisDoctorAdviceInfo {
  908. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 && subItem.BaseDrugLib.IsUser != 1 {
  909. //var randNum int
  910. //randNum = rand.Intn(10000) + 1000
  911. cus := &models.NewCustom{
  912. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  913. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  914. FeedetlSn: subItem.FeedetlSn,
  915. Price: fmt.Sprintf("%.4f", subItem.Price),
  916. MedListCodg: subItem.BaseDrugLib.MedicalInsuranceNumber,
  917. HospApprFlag: subItem.BaseDrugLib.HospApprFlag,
  918. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  919. }
  920. customs = append(customs, cus)
  921. }
  922. }
  923. }
  924. if item.Type == 2 { //项目
  925. for _, subItem := range item.HisPrescriptionProject {
  926. //var randNum int
  927. //randNum = rand.Intn(10000) + 1000
  928. if subItem.Type == 2 {
  929. if len(subItem.HisProject.MedicalCode) > 0 {
  930. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  931. cus := &models.NewCustom{
  932. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  933. Cut: fmt.Sprintf("%.4f", cnt),
  934. FeedetlSn: subItem.FeedetlSn,
  935. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  936. MedListCodg: subItem.HisProject.MedicalCode,
  937. HospApprFlag: -1,
  938. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  939. }
  940. customs = append(customs, cus)
  941. }
  942. } else if subItem.Type == 3 {
  943. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 && subItem.GoodInfo.IsUser != 1 {
  944. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  945. cus := &models.NewCustom{
  946. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  947. Cut: fmt.Sprintf("%.4f", cnt),
  948. FeedetlSn: subItem.FeedetlSn,
  949. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  950. MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  951. HospApprFlag: -1,
  952. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  953. }
  954. customs = append(customs, cus)
  955. }
  956. }
  957. }
  958. }
  959. }
  960. //总页数,向上取整,注意除之前要先转换类型为float64
  961. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  962. var ress []*ResultFour
  963. for curpage = 1; curpage <= pagecount; curpage++ {
  964. if curpage == 1 {
  965. start = 1
  966. } else {
  967. start = (curpage-1)*pagesize + 1
  968. }
  969. stop = curpage * pagesize
  970. if stop > len(customs) {
  971. stop = len(customs)
  972. }
  973. var result string
  974. var requestLog string
  975. if miConfig.MdtrtareaAdmvs == "150499" {
  976. data := make(map[string]interface{})
  977. if record.MedType == 14 {
  978. if record.InsutypeType == "390" {
  979. data["med_type"] = "9933"
  980. } else if record.InsutypeType == "310" {
  981. data["med_type"] = "990502"
  982. }
  983. } else if record.MedType == 11 {
  984. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  985. }
  986. data["psn_no"] = record.PsnNo
  987. data["number"] = record.Number
  988. data["customs"] = customs[start-1 : stop]
  989. data["chrg_bchno"] = chrg_bchno
  990. data["dept"] = strconv.FormatInt(department.ID, 10)
  991. data["dept_code"] = department.Number
  992. data["doctor_code"] = doctor_info.DoctorNumber
  993. data["doctor_name"] = doctor_info.UserName
  994. data["org_name"] = miConfig.OrgName
  995. data["opertor"] = roles.UserName
  996. data["fixmedins_code"] = miConfig.Code
  997. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  998. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  999. data["secret_key"] = miConfig.SecretKey
  1000. var req *http.Request
  1001. bytesData, _ := json.Marshal(data)
  1002. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2301", bytes.NewReader(bytesData))
  1003. client := &http.Client{}
  1004. resp, _ := client.Do(req)
  1005. defer resp.Body.Close()
  1006. body, ioErr := ioutil.ReadAll(resp.Body)
  1007. if ioErr != nil {
  1008. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1010. return
  1011. }
  1012. var respJSON map[string]interface{}
  1013. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1014. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1016. return
  1017. }
  1018. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1019. result_byte, _ := json.Marshal(respJSON)
  1020. result = string(result_byte)
  1021. } else {
  1022. result, requestLog = service.ZHGdyb2301(record.PsnNo, record.Number, customs[start-1:stop], chrg_bchno, miConfig.OrgName, roles.UserName, strconv.FormatInt(department.ID, 10), miConfig.Code, department.Number, strconv.FormatInt(roles.AdminUserId, 10), record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, data["med_type"].(string), doctor_info.DoctorNumber, doctor_info.UserName)
  1023. saveLog(result, requestLog, "2301", "上传明细")
  1024. }
  1025. var dat map[string]interface{}
  1026. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1027. fmt.Println(dat)
  1028. } else {
  1029. fmt.Println(err)
  1030. }
  1031. userJSONBytes, _ := json.Marshal(dat)
  1032. var res ResultFour
  1033. var resFour10265 ResultFour10265
  1034. if miConfig.Code == "H15049901371" {
  1035. if err := json.Unmarshal(userJSONBytes, &resFour10265); err != nil {
  1036. utils.ErrorLog("解析失败:%v", err)
  1037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1038. return
  1039. }
  1040. res.WarnMsg = resFour10265.WarnMsg
  1041. res.Output = resFour10265.Output
  1042. res.ErrMsg = resFour10265.ErrMsg
  1043. res.RespondTime = resFour10265.RespondTime
  1044. res.InfRefmsgid = resFour10265.InfRefmsgid
  1045. Infcode, _ := strconv.ParseInt(resFour10265.Infcode, 10, 64)
  1046. res.Infcode = Infcode
  1047. } else {
  1048. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1049. utils.ErrorLog("解析失败:%v", err)
  1050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1051. return
  1052. }
  1053. }
  1054. if res.Infcode == 0 {
  1055. ress = append(ress, &res)
  1056. } else {
  1057. isSuccess = false
  1058. errlog := &models.HisOrderError{
  1059. UserOrgId: adminUser.CurrentOrgId,
  1060. Ctime: time.Now().Unix(),
  1061. Mtime: time.Now().Unix(),
  1062. Number: chrg_bchno,
  1063. ErrMsg: "",
  1064. Status: 1,
  1065. PatientId: id,
  1066. RecordTime: recordDateTime,
  1067. Stage: 4,
  1068. }
  1069. service.CreateErrMsgLog(errlog)
  1070. c.ServeSuccessJSON(map[string]interface{}{
  1071. "failed_code": -10,
  1072. "msg": "上传明细错误,请联系his厂商",
  1073. })
  1074. return
  1075. }
  1076. }
  1077. if isSuccess == true {
  1078. if settle_accounts_type == 1 {
  1079. for _, subItem := range ress {
  1080. for _, item := range subItem.Output.Result {
  1081. temp := strings.Split(item.FeedetlSn, "-")
  1082. var advice_id int64 = 0
  1083. var project_id int64 = 0
  1084. var types int64 = 0
  1085. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1086. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1087. if temp[1] == "1" {
  1088. advice_id = id
  1089. project_id = 0
  1090. } else if temp[1] == "2" {
  1091. advice_id = 0
  1092. project_id = id
  1093. }
  1094. info := &models.HisOrderInfo{
  1095. OrderNumber: record.Number,
  1096. FeedetlSn: item.FeedetlSn,
  1097. UploadDate: recordDateTime,
  1098. AdviceId: advice_id,
  1099. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1100. Cnt: item.Cnt,
  1101. Pric: float64(item.Pric),
  1102. PatientId: record.PatientId,
  1103. PricUplmtAmt: item.PricUplmtAmt,
  1104. SelfpayProp: item.SelfpayProp,
  1105. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1106. OverlmtAmt: item.OverlmtAmt,
  1107. PreselfpayAmt: item.PreselfpayAmt,
  1108. BasMednFlag: item.BasMednFlag,
  1109. MedChrgitmType: item.MedChrgitmType,
  1110. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1111. Status: 1,
  1112. Memo: item.Memo,
  1113. Mtime: time.Now().Unix(),
  1114. InscpScpAmt: item.InscpScpAmt,
  1115. DrtReimFlag: item.DrtReimFlag,
  1116. Ctime: time.Now().Unix(),
  1117. ListSpItemFlag: item.ListSpItemFlag,
  1118. ChldMedcFlag: item.ChldMedcFlag,
  1119. LmtUsedFlag: item.LmtUsedFlag,
  1120. ChrgitmLv: item.ChrgitmLv,
  1121. UserOrgId: adminUser.CurrentOrgId,
  1122. HisPatientId: record.ID,
  1123. OrderId: 0,
  1124. ProjectId: project_id,
  1125. Type: types,
  1126. SettleType: settle_accounts_type,
  1127. }
  1128. service.CreateOrderInfo(info)
  1129. }
  1130. }
  1131. err := service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  1132. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  1133. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  1134. if err == nil {
  1135. c.ServeSuccessJSON(map[string]interface{}{
  1136. "msg": "上传费用明细成功",
  1137. })
  1138. return
  1139. } else {
  1140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1141. return
  1142. }
  1143. } else {
  1144. for _, subItem := range ress {
  1145. for _, item := range subItem.Output.Result {
  1146. temp := strings.Split(item.FeedetlSn, "-")
  1147. var advice_id int64 = 0
  1148. var project_id int64 = 0
  1149. var types int64 = 0
  1150. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1151. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1152. if temp[1] == "1" {
  1153. advice_id = id
  1154. project_id = 0
  1155. } else if temp[1] == "2" {
  1156. advice_id = 0
  1157. project_id = id
  1158. }
  1159. info := &models.HisOrderInfo{
  1160. OrderNumber: record.Number,
  1161. FeedetlSn: item.FeedetlSn,
  1162. UploadDate: time.Now().Unix(),
  1163. AdviceId: advice_id,
  1164. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1165. Cnt: item.Cnt,
  1166. Pric: float64(item.Pric),
  1167. PatientId: record.PatientId,
  1168. PricUplmtAmt: item.PricUplmtAmt,
  1169. SelfpayProp: item.SelfpayProp,
  1170. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1171. OverlmtAmt: item.OverlmtAmt,
  1172. PreselfpayAmt: item.PreselfpayAmt,
  1173. BasMednFlag: item.BasMednFlag,
  1174. MedChrgitmType: item.MedChrgitmType,
  1175. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1176. Status: 1,
  1177. Memo: item.Memo,
  1178. Mtime: time.Now().Unix(),
  1179. InscpScpAmt: item.InscpScpAmt,
  1180. DrtReimFlag: item.DrtReimFlag,
  1181. Ctime: time.Now().Unix(),
  1182. ListSpItemFlag: item.ListSpItemFlag,
  1183. ChldMedcFlag: item.ChldMedcFlag,
  1184. LmtUsedFlag: item.LmtUsedFlag,
  1185. ChrgitmLv: item.ChrgitmLv,
  1186. UserOrgId: adminUser.CurrentOrgId,
  1187. HisPatientId: record.ID,
  1188. ProjectId: project_id,
  1189. Type: types,
  1190. SettleType: settle_accounts_type,
  1191. }
  1192. service.CreateOrderInfo(info)
  1193. }
  1194. }
  1195. service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  1196. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  1197. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  1198. c.ServeSuccessJSON(map[string]interface{}{
  1199. "msg": "上传费用明细成功",
  1200. })
  1201. }
  1202. }
  1203. }
  1204. }
  1205. func (c *ZHHisApiController) RefundLingBao() {
  1206. }
  1207. func (c *ZHHisApiController) GetLingBao() {
  1208. }
  1209. func (c *ZHHisApiController) ReadEleCard() {
  1210. id_card_type, _ := c.GetInt64("id_card_type")
  1211. admin_user_id, _ := c.GetInt64("admin_user_id")
  1212. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  1213. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  1214. var api string
  1215. api = "http://172.16.13.254:9532/" + "nmyb/readcard?" + "fixmedins_code=" + miConfig.Code + "&secret_key=" + miConfig.SecretKey + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName +
  1216. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&url=" + miConfig.Url + "&cainfo=" + miConfig.Cainfo + "&id_card_type=" + strconv.FormatInt(id_card_type, 10) + "&operator_id=" + strconv.FormatInt(admin_user_id, 10) + "&operator=" + roles.UserName
  1217. fmt.Println(api)
  1218. resp, requestErr := http.Get(api)
  1219. if requestErr != nil {
  1220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1221. return
  1222. }
  1223. body, ioErr := ioutil.ReadAll(resp.Body)
  1224. if ioErr != nil {
  1225. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1227. return
  1228. }
  1229. var respJSON map[string]interface{}
  1230. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1231. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1233. return
  1234. }
  1235. var status string
  1236. status = respJSON["data"].(map[string]interface{})["status"].(string)
  1237. //card_type := respJSON["data"].(map[string]interface{})["type"].(string)
  1238. var token string
  1239. var res ResultTwo //1101结果
  1240. var res10265 ResultTwo10265 //1101结果
  1241. if status == "0" { //读卡成功
  1242. token = respJSON["data"].(map[string]interface{})["token"].(string)
  1243. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  1244. result, _ := json.Marshal(respJSON)
  1245. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  1246. utils.ErrorLog("解析失败:%v", err)
  1247. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1248. return
  1249. }
  1250. res.ErrMsg = res10265.ErrMsg
  1251. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  1252. res.Infcode = infocode
  1253. res.Output = res10265.Output
  1254. res.InfRefmsgid = res10265.InfRefmsgid
  1255. if res.Infcode == 0 {
  1256. c.ServeSuccessJSON(map[string]interface{}{
  1257. "number": token,
  1258. })
  1259. }
  1260. } else {
  1261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  1262. return
  1263. }
  1264. }
  1265. func (c *ZHHisApiController) ClearSettle() {
  1266. order_id, _ := c.GetInt64("order_id")
  1267. admin_user_id, _ := c.GetInt64("admin_user_id")
  1268. adminUser := c.GetAdminUserInfo()
  1269. var order models.HisOrder
  1270. order, _ = service.GetHisOrderByID(order_id)
  1271. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  1272. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1273. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1274. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1275. if miConfig.MdtrtareaAdmvs == "350500" {
  1276. record, _ := service.GetUploadRecord(order_id)
  1277. record.Status = 0
  1278. service.UpdateRecord(&record)
  1279. c.ServeSuccessJSON(map[string]interface{}{
  1280. "msg": "撤销成功",
  1281. })
  1282. } else {
  1283. if config.IsOpen == 1 { //对接了医保,走医保流程
  1284. var result string
  1285. var requestLog string
  1286. result, requestLog = service.Gdyb90306(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  1287. saveLog(result, requestLog, "90306", "撤销结算清单")
  1288. var dat map[string]interface{}
  1289. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1290. fmt.Println(dat)
  1291. } else {
  1292. fmt.Println(err)
  1293. }
  1294. userJSONBytes, _ := json.Marshal(dat)
  1295. var res ResultSix
  1296. //var resSixteen ResultSixteen10265
  1297. if miConfig.Code == "H15049901371" {
  1298. //if err := json.Unmarshal(userJSONBytes, &resSixteen); err != nil {
  1299. // utils.ErrorLog("解析失败:%v", err)
  1300. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1301. // return
  1302. //}
  1303. //res.Cainfo = resSixteen.Cainfo
  1304. //res.WarnMsg = resSixteen.WarnMsg
  1305. //res.Output = resSixteen.Output
  1306. //res.ErrMsg = resSixteen.ErrMsg
  1307. //res.RespondTime = resSixteen.RespondTime
  1308. //Infcode, _ := strconv.ParseInt(resSixteen.Infcode, 10, 64)
  1309. //res.Infcode = Infcode
  1310. } else {
  1311. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1312. utils.ErrorLog("解析失败:%v", err)
  1313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1314. return
  1315. }
  1316. }
  1317. if res.Infcode == 0 {
  1318. record, _ := service.GetUploadRecord(order_id)
  1319. record.Status = 0
  1320. service.UpdateRecord(&record)
  1321. c.ServeSuccessJSON(map[string]interface{}{
  1322. "msg": "撤销成功",
  1323. })
  1324. } else {
  1325. c.ServeSuccessJSON(map[string]interface{}{
  1326. "code": -10,
  1327. "msg": res.ErrMsg,
  1328. })
  1329. }
  1330. }
  1331. }
  1332. }
  1333. func (c *ZHHisApiController) GetZHPatientInfo() {
  1334. id_card_no := c.GetString("id_card_no")
  1335. admin_user_id, _ := c.GetInt64("admin_user_id")
  1336. patient, _ := service.GetPatientByIDCard(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  1337. if patient.ID == 0 {
  1338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1339. return
  1340. }
  1341. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  1342. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  1343. config, _ := service.GetMedicalInsuranceConfig(c.GetAdminUserInfo().CurrentOrgId)
  1344. if config.IsOpen == 1 {
  1345. var result string
  1346. var request_log string
  1347. var result_log string
  1348. if miConfig.MdtrtareaAdmvs == "150499" {
  1349. var insuplc_admdvs string
  1350. if len(patient.InsuplcAdmdvs) > 0 {
  1351. insuplc_admdvs = patient.InsuplcAdmdvs
  1352. } else {
  1353. insuplc_admdvs = miConfig.InsuplcAdmdvs
  1354. }
  1355. //请求内网数据
  1356. api := "http://172.16.13.254:9532/" + "nmyb/1101?cert_no=" + patient.IdCardNo +
  1357. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  1358. "&insuplc_admdvs=" + insuplc_admdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(2, 10) + "&card_sn=" + "" + "&certificates=" + strconv.FormatInt(1, 10) + "&name=" + patient.Name
  1359. resp, requestErr := http.Get(api)
  1360. if requestErr != nil {
  1361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1362. return
  1363. }
  1364. body, ioErr := ioutil.ReadAll(resp.Body)
  1365. if ioErr != nil {
  1366. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1368. return
  1369. }
  1370. var respJSON map[string]interface{}
  1371. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1372. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1374. return
  1375. }
  1376. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1377. result_byte, _ := json.Marshal(respJSON)
  1378. result = string(result_byte)
  1379. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  1380. } else if miConfig.MdtrtareaAdmvs == "360399" || miConfig.MdtrtareaAdmvs == "361025" || miConfig.MdtrtareaAdmvs == "360100" {
  1381. result, request_log = service.JxybZY1101(patient.IdCardNo, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, 2, "", 0, miConfig.Url, miConfig.AccessKey, patient.Name, patient.IdCardNo, patient.Name)
  1382. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  1383. }else if miConfig.MdtrtareaAdmvs == "341203"{
  1384. var insuplc_admdvs string
  1385. if len(patient.InsuplcAdmdvs) > 0 {
  1386. insuplc_admdvs = patient.InsuplcAdmdvs
  1387. } else {
  1388. insuplc_admdvs = miConfig.InsuplcAdmdvs
  1389. }
  1390. //请求内网数据
  1391. api := miConfig.SecretKey + "ahyb/1101?url=" + miConfig.Url + "&cert_no=" + patient.IdCardNo +
  1392. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  1393. "&insuplc_admdvs=" + insuplc_admdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(2, 10) + "&card_sn=" + "" + "&certificates=" + strconv.FormatInt(1, 10) + "&name=" + patient.Name+"&token="+""
  1394. resp, requestErr := http.Get(api)
  1395. if requestErr != nil {
  1396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1397. return
  1398. }
  1399. body, ioErr := ioutil.ReadAll(resp.Body)
  1400. if ioErr != nil {
  1401. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1403. return
  1404. }
  1405. var respJSON map[string]interface{}
  1406. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1407. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1409. return
  1410. }
  1411. status := respJSON["data"].(map[string]interface{})["status"].(string)
  1412. if status == "0"{
  1413. err_msg := respJSON["data"].(map[string]interface{})["msg"].(string)
  1414. c.ServeSuccessJSON(map[string]interface{}{
  1415. "failed_code": -10,
  1416. "msg": err_msg,
  1417. })
  1418. return
  1419. }
  1420. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1421. result_byte, _ := json.Marshal(respJSON)
  1422. result = string(result_byte)
  1423. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  1424. }else if miConfig.MdtrtareaAdmvs == "340699"{
  1425. var insuplc_admdvs string
  1426. if len(patient.InsuplcAdmdvs) > 0 {
  1427. insuplc_admdvs = patient.InsuplcAdmdvs
  1428. } else {
  1429. insuplc_admdvs = miConfig.InsuplcAdmdvs
  1430. }
  1431. //请求内网数据
  1432. api := miConfig.SecretKey + "ahyb/1101?url=" + miConfig.Url + "&cert_no=" + patient.IdCardNo +
  1433. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  1434. "&insuplc_admdvs=" + insuplc_admdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(2, 10) + "&card_sn=" + "" + "&certificates=" + strconv.FormatInt(1, 10) + "&name=" + patient.Name+"&token="+""
  1435. resp, requestErr := http.Get(api)
  1436. if requestErr != nil {
  1437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1438. return
  1439. }
  1440. body, ioErr := ioutil.ReadAll(resp.Body)
  1441. if ioErr != nil {
  1442. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1444. return
  1445. }
  1446. var respJSON map[string]interface{}
  1447. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1448. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1450. return
  1451. }
  1452. status := respJSON["data"].(map[string]interface{})["status"].(string)
  1453. if status == "0"{
  1454. err_msg := respJSON["data"].(map[string]interface{})["msg"].(string)
  1455. c.ServeSuccessJSON(map[string]interface{}{
  1456. "failed_code": -10,
  1457. "msg": err_msg,
  1458. })
  1459. return
  1460. }
  1461. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1462. result_byte, _ := json.Marshal(respJSON)
  1463. result = string(result_byte)
  1464. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  1465. } else {
  1466. var insuplc_admdvs string
  1467. if len(patient.InsuplcAdmdvs) > 0 {
  1468. insuplc_admdvs = patient.InsuplcAdmdvs
  1469. } else {
  1470. insuplc_admdvs = miConfig.InsuplcAdmdvs
  1471. }
  1472. result, request_log, result_log = service.ZHGdyb1101(patient.IdCardNo, miConfig.OrgName, role.UserName, miConfig.Code, insuplc_admdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, 2, "", 1, "",admin_user_id)
  1473. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  1474. }
  1475. //result := service.Gdyb1101A(id_card_no, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, patient.Name)
  1476. var dat map[string]interface{}
  1477. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1478. fmt.Println(dat)
  1479. } else {
  1480. fmt.Println(err)
  1481. }
  1482. userJSONBytes, _ := json.Marshal(dat)
  1483. var res ResultTwo
  1484. var resTwo10265 ResultTwo10265
  1485. if miConfig.Code == "H15049901371" {
  1486. if err := json.Unmarshal(userJSONBytes, &resTwo10265); err != nil {
  1487. utils.ErrorLog("解析失败:%v", err)
  1488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1489. return
  1490. }
  1491. Infcode, _ := strconv.ParseInt(resTwo10265.Infcode, 10, 64)
  1492. res.Infcode = Infcode
  1493. res.ErrMsg = resTwo10265.ErrMsg
  1494. res.Output = resTwo10265.Output
  1495. res.InfRefmsgid = resTwo10265.InfRefmsgid
  1496. res.RespondTime = resTwo10265.RespondTime
  1497. res.WarnInfo = resTwo10265.WarnInfo
  1498. }else if miConfig.MdtrtareaAdmvs == "441799" {
  1499. //请求内网数据
  1500. api := miConfig.Url + "gdyb/1101?cert_no=" + patient.IdCardNo +
  1501. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  1502. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(2, 10) + "&card_sn=" + "" + "&certificates=" + strconv.FormatInt(1, 10) + "&name=" + patient.Name
  1503. resp, requestErr := http.Get(api)
  1504. if requestErr != nil {
  1505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1506. return
  1507. }
  1508. body, ioErr := ioutil.ReadAll(resp.Body)
  1509. if ioErr != nil {
  1510. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1512. return
  1513. }
  1514. var respJSON map[string]interface{}
  1515. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1516. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1518. return
  1519. }
  1520. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1521. result_byte, _ := json.Marshal(respJSON)
  1522. result = string(result_byte)
  1523. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  1524. if err := json.Unmarshal([]byte(result), &res); err != nil {
  1525. utils.ErrorLog("解析失败:%v", err)
  1526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1527. return
  1528. }
  1529. } else if miConfig.MdtrtareaAdmvs == "450721"{
  1530. c.ServeSuccessJSON(map[string]interface{}{
  1531. "msg": "",
  1532. })
  1533. } else {
  1534. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1535. utils.ErrorLog("解析失败:%v", err)
  1536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1537. return
  1538. }
  1539. }
  1540. var insutypes []string
  1541. var insutype string
  1542. var is390 int = 0
  1543. var is310 int = 0
  1544. for _, item := range res.Output.Iinfo {
  1545. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1546. insutypes = append(insutypes, item.Insutype)
  1547. }
  1548. }
  1549. if len(insutypes) == 1 {
  1550. insutype = insutypes[0]
  1551. } else {
  1552. for _, i := range insutypes {
  1553. if i == "390" {
  1554. is390 = 1
  1555. }
  1556. if i == "310" {
  1557. is310 = 1
  1558. }
  1559. }
  1560. }
  1561. if is390 == 1 {
  1562. insutype = "390"
  1563. }
  1564. if is310 == 1 {
  1565. insutype = "310"
  1566. }
  1567. if len(insutypes) == 0 {
  1568. for _, item := range res.Output.Iinfo {
  1569. if (item.Insutype == "390" && item.PsnInsuStas == "2") || (item.Insutype == "310" && item.PsnInsuStas == "2") {
  1570. insutypes = append(insutypes, item.Insutype)
  1571. }
  1572. }
  1573. if len(insutypes) == 1 {
  1574. insutype = insutypes[0]
  1575. } else {
  1576. for _, i := range insutypes {
  1577. if i == "390" {
  1578. is390 = 1
  1579. }
  1580. if i == "310" {
  1581. is310 = 1
  1582. }
  1583. }
  1584. }
  1585. if is390 == 1 {
  1586. insutype = "390"
  1587. }
  1588. if is310 == 1 {
  1589. insutype = "310"
  1590. }
  1591. }
  1592. var InsuplcAdmdvs string
  1593. for _, item := range res.Output.Iinfo {
  1594. utils.ErrorLog("解析失败:%v", item.Insutype)
  1595. utils.ErrorLog("解析失败:%v", insutype)
  1596. if item.Insutype == insutype {
  1597. InsuplcAdmdvs = item.InsuplcAdmdvs
  1598. }
  1599. }
  1600. utils.ErrorLog("解析失败:%v", InsuplcAdmdvs)
  1601. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  1602. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  1603. infoStr := string(Iinfos)
  1604. idetinfoStr := string(Idetinfos)
  1605. psn := &models.HisPsn{
  1606. PsnNo: res.Output.Baseinfo.PsnNo,
  1607. Age: res.Output.Baseinfo.Age,
  1608. PatientId: patient.ID,
  1609. Certno: res.Output.Baseinfo.Certno,
  1610. Gend: res.Output.Baseinfo.Gend,
  1611. Naty: res.Output.Baseinfo.Naty,
  1612. PsnCertType: res.Output.Baseinfo.PsnCertType,
  1613. PsnName: res.Output.Baseinfo.PsnName,
  1614. Idetinfo: idetinfoStr,
  1615. Insuinfo: infoStr,
  1616. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1617. VerifyNumber: "",
  1618. InsuplcAdmdvs: InsuplcAdmdvs,
  1619. }
  1620. service.CreateHisPsn(psn)
  1621. if res.Infcode == -1 {
  1622. c.ServeSuccessJSON(map[string]interface{}{
  1623. "failed_code": -10,
  1624. "msg": res.ErrMsg,
  1625. })
  1626. } else {
  1627. c.ServeSuccessJSON(map[string]interface{}{
  1628. "failed_code": 0,
  1629. "info": res,
  1630. "insutype": insutype,
  1631. })
  1632. }
  1633. }
  1634. }
  1635. func (c *ZHHisApiController) GetZHInHospitalCheck() {
  1636. id, _ := c.GetInt64("id")
  1637. record_time := c.GetString("record_time")
  1638. name := c.GetString("name")
  1639. phone := c.GetString("phone")
  1640. id_card_type, _ := c.GetInt64("id_card_type")
  1641. certificates, _ := c.GetInt64("certificates")
  1642. id_card_no := c.GetString("id_card_no")
  1643. doctor, _ := c.GetInt64("doctor")
  1644. admin_user_id, _ := c.GetInt64("admin_user_id")
  1645. department, _ := c.GetInt64("department")
  1646. adm_bed, _ := c.GetInt64("adm_bed")
  1647. diagnosis_ids := c.GetString("diagnosis")
  1648. sick_type, _ := c.GetInt64("sick_type")
  1649. start_time := c.GetString("start_time")
  1650. insuplc_admdvs := c.GetString("insuplc_admdvs")
  1651. balance_accounts_type, _ := c.GetInt64("balance_accounts_type")
  1652. social_type, _ := c.GetInt64("social_type")
  1653. psn_type, _ := c.GetInt64("psn_type")
  1654. //reg_type, _ := c.GetInt64("p_type")
  1655. med_type, _ := c.GetInt64("med_type")
  1656. diagnosis_ids_arr := strings.Split(diagnosis_ids, "-")
  1657. timeLayout := "2006-01-02"
  1658. loc, _ := time.LoadLocation("Local")
  1659. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1660. if err != nil {
  1661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1662. return
  1663. }
  1664. recordDateTime := theTime.Unix()
  1665. adminInfo := c.GetAdminUserInfo()
  1666. record, _ := service.GetLastHospitalRecord(id, adminInfo.CurrentOrgId)
  1667. if record.ID != 0 {
  1668. if record.InHospitalStatus == 1 && record.OutHospitalStatus != 1 {
  1669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalExistDataException)
  1670. return
  1671. }
  1672. }
  1673. var patient service.Patients
  1674. if id == 0 {
  1675. patient, _ = service.GetPatientByIDCard(id_card_no, adminInfo.CurrentOrgId)
  1676. } else {
  1677. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  1678. }
  1679. diagnosisConfig, _ := service.FindDiagnoseByIds(diagnosis_ids_arr)
  1680. sickConfig, _ := service.FindSickById(sick_type)
  1681. departmentInfo, _ := service.GetDepartMentDetail(department)
  1682. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1683. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1684. var result string
  1685. var request_log string
  1686. var result_log string
  1687. var res2 ResultTwo
  1688. var resTwo10265 ResultTwo10265
  1689. psn_info, _ := service.GetPsnByPatientId(patient.ID)
  1690. if miConfig.MdtrtareaAdmvs == "150499" {
  1691. if id_card_type == 2 {
  1692. mdtrt_cert_no := ""
  1693. mdtrt_cert_no = id_card_no
  1694. //请求内网数据
  1695. api := "http://172.16.13.254:9532/" + "nmyb/1101?cert_no=" + mdtrt_cert_no +
  1696. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  1697. "&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) + "&name=" + patient.Name
  1698. resp, requestErr := http.Get(api)
  1699. if requestErr != nil {
  1700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1701. return
  1702. }
  1703. body, ioErr := ioutil.ReadAll(resp.Body)
  1704. if ioErr != nil {
  1705. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1707. return
  1708. }
  1709. var respJSON map[string]interface{}
  1710. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1711. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1713. return
  1714. }
  1715. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1716. result_byte, _ := json.Marshal(respJSON)
  1717. result = string(result_byte)
  1718. var dat map[string]interface{}
  1719. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1720. fmt.Println(dat)
  1721. } else {
  1722. fmt.Println(err)
  1723. }
  1724. userJSONBytes, _ := json.Marshal(dat)
  1725. if err := json.Unmarshal(userJSONBytes, &resTwo10265); err != nil {
  1726. utils.ErrorLog("解析失败:%v", err)
  1727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1728. return
  1729. }
  1730. Infcode, _ := strconv.ParseInt(resTwo10265.Infcode, 10, 64)
  1731. res2.Infcode = Infcode
  1732. res2.ErrMsg = resTwo10265.ErrMsg
  1733. res2.Output = resTwo10265.Output
  1734. res2.InfRefmsgid = resTwo10265.InfRefmsgid
  1735. res2.RespondTime = resTwo10265.RespondTime
  1736. res2.WarnInfo = resTwo10265.WarnInfo
  1737. } else {
  1738. res2.Infcode = 0
  1739. res2.Output.Baseinfo.PsnNo = psn_info.PsnNo
  1740. res2.Output.Baseinfo.Certno = patient.IdCardNo
  1741. }
  1742. } else if miConfig.MdtrtareaAdmvs == "421182" {
  1743. res2.Infcode = 0
  1744. res2.Output.Baseinfo.PsnNo = psn_info.PsnNo
  1745. res2.Output.Baseinfo.Certno = patient.IdCardNo
  1746. } else if miConfig.MdtrtareaAdmvs == "360399" {
  1747. //res2.Infcode = 0
  1748. //res2.Output.Baseinfo.PsnNo = psn_info.PsnNo
  1749. //res2.Output.Baseinfo.Certno = patient.IdCardNo
  1750. //result, request_log = service.JxybZY1101(patient.IdCardNo, miConfig.OrgName, role.UserName, miConfig.Code, insuplc_admdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, ca, certificates, miConfig.Url, miConfig.AccessKey, "", patient.IdCardNo, "")
  1751. if id_card_type == 1{
  1752. bas := strings.Split(psn_info.CardInfo, "|")
  1753. cardNumber := bas[3]
  1754. result, request_log = service.Jxyb1101(patient.IdCardNo, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, cardNumber, "1", miConfig.Url, miConfig.AccessKey, "")
  1755. saveLog(result, request_log, "1101", "人员基本信息获取")
  1756. }else{
  1757. cardNumber := psn_info.VerifyNumber
  1758. result, request_log = service.Jxyb1101(patient.IdCardNo, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, cardNumber, "1", miConfig.Url, miConfig.AccessKey, psn_info.PsnName)
  1759. saveLog(result, request_log, "1101", "人员基本信息获取")
  1760. }
  1761. } else {
  1762. result, request_log, result_log = service.ZHGdyb1101(patient.IdCardNo, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, "", certificates, name,admin_user_id)
  1763. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  1764. }
  1765. doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor)
  1766. deviceNumber, _ := service.GetDeviceNumberByID(adm_bed, adminInfo.CurrentOrgId)
  1767. if miConfig.MdtrtareaAdmvs != "150499" && miConfig.MdtrtareaAdmvs != "421182" {
  1768. var dat map[string]interface{}
  1769. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1770. fmt.Println(dat)
  1771. } else {
  1772. fmt.Println(err)
  1773. }
  1774. userJSONBytes, _ := json.Marshal(dat)
  1775. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  1776. utils.ErrorLog("解析失败:%v", err)
  1777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1778. return
  1779. }
  1780. }
  1781. var infoStr string
  1782. if miConfig.MdtrtareaAdmvs == "150499" {
  1783. if id_card_type == 2 {
  1784. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  1785. infoStr = string(Iinfos)
  1786. } else {
  1787. infoStr = psn_info.Insuinfo
  1788. }
  1789. } else if miConfig.MdtrtareaAdmvs == "421182" {
  1790. infoStr = psn_info.Insuinfo
  1791. } else {
  1792. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  1793. infoStr = string(Iinfos)
  1794. }
  1795. var rf []*ResultFive
  1796. json.Unmarshal([]byte(infoStr), &rf)
  1797. var insutypes []*ResultFive
  1798. var insutype string
  1799. var is390 int = 0
  1800. var is310 int = 0
  1801. for _, item := range rf {
  1802. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1803. insutypes = append(insutypes, item)
  1804. }
  1805. }
  1806. if len(insutypes) == 1 {
  1807. insutype = insutypes[0].Insutype
  1808. //insuplc_admdvs = insutypes[0].InsuplcAdmdvs
  1809. } else {
  1810. for _, i := range insutypes {
  1811. if i.Insutype == "390" {
  1812. is390 = 1
  1813. }
  1814. if i.Insutype == "310" {
  1815. is310 = 1
  1816. }
  1817. }
  1818. }
  1819. if is390 == 1 {
  1820. insutype = "390"
  1821. }
  1822. if is310 == 1 {
  1823. insutype = "310"
  1824. }
  1825. if len(insutypes) == 0 {
  1826. insutype = "310"
  1827. }
  1828. if len(insutypes) == 2 {
  1829. insutype = strconv.FormatInt(social_type, 10)
  1830. }
  1831. //for _, item := range rf {
  1832. // if item.Insutype == insutype {
  1833. // insuplc_admdvs = item.InsuplcAdmdvs
  1834. // }
  1835. //}
  1836. if res2.Infcode == 0 {
  1837. //var insutypes []string
  1838. //
  1839. //var insutype string
  1840. //var is390 int = 0
  1841. //var is310 int = 0
  1842. //for _, item := range res2.Output.Iinfo {
  1843. // if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1844. // insutypes = append(insutypes, item.Insutype)
  1845. // }
  1846. //}
  1847. //if len(insutypes) == 1 {
  1848. // insutype = insutypes[0]
  1849. //} else {
  1850. // for _, i := range insutypes {
  1851. // if i == "390" {
  1852. // is390 = 1
  1853. // }
  1854. //
  1855. // if i == "310" {
  1856. // is310 = 1
  1857. // }
  1858. // }
  1859. //}
  1860. //if is390 == 1 {
  1861. // insutype = "390"
  1862. //}
  1863. //if is310 == 1 {
  1864. // insutype = "310"
  1865. //}
  1866. //
  1867. //if len(insutypes) == 0 {
  1868. // insutype = "310"
  1869. //}
  1870. if len(insuplc_admdvs) == 0 {
  1871. insuplc_admdvs = miConfig.InsuplcAdmdvs
  1872. }
  1873. timestamp := time.Now().Unix()
  1874. tempTime := time.Unix(timestamp, 0)
  1875. timeFormat := tempTime.Format("20060102150405")
  1876. chrgBchno := rand.Intn(100000) + 10000
  1877. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(id, 10)
  1878. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  1879. var struct2401 service.Struct2401
  1880. //insutype = "310"
  1881. struct2401.Insutype = insutype
  1882. psn_info, _ := service.GetPsnByPatientId(patient.ID)
  1883. if id_card_type == 1 {
  1884. struct2401.MdtrtCertType = "03"
  1885. bas := strings.Split(psn_info.CardInfo, "|")
  1886. cardNumber := bas[2]
  1887. struct2401.MdtrtCertNo = cardNumber
  1888. struct2401.PsnNo = res2.Output.Baseinfo.PsnNo
  1889. } else if id_card_type == 4 {
  1890. struct2401.MdtrtCertType = "01"
  1891. struct2401.MdtrtCertNo = psn_info.VerifyNumber
  1892. struct2401.PsnNo = psn_info.PsnNo
  1893. } else {
  1894. struct2401.MdtrtCertType = "02"
  1895. struct2401.MdtrtCertNo = id_card_no
  1896. struct2401.PsnNo = res2.Output.Baseinfo.PsnNo
  1897. }
  1898. if miConfig.Code == "H15049901371" {
  1899. if med_type == 14 {
  1900. if insutype == "390" {
  1901. struct2401.MedType = "9933"
  1902. } else if insutype == "310" {
  1903. struct2401.MedType = "990502"
  1904. }
  1905. } else if med_type == 11 {
  1906. struct2401.MedType = "21"
  1907. }
  1908. } else {
  1909. if med_type == 11 {
  1910. struct2401.MedType = "21"
  1911. med_type = 21
  1912. } else {
  1913. struct2401.MedType = strconv.FormatInt(int64(med_type), 10)
  1914. }
  1915. }
  1916. struct2401.IptNo = ipt_otp_no
  1917. struct2401.AtddrNo = doctorInfo.DoctorNumber
  1918. struct2401.ChfpdrName = doctorInfo.UserName
  1919. struct2401.AdmDiagDscr = diagnosisConfig[0].ClassName
  1920. struct2401.AdmDeptCodg = strconv.FormatInt(int64(departmentInfo.ID), 10)
  1921. struct2401.AdmDeptName = departmentInfo.Name
  1922. struct2401.AdmBed = deviceNumber.Number
  1923. struct2401.AdmBed = "待定"
  1924. struct2401.DscgMaindiagName = diagnosisConfig[0].ClassName
  1925. struct2401.DscgMaindiagCode = diagnosisConfig[0].CountryCode
  1926. struct2401.Begntime = start_time
  1927. struct2401.DiseCodg = sickConfig.CountryCode
  1928. struct2401.DiseName = sickConfig.ClassName
  1929. var dises []service.DiseinfoStruct
  1930. for index, item := range diagnosisConfig {
  1931. var dise service.DiseinfoStruct
  1932. if id_card_type == 4 || id_card_type == 1 {
  1933. dise.PsnNo = psn_info.PsnNo
  1934. } else {
  1935. dise.PsnNo = res2.Output.Baseinfo.PsnNo
  1936. }
  1937. dise.DiagType = "1"
  1938. if index == 0 {
  1939. dise.MaindiagFlag = "1"
  1940. } else {
  1941. dise.MaindiagFlag = "2"
  1942. }
  1943. dise.DiagSrtNo = strconv.FormatInt(int64(index), 10)
  1944. dise.DiseDorName = doctorInfo.UserName
  1945. dise.DiagCode = item.CountryCode
  1946. dise.DiagName = item.ClassName
  1947. dise.DiagDept = departmentInfo.Name
  1948. dise.DiseDorNo = doctorInfo.DoctorNumber
  1949. dise.DiagTime = timeFormatOne
  1950. dises = append(dises, dise)
  1951. }
  1952. struct2401.Diseinfo = dises
  1953. var result string
  1954. var request_log string
  1955. if miConfig.MdtrtareaAdmvs == "150499" {
  1956. data := make(map[string]interface{})
  1957. data["org_name"] = miConfig.OrgName
  1958. data["doctor"] = role.UserName
  1959. data["fixmedins_code"] = miConfig.Code
  1960. data["insuplc_admdvs"] = insuplc_admdvs
  1961. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1962. data["secret_key"] = miConfig.SecretKey
  1963. data["struct_2401"] = struct2401
  1964. var req *http.Request
  1965. bytesData, _ := json.Marshal(data)
  1966. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2401", bytes.NewReader(bytesData))
  1967. client := &http.Client{}
  1968. resp, _ := client.Do(req)
  1969. defer resp.Body.Close()
  1970. body, ioErr := ioutil.ReadAll(resp.Body)
  1971. if ioErr != nil {
  1972. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1974. return
  1975. }
  1976. var respJSON map[string]interface{}
  1977. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1978. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1979. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1980. return
  1981. }
  1982. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1983. result_byte, _ := json.Marshal(respJSON)
  1984. result = string(result_byte)
  1985. } else if miConfig.MdtrtareaAdmvs == "421182" {
  1986. data := make(map[string]interface{})
  1987. data["org_name"] = miConfig.OrgName
  1988. data["doctor"] = role.UserName
  1989. data["fixmedins_code"] = miConfig.Code
  1990. data["insuplc_admdvs"] = insuplc_admdvs
  1991. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1992. data["secret_key"] = miConfig.SecretKey
  1993. data["struct_2401"] = struct2401
  1994. var req *http.Request
  1995. bytesData, _ := json.Marshal(data)
  1996. req, _ = http.NewRequest("POST", miConfig.Url +"hbyb/2401", bytes.NewReader(bytesData))
  1997. client := &http.Client{}
  1998. resp, _ := client.Do(req)
  1999. defer resp.Body.Close()
  2000. body, ioErr := ioutil.ReadAll(resp.Body)
  2001. if ioErr != nil {
  2002. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2004. return
  2005. }
  2006. var respJSON map[string]interface{}
  2007. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  2008. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2010. return
  2011. }
  2012. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2013. //result, _ := json.Marshal(respJSON)
  2014. //result = string(result_byte)
  2015. //decoder := simplifiedchinese.GBK.NewDecoder()
  2016. result_byte, _ := json.Marshal(respJSON)
  2017. result = string(result_byte)
  2018. //enc := mahonia.NewEncoder("gbk")
  2019. //result = enc.ConvertString(string(result_byte))
  2020. fmt.Println(string(result)) // 输出:中文
  2021. } else if miConfig.MdtrtareaAdmvs == "360399" {
  2022. if !strings.Contains(insuplc_admdvs, "3603") {
  2023. if id_card_type == 1 {
  2024. bas := strings.Split(psn_info.CardInfo, "|")
  2025. card_sn := bas[3]
  2026. card_no := bas[1]
  2027. struct2401.Cardsn = card_sn
  2028. struct2401.PsnCertType = "01"
  2029. struct2401.Certno = card_no
  2030. struct2401.PsnType = psn_type
  2031. struct2401.PsnName = patient.Name
  2032. }
  2033. }
  2034. result, request_log = service.Jxyb2401(struct2401, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, insuplc_admdvs, miConfig.MdtrtareaAdmvs, miConfig.Url, "", miConfig.AccessKey)
  2035. saveLog(result, request_log, "2401", "入院登记")
  2036. } else {
  2037. //住院登记调用事前
  2038. //var hisPrescription []*models.HisPrescription
  2039. //res3101 := Check3101ForOne(c, patient.ID, struct2401, admin_user_id, "3", record_time, hisPrescription, res2, recordDateTime)
  2040. var res3101 Result3101
  2041. res3101.Infcode = 0
  2042. if res3101.Infcode == 0 {
  2043. result, request_log = service.ZHGdyb2401(struct2401, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, insuplc_admdvs, miConfig.MdtrtareaAdmvs)
  2044. saveLog(result, request_log, "2401", "入院登记")
  2045. } else {
  2046. c.ServeSuccessJSON(map[string]interface{}{
  2047. "failed_code": -10,
  2048. "msg": res3101.ErrMsg,
  2049. })
  2050. return
  2051. }
  2052. }
  2053. var dat map[string]interface{}
  2054. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2055. fmt.Println(dat)
  2056. } else {
  2057. fmt.Println(err)
  2058. }
  2059. userJSONBytes, _ := json.Marshal(dat)
  2060. var res ResultThree
  2061. var resThree10265 ResultThree10265
  2062. if miConfig.Code == "H15049901371" {
  2063. if err := json.Unmarshal(userJSONBytes, &resThree10265); err != nil {
  2064. utils.ErrorLog("解析失败:%v", err)
  2065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2066. return
  2067. }
  2068. Infcode, _ := strconv.ParseInt(resThree10265.Infcode, 10, 64)
  2069. res.Infcode = Infcode
  2070. res.ErrMsg = resThree10265.ErrMsg
  2071. res.Output = resThree10265.Output
  2072. res.InfRefmsgid = resThree10265.InfRefmsgid
  2073. res.RespondTime = resThree10265.RespondTime
  2074. } else {
  2075. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2076. utils.ErrorLog("解析失败:%v", err)
  2077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2078. return
  2079. }
  2080. }
  2081. if res.Infcode == 0 {
  2082. //result2 := service.Gdyb5301Two(res2.Output.Baseinfo.PsnNo, miConfig.OrgName, role.UserName, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  2083. //fmt.Println(result2)
  2084. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  2085. Idetinfos, _ := json.Marshal(res2.Output.Idetinfo)
  2086. infoStr := string(Iinfos)
  2087. idetinfoStr := string(Idetinfos)
  2088. inHospital := &models.HisHospitalCheckRecord{
  2089. PatientId: id,
  2090. Name: name,
  2091. MedicalTreatmentType: med_type,
  2092. RecordDate: recordDateTime,
  2093. IdCardNo: id_card_no,
  2094. AdminUserId: admin_user_id,
  2095. Departments: department,
  2096. UserOrgId: adminInfo.CurrentOrgId,
  2097. Status: 1,
  2098. Ctime: time.Now().Unix(),
  2099. Mtime: time.Now().Unix(),
  2100. Number: res.Output.Result.MdtrtID,
  2101. Doctor: doctor,
  2102. PsnNo: res2.Output.Baseinfo.PsnNo,
  2103. PsnCertType: res2.Output.Baseinfo.PsnCertType,
  2104. Certno: res2.Output.Baseinfo.Certno,
  2105. PsnName: res2.Output.Baseinfo.PsnName,
  2106. Gend: res2.Output.Baseinfo.Gend,
  2107. Naty: res2.Output.Baseinfo.Naty,
  2108. MedType: med_type,
  2109. InsutypeType: insutype,
  2110. Iinfo: infoStr,
  2111. Idetinfo: idetinfoStr,
  2112. IptOtpNo: ipt_otp_no,
  2113. AdmBed: adm_bed,
  2114. IdCardType: id_card_type,
  2115. Diagnosis: diagnosis_ids,
  2116. SickType: sick_type,
  2117. MdtrtCertType: "02",
  2118. InHosptialTime: start_time,
  2119. OutHosptialTime: "",
  2120. InHospitalStatus: 1,
  2121. Certificates: certificates,
  2122. Phone: phone,
  2123. BalanceAccountsType: balance_accounts_type,
  2124. PsnType: psn_type,
  2125. InsuplcAdmdvs: insuplc_admdvs,
  2126. }
  2127. service.CreateHospitalRecord(inHospital)
  2128. c.ServeSuccessJSON(map[string]interface{}{
  2129. "msg": "办理入院成功",
  2130. "info": inHospital,
  2131. })
  2132. } else {
  2133. c.ServeSuccessJSON(map[string]interface{}{
  2134. "failed_code": -10,
  2135. "msg": res.ErrMsg,
  2136. })
  2137. }
  2138. } else {
  2139. c.ServeSuccessJSON(map[string]interface{}{
  2140. "failed_code": -10,
  2141. "msg": res2.ErrMsg,
  2142. })
  2143. return
  2144. }
  2145. }
  2146. func (this *ZHHisApiController) GetZHOutHospitalCheck() {
  2147. id, _ := this.GetInt64("id")
  2148. patient_id, _ := this.GetInt64("patient_id")
  2149. admin_user_id, _ := this.GetInt64("admin_user_id")
  2150. record_time := this.GetString("record_time")
  2151. out_time := this.GetString("out_time")
  2152. adminInfo := this.GetAdminUserInfo()
  2153. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  2154. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  2155. //service.getpre
  2156. record, _ := service.GetInHospitalRecord(id)
  2157. if record.ID == 0 {
  2158. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  2159. return
  2160. }
  2161. infos, _ := service.FindLastPatientPrescriptionInfoTwo2(this.GetAdminUserInfo().CurrentOrgId, patient_id, strings.Split(record.InHosptialTime, " ")[0], strings.Split(out_time, " ")[0])
  2162. timeLayout := "2006-01-02"
  2163. loc, _ := time.LoadLocation("Local")
  2164. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2165. if err != nil {
  2166. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2167. return
  2168. }
  2169. recordDateTime := theTime.Unix()
  2170. //var patient service.Patients
  2171. //if patient_id == 0 {
  2172. // patient, _ = service.GetPatientByIDCard(record.IdCardNo, adminInfo.CurrentOrgId)
  2173. //} else {
  2174. // patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  2175. //}
  2176. for _, item := range infos {
  2177. record.Diagnosis = record.Diagnosis + "," + item.Diagnosis
  2178. }
  2179. diagnosis_ids_arr := strings.Split(record.Diagnosis, ",")
  2180. fmt.Println(diagnosis_ids_arr)
  2181. diagnosis_ids_arr = RemoveRepeatedPurviewElement2(diagnosis_ids_arr)
  2182. fmt.Println(diagnosis_ids_arr)
  2183. diagnosisConfig, _ := service.FindDiagnoseByIds(diagnosis_ids_arr)
  2184. departmentInfo, _ := service.GetDepartMentDetail(record.Departments)
  2185. doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, record.Doctor)
  2186. //deviceNumber, _ := service.GetDeviceNumberByID(record.AdmBed, adminInfo.CurrentOrgId)
  2187. sickConfig, _ := service.FindSickById(record.SickType)
  2188. var struct2402 service.Struct2402
  2189. timestamp := time.Now().Unix()
  2190. tempTime := time.Unix(timestamp, 0)
  2191. //timeFormat := tempTime.Format("20060102150405")
  2192. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  2193. struct2402.PsnNo = record.PsnNo
  2194. struct2402.Insutype = record.InsutypeType
  2195. struct2402.DscgWay = "1"
  2196. struct2402.Endtime = out_time
  2197. struct2402.DscgDeptName = departmentInfo.Number
  2198. struct2402.DscgDeptCodg = strconv.FormatInt(int64(departmentInfo.ID), 10)
  2199. struct2402.MdtrtId = record.Number
  2200. var dises []service.Diseinfo2402Struct
  2201. for index, item := range diagnosisConfig {
  2202. var dise service.Diseinfo2402Struct
  2203. dise.PsnNo = record.PsnNo
  2204. if index == 0 {
  2205. dise.DiagType = "1"
  2206. dise.MaindiagFlag = "1"
  2207. } else {
  2208. dise.DiagType = "1"
  2209. dise.MaindiagFlag = "0"
  2210. }
  2211. dise.MdtrtId = record.Number
  2212. dise.DiagSrtNo = strconv.FormatInt(int64(index), 10)
  2213. dise.DiseDorName = doctorInfo.UserName
  2214. dise.DiagCode = item.CountryCode
  2215. dise.DiagName = item.ClassName
  2216. dise.DiagDept = departmentInfo.Name
  2217. dise.DiseDorNo = doctorInfo.DoctorNumber
  2218. dise.DiagTime = timeFormatOne
  2219. dises = append(dises, dise)
  2220. }
  2221. struct2402.Diseinfo = dises
  2222. struct2402.DiseName = sickConfig.ClassName
  2223. struct2402.DiseCode = sickConfig.CountryCode
  2224. var result string
  2225. var request_log string
  2226. if miConfig.MdtrtareaAdmvs == "150499" {
  2227. data := make(map[string]interface{})
  2228. data["org_name"] = miConfig.OrgName
  2229. data["doctor"] = role.UserName
  2230. data["fixmedins_code"] = miConfig.Code
  2231. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  2232. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  2233. data["secret_key"] = miConfig.SecretKey
  2234. data["struct_2402"] = struct2402
  2235. var req *http.Request
  2236. bytesData, _ := json.Marshal(data)
  2237. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2402", bytes.NewReader(bytesData))
  2238. client := &http.Client{}
  2239. resp, _ := client.Do(req)
  2240. defer resp.Body.Close()
  2241. body, ioErr := ioutil.ReadAll(resp.Body)
  2242. if ioErr != nil {
  2243. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2245. return
  2246. }
  2247. var respJSON map[string]interface{}
  2248. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  2249. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2250. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2251. return
  2252. }
  2253. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2254. result_byte, _ := json.Marshal(respJSON)
  2255. result = string(result_byte)
  2256. } else if miConfig.MdtrtareaAdmvs == "421182" {
  2257. data := make(map[string]interface{})
  2258. data["org_name"] = miConfig.OrgName
  2259. data["doctor"] = role.UserName
  2260. data["fixmedins_code"] = miConfig.Code
  2261. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  2262. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  2263. data["secret_key"] = miConfig.SecretKey
  2264. data["struct_2402"] = struct2402
  2265. var req *http.Request
  2266. bytesData, _ := json.Marshal(data)
  2267. req, _ = http.NewRequest("POST", miConfig.Url +"hbyb/2402", bytes.NewReader(bytesData))
  2268. client := &http.Client{}
  2269. resp, _ := client.Do(req)
  2270. defer resp.Body.Close()
  2271. body, ioErr := ioutil.ReadAll(resp.Body)
  2272. if ioErr != nil {
  2273. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2274. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2275. return
  2276. }
  2277. var respJSON map[string]interface{}
  2278. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  2279. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2280. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2281. return
  2282. }
  2283. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2284. result_byte, _ := json.Marshal(respJSON)
  2285. result = string(result_byte)
  2286. } else if miConfig.MdtrtareaAdmvs == "360399" {
  2287. result, request_log = service.Jxyb2402(struct2402, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.Url, "", miConfig.AccessKey)
  2288. saveLog(result, request_log, "2402", "出院")
  2289. } else {
  2290. result, request_log = service.ZHGdyb2402(struct2402, miConfig.OrgName, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  2291. saveLog(result, request_log, "2402", "出院")
  2292. }
  2293. var dat map[string]interface{}
  2294. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2295. fmt.Println(dat)
  2296. } else {
  2297. fmt.Println(err)
  2298. }
  2299. userJSONBytes, _ := json.Marshal(dat)
  2300. var res ResultEmpty
  2301. var resEmpty10265 ResultEmpty10265
  2302. if miConfig.Code == "H15049901371" {
  2303. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2304. utils.ErrorLog("解析失败:%v", err)
  2305. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2306. return
  2307. }
  2308. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2309. res.Infcode = Infcode
  2310. res.RespondTime = resEmpty10265.RespondTime
  2311. res.ErrMsg = resEmpty10265.ErrMsg
  2312. res.Output = resEmpty10265.Output
  2313. res.WarnMsg = resEmpty10265.WarnMsg
  2314. } else {
  2315. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2316. utils.ErrorLog("解析失败:%v", err)
  2317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2318. return
  2319. }
  2320. }
  2321. if res.Infcode == 0 {
  2322. record.OutHospitalStatus = 1
  2323. record.OutHosptialTime = struct2402.Endtime
  2324. record.OutWay = 1
  2325. service.CreateHospitalRecord(&record)
  2326. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  2327. var total float64
  2328. for _, item := range orders {
  2329. total = total + item.DetItemFeeSumamt
  2330. }
  2331. order := &models.HisOrder{
  2332. UserOrgId: adminInfo.CurrentOrgId,
  2333. HisPatientId: record.ID,
  2334. PatientId: record.PatientId,
  2335. SettleAccountsDate: recordDateTime,
  2336. Ctime: time.Now().Unix(),
  2337. Mtime: time.Now().Unix(),
  2338. Status: 1,
  2339. Number: record.Number,
  2340. Infcode: 0,
  2341. WarnMsg: "",
  2342. Cainfo: "",
  2343. ErrMsg: "",
  2344. RespondTime: "",
  2345. InfRefmsgid: "",
  2346. OrderStatus: 1,
  2347. MdtrtId: record.Number,
  2348. IsMedicineInsurance: 1,
  2349. PType: 1,
  2350. MedfeeSumamt: total,
  2351. }
  2352. err = service.CreateOrder(order)
  2353. if err != nil {
  2354. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2355. return
  2356. }
  2357. this.ServeSuccessJSON(map[string]interface{}{
  2358. "msg": "出院成功",
  2359. })
  2360. } else {
  2361. this.ServeSuccessJSON(map[string]interface{}{
  2362. "failed_code": -10,
  2363. "msg": res.ErrMsg,
  2364. })
  2365. }
  2366. }
  2367. func (c *ZHHisApiController) Get4102() {
  2368. order_id, _ := c.GetInt64("order_id")
  2369. admin_user_id, _ := c.GetInt64("admin_user_id")
  2370. stas_type := c.GetString("stas_type")
  2371. adminUser := c.GetAdminUserInfo()
  2372. order, _ := service.GetHisOrderByID(order_id)
  2373. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2374. var user_name string
  2375. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2376. if role.ID == 0 {
  2377. user_name = "管理员"
  2378. } else {
  2379. user_name = role.UserName
  2380. }
  2381. baseParams := models.BaseParams{
  2382. SecretKey: miConfig.SecretKey,
  2383. FixmedinsCode: miConfig.Code,
  2384. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2385. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2386. OrgName: miConfig.OrgName,
  2387. Doctor: user_name,
  2388. RequestUrl: miConfig.Url,
  2389. AccessKey: miConfig.AccessKey,
  2390. }
  2391. businessParams := models.BusinessParams{
  2392. PsnNo: order.PsnNo,
  2393. MdtrtId: order.MdtrtId,
  2394. SetlId: order.SetlId,
  2395. StasType: stas_type,
  2396. }
  2397. api := "http://172.16.13.254:9532/" + "nmyb/4102?psn_no=" + businessParams.PsnNo + "&mdtrt_id=" + businessParams.MdtrtId + "&setl_id=" + businessParams.SetlId +
  2398. "&org_name=" + miConfig.OrgName + "&doctor=" + baseParams.Doctor + "&fixmedins_code=" + miConfig.Code +
  2399. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&stas_type=" + stas_type
  2400. resp, requestErr := http.Get(api)
  2401. if requestErr != nil {
  2402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2403. return
  2404. }
  2405. body, ioErr := ioutil.ReadAll(resp.Body)
  2406. if ioErr != nil {
  2407. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2409. return
  2410. }
  2411. var respJSON map[string]interface{}
  2412. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2413. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2415. return
  2416. }
  2417. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2418. result, _ := json.Marshal(respJSON)
  2419. fmt.Println("log")
  2420. fmt.Println(string(result))
  2421. var res2 ResultSix
  2422. var resEmpty10265 ResultEmpty10265
  2423. if err := json.Unmarshal(result, &resEmpty10265); err != nil {
  2424. utils.ErrorLog("解析失败:%v", err)
  2425. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2426. return
  2427. }
  2428. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2429. res2.Infcode = Infcode
  2430. res2.RespondTime = resEmpty10265.RespondTime
  2431. res2.ErrMsg = resEmpty10265.ErrMsg
  2432. res2.Output = resEmpty10265.Output
  2433. res2.WarnMsg = resEmpty10265.WarnMsg
  2434. if res2.Infcode == 0 {
  2435. c.ServeSuccessJSON(map[string]interface{}{
  2436. "msg": "确认成功",
  2437. })
  2438. } else {
  2439. c.ServeSuccessJSON(map[string]interface{}{
  2440. "failed_code": -10,
  2441. "msg": res2.ErrMsg,
  2442. })
  2443. }
  2444. }
  2445. func (c *ZHHisApiController) Get4103() {
  2446. order_id, _ := c.GetInt64("order_id")
  2447. admin_user_id, _ := c.GetInt64("admin_user_id")
  2448. stas_type := c.GetString("stas_type")
  2449. adminUser := c.GetAdminUserInfo()
  2450. order, _ := service.GetHisOrderByID(order_id)
  2451. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2452. var user_name string
  2453. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2454. if role.ID == 0 {
  2455. user_name = "管理员"
  2456. } else {
  2457. user_name = role.UserName
  2458. }
  2459. baseParams := models.BaseParams{
  2460. SecretKey: miConfig.SecretKey,
  2461. FixmedinsCode: miConfig.Code,
  2462. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2463. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2464. OrgName: miConfig.OrgName,
  2465. Doctor: user_name,
  2466. RequestUrl: miConfig.Url,
  2467. AccessKey: miConfig.AccessKey,
  2468. }
  2469. businessParams := models.BusinessParams{
  2470. PsnNo: order.PsnNo,
  2471. MdtrtId: order.MdtrtId,
  2472. SetlId: order.SetlId,
  2473. StasType: stas_type,
  2474. }
  2475. api := "http://172.16.13.254:9532/" + "nmyb/4103?psn_no=" + businessParams.PsnNo + "&mdtrt_id=" + businessParams.MdtrtId + "&setl_id=" + businessParams.SetlId +
  2476. "&org_name=" + miConfig.OrgName + "&doctor=" + baseParams.Doctor + "&fixmedins_code=" + miConfig.Code +
  2477. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&stas_type=" + stas_type
  2478. resp, requestErr := http.Get(api)
  2479. if requestErr != nil {
  2480. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2481. return
  2482. }
  2483. body, ioErr := ioutil.ReadAll(resp.Body)
  2484. if ioErr != nil {
  2485. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2487. return
  2488. }
  2489. var respJSON map[string]interface{}
  2490. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2491. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2493. return
  2494. }
  2495. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2496. result, _ := json.Marshal(respJSON)
  2497. fmt.Println("log")
  2498. fmt.Println(string(result))
  2499. var res2 ResultSix
  2500. var resEmpty10265 ResultEmpty10265
  2501. if err := json.Unmarshal(result, &resEmpty10265); err != nil {
  2502. utils.ErrorLog("解析失败:%v", err)
  2503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2504. return
  2505. }
  2506. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2507. res2.Infcode = Infcode
  2508. res2.RespondTime = resEmpty10265.RespondTime
  2509. res2.ErrMsg = resEmpty10265.ErrMsg
  2510. res2.Output = resEmpty10265.Output
  2511. res2.WarnMsg = resEmpty10265.WarnMsg
  2512. if res2.Infcode == 0 {
  2513. c.ServeSuccessJSON(map[string]interface{}{
  2514. "msg": string(result),
  2515. })
  2516. } else {
  2517. c.ServeSuccessJSON(map[string]interface{}{
  2518. "failed_code": -10,
  2519. "msg": res2.ErrMsg,
  2520. })
  2521. }
  2522. }
  2523. //func (c *ZHHisApiController) Get4104() {
  2524. // order_id, _ := c.GetInt64("order_id")
  2525. // admin_user_id, _ := c.GetInt64("admin_user_id")
  2526. // adminUser := c.GetAdminUserInfo()
  2527. // order, _ := service.GetHisOrderByID(order_id)
  2528. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2529. // var user_name string
  2530. // role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2531. // if role.ID == 0 {
  2532. // user_name = "管理员"
  2533. // } else {
  2534. // user_name = role.UserName
  2535. // }
  2536. // baseParams := models.BaseParams{
  2537. // SecretKey: miConfig.SecretKey,
  2538. // FixmedinsCode: miConfig.Code,
  2539. // InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2540. // MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2541. // OrgName: miConfig.OrgName,
  2542. // Doctor: user_name,
  2543. // RequestUrl: miConfig.Url,
  2544. // AccessKey: miConfig.AccessKey,
  2545. // }
  2546. //
  2547. // businessParams := models.BusinessParams{
  2548. // PsnNo: order.PsnNo,
  2549. // MdtrtId: order.MdtrtId,
  2550. // SetlId: order.SetlId,
  2551. // }
  2552. //
  2553. // api := "http://172.16.13.254:9532/" + "nmyb/4104?psn_no=" + businessParams.PsnNo + "&mdtrt_id=" + businessParams.MdtrtId + "&setl_id=" + businessParams.SetlId +
  2554. // "&org_name=" + miConfig.OrgName + "&doctor=" + baseParams.Doctor + "&fixmedins_code=" + miConfig.Code +
  2555. // "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&stas_type=" + stas_type
  2556. // resp, requestErr := http.Get(api)
  2557. // if requestErr != nil {
  2558. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2559. // return
  2560. // }
  2561. // body, ioErr := ioutil.ReadAll(resp.Body)
  2562. // if ioErr != nil {
  2563. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2564. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2565. // return
  2566. // }
  2567. // var respJSON map[string]interface{}
  2568. // if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2569. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2570. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2571. // return
  2572. // }
  2573. //
  2574. // respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2575. // result, _ := json.Marshal(respJSON)
  2576. // fmt.Println("log")
  2577. // fmt.Println(string(result))
  2578. //
  2579. // var res2 ResultSix
  2580. // var resEmpty10265 ResultEmpty10265
  2581. //
  2582. // if err := json.Unmarshal(result, &resEmpty10265); err != nil {
  2583. // utils.ErrorLog("解析失败:%v", err)
  2584. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2585. // return
  2586. // }
  2587. // Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2588. // res2.Infcode = Infcode
  2589. // res2.RespondTime = resEmpty10265.RespondTime
  2590. // res2.ErrMsg = resEmpty10265.ErrMsg
  2591. // res2.Output = resEmpty10265.Output
  2592. // res2.WarnMsg = resEmpty10265.WarnMsg
  2593. //
  2594. // if res2.Infcode == 0 {
  2595. // c.ServeSuccessJSON(map[string]interface{}{
  2596. // "msg": "确认成功",
  2597. // })
  2598. //
  2599. // } else {
  2600. // c.ServeSuccessJSON(map[string]interface{}{
  2601. // "failed_code": -10,
  2602. // "msg": res2.ErrMsg,
  2603. // })
  2604. //
  2605. // }
  2606. //
  2607. //}
  2608. func (c *ZHHisApiController) GetSettleInfo() {
  2609. order_id, _ := c.GetInt64("order_id")
  2610. patient_id, _ := c.GetInt64("patient_id")
  2611. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  2612. admin_user_id, _ := c.GetInt64("admin_user_id")
  2613. pay_way, _ := c.GetInt64("pay_way")
  2614. pay_price, _ := c.GetFloat("pay_price")
  2615. pay_card_no := c.GetString("pay_card_no")
  2616. discount_price, _ := c.GetFloat("discount_price")
  2617. preferential_price, _ := c.GetFloat("preferential_price")
  2618. reality_price, _ := c.GetFloat("reality_price")
  2619. found_price, _ := c.GetFloat("found_price")
  2620. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2621. private_price, _ := c.GetFloat("private_price")
  2622. fapiao_code := c.GetString("fapiao_code")
  2623. fapiao_number := c.GetString("fapiao_number")
  2624. record, _ := service.GetInHospitalRecord(in_hospital_id)
  2625. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  2626. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  2627. order, _ := service.GetHisOrderByID(order_id)
  2628. //dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  2629. //tmp_decimal := c.GetString("tmp_decimal")
  2630. //var decimal float64 //本次使用的押金
  2631. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  2632. tmp_decimal := c.GetString("tmp_decimal")
  2633. var decimal float64 //本次使用的押金
  2634. var errmsg error
  2635. if dec_way == "true" && tmp_decimal == "0" || dec_way == "true" && tmp_decimal == "" {
  2636. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  2637. return
  2638. }
  2639. if len(tmp_decimal) > 0 {
  2640. if tmp_decimal[0] == 45 {
  2641. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  2642. return
  2643. }
  2644. }
  2645. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  2646. if errs != nil {
  2647. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
  2648. return
  2649. }
  2650. decimal = tt
  2651. var rf []*ResultFive
  2652. json.Unmarshal([]byte(record.Iinfo), &rf)
  2653. chrg_bchno := order.Number
  2654. cert_no := record.Certno
  2655. if record.ID == 0 {
  2656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2657. return
  2658. }
  2659. if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  2660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  2661. return
  2662. }
  2663. if record.IdCardType == 1 {
  2664. } else {
  2665. cert_no = record.Certno
  2666. }
  2667. var result string
  2668. var src_resquest string
  2669. timeLayout := "2006-01-02"
  2670. loc, _ := time.LoadLocation("Local")
  2671. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record.InHosptialTime, loc)
  2672. if err != nil {
  2673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2674. return
  2675. }
  2676. recordStartDateTime := theTime.Unix()
  2677. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", record.OutHosptialTime, loc)
  2678. if err != nil {
  2679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2680. return
  2681. }
  2682. recordEndDateTime := theTimeEnd.Unix()
  2683. prescriptions, _ := service.GetZHSettleMonthHisPrescription(c.GetAdminUserInfo().CurrentOrgId, patient_id, recordStartDateTime, recordEndDateTime)
  2684. var total float64
  2685. for _, item := range prescriptions {
  2686. if item.Type == 1 { //药品
  2687. for _, subItem := range item.HisDoctorAdviceInfo {
  2688. total = total + (subItem.Price * subItem.PrescribingNumber)
  2689. }
  2690. }
  2691. if item.Type == 2 { //项目
  2692. for _, subItem := range item.HisPrescriptionProject {
  2693. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  2694. total = total + (subItem.Price * cnt)
  2695. }
  2696. }
  2697. }
  2698. //allTotal := fmt.Sprintf("%.2f", total)
  2699. var allTotal string
  2700. if record.OutHospitalStatus == 0 && order.ID == 0 {
  2701. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  2702. var total float64
  2703. for _, item := range orders {
  2704. total = total + item.DetItemFeeSumamt
  2705. }
  2706. allTotal = fmt.Sprintf("%.4f", total)
  2707. } else {
  2708. allTotal = fmt.Sprintf("%.4f", order.MedfeeSumamt)
  2709. }
  2710. if miConfig.MdtrtareaAdmvs == "150499" {
  2711. psn_info, _ := service.GetPsnByPatientId(patient_id)
  2712. mdtrt_cert_no := ""
  2713. if record.IdCardType == 1 {
  2714. bas := strings.Split(psn_info.CardInfo, "|")
  2715. cardNumber := bas[2]
  2716. mdtrt_cert_no = cardNumber
  2717. } else {
  2718. mdtrt_cert_no = record.Certno
  2719. }
  2720. var acct_used_flag string
  2721. if pay_way == 4 {
  2722. acct_used_flag = "1"
  2723. } else {
  2724. acct_used_flag = "0"
  2725. }
  2726. if pay_way == 6 {
  2727. mdtrt_cert_no = psn_info.VerifyNumber
  2728. acct_used_flag = "1"
  2729. record.IdCardType = 4
  2730. } else {
  2731. acct_used_flag = "0"
  2732. }
  2733. fmt.Println(mdtrt_cert_no)
  2734. fmt.Println(acct_used_flag)
  2735. fmt.Println(record.IdCardType)
  2736. //请求内网数据
  2737. api := "http://172.16.13.254:9532/" + "nmyb/2304?psn_no=" + record.PsnNo + "&mdtrt_id=" + record.Number + "&chrg_bchno=" + chrg_bchno +
  2738. "&insutype_type=" + record.InsutypeType + "&total=" + allTotal +
  2739. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2740. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(record.IdCardType, 10) + "&card_sn=" + "" + "&certificates=" + strconv.FormatInt(record.Certificates, 10) + "&name=" + record.Name + "&cert_no=" + mdtrt_cert_no + "&fapiao_number=" + fapiao_number + "&acct_used_flag=" + acct_used_flag
  2741. resp, requestErr := http.Get(api)
  2742. if requestErr != nil {
  2743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2744. return
  2745. }
  2746. body, ioErr := ioutil.ReadAll(resp.Body)
  2747. if ioErr != nil {
  2748. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2750. return
  2751. }
  2752. var respJSON map[string]interface{}
  2753. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2754. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2756. return
  2757. }
  2758. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2759. result_byte, _ := json.Marshal(respJSON)
  2760. result = string(result_byte)
  2761. } else if miConfig.MdtrtareaAdmvs == "421182" {
  2762. psn_info, _ := service.GetPsnByPatientId(patient_id)
  2763. mdtrt_cert_no := ""
  2764. if record.IdCardType == 1 {
  2765. bas := strings.Split(psn_info.CardInfo, "|")
  2766. cardNumber := bas[2]
  2767. mdtrt_cert_no = cardNumber
  2768. } else {
  2769. mdtrt_cert_no = record.Certno
  2770. }
  2771. var acct_used_flag string
  2772. if pay_way == 4 {
  2773. acct_used_flag = "1"
  2774. } else {
  2775. acct_used_flag = "0"
  2776. }
  2777. if pay_way == 6 {
  2778. mdtrt_cert_no = psn_info.VerifyNumber
  2779. acct_used_flag = "1"
  2780. record.IdCardType = 4
  2781. } else {
  2782. acct_used_flag = "0"
  2783. }
  2784. fmt.Println(mdtrt_cert_no)
  2785. fmt.Println(acct_used_flag)
  2786. fmt.Println(record.IdCardType)
  2787. //请求内网数据
  2788. api := miConfig.Url + "hbyb/2304?psn_no=" + record.PsnNo + "&mdtrt_id=" + record.Number + "&chrg_bchno=" + chrg_bchno +
  2789. "&insutype_type=" + record.InsutypeType + "&total=" + allTotal +
  2790. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2791. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(record.IdCardType, 10) + "&card_sn=" + "" + "&certificates=" + strconv.FormatInt(record.Certificates, 10) + "&name=" + record.Name + "&cert_no=" + mdtrt_cert_no + "&fapiao_number=" + fapiao_number + "&acct_used_flag=" + acct_used_flag
  2792. resp, requestErr := http.Get(api)
  2793. if requestErr != nil {
  2794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2795. return
  2796. }
  2797. body, ioErr := ioutil.ReadAll(resp.Body)
  2798. if ioErr != nil {
  2799. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2801. return
  2802. }
  2803. var respJSON map[string]interface{}
  2804. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2805. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2807. return
  2808. }
  2809. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2810. result_byte, _ := json.Marshal(respJSON)
  2811. result = string(result_byte)
  2812. } else if miConfig.MdtrtareaAdmvs == "360399" {
  2813. psn_info, _ := service.GetPsnByPatientId(patient_id)
  2814. if len(psn_info.CardInfo) > 0 && len(psn_info.VerifyNumber) == 0{
  2815. cert_no = record.Certno
  2816. } else if len(psn_info.CardInfo) == 0 && len(psn_info.VerifyNumber) > 0{
  2817. cert_no = psn_info.VerifyNumber
  2818. }
  2819. //result, src_resquest = service.Jxyb2304(record.PsnNo, record.Number, cert_no, record.InsutypeType, allTotal, record.Certificates, record.IdCardType, "", miConfig.SecretKey, miConfig.OrgName, miConfig.Code, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.Url, "", miConfig.AccessKey, "", "1")
  2820. if strings.Contains(record.InsuplcAdmdvs, "3603") {
  2821. bas := strings.Split(psn_info.CardInfo, "|")
  2822. card_sn := bas[3]
  2823. result, src_resquest = service.Jxyb2304(record.PsnNo, record.Number, cert_no, record.InsutypeType, allTotal, record.Certificates, record.IdCardType, "", miConfig.SecretKey, miConfig.OrgName, miConfig.Code, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.Url, "", miConfig.AccessKey, "", "1",card_sn,"","","","")
  2824. saveLog(result, src_resquest, "2304", "住院结算")
  2825. //if record.IdCardType == 1 {
  2826. //basNumber := bas[2]
  2827. // result, src_resquest = service.Jxyb2303(record.PsnNo, record.Number, cert_no, record.InsutypeType, allTotal, record.Certificates, record.IdCardType, "", miConfig.SecretKey, miConfig.OrgName, miConfig.Code, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.Url, "", miConfig.AccessKey, card_sn, record.PsnType, record.PsnCertType, record.IdCardNo, record.Name)
  2828. // saveLog(result, src_resquest, "2303", "住院预结算")
  2829. //}
  2830. }else{
  2831. bas := strings.Split(psn_info.CardInfo, "|")
  2832. card_sn := bas[3]
  2833. result, src_resquest = service.Jxyb2304a(record.PsnNo, record.Number, cert_no, record.InsutypeType, allTotal, record.Certificates, record.IdCardType, "", miConfig.SecretKey, miConfig.OrgName, miConfig.Code, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.Url, "", miConfig.AccessKey, "", "1",card_sn,record.PsnType,record.PsnCertType,record.IdCardNo,record.Name)
  2834. //result, src_resquest = service.Jxyb2303(record.PsnNo, record.Number, cert_no, record.InsutypeType, allTotal, record.Certificates, record.IdCardType, "", miConfig.SecretKey, miConfig.OrgName, miConfig.Code, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.Url, "", miConfig.AccessKey,"",record.PsnType,record.PsnCertType,record.IdCardNo,record.Name)
  2835. saveLog(result, src_resquest, "2303", "住院预结算")
  2836. }
  2837. } else {
  2838. result3101 := Check3102(c, record.PatientId, record.ID, admin_user_id, "8", order.ID)
  2839. if result3101.Infcode == 0 {
  2840. if len(result3101.Output.Result) > 0 {
  2841. var errMsgs []string
  2842. for _, item := range result3101.Output.Result {
  2843. errMsgs = append(errMsgs, item.VolaCont)
  2844. }
  2845. c.ServeSuccessJSON(map[string]interface{}{
  2846. "failed_code": -10,
  2847. "msg": errMsgs,
  2848. })
  2849. return
  2850. } else {
  2851. result, src_resquest = service.ZHGdyb2304(record.PsnNo, record.Number, chrg_bchno, cert_no, record.InsutypeType, allTotal, miConfig.OrgName, roles.UserName, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "0", record.IdCardType, 0, 0, 0, 0, record.Certificates, "", "1")
  2852. saveLog(result, src_resquest, "2304", "住院结算")
  2853. }
  2854. } else {
  2855. c.ServeSuccessJSON(map[string]interface{}{
  2856. "failed_code": -10,
  2857. "msg": result3101.ErrMsg,
  2858. })
  2859. return
  2860. }
  2861. }
  2862. var dat map[string]interface{}
  2863. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2864. fmt.Println(dat)
  2865. } else {
  2866. fmt.Println(err)
  2867. }
  2868. userJSONBytes, _ := json.Marshal(dat)
  2869. var res ResultSeven
  2870. var resSeven10265 ResultSeven10265
  2871. if miConfig.Code == "H15049901371" {
  2872. if err := json.Unmarshal(userJSONBytes, &resSeven10265); err != nil {
  2873. utils.ErrorLog("解析失败:%v", err)
  2874. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2875. return
  2876. }
  2877. Infcode, _ := strconv.ParseInt(resSeven10265.Infcode, 10, 64)
  2878. res.Infcode = Infcode
  2879. res.InfRefmsgid = resSeven10265.InfRefmsgid
  2880. res.RespondTime = resSeven10265.RespondTime
  2881. res.ErrMsg = resSeven10265.ErrMsg
  2882. res.Output = resSeven10265.Output
  2883. res.WarnMsg = resSeven10265.WarnMsg
  2884. res.Cainfo = resSeven10265.Cainfo
  2885. } else {
  2886. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2887. utils.ErrorLog("解析失败:%v", err)
  2888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2889. return
  2890. }
  2891. }
  2892. if res.Infcode != 0 {
  2893. errlog := &models.HisOrderError{
  2894. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2895. Ctime: time.Now().Unix(),
  2896. Mtime: time.Now().Unix(),
  2897. Number: chrg_bchno,
  2898. ErrMsg: res.ErrMsg,
  2899. Status: 1,
  2900. PatientId: patient_id,
  2901. RecordTime: time.Now().Unix(),
  2902. Stage: 6,
  2903. }
  2904. service.CreateErrMsgLog(errlog)
  2905. c.ServeSuccessJSON(map[string]interface{}{
  2906. "failed_code": -10,
  2907. "msg": res.ErrMsg,
  2908. })
  2909. return
  2910. } else {
  2911. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2912. order.OrderStatus = 2
  2913. order.DiscountPrice = discount_price
  2914. order.MedicalInsurancePrice = medical_insurance_price
  2915. order.FaPiaoNumber = fapiao_number
  2916. order.FaPiaoCode = fapiao_code
  2917. order.PayWay = pay_way
  2918. order.PayPrice = pay_price
  2919. order.PayCardNo = pay_card_no
  2920. order.PreferentialPrice = preferential_price
  2921. order.RealityPrice = reality_price
  2922. order.FoundPrice = found_price
  2923. order.PrivatePrice = private_price
  2924. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2925. order.SetlId = res.Output.Setlinfo.SetlID
  2926. order.PsnNo = res.Output.Setlinfo.PsnNo
  2927. order.PsnName = res.Output.Setlinfo.PsnName
  2928. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2929. order.Certno = res.Output.Setlinfo.Certno
  2930. order.Gend = res.Output.Setlinfo.Gend
  2931. order.Naty = res.Output.Setlinfo.Naty
  2932. order.Age = res.Output.Setlinfo.Age
  2933. order.Insutype = res.Output.Setlinfo.Insutype
  2934. order.PsnType = res.Output.Setlinfo.PsnType
  2935. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2936. order.SetlTime = res.Output.Setlinfo.SetlTime
  2937. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2938. if res.Output.Setlinfo.MedType == "140104" {
  2939. order.MedType = "14"
  2940. } else {
  2941. order.MedType = res.Output.Setlinfo.MedType
  2942. }
  2943. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2944. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2945. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2946. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2947. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2948. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2949. order.HifpPay = res.Output.Setlinfo.HifpPay
  2950. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2951. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2952. order.HifesPay = res.Output.Setlinfo.HifesPay
  2953. order.HifobPay = res.Output.Setlinfo.HifobPay
  2954. order.MafPay = res.Output.Setlinfo.MafPay
  2955. order.OthPay = res.Output.Setlinfo.OthPay
  2956. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2957. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2958. order.AcctPay = res.Output.Setlinfo.AcctPay
  2959. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2960. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2961. order.Balc = res.Output.Setlinfo.Balc
  2962. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2963. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2964. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2965. order.ClrWay = res.Output.Setlinfo.ClrWay
  2966. order.Creator = order.Creator
  2967. order.Modify = roles.AdminUserId
  2968. order.RequestLog = src_resquest
  2969. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2970. detailStr := string(setlDetail)
  2971. order.SetlDetail = detailStr
  2972. err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  2973. err = service.UpDateOrder(order)
  2974. if err == nil {
  2975. //判断是否使用了押金
  2976. if dec_way == "true" {
  2977. tmpstring := strconv.FormatInt(order.ID, 10)
  2978. order.Decimal = decimal
  2979. err = service.UpDateOrder(order)
  2980. //扣押金
  2981. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, patient_id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  2982. if errmsg != nil {
  2983. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  2984. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  2985. return
  2986. }
  2987. }
  2988. c.ServeSuccessJSON(map[string]interface{}{
  2989. "msg": "结算成功",
  2990. })
  2991. } else {
  2992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2993. return
  2994. }
  2995. }
  2996. }
  2997. func (c *ZHHisApiController) GetPreSettleInfo() {
  2998. order_id, _ := c.GetInt64("order_id")
  2999. patient_id, _ := c.GetInt64("patient_id")
  3000. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  3001. admin_user_id, _ := c.GetInt64("admin_user_id")
  3002. record, _ := service.GetInHospitalRecord(in_hospital_id)
  3003. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  3004. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  3005. order, _ := service.GetHisOrderByID(order_id)
  3006. var allTotal string
  3007. if record.OutHospitalStatus == 0 && order.ID == 0 {
  3008. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  3009. var total float64
  3010. for _, item := range orders {
  3011. total = total + item.DetItemFeeSumamt
  3012. }
  3013. allTotal = fmt.Sprintf("%.2f", total)
  3014. } else {
  3015. allTotal = fmt.Sprintf("%.2f", order.MedfeeSumamt)
  3016. }
  3017. var rf []*ResultFive
  3018. json.Unmarshal([]byte(record.Iinfo), &rf)
  3019. chrg_bchno := order.Number
  3020. cert_no := record.Certno
  3021. if record.ID == 0 {
  3022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3023. return
  3024. }
  3025. //if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  3026. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  3027. // return
  3028. //}
  3029. psn_info, _ := service.GetPsnByPatientId(patient_id)
  3030. if record.IdCardType == 1 {
  3031. bas := strings.Split(psn_info.CardInfo, "|")
  3032. cardNumber := bas[2]
  3033. cert_no = cardNumber
  3034. } else if record.IdCardType == 4 {
  3035. cert_no = psn_info.VerifyNumber
  3036. } else {
  3037. cert_no = record.Certno
  3038. }
  3039. var result string
  3040. var src_resquest string
  3041. if miConfig.MdtrtareaAdmvs == "150499" {
  3042. //请求内网数据
  3043. api := "http://172.16.13.254:9532/" + "nmyb/2303?psn_no=" + record.PsnNo + "&mdtrt_id=" + record.Number + "&chrg_bchno=" + chrg_bchno +
  3044. "&insutype_type=" + record.InsutypeType + "&total=" + allTotal +
  3045. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  3046. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(record.IdCardType, 10) + "&card_sn=" + "" + "&certificates=" + strconv.FormatInt(record.Certificates, 10) + "&name=" + record.Name + "&cert_no=" + cert_no
  3047. resp, requestErr := http.Get(api)
  3048. if requestErr != nil {
  3049. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3050. return
  3051. }
  3052. body, ioErr := ioutil.ReadAll(resp.Body)
  3053. if ioErr != nil {
  3054. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3056. return
  3057. }
  3058. var respJSON map[string]interface{}
  3059. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3060. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3062. return
  3063. }
  3064. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3065. result_byte, _ := json.Marshal(respJSON)
  3066. result = string(result_byte)
  3067. }else if miConfig.MdtrtareaAdmvs == "421182" {
  3068. //请求内网数据
  3069. api := miConfig.Url + "hbyb/2303?psn_no=" + record.PsnNo + "&mdtrt_id=" + record.Number + "&chrg_bchno=" + chrg_bchno +
  3070. "&insutype_type=" + record.InsutypeType + "&total=" + allTotal +
  3071. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  3072. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(record.IdCardType, 10) + "&card_sn=" + "" + "&certificates=" + strconv.FormatInt(record.Certificates, 10) + "&name=" + record.Name + "&cert_no=" + cert_no
  3073. resp, requestErr := http.Get(api)
  3074. if requestErr != nil {
  3075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3076. return
  3077. }
  3078. body, ioErr := ioutil.ReadAll(resp.Body)
  3079. if ioErr != nil {
  3080. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3082. return
  3083. }
  3084. var respJSON map[string]interface{}
  3085. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3086. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3088. return
  3089. }
  3090. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3091. result_byte, _ := json.Marshal(respJSON)
  3092. result = string(result_byte)
  3093. } else if miConfig.MdtrtareaAdmvs == "360399" {
  3094. if !strings.Contains(record.InsuplcAdmdvs, "3603") {
  3095. if record.IdCardType == 1 {
  3096. bas := strings.Split(psn_info.CardInfo, "|")
  3097. //basNumber := bas[2]
  3098. card_sn := bas[3]
  3099. result, src_resquest = service.Jxyb2303(record.PsnNo, record.Number, cert_no, record.InsutypeType, allTotal, record.Certificates, record.IdCardType, "", miConfig.SecretKey, miConfig.OrgName, miConfig.Code, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.Url, "", miConfig.AccessKey, card_sn, record.PsnType, record.PsnCertType, record.IdCardNo, record.Name)
  3100. saveLog(result, src_resquest, "2303", "住院预结算")
  3101. }
  3102. }else{
  3103. result, src_resquest = service.Jxyb2303(record.PsnNo, record.Number, cert_no, record.InsutypeType, allTotal, record.Certificates, record.IdCardType, "", miConfig.SecretKey, miConfig.OrgName, miConfig.Code, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.Url, "", miConfig.AccessKey,"",record.PsnType,record.PsnCertType,record.IdCardNo,record.Name)
  3104. saveLog(result, src_resquest, "2303", "住院预结算")
  3105. }
  3106. } else {
  3107. if record.OutHospitalStatus == 1 && order.ID > 0 { //出院的情况下,再去做事中监测
  3108. result3101 := Check3102(c, record.PatientId, record.ID, admin_user_id, "8", order.ID)
  3109. if result3101.Infcode == 0 {
  3110. if len(result3101.Output.Result) > 0 {
  3111. var errMsgs []string
  3112. for _, item := range result3101.Output.Result {
  3113. errMsgs = append(errMsgs, item.VolaCont)
  3114. }
  3115. c.ServeSuccessJSON(map[string]interface{}{
  3116. "failed_code": -10,
  3117. "msg": errMsgs,
  3118. })
  3119. return
  3120. } else {
  3121. result, src_resquest = service.ZHGdyb2303(record.PsnNo, record.Number, chrg_bchno, cert_no, record.InsutypeType, allTotal, miConfig.OrgName, roles.UserName, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "0", record.IdCardType, 0, 0, 0, 0, record.Certificates)
  3122. saveLog(result, src_resquest, "2303", "住院预结算")
  3123. }
  3124. } else {
  3125. c.ServeSuccessJSON(map[string]interface{}{
  3126. "failed_code": -10,
  3127. "msg": result3101.ErrMsg,
  3128. })
  3129. return
  3130. }
  3131. } else {
  3132. result, src_resquest = service.ZHGdyb2303(record.PsnNo, record.Number, chrg_bchno, cert_no, record.InsutypeType, allTotal, miConfig.OrgName, roles.UserName, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "0", record.IdCardType, 0, 0, 0, 0, record.Certificates)
  3133. saveLog(result, src_resquest, "2303", "住院预结算")
  3134. }
  3135. }
  3136. var dat map[string]interface{}
  3137. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3138. fmt.Println(dat)
  3139. } else {
  3140. fmt.Println(err)
  3141. }
  3142. userJSONBytes, _ := json.Marshal(dat)
  3143. var res2 ResultSevenTwo
  3144. var res ResultSeven
  3145. var resSeven10265 ResultSeven10265
  3146. if miConfig.MdtrtareaAdmvs == "360399" {
  3147. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  3148. utils.ErrorLog("解析失败:%v", err)
  3149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3150. return
  3151. }
  3152. if res2.Infcode != 0 {
  3153. errlog := &models.HisOrderError{
  3154. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3155. Ctime: time.Now().Unix(),
  3156. Mtime: time.Now().Unix(),
  3157. Number: chrg_bchno,
  3158. ErrMsg: res.ErrMsg,
  3159. Status: 1,
  3160. PatientId: patient_id,
  3161. RecordTime: time.Now().Unix(),
  3162. Stage: 6,
  3163. }
  3164. service.CreateErrMsgLog(errlog)
  3165. c.ServeSuccessJSON(map[string]interface{}{
  3166. "failed_code": -10,
  3167. "msg": res.ErrMsg,
  3168. })
  3169. return
  3170. } else {
  3171. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  3172. order.OrderStatus = 1
  3173. order.MdtrtId = res2.Output.Setlinfo.MdtrtID
  3174. order.SetlId = res2.Output.Setlinfo.SetlID
  3175. order.PsnNo = res2.Output.Setlinfo.PsnNo
  3176. order.PsnName = res2.Output.Setlinfo.PsnName
  3177. order.PsnCertType = res2.Output.Setlinfo.PsnCertType
  3178. order.Certno = res2.Output.Setlinfo.Certno
  3179. order.Gend = res2.Output.Setlinfo.Gend
  3180. order.Naty = res2.Output.Setlinfo.Naty
  3181. val, _ := strconv.ParseFloat(res2.Output.Setlinfo.Age, 64)
  3182. order.Age = val
  3183. order.Insutype = res2.Output.Setlinfo.Insutype
  3184. order.PsnType = res2.Output.Setlinfo.PsnType
  3185. order.CvlservFlag = res2.Output.Setlinfo.CvlservFlag
  3186. order.SetlTime = res2.Output.Setlinfo.SetlTime
  3187. order.MdtrtCertType = res2.Output.Setlinfo.MdtrtCertType
  3188. if res.Output.Setlinfo.MedType == "140104" {
  3189. order.MedType = "14"
  3190. } else {
  3191. order.MedType = res2.Output.Setlinfo.MedType
  3192. }
  3193. order.MedfeeSumamt = res2.Output.Setlinfo.MedfeeSumamt
  3194. order.FulamtOwnpayAmt = res2.Output.Setlinfo.FulamtOwnpayAmt
  3195. order.OverlmtSelfPay = res2.Output.Setlinfo.OverlmtSelfpay
  3196. order.PreselfpayAmt = res2.Output.Setlinfo.PreselfpayAmt
  3197. order.InscpScpAmt = res2.Output.Setlinfo.InscpScpAmt
  3198. order.ActPayDedc = res2.Output.Setlinfo.ActPayDedc
  3199. order.HifmiPay = res2.Output.Setlinfo.HifmiPay
  3200. order.HifpPay = res2.Output.Setlinfo.HifpPay
  3201. order.HifesPay = res2.Output.Setlinfo.HifesPay
  3202. order.HifobPay = res2.Output.Setlinfo.HifobPay
  3203. order.MafPay = res2.Output.Setlinfo.MafPay
  3204. order.OthPay = res2.Output.Setlinfo.OthPay
  3205. order.CvlservPay = res2.Output.Setlinfo.CvlservPay
  3206. order.PoolPropSelfpay = res2.Output.Setlinfo.PoolPropSelfpay
  3207. order.FundPaySumamt = res2.Output.Setlinfo.FundPaySumamt
  3208. order.PsnPartAmt = res2.Output.Setlinfo.PsnPartAmt
  3209. order.AcctPay = res2.Output.Setlinfo.AcctPay
  3210. order.PsnCashPay = res2.Output.Setlinfo.PsnCashPay
  3211. order.HospPartAmt = res2.Output.Setlinfo.HospPartAmt
  3212. order.Balc = res2.Output.Setlinfo.Balc
  3213. order.AcctMulaidPay = res2.Output.Setlinfo.AcctMulaidPay
  3214. order.MedinsSetlId = res2.Output.Setlinfo.MedinsSetlID
  3215. order.ClrOptins = res2.Output.Setlinfo.ClrOptins
  3216. order.ClrWay = res2.Output.Setlinfo.ClrWay
  3217. order.Creator = order.Creator
  3218. order.Modify = roles.AdminUserId
  3219. order.RequestLog = src_resquest
  3220. setlDetail, _ := json.Marshal(res2.Output.Setldetail)
  3221. detailStr := string(setlDetail)
  3222. order.SetlDetail = detailStr
  3223. //err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  3224. if record.OutHospitalStatus == 1 && order.ID > 0 {
  3225. err := service.UpDateOrder(order)
  3226. if err == nil {
  3227. c.ServeSuccessJSON(map[string]interface{}{
  3228. "msg": "预结算成功",
  3229. "order_way": 1,
  3230. })
  3231. } else {
  3232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  3233. return
  3234. }
  3235. } else if record.OutHospitalStatus == 0 && order.ID == 0 {
  3236. var order models.HisOrder
  3237. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  3238. order.OrderStatus = 1
  3239. order.MdtrtId = res2.Output.Setlinfo.MdtrtID
  3240. order.SetlId = res2.Output.Setlinfo.SetlID
  3241. order.PsnNo = res2.Output.Setlinfo.PsnNo
  3242. order.PsnName = res2.Output.Setlinfo.PsnName
  3243. order.PsnCertType = res2.Output.Setlinfo.PsnCertType
  3244. order.Certno = res2.Output.Setlinfo.Certno
  3245. order.Gend = res2.Output.Setlinfo.Gend
  3246. order.Naty = res2.Output.Setlinfo.Naty
  3247. val, _ := strconv.ParseFloat(res2.Output.Setlinfo.Age, 64)
  3248. order.Age = val
  3249. order.Insutype = res2.Output.Setlinfo.Insutype
  3250. order.PsnType = res2.Output.Setlinfo.PsnType
  3251. order.CvlservFlag = res2.Output.Setlinfo.CvlservFlag
  3252. order.SetlTime = res2.Output.Setlinfo.SetlTime
  3253. order.MdtrtCertType = res2.Output.Setlinfo.MdtrtCertType
  3254. if res2.Output.Setlinfo.MedType == "140104" {
  3255. order.MedType = "14"
  3256. } else {
  3257. order.MedType = res2.Output.Setlinfo.MedType
  3258. }
  3259. order.MedfeeSumamt = res2.Output.Setlinfo.MedfeeSumamt
  3260. order.FulamtOwnpayAmt = res2.Output.Setlinfo.FulamtOwnpayAmt
  3261. order.OverlmtSelfPay = res2.Output.Setlinfo.OverlmtSelfpay
  3262. order.PreselfpayAmt = res2.Output.Setlinfo.PreselfpayAmt
  3263. order.InscpScpAmt = res2.Output.Setlinfo.InscpScpAmt
  3264. order.ActPayDedc = res2.Output.Setlinfo.ActPayDedc
  3265. order.HifmiPay = res2.Output.Setlinfo.HifmiPay
  3266. order.HifpPay = res2.Output.Setlinfo.HifpPay
  3267. order.HifesPay = res2.Output.Setlinfo.HifesPay
  3268. order.HifobPay = res2.Output.Setlinfo.HifobPay
  3269. order.MafPay = res2.Output.Setlinfo.MafPay
  3270. order.OthPay = res2.Output.Setlinfo.OthPay
  3271. order.CvlservPay = res2.Output.Setlinfo.CvlservPay
  3272. order.PoolPropSelfpay = res2.Output.Setlinfo.PoolPropSelfpay
  3273. order.FundPaySumamt = res2.Output.Setlinfo.FundPaySumamt
  3274. order.PsnPartAmt = res2.Output.Setlinfo.PsnPartAmt
  3275. order.AcctPay = res2.Output.Setlinfo.AcctPay
  3276. order.PsnCashPay = res2.Output.Setlinfo.PsnCashPay
  3277. order.HospPartAmt = res2.Output.Setlinfo.HospPartAmt
  3278. order.Balc = res2.Output.Setlinfo.Balc
  3279. order.AcctMulaidPay = res2.Output.Setlinfo.AcctMulaidPay
  3280. order.MedinsSetlId = res2.Output.Setlinfo.MedinsSetlID
  3281. order.ClrOptins = res2.Output.Setlinfo.ClrOptins
  3282. order.ClrWay = res2.Output.Setlinfo.ClrWay
  3283. order.Creator = order.Creator
  3284. order.Modify = roles.AdminUserId
  3285. order.RequestLog = src_resquest
  3286. setlDetail, _ := json.Marshal(res2.Output.Setldetail)
  3287. detailStr := string(setlDetail)
  3288. order.SetlDetail = detailStr
  3289. c.ServeSuccessJSON(map[string]interface{}{
  3290. "msg": "预结算成功",
  3291. "order": order,
  3292. "order_way": 2,
  3293. })
  3294. }
  3295. }
  3296. } else {
  3297. if miConfig.Code == "H15049901371" {
  3298. if err := json.Unmarshal(userJSONBytes, &resSeven10265); err != nil {
  3299. utils.ErrorLog("解析失败:%v", err)
  3300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3301. return
  3302. }
  3303. Infcode, _ := strconv.ParseInt(resSeven10265.Infcode, 10, 64)
  3304. res.Infcode = Infcode
  3305. res.InfRefmsgid = resSeven10265.InfRefmsgid
  3306. res.RespondTime = resSeven10265.RespondTime
  3307. res.ErrMsg = resSeven10265.ErrMsg
  3308. res.Output = resSeven10265.Output
  3309. res.WarnMsg = resSeven10265.WarnMsg
  3310. res.Cainfo = resSeven10265.Cainfo
  3311. } else {
  3312. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3313. utils.ErrorLog("解析失败:%v", err)
  3314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3315. return
  3316. }
  3317. }
  3318. if res.Infcode != 0 {
  3319. errlog := &models.HisOrderError{
  3320. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3321. Ctime: time.Now().Unix(),
  3322. Mtime: time.Now().Unix(),
  3323. Number: chrg_bchno,
  3324. ErrMsg: res.ErrMsg,
  3325. Status: 1,
  3326. PatientId: patient_id,
  3327. RecordTime: time.Now().Unix(),
  3328. Stage: 6,
  3329. }
  3330. service.CreateErrMsgLog(errlog)
  3331. c.ServeSuccessJSON(map[string]interface{}{
  3332. "failed_code": -10,
  3333. "msg": res.ErrMsg,
  3334. })
  3335. return
  3336. } else {
  3337. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  3338. order.OrderStatus = 1
  3339. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  3340. order.SetlId = res.Output.Setlinfo.SetlID
  3341. order.PsnNo = res.Output.Setlinfo.PsnNo
  3342. order.PsnName = res.Output.Setlinfo.PsnName
  3343. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  3344. order.Certno = res.Output.Setlinfo.Certno
  3345. order.Gend = res.Output.Setlinfo.Gend
  3346. order.Naty = res.Output.Setlinfo.Naty
  3347. order.Age = res.Output.Setlinfo.Age
  3348. order.Insutype = res.Output.Setlinfo.Insutype
  3349. order.PsnType = res.Output.Setlinfo.PsnType
  3350. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  3351. order.SetlTime = res.Output.Setlinfo.SetlTime
  3352. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  3353. if res.Output.Setlinfo.MedType == "140104" {
  3354. order.MedType = "14"
  3355. } else {
  3356. order.MedType = res.Output.Setlinfo.MedType
  3357. }
  3358. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  3359. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  3360. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  3361. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  3362. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  3363. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  3364. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  3365. order.HifpPay = res.Output.Setlinfo.HifpPay
  3366. order.HifesPay = res.Output.Setlinfo.HifesPay
  3367. order.HifobPay = res.Output.Setlinfo.HifobPay
  3368. order.MafPay = res.Output.Setlinfo.MafPay
  3369. order.OthPay = res.Output.Setlinfo.OthPay
  3370. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  3371. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  3372. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  3373. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  3374. order.AcctPay = res.Output.Setlinfo.AcctPay
  3375. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  3376. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  3377. order.Balc = res.Output.Setlinfo.Balc
  3378. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  3379. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  3380. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  3381. order.ClrWay = res.Output.Setlinfo.ClrWay
  3382. order.Creator = order.Creator
  3383. order.Modify = roles.AdminUserId
  3384. order.RequestLog = src_resquest
  3385. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  3386. detailStr := string(setlDetail)
  3387. order.SetlDetail = detailStr
  3388. //err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  3389. if record.OutHospitalStatus == 1 && order.ID > 0 {
  3390. err := service.UpDateOrder(order)
  3391. if err == nil {
  3392. c.ServeSuccessJSON(map[string]interface{}{
  3393. "msg": "预结算成功",
  3394. "order_way": 1,
  3395. })
  3396. } else {
  3397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  3398. return
  3399. }
  3400. } else if record.OutHospitalStatus == 0 && order.ID == 0 {
  3401. c.ServeSuccessJSON(map[string]interface{}{
  3402. "msg": "预结算成功",
  3403. "order": order,
  3404. "order_way": 2,
  3405. })
  3406. }
  3407. }
  3408. }
  3409. }
  3410. func (c *ZHHisApiController) GetUploadInfo() {
  3411. id, _ := c.GetInt64("id")
  3412. record_time := c.GetString("record_time")
  3413. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  3414. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  3415. admin_user_id, _ := c.GetInt64("admin_user_id")
  3416. timeLayout := "2006-01-02"
  3417. loc, _ := time.LoadLocation("Local")
  3418. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3419. if err != nil {
  3420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3421. return
  3422. }
  3423. recordDateTime := theTime.Unix()
  3424. adminUser := c.GetAdminUserInfo()
  3425. var prescriptions []*models.HisPrescription
  3426. data := make(map[string]interface{})
  3427. if settle_accounts_type == 1 { //日结
  3428. prescriptions, _ = service.GetZHHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  3429. } else { //月结
  3430. start_time_str := c.GetString("start_time")
  3431. end_time_str := c.GetString("end_time")
  3432. timeLayout := "2006-01-02"
  3433. loc, _ := time.LoadLocation("Local")
  3434. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  3435. if err != nil {
  3436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3437. return
  3438. }
  3439. recordStartTime := theStartTime.Unix()
  3440. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3441. if err != nil {
  3442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3443. return
  3444. }
  3445. recordEndTime := theEndTime.Unix()
  3446. prescriptions, _ = service.GetZHMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  3447. }
  3448. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3449. record, _ := service.GetInHospitalRecord(in_hospital_id)
  3450. if record.ID == 0 {
  3451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3452. return
  3453. }
  3454. timestamp := time.Now().Unix()
  3455. tempTime := time.Unix(timestamp, 0)
  3456. timeFormat := tempTime.Format("20060102150405")
  3457. chrgBchno := rand.Intn(100000) + 10000
  3458. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(record.PatientId, 10)
  3459. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3460. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  3461. department, _ := service.GetDepartMentDetail(record.Departments)
  3462. strconv.FormatInt(record.PatientId, 10)
  3463. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.Creator)
  3464. //client := &http.Client{}
  3465. data["psn_no"] = record.PsnNo
  3466. data["mdtrt_id"] = record.Number
  3467. data["chrg_bchno"] = chrg_bchno
  3468. data["org_name"] = miConfig.OrgName
  3469. data["doctor"] = roles.UserName
  3470. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  3471. data["dept"] = strconv.FormatInt(department.ID, 10)
  3472. data["fixmedins_code"] = miConfig.Code
  3473. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  3474. data["dept_code"] = "15"
  3475. } else {
  3476. data["dept_code"] = department.Number
  3477. }
  3478. if miConfig.Code == "H15049901371" {
  3479. if record.MedType == 14 {
  3480. if record.InsutypeType == "390" {
  3481. data["med_type"] = ""
  3482. } else if record.InsutypeType == "310" {
  3483. data["med_type"] = ""
  3484. }
  3485. } else if record.MedType == 11 {
  3486. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  3487. }
  3488. } else {
  3489. if record.MedType == 1112 {
  3490. data["med_type"] = strconv.FormatInt(11, 10)
  3491. } else {
  3492. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  3493. }
  3494. }
  3495. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  3496. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  3497. data["secret_key"] = miConfig.SecretKey
  3498. var ids []int64
  3499. fmt.Println(data)
  3500. for _, item := range prescriptions {
  3501. ids = append(ids, item.ID)
  3502. }
  3503. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3504. if config.IsOpen == 1 { //对接了医保,走医保流程
  3505. var pagesize int = 10
  3506. var start int = 1
  3507. var stop int
  3508. var pagecount int
  3509. var curpage int
  3510. var isSuccess bool = true
  3511. var customs []*models.NewCustom
  3512. var empty_code_errs []string
  3513. for _, item := range prescriptions {
  3514. if item.Type == 1 { //药品
  3515. for _, subItem := range item.HisDoctorAdviceInfo {
  3516. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) == 0 && subItem.Price > 0{
  3517. empty_code_errs = append(empty_code_errs,subItem.BaseDrugLib.DrugName)
  3518. }
  3519. }
  3520. }
  3521. if item.Type == 2 { //项目
  3522. for _, subItem := range item.HisPrescriptionProject {
  3523. //var randNum int
  3524. //randNum = rand.Intn(10000) + 1000
  3525. if subItem.Type == 2 {
  3526. if len(subItem.HisProject.MedicalCode) == 0 && subItem.Price > 0{
  3527. empty_code_errs = append(empty_code_errs,subItem.HisProject.ProjectName)
  3528. }
  3529. } else if subItem.Type == 3 {
  3530. if len(subItem.GoodInfo.MedicalInsuranceNumber) == 0 && subItem.Price > 0 {
  3531. empty_code_errs = append(empty_code_errs,subItem.GoodInfo.GoodName)
  3532. }
  3533. }
  3534. }
  3535. }
  3536. }
  3537. if len(empty_code_errs) > 0{
  3538. var err string
  3539. for _, item := range empty_code_errs{
  3540. if len(err) == 0{
  3541. err = item
  3542. }else{
  3543. err = err +"," + item
  3544. }
  3545. }
  3546. c.ServeSuccessJSON(map[string]interface{}{
  3547. "failed_code": -10,
  3548. "msg": err +" "+ "没有填写国家编码",
  3549. })
  3550. return
  3551. }
  3552. for _, item := range prescriptions {
  3553. tm := time.Unix(item.PreTime, 0)
  3554. if item.Type == 1 { //药品
  3555. for _, subItem := range item.HisDoctorAdviceInfo {
  3556. //var randNum int
  3557. //randNum = rand.Intn(10000) + 1000
  3558. cus := &models.NewCustom{
  3559. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  3560. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  3561. FeedetlSn: subItem.FeedetlSn,
  3562. Price: fmt.Sprintf("%.4f", subItem.Price),
  3563. MedListCodg: subItem.BaseDrugLib.MedicalInsuranceNumber,
  3564. HospApprFlag: subItem.BaseDrugLib.HospApprFlag,
  3565. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  3566. DoctorId: item.Creator,
  3567. }
  3568. customs = append(customs, cus)
  3569. }
  3570. }
  3571. if item.Type == 2 { //项目
  3572. for _, subItem := range item.HisPrescriptionProject {
  3573. //var randNum int
  3574. //randNum = rand.Intn(10000) + 1000
  3575. if subItem.Type == 2 {
  3576. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  3577. cus := &models.NewCustom{
  3578. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  3579. Cut: fmt.Sprintf("%.4f", cnt),
  3580. FeedetlSn: subItem.FeedetlSn,
  3581. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  3582. MedListCodg: subItem.HisProject.MedicalCode,
  3583. HospApprFlag: -1,
  3584. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  3585. DoctorId: item.Creator,
  3586. }
  3587. customs = append(customs, cus)
  3588. } else if subItem.Type == 3 {
  3589. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  3590. cus := &models.NewCustom{
  3591. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  3592. Cut: fmt.Sprintf("%.4f", cnt),
  3593. FeedetlSn: subItem.FeedetlSn,
  3594. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  3595. MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  3596. HospApprFlag: -1,
  3597. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  3598. DoctorId: item.Creator,
  3599. }
  3600. customs = append(customs, cus)
  3601. }
  3602. }
  3603. }
  3604. }
  3605. //总页数,向上取整,注意除之前要先转换类型为float64
  3606. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  3607. var ress []*ResultFour
  3608. for curpage = 1; curpage <= pagecount; curpage++ {
  3609. if curpage == 1 {
  3610. start = 1
  3611. } else {
  3612. start = (curpage-1)*pagesize + 1
  3613. }
  3614. stop = curpage * pagesize
  3615. if stop > len(customs) {
  3616. stop = len(customs)
  3617. }
  3618. var result string
  3619. var requestLog string
  3620. if miConfig.MdtrtareaAdmvs == "150499" {
  3621. data := make(map[string]interface{})
  3622. if record.MedType == 14 {
  3623. if record.InsutypeType == "390" {
  3624. data["med_type"] = "9933"
  3625. } else if record.InsutypeType == "310" {
  3626. data["med_type"] = "990502"
  3627. }
  3628. } else if record.MedType == 11 {
  3629. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  3630. }
  3631. data["psn_no"] = record.PsnNo
  3632. data["number"] = record.Number
  3633. data["customs"] = customs[start-1 : stop]
  3634. data["chrg_bchno"] = chrg_bchno
  3635. data["dept"] = strconv.FormatInt(department.ID, 10)
  3636. data["dept_code"] = department.Number
  3637. data["doctor_code"] = doctor_info.DoctorNumber
  3638. data["doctor_name"] = doctor_info.UserName
  3639. data["org_name"] = miConfig.OrgName
  3640. data["opertor"] = roles.UserName
  3641. data["fixmedins_code"] = miConfig.Code
  3642. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  3643. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  3644. data["secret_key"] = miConfig.SecretKey
  3645. var req *http.Request
  3646. bytesData, _ := json.Marshal(data)
  3647. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2301", bytes.NewReader(bytesData))
  3648. client := &http.Client{}
  3649. resp, _ := client.Do(req)
  3650. defer resp.Body.Close()
  3651. body, ioErr := ioutil.ReadAll(resp.Body)
  3652. if ioErr != nil {
  3653. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3655. return
  3656. }
  3657. var respJSON map[string]interface{}
  3658. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  3659. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3661. return
  3662. }
  3663. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3664. result_byte, _ := json.Marshal(respJSON)
  3665. result = string(result_byte)
  3666. } else if miConfig.MdtrtareaAdmvs == "421182" {
  3667. data := make(map[string]interface{})
  3668. //if record.MedType == 14 {
  3669. // if record.InsutypeType == "390" {
  3670. //
  3671. // data["med_type"] = "9933"
  3672. //
  3673. // } else if record.InsutypeType == "310" {
  3674. //
  3675. // data["med_type"] = "990502"
  3676. //
  3677. // }
  3678. //
  3679. //} else if record.MedType == 11 {
  3680. //
  3681. //
  3682. //}
  3683. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  3684. data["psn_no"] = record.PsnNo
  3685. data["number"] = record.Number
  3686. data["customs"] = customs[start-1 : stop]
  3687. data["chrg_bchno"] = chrg_bchno
  3688. data["dept"] = strconv.FormatInt(department.ID, 10)
  3689. data["dept_code"] = department.Number
  3690. data["doctor_code"] = doctor_info.DoctorNumber
  3691. data["doctor_name"] = doctor_info.UserName
  3692. data["org_name"] = miConfig.OrgName
  3693. data["opertor"] = roles.UserName
  3694. data["fixmedins_code"] = miConfig.Code
  3695. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  3696. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  3697. data["secret_key"] = miConfig.SecretKey
  3698. var req *http.Request
  3699. bytesData, _ := json.Marshal(data)
  3700. req, _ = http.NewRequest("POST", miConfig.Url +"hbyb/2301", bytes.NewReader(bytesData))
  3701. client := &http.Client{}
  3702. resp, _ := client.Do(req)
  3703. defer resp.Body.Close()
  3704. body, ioErr := ioutil.ReadAll(resp.Body)
  3705. if ioErr != nil {
  3706. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3708. return
  3709. }
  3710. var respJSON map[string]interface{}
  3711. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  3712. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3714. return
  3715. }
  3716. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3717. result_byte, _ := json.Marshal(respJSON)
  3718. result = string(result_byte)
  3719. } else if miConfig.MdtrtareaAdmvs == "360399" {
  3720. result, requestLog = service.Jxyb2301(record.PsnNo, record.Number, customs[start-1:stop], data["med_type"].(string), chrg_bchno, department.Number, strconv.FormatInt(department.ID, 10), strconv.FormatInt(roles.AdminUserId, 10), miConfig.SecretKey, miConfig.OrgName, miConfig.Code, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.Url, "", miConfig.AccessKey)
  3721. saveLog(result, requestLog, "2301", "上传明细")
  3722. } else {
  3723. fmt.Println("--------")
  3724. fmt.Println(prescriptions)
  3725. fmt.Println("--------")
  3726. res3101 := Check3101(c, record.PatientId, record.ID, admin_user_id, "4", record_time, prescriptions)
  3727. if res3101.Infcode == 0 {
  3728. if len(res3101.Output.Result) > 0 {
  3729. var errMsgs []string
  3730. for _, item := range res3101.Output.Result {
  3731. errMsgs = append(errMsgs, item.VolaCont)
  3732. }
  3733. c.ServeSuccessJSON(map[string]interface{}{
  3734. "failed_code": -10,
  3735. "msg": errMsgs,
  3736. })
  3737. return
  3738. } else {
  3739. result, requestLog = service.ZHGdyb2301(record.PsnNo, record.Number, customs[start-1:stop], chrg_bchno, miConfig.OrgName, roles.UserName, strconv.FormatInt(department.ID, 10), miConfig.Code, department.Number, strconv.FormatInt(roles.AdminUserId, 10), record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, data["med_type"].(string), doctor_info.UserName, doctor_info.DoctorNumber)
  3740. saveLog(result, requestLog, "2301", "上传明细")
  3741. }
  3742. } else {
  3743. c.ServeSuccessJSON(map[string]interface{}{
  3744. "failed_code": -10,
  3745. "msg": res3101.ErrMsg,
  3746. })
  3747. return
  3748. }
  3749. }
  3750. var dat map[string]interface{}
  3751. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3752. fmt.Println(dat)
  3753. } else {
  3754. fmt.Println(err)
  3755. }
  3756. userJSONBytes, _ := json.Marshal(dat)
  3757. var res ResultFour
  3758. var resFour10265 ResultFour10265
  3759. if miConfig.Code == "H15049901371" {
  3760. if err := json.Unmarshal(userJSONBytes, &resFour10265); err != nil {
  3761. utils.ErrorLog("解析失败:%v", err)
  3762. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3763. return
  3764. }
  3765. res.WarnMsg = resFour10265.WarnMsg
  3766. res.Output = resFour10265.Output
  3767. res.ErrMsg = resFour10265.ErrMsg
  3768. res.RespondTime = resFour10265.RespondTime
  3769. res.InfRefmsgid = resFour10265.InfRefmsgid
  3770. Infcode, _ := strconv.ParseInt(resFour10265.Infcode, 10, 64)
  3771. res.Infcode = Infcode
  3772. } else {
  3773. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3774. utils.ErrorLog("解析失败:%v", err)
  3775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3776. return
  3777. }
  3778. }
  3779. if res.Infcode == 0 {
  3780. ress = append(ress, &res)
  3781. } else {
  3782. isSuccess = false
  3783. errlog := &models.HisOrderError{
  3784. UserOrgId: adminUser.CurrentOrgId,
  3785. Ctime: time.Now().Unix(),
  3786. Mtime: time.Now().Unix(),
  3787. Number: chrg_bchno,
  3788. ErrMsg: "",
  3789. Status: 1,
  3790. PatientId: id,
  3791. RecordTime: recordDateTime,
  3792. Stage: 4,
  3793. }
  3794. service.CreateErrMsgLog(errlog)
  3795. c.ServeSuccessJSON(map[string]interface{}{
  3796. "failed_code": -10,
  3797. "msg": "上传明细错误,请联系his厂商",
  3798. })
  3799. return
  3800. }
  3801. }
  3802. if isSuccess == true {
  3803. if settle_accounts_type == 1 {
  3804. for _, subItem := range ress {
  3805. for _, item := range subItem.Output.Result {
  3806. temp := strings.Split(item.FeedetlSn, "-")
  3807. var advice_id int64 = 0
  3808. var project_id int64 = 0
  3809. var types int64 = 0
  3810. id, _ := strconv.ParseInt(temp[2], 10, 64)
  3811. types, _ = strconv.ParseInt(temp[1], 10, 64)
  3812. if temp[1] == "1" {
  3813. advice_id = id
  3814. project_id = 0
  3815. } else if temp[1] == "2" {
  3816. advice_id = 0
  3817. project_id = id
  3818. }
  3819. info := &models.HisOrderInfo{
  3820. OrderNumber: record.Number,
  3821. FeedetlSn: item.FeedetlSn,
  3822. UploadDate: recordDateTime,
  3823. AdviceId: advice_id,
  3824. DetItemFeeSumamt: item.DetItemFeeSumamt,
  3825. Cnt: item.Cnt,
  3826. Pric: float64(item.Pric),
  3827. PatientId: record.PatientId,
  3828. PricUplmtAmt: item.PricUplmtAmt,
  3829. SelfpayProp: item.SelfpayProp,
  3830. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  3831. OverlmtAmt: item.OverlmtAmt,
  3832. PreselfpayAmt: item.PreselfpayAmt,
  3833. BasMednFlag: item.BasMednFlag,
  3834. MedChrgitmType: item.MedChrgitmType,
  3835. HiNegoDrugFlag: item.HiNegoDrugFlag,
  3836. Status: 1,
  3837. Memo: item.Memo,
  3838. Mtime: time.Now().Unix(),
  3839. InscpScpAmt: item.InscpScpAmt,
  3840. DrtReimFlag: item.DrtReimFlag,
  3841. Ctime: time.Now().Unix(),
  3842. ListSpItemFlag: item.ListSpItemFlag,
  3843. ChldMedcFlag: item.ChldMedcFlag,
  3844. LmtUsedFlag: item.LmtUsedFlag,
  3845. ChrgitmLv: item.ChrgitmLv,
  3846. UserOrgId: adminUser.CurrentOrgId,
  3847. HisPatientId: record.ID,
  3848. OrderId: 0,
  3849. ProjectId: project_id,
  3850. Type: types,
  3851. SettleType: settle_accounts_type,
  3852. }
  3853. service.CreateOrderInfo(info)
  3854. }
  3855. }
  3856. err := service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  3857. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  3858. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  3859. if err == nil {
  3860. c.ServeSuccessJSON(map[string]interface{}{
  3861. "msg": "上传费用明细成功",
  3862. })
  3863. return
  3864. } else {
  3865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3866. return
  3867. }
  3868. } else {
  3869. for _, subItem := range ress {
  3870. for _, item := range subItem.Output.Result {
  3871. temp := strings.Split(item.FeedetlSn, "-")
  3872. var advice_id int64 = 0
  3873. var project_id int64 = 0
  3874. var types int64 = 0
  3875. id, _ := strconv.ParseInt(temp[2], 10, 64)
  3876. types, _ = strconv.ParseInt(temp[1], 10, 64)
  3877. if temp[1] == "1" {
  3878. advice_id = id
  3879. project_id = 0
  3880. } else if temp[1] == "2" {
  3881. advice_id = 0
  3882. project_id = id
  3883. }
  3884. info := &models.HisOrderInfo{
  3885. OrderNumber: record.Number,
  3886. FeedetlSn: item.FeedetlSn,
  3887. UploadDate: time.Now().Unix(),
  3888. AdviceId: advice_id,
  3889. DetItemFeeSumamt: item.DetItemFeeSumamt,
  3890. Cnt: item.Cnt,
  3891. Pric: float64(item.Pric),
  3892. PatientId: record.PatientId,
  3893. PricUplmtAmt: item.PricUplmtAmt,
  3894. SelfpayProp: item.SelfpayProp,
  3895. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  3896. OverlmtAmt: item.OverlmtAmt,
  3897. PreselfpayAmt: item.PreselfpayAmt,
  3898. BasMednFlag: item.BasMednFlag,
  3899. MedChrgitmType: item.MedChrgitmType,
  3900. HiNegoDrugFlag: item.HiNegoDrugFlag,
  3901. Status: 1,
  3902. Memo: item.Memo,
  3903. Mtime: time.Now().Unix(),
  3904. InscpScpAmt: item.InscpScpAmt,
  3905. DrtReimFlag: item.DrtReimFlag,
  3906. Ctime: time.Now().Unix(),
  3907. ListSpItemFlag: item.ListSpItemFlag,
  3908. ChldMedcFlag: item.ChldMedcFlag,
  3909. LmtUsedFlag: item.LmtUsedFlag,
  3910. ChrgitmLv: item.ChrgitmLv,
  3911. UserOrgId: adminUser.CurrentOrgId,
  3912. HisPatientId: record.ID,
  3913. ProjectId: project_id,
  3914. Type: types,
  3915. SettleType: settle_accounts_type,
  3916. }
  3917. service.CreateOrderInfo(info)
  3918. }
  3919. }
  3920. service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  3921. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  3922. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  3923. c.ServeSuccessJSON(map[string]interface{}{
  3924. "msg": "上传费用明细成功",
  3925. })
  3926. }
  3927. }
  3928. }
  3929. }
  3930. func (c *ZHHisApiController) ZHRefund() {
  3931. order_id, _ := c.GetInt64("order_id")
  3932. admin_user_id, _ := c.GetInt64("admin_user_id")
  3933. adminUser := c.GetAdminUserInfo()
  3934. var order models.HisOrder
  3935. order, _ = service.GetHisOrderByID(order_id)
  3936. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  3937. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3938. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3939. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3940. if config.IsOpen == 1 { //对接了医保,走医保流程
  3941. var result string
  3942. var requestLog string
  3943. if miConfig.MdtrtareaAdmvs == "150499" {
  3944. //请求内网数据
  3945. api := "http://172.16.13.254:9532/" + "nmyb/2305?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo + "&setl_id=" + order.SetlId +
  3946. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  3947. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3948. resp, requestErr := http.Get(api)
  3949. if requestErr != nil {
  3950. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3951. return
  3952. }
  3953. body, ioErr := ioutil.ReadAll(resp.Body)
  3954. if ioErr != nil {
  3955. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3957. return
  3958. }
  3959. var respJSON map[string]interface{}
  3960. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3961. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3963. return
  3964. }
  3965. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3966. result_byte, _ := json.Marshal(respJSON)
  3967. result = string(result_byte)
  3968. //saveLog(result, requestLog, "2404", "入院登记撤销")
  3969. saveLog(result, requestLog, "2305", "退费")
  3970. } else if miConfig.MdtrtareaAdmvs == "421182" {
  3971. //请求内网数据
  3972. api := miConfig.Url + "hbyb/2305?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo + "&setl_id=" + order.SetlId +
  3973. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  3974. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3975. resp, requestErr := http.Get(api)
  3976. if requestErr != nil {
  3977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3978. return
  3979. }
  3980. body, ioErr := ioutil.ReadAll(resp.Body)
  3981. if ioErr != nil {
  3982. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3983. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3984. return
  3985. }
  3986. var respJSON map[string]interface{}
  3987. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3988. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3990. return
  3991. }
  3992. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3993. result_byte, _ := json.Marshal(respJSON)
  3994. result = string(result_byte)
  3995. saveLog(result, requestLog, "2305", "退费")
  3996. } else if miConfig.MdtrtareaAdmvs == "360399" {
  3997. result, requestLog := service.Jxyb2305(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.Url, "", miConfig.AccessKey)
  3998. saveLog(result, requestLog, "2305", "退费")
  3999. } else {
  4000. result, requestLog := service.Gdyb2305(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  4001. saveLog(result, requestLog, "2305", "退费")
  4002. }
  4003. var dat map[string]interface{}
  4004. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4005. fmt.Println(dat)
  4006. } else {
  4007. fmt.Println(err)
  4008. }
  4009. userJSONBytes, _ := json.Marshal(dat)
  4010. var res ResultSixteen
  4011. var resSixteen ResultSixteen10265
  4012. if miConfig.Code == "H15049901371" {
  4013. if err := json.Unmarshal(userJSONBytes, &resSixteen); err != nil {
  4014. utils.ErrorLog("解析失败:%v", err)
  4015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4016. return
  4017. }
  4018. res.Cainfo = resSixteen.Cainfo
  4019. res.WarnMsg = resSixteen.WarnMsg
  4020. res.Output = resSixteen.Output
  4021. res.ErrMsg = resSixteen.ErrMsg
  4022. res.RespondTime = resSixteen.RespondTime
  4023. Infcode, _ := strconv.ParseInt(resSixteen.Infcode, 10, 64)
  4024. res.Infcode = Infcode
  4025. } else {
  4026. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4027. utils.ErrorLog("解析失败:%v", err)
  4028. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4029. return
  4030. }
  4031. }
  4032. if res.Infcode == 0 {
  4033. err := service.UpdataOrderStatusThree(order_id, order.Number, adminUser.CurrentOrgId, "", result)
  4034. //不同地区退费流程不一样,肇庆那边退费就包括撤销出院,内蒙古退费不包括撤销明细,所以下面需要根据不同情况进行判断
  4035. if miConfig.UserOrgId == 10215 {
  4036. record.OutHospitalStatus = 0
  4037. service.CreateHospitalRecord(&record)
  4038. }
  4039. service.UpdataOrderStatusByNumber(record.Number)
  4040. if err == nil {
  4041. ////当押金不为零时产生退费记录
  4042. if order.Decimal != 0 {
  4043. tmp := strconv.FormatInt(order.ID, 10)
  4044. err = service.MoneyIncrease(adminUser.CurrentOrgId, order.PatientId, tmp, order.Decimal)
  4045. if err != nil {
  4046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4047. return
  4048. }
  4049. }
  4050. c.ServeSuccessJSON(map[string]interface{}{
  4051. "msg": "退费成功",
  4052. })
  4053. } else {
  4054. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4055. return
  4056. }
  4057. } else {
  4058. c.ServeSuccessJSON(map[string]interface{}{
  4059. "code": -10,
  4060. "msg": res.ErrMsg,
  4061. })
  4062. }
  4063. } else {
  4064. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  4065. if err == nil {
  4066. c.ServeSuccessJSON(map[string]interface{}{
  4067. "msg": "退费成功",
  4068. })
  4069. } else {
  4070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4071. return
  4072. }
  4073. }
  4074. }
  4075. func (c *ZHHisApiController) ZHRefundDetail() {
  4076. patient_id, _ := c.GetInt64("patient_id")
  4077. his_patient_id, _ := c.GetInt64("his_patient_id")
  4078. record_time := c.GetString("record_time")
  4079. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  4080. //order_id, _ := c.GetInt64("order_id")
  4081. admin_user_id, _ := c.GetInt64("admin_user_id")
  4082. timeLayout := "2006-01-02"
  4083. loc, _ := time.LoadLocation("Local")
  4084. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4085. if err != nil {
  4086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4087. return
  4088. }
  4089. recordDateTime := theTime.Unix()
  4090. adminUser := c.GetAdminUserInfo()
  4091. theTimeTwo, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 23:59:59", loc)
  4092. if err != nil {
  4093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4094. return
  4095. }
  4096. recordDateTimeTwo := theTimeTwo.Unix()
  4097. //var prescriptions []*models.HisPrescription
  4098. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4099. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4100. if settle_accounts_type == 1 { //日结
  4101. record, _ := service.GetInHospitalRecord(his_patient_id)
  4102. infos, _ := service.GetZHHisUploadOrderInfo(adminUser.CurrentOrgId, patient_id, recordDateTime, recordDateTimeTwo, record.Number)
  4103. var isSuccess bool = true
  4104. for _, item := range infos {
  4105. var result string
  4106. var requestLog string
  4107. if miConfig.MdtrtareaAdmvs == "150499" {
  4108. //请求内网数据
  4109. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&feedetl_sn=" + item.FeedetlSn +
  4110. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  4111. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=" + "1"
  4112. resp, requestErr := http.Get(api)
  4113. if requestErr != nil {
  4114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4115. return
  4116. }
  4117. body, ioErr := ioutil.ReadAll(resp.Body)
  4118. if ioErr != nil {
  4119. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4121. return
  4122. }
  4123. var respJSON map[string]interface{}
  4124. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4125. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4127. return
  4128. }
  4129. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4130. result_byte, _ := json.Marshal(respJSON)
  4131. result = string(result_byte)
  4132. saveLog(result, requestLog, "2302", "日结退明细")
  4133. } else if miConfig.MdtrtareaAdmvs == "421182" {
  4134. //请求内网数据
  4135. api := miConfig.Url + "hbyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&feedetl_sn=" + item.FeedetlSn +
  4136. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  4137. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=" + "1"
  4138. resp, requestErr := http.Get(api)
  4139. if requestErr != nil {
  4140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4141. return
  4142. }
  4143. body, ioErr := ioutil.ReadAll(resp.Body)
  4144. if ioErr != nil {
  4145. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4147. return
  4148. }
  4149. var respJSON map[string]interface{}
  4150. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4151. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4153. return
  4154. }
  4155. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4156. result_byte, _ := json.Marshal(respJSON)
  4157. result = string(result_byte)
  4158. saveLog(result, requestLog, "2302", "日结退明细")
  4159. } else if miConfig.MdtrtareaAdmvs == "360399" {
  4160. result, requestLog := service.Jxyb2302(record.PsnNo, record.Number, 1, item.FeedetlSn, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.Url, "", miConfig.AccessKey)
  4161. saveLog(result, requestLog, "2302", "日结退明细")
  4162. } else {
  4163. result, requestLog := service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, item.FeedetlSn, 1)
  4164. saveLog(result, requestLog, "2302", "日结退明细")
  4165. }
  4166. var dat map[string]interface{}
  4167. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4168. fmt.Println(dat)
  4169. } else {
  4170. fmt.Println(err)
  4171. }
  4172. userJSONBytes, _ := json.Marshal(dat)
  4173. var res2 ResultEmpty
  4174. var resEmpty10265 ResultEmpty10265
  4175. if miConfig.Code == "H15049901371" {
  4176. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  4177. utils.ErrorLog("解析失败:%v", err)
  4178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4179. return
  4180. }
  4181. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  4182. res2.Infcode = Infcode
  4183. res2.RespondTime = resEmpty10265.RespondTime
  4184. res2.ErrMsg = resEmpty10265.ErrMsg
  4185. res2.Output = resEmpty10265.Output
  4186. res2.WarnMsg = resEmpty10265.WarnMsg
  4187. } else {
  4188. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  4189. utils.ErrorLog("解析失败:%v", err)
  4190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4191. return
  4192. }
  4193. }
  4194. if res2.Infcode == -1 {
  4195. isSuccess = false
  4196. }
  4197. }
  4198. if isSuccess {
  4199. err := service.UpDateOrderInfoStatus(patient_id, recordDateTime, adminUser.CurrentOrgId, recordDateTimeTwo)
  4200. if err != nil {
  4201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4202. return
  4203. }
  4204. err1 := service.UpDatePrescriptionOrderStatusTwo(patient_id, recordDateTime, adminUser.CurrentOrgId)
  4205. if err1 != nil {
  4206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4207. return
  4208. }
  4209. c.ServeSuccessJSON(map[string]interface{}{
  4210. "msg": "撤销明细成功",
  4211. })
  4212. }
  4213. } else {
  4214. //prescriptions, _ = service.GetZHMonthHisUploadPrescription(adminUser.CurrentOrgId, patient_id, recordDateTime)
  4215. //var order models.HisOrder
  4216. //order, _ = service.GetHisOrderByID(order_id)
  4217. //record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  4218. var result string
  4219. var requestLog string
  4220. record, _ := service.GetInHospitalRecord(his_patient_id)
  4221. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4222. if config.IsOpen == 1 { //对接了医保,走医保流程
  4223. if miConfig.MdtrtareaAdmvs == "150499" {
  4224. //请求内网数据
  4225. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&number=0000" +
  4226. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  4227. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=" + "0"
  4228. resp, requestErr := http.Get(api)
  4229. if requestErr != nil {
  4230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4231. return
  4232. }
  4233. body, ioErr := ioutil.ReadAll(resp.Body)
  4234. if ioErr != nil {
  4235. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4237. return
  4238. }
  4239. var respJSON map[string]interface{}
  4240. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4241. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4243. return
  4244. }
  4245. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4246. result_byte, _ := json.Marshal(respJSON)
  4247. result = string(result_byte)
  4248. //saveLog(result, requestLog, "2302", "日结退明细")
  4249. } else if miConfig.MdtrtareaAdmvs == "421182" {
  4250. //请求内网数据
  4251. api := miConfig.Url + "hbyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&number=0000" +
  4252. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  4253. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=" + "0"
  4254. resp, requestErr := http.Get(api)
  4255. if requestErr != nil {
  4256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4257. return
  4258. }
  4259. body, ioErr := ioutil.ReadAll(resp.Body)
  4260. if ioErr != nil {
  4261. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4263. return
  4264. }
  4265. var respJSON map[string]interface{}
  4266. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4267. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4269. return
  4270. }
  4271. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4272. result_byte, _ := json.Marshal(respJSON)
  4273. result = string(result_byte)
  4274. //saveLog(result, requestLog, "2302", "日结退明细")
  4275. } else if miConfig.MdtrtareaAdmvs == "360399" {
  4276. result, requestLog = service.Jxyb2302(record.PsnNo, record.Number, 0, "0000", miConfig.SecretKey, miConfig.OrgName, miConfig.Code, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.Url, "", miConfig.AccessKey)
  4277. saveLog(result, requestLog, "2302", "月结退明细")
  4278. } else {
  4279. result, requestLog = service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, "0000", 0)
  4280. saveLog(result, requestLog, "2302", "月结退明细")
  4281. }
  4282. var dat map[string]interface{}
  4283. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4284. fmt.Println(dat)
  4285. } else {
  4286. fmt.Println(err)
  4287. }
  4288. userJSONBytes, _ := json.Marshal(dat)
  4289. var res2 ResultEmpty
  4290. var resEmpty10265 ResultEmpty10265
  4291. if miConfig.Code == "H15049901371" {
  4292. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  4293. utils.ErrorLog("解析失败:%v", err)
  4294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4295. return
  4296. }
  4297. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  4298. res2.Infcode = Infcode
  4299. res2.RespondTime = resEmpty10265.RespondTime
  4300. res2.ErrMsg = resEmpty10265.ErrMsg
  4301. res2.Output = resEmpty10265.Output
  4302. res2.WarnMsg = resEmpty10265.WarnMsg
  4303. } else {
  4304. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  4305. utils.ErrorLog("解析失败:%v", err)
  4306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4307. return
  4308. }
  4309. }
  4310. if res2.Infcode == 0 {
  4311. err := service.UpdataHospitalOrderStatus(record.Number, adminUser.CurrentOrgId)
  4312. if err == nil {
  4313. c.ServeSuccessJSON(map[string]interface{}{
  4314. "msg": "撤销明细成功",
  4315. })
  4316. } else {
  4317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4318. return
  4319. }
  4320. } else {
  4321. c.ServeSuccessJSON(map[string]interface{}{
  4322. "code": -10,
  4323. "msg": res2.ErrMsg,
  4324. })
  4325. }
  4326. }
  4327. }
  4328. }
  4329. func (this *ZHHisApiController) GetZHOutHospitalUnCheck() {
  4330. id, _ := this.GetInt64("id")
  4331. admin_user_id, _ := this.GetInt64("admin_user_id")
  4332. adminInfo := this.GetAdminUserInfo()
  4333. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  4334. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  4335. record, _ := service.GetInHospitalRecord(id)
  4336. if record.ID == 0 {
  4337. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  4338. return
  4339. }
  4340. var result string
  4341. var requestLog string
  4342. if miConfig.MdtrtareaAdmvs == "150499" {
  4343. //请求内网数据
  4344. api := "http://172.16.13.254:9532/" + "nmyb/2405?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  4345. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  4346. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4347. fmt.Println(api)
  4348. resp, requestErr := http.Get(api)
  4349. if requestErr != nil {
  4350. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4351. return
  4352. }
  4353. body, ioErr := ioutil.ReadAll(resp.Body)
  4354. if ioErr != nil {
  4355. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4356. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4357. return
  4358. }
  4359. var respJSON map[string]interface{}
  4360. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4361. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4362. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4363. return
  4364. }
  4365. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4366. result_byte, _ := json.Marshal(respJSON)
  4367. result = string(result_byte)
  4368. } else if miConfig.MdtrtareaAdmvs == "421182" {
  4369. //请求内网数据
  4370. api := miConfig.Url + "hbyb/2405?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  4371. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  4372. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4373. fmt.Println(api)
  4374. resp, requestErr := http.Get(api)
  4375. if requestErr != nil {
  4376. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4377. return
  4378. }
  4379. body, ioErr := ioutil.ReadAll(resp.Body)
  4380. if ioErr != nil {
  4381. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4382. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4383. return
  4384. }
  4385. var respJSON map[string]interface{}
  4386. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4387. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4388. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4389. return
  4390. }
  4391. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4392. result_byte, _ := json.Marshal(respJSON)
  4393. result = string(result_byte)
  4394. } else if miConfig.MdtrtareaAdmvs == "360399" {
  4395. result, requestLog = service.Jxyb2405(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.Url, "", miConfig.AccessKey)
  4396. saveLog(result, requestLog, "2405", "出院登记撤销")
  4397. } else {
  4398. result, requestLog = service.ZHGdyb2405(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  4399. saveLog(result, requestLog, "2405", "出院登记撤销")
  4400. }
  4401. var dat map[string]interface{}
  4402. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4403. fmt.Println(dat)
  4404. } else {
  4405. fmt.Println(err)
  4406. }
  4407. userJSONBytes, _ := json.Marshal(dat)
  4408. var res ResultEmpty
  4409. var resEmpty10265 ResultEmpty10265
  4410. if miConfig.Code == "H15049901371" {
  4411. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  4412. utils.ErrorLog("解析失败:%v", err)
  4413. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4414. return
  4415. }
  4416. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  4417. res.Infcode = Infcode
  4418. res.RespondTime = resEmpty10265.RespondTime
  4419. res.ErrMsg = resEmpty10265.ErrMsg
  4420. res.Output = resEmpty10265.Output
  4421. res.WarnMsg = resEmpty10265.WarnMsg
  4422. } else {
  4423. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4424. utils.ErrorLog("解析失败:%v", err)
  4425. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4426. return
  4427. }
  4428. }
  4429. if res.Infcode == 0 {
  4430. record.OutHospitalStatus = 0
  4431. service.CreateHospitalRecord(&record)
  4432. service.UpdataOrderStatusByNumber(record.Number)
  4433. this.ServeSuccessJSON(map[string]interface{}{
  4434. "msg": "撤销出院成功",
  4435. })
  4436. } else {
  4437. this.ServeSuccessJSON(map[string]interface{}{
  4438. "failed_code": -10,
  4439. "msg": res.ErrMsg,
  4440. })
  4441. }
  4442. }
  4443. func (this *ZHHisApiController) GetZHInHospitalUnCheck() {
  4444. id, _ := this.GetInt64("id")
  4445. admin_user_id, _ := this.GetInt64("admin_user_id")
  4446. adminInfo := this.GetAdminUserInfo()
  4447. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  4448. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  4449. record, _ := service.GetInHospitalRecord(id)
  4450. if record.ID == 0 {
  4451. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  4452. return
  4453. }
  4454. var result string
  4455. var requestLog string
  4456. orders, _ := service.GetHisOrderInfoByNumber(record.Number)
  4457. if len(orders) > 0 { //判断是否上传过明细,有的话需要退明细,后撤销入院
  4458. if miConfig.MdtrtareaAdmvs == "150499" {
  4459. //请求内网数据
  4460. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&number=" + "0000" +
  4461. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  4462. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=0"
  4463. resp, requestErr := http.Get(api)
  4464. if requestErr != nil {
  4465. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4466. return
  4467. }
  4468. body, ioErr := ioutil.ReadAll(resp.Body)
  4469. if ioErr != nil {
  4470. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4471. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4472. return
  4473. }
  4474. var respJSON map[string]interface{}
  4475. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4476. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4477. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4478. return
  4479. }
  4480. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4481. result_byte, _ := json.Marshal(respJSON)
  4482. result = string(result_byte)
  4483. saveLog(result, requestLog, "2302", "月结退明细")
  4484. }else if miConfig.MdtrtareaAdmvs == "421182" {
  4485. //请求内网数据
  4486. api := miConfig.Url + "hbyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&number=" + "0000" +
  4487. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  4488. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=0"
  4489. resp, requestErr := http.Get(api)
  4490. if requestErr != nil {
  4491. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4492. return
  4493. }
  4494. body, ioErr := ioutil.ReadAll(resp.Body)
  4495. if ioErr != nil {
  4496. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4497. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4498. return
  4499. }
  4500. var respJSON map[string]interface{}
  4501. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4502. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4503. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4504. return
  4505. }
  4506. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4507. result_byte, _ := json.Marshal(respJSON)
  4508. result = string(result_byte)
  4509. saveLog(result, requestLog, "2302", "月结退明细")
  4510. } else if miConfig.MdtrtareaAdmvs == "360399" {
  4511. result, requestLog = service.Jxyb2302(record.PsnNo, record.Number, 0, "0000", miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.Url, "", miConfig.AccessKey)
  4512. saveLog(result, requestLog, "2302", "月结退明细")
  4513. } else {
  4514. result, requestLog = service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, "0000", 0)
  4515. saveLog(result, requestLog, "2302", "月结退明细")
  4516. }
  4517. var dat map[string]interface{}
  4518. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4519. fmt.Println(dat)
  4520. } else {
  4521. fmt.Println(err)
  4522. }
  4523. userJSONBytes, _ := json.Marshal(dat)
  4524. var res2 ResultEmpty
  4525. var resEmpty10265 ResultEmpty10265
  4526. if miConfig.Code == "H15049901371" {
  4527. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  4528. utils.ErrorLog("解析失败:%v", err)
  4529. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4530. return
  4531. }
  4532. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  4533. res2.Infcode = Infcode
  4534. res2.RespondTime = resEmpty10265.RespondTime
  4535. res2.ErrMsg = resEmpty10265.ErrMsg
  4536. res2.Output = resEmpty10265.Output
  4537. res2.WarnMsg = resEmpty10265.WarnMsg
  4538. } else {
  4539. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  4540. utils.ErrorLog("解析失败:%v", err)
  4541. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4542. return
  4543. }
  4544. }
  4545. if res2.Infcode == 0 {
  4546. service.UpdataHospitalOrderStatus(record.Number, adminInfo.CurrentOrgId)
  4547. var result string
  4548. var requestLog string
  4549. if miConfig.MdtrtareaAdmvs == "150499" {
  4550. //请求内网数据
  4551. api := "http://172.16.13.254:9532/" + "nmyb/2404?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  4552. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  4553. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4554. resp, requestErr := http.Get(api)
  4555. if requestErr != nil {
  4556. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4557. return
  4558. }
  4559. body, ioErr := ioutil.ReadAll(resp.Body)
  4560. if ioErr != nil {
  4561. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4562. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4563. return
  4564. }
  4565. var respJSON map[string]interface{}
  4566. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4567. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4568. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4569. return
  4570. }
  4571. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4572. result_byte, _ := json.Marshal(respJSON)
  4573. result = string(result_byte)
  4574. } else if miConfig.MdtrtareaAdmvs == "421182" {
  4575. //请求内网数据
  4576. api := miConfig.Url + "hbyb/2404?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  4577. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  4578. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4579. resp, requestErr := http.Get(api)
  4580. if requestErr != nil {
  4581. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4582. return
  4583. }
  4584. body, ioErr := ioutil.ReadAll(resp.Body)
  4585. if ioErr != nil {
  4586. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4587. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4588. return
  4589. }
  4590. var respJSON map[string]interface{}
  4591. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4592. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4593. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4594. return
  4595. }
  4596. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4597. result_byte, _ := json.Marshal(respJSON)
  4598. result = string(result_byte)
  4599. } else if miConfig.MdtrtareaAdmvs == "360399" {
  4600. result, requestLog = service.Jxyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.Url, "", miConfig.AccessKey)
  4601. saveLog(result, requestLog, "2404", "入院登记撤销")
  4602. } else {
  4603. result, requestLog = service.ZHGdyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  4604. saveLog(result, requestLog, "2404", "入院登记撤销")
  4605. }
  4606. var dat map[string]interface{}
  4607. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4608. fmt.Println(dat)
  4609. } else {
  4610. fmt.Println(err)
  4611. }
  4612. userJSONBytes, _ := json.Marshal(dat)
  4613. var res ResultEmpty
  4614. var resEmpty10265 ResultEmpty10265
  4615. if miConfig.Code == "H15049901371" {
  4616. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  4617. utils.ErrorLog("解析失败:%v", err)
  4618. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4619. return
  4620. }
  4621. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  4622. res.Infcode = Infcode
  4623. res.RespondTime = resEmpty10265.RespondTime
  4624. res.ErrMsg = resEmpty10265.ErrMsg
  4625. res.Output = resEmpty10265.Output
  4626. res.WarnMsg = resEmpty10265.WarnMsg
  4627. } else {
  4628. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4629. utils.ErrorLog("解析失败:%v", err)
  4630. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4631. return
  4632. }
  4633. }
  4634. if res.Infcode == 0 {
  4635. record.Status = 0
  4636. service.CreateHospitalRecord(&record)
  4637. this.ServeSuccessJSON(map[string]interface{}{
  4638. "msg": "撤销入院成功",
  4639. })
  4640. } else {
  4641. this.ServeSuccessJSON(map[string]interface{}{
  4642. "failed_code": -10,
  4643. "msg": res.ErrMsg,
  4644. })
  4645. }
  4646. } else {
  4647. this.ServeSuccessJSON(map[string]interface{}{
  4648. "code": -10,
  4649. "msg": res2.ErrMsg,
  4650. })
  4651. }
  4652. } else { //没有上传过明细的,直接撤销入院
  4653. var result string
  4654. var requestLog string
  4655. if miConfig.MdtrtareaAdmvs == "150499" {
  4656. //请求内网数据
  4657. api := "http://172.16.13.254:9532/" + "nmyb/2404?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  4658. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  4659. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4660. resp, requestErr := http.Get(api)
  4661. if requestErr != nil {
  4662. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4663. return
  4664. }
  4665. body, ioErr := ioutil.ReadAll(resp.Body)
  4666. if ioErr != nil {
  4667. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4668. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4669. return
  4670. }
  4671. var respJSON map[string]interface{}
  4672. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4673. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4674. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4675. return
  4676. }
  4677. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4678. result_byte, _ := json.Marshal(respJSON)
  4679. result = string(result_byte)
  4680. } else if miConfig.MdtrtareaAdmvs == "421182" {
  4681. //请求内网数据
  4682. api := miConfig.Url + "hbyb/2404?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  4683. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  4684. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4685. resp, requestErr := http.Get(api)
  4686. if requestErr != nil {
  4687. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4688. return
  4689. }
  4690. body, ioErr := ioutil.ReadAll(resp.Body)
  4691. if ioErr != nil {
  4692. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4693. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4694. return
  4695. }
  4696. var respJSON map[string]interface{}
  4697. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4698. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4699. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4700. return
  4701. }
  4702. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4703. result_byte, _ := json.Marshal(respJSON)
  4704. result = string(result_byte)
  4705. } else if miConfig.MdtrtareaAdmvs == "360399" {
  4706. result, requestLog = service.Jxyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.Url, "", miConfig.AccessKey)
  4707. saveLog(result, requestLog, "2404", "入院登记撤销")
  4708. } else {
  4709. result, requestLog = service.ZHGdyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  4710. saveLog(result, requestLog, "2404", "入院登记撤销")
  4711. }
  4712. var dat map[string]interface{}
  4713. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4714. fmt.Println(dat)
  4715. } else {
  4716. fmt.Println(err)
  4717. }
  4718. userJSONBytes, _ := json.Marshal(dat)
  4719. var res ResultEmpty
  4720. var resEmpty10265 ResultEmpty10265
  4721. if miConfig.Code == "H15049901371" {
  4722. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  4723. utils.ErrorLog("解析失败:%v", err)
  4724. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4725. return
  4726. }
  4727. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  4728. res.Infcode = Infcode
  4729. res.RespondTime = resEmpty10265.RespondTime
  4730. res.ErrMsg = resEmpty10265.ErrMsg
  4731. res.Output = resEmpty10265.Output
  4732. res.WarnMsg = resEmpty10265.WarnMsg
  4733. } else {
  4734. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4735. utils.ErrorLog("解析失败:%v", err)
  4736. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4737. return
  4738. }
  4739. }
  4740. if res.Infcode == 0 {
  4741. record.Status = 0
  4742. service.CreateHospitalRecord(&record)
  4743. this.ServeSuccessJSON(map[string]interface{}{
  4744. "msg": "撤销入院成功",
  4745. })
  4746. } else {
  4747. this.ServeSuccessJSON(map[string]interface{}{
  4748. "failed_code": -10,
  4749. "msg": res.ErrMsg,
  4750. })
  4751. }
  4752. }
  4753. }
  4754. func saveLog(result string, request string, infno string, desc string) {
  4755. org_id, _ := beego.AppConfig.Int64("org_id")
  4756. miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  4757. dir := miConfig.OrgName + "日志"
  4758. utils.Mkdir(dir)
  4759. month := time.Unix(1557042972, 0).Format("1")
  4760. year := time.Now().Format("2006")
  4761. month = time.Now().Format("01")
  4762. day := time.Now().Format("02")
  4763. hour := time.Now().Format("15")
  4764. min := time.Now().Format("04")
  4765. sec := time.Now().Format("05")
  4766. result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  4767. file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  4768. file_name := file + ".txt"
  4769. file_path := miConfig.OrgName + "日志" + "/" + file_name
  4770. exist, _ := utils.PathExists(file_path)
  4771. if exist { //存在
  4772. fmt.Println("存在")
  4773. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  4774. if err != nil {
  4775. fmt.Println("read fail")
  4776. }
  4777. content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  4778. n, _ := f.Seek(0, 2)
  4779. _, err = f.WriteAt([]byte(content), n)
  4780. } else { //不存在
  4781. fmt.Println("文件不存在,创建文件")
  4782. f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  4783. defer f.Close()
  4784. if err != nil {
  4785. } else {
  4786. _, err = f.Write([]byte("记录日志"))
  4787. }
  4788. }
  4789. }
  4790. type Charset string
  4791. const (
  4792. UTF8 = Charset("UTF-8")
  4793. GB18030 = Charset("GB18030")
  4794. )
  4795. func ConvertToString(src string, srcCode string, tagCode string) string {
  4796. srcCoder := mahonia.NewDecoder(srcCode)
  4797. srcResult := srcCoder.ConvertString(src)
  4798. tagCoder := mahonia.NewDecoder(tagCode)
  4799. _, cdata, _ := tagCoder.Translate([]byte(srcResult), true)
  4800. result := string(cdata)
  4801. return result
  4802. }
  4803. type ELeData struct {
  4804. Data struct {
  4805. IdNo string `json:"idNo"`
  4806. IdType string `json:"idType"`
  4807. UserName string `json:"userName"`
  4808. EcToken string `json:"ecToken"`
  4809. InsuOrg string `json:"insuOrg"`
  4810. Gender string `json:"gender"`
  4811. Birthday string `json:"birthday"`
  4812. Nationality string `json:"nationality"`
  4813. Email string `json:"email"`
  4814. Extra string `json:"extra"`
  4815. } `json:"data"`
  4816. Code int `json:"code"`
  4817. Message string `json:"message"`
  4818. }
  4819. var initFlagTwo int64 = 0
  4820. func (c *ZHHisApiController) TestGetJiangXiBasBaseInit() {
  4821. DllDef := syscall.MustLoadDLL("SSCard.dll")
  4822. Iinit := DllDef.MustFindProc("Init")
  4823. //miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  4824. //http://10.77.211.236/CSB/hsa-fsi-1303
  4825. ret, _, err := Iinit.Call(StrPtr("http://10.77.224.18:9001/1.0.0/agent-card-init"), StrPtr("360399"))
  4826. if ret != 0 {
  4827. fmt.Println("SSCard的报错原因:", err)
  4828. fmt.Println("SSCard的运算结果为:", ret)
  4829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  4830. return
  4831. }
  4832. result := int(ret)
  4833. fmt.Println("SSCard的运算结果为1:", result)
  4834. initFlag = 1
  4835. return
  4836. }
  4837. func (c *ZHHisApiController) GetBasBaseInfoxxx() string {
  4838. DllDef := syscall.MustLoadDLL("SSCard.dll")
  4839. readCard := DllDef.MustFindProc("ReadCardBas")
  4840. if readCard == nil {
  4841. fmt.Println("readcard is nil")
  4842. readCard = DllDef.MustFindProc("ReadCardBas")
  4843. }
  4844. str := make([]byte, 1024)
  4845. str1 := make([]byte, 1024)
  4846. ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), uintptr(1024), (uintptr)(unsafe.Pointer(&str1[0])), uintptr(1024))
  4847. fmt.Println(string(str1))
  4848. fmt.Println(string(str))
  4849. fmt.Println(":", ConvertToString(string(str1), "gbk", "utf-8"))
  4850. fmt.Println(":", ConvertToString(string(str), "gbk", "utf-8"))
  4851. if ret2 != 0 {
  4852. return ""
  4853. }
  4854. return string(str)
  4855. }
  4856. func (c *ZHHisApiController) ReadEleCardfordevice() {
  4857. admin_user_id, _ := c.GetInt64("admin_user_id")
  4858. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  4859. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  4860. GetjxELekeyInfo(miConfig.Code, "1", roles.UserName)
  4861. }
  4862. func (c *ZHHisApiController) ReadCard() {
  4863. id_card_type, _ := c.GetInt64("id_card_type")
  4864. admin_user_id, _ := c.GetInt64("admin_user_id")
  4865. is_settle := c.GetString("is_settle")
  4866. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  4867. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  4868. switch id_card_type {
  4869. case 1: //社保卡
  4870. if miConfig.MdtrtareaAdmvs == "150499" {
  4871. var api string
  4872. api = "http://172.16.13.254:9532/" + "nmyb/readcard?" + "fixmedins_code=" + miConfig.Code + "&secret_key=" + miConfig.SecretKey + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName +
  4873. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&url=" + miConfig.Url + "&cainfo=" + miConfig.Cainfo + "&id_card_type=" + strconv.FormatInt(id_card_type, 10) + "&operator_id=" + strconv.FormatInt(admin_user_id, 10) + "&operator=" + roles.UserName
  4874. fmt.Println(api)
  4875. resp, requestErr := http.Get(api)
  4876. if requestErr != nil {
  4877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4878. return
  4879. }
  4880. body, ioErr := ioutil.ReadAll(resp.Body)
  4881. if ioErr != nil {
  4882. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4884. return
  4885. }
  4886. var respJSON map[string]interface{}
  4887. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4888. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4889. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4890. return
  4891. }
  4892. var status string
  4893. status = respJSON["data"].(map[string]interface{})["status"].(string)
  4894. card_type := respJSON["data"].(map[string]interface{})["type"].(string)
  4895. //console.log()
  4896. fmt.Println("type===")
  4897. fmt.Println(card_type)
  4898. var token string
  4899. var res ResultTwo //1101结果
  4900. var res10265 ResultTwo10265 //1101结果
  4901. var card_info string //卡信息
  4902. var busi_card_info string
  4903. card_info = respJSON["data"].(map[string]interface{})["card_info"].(string)
  4904. busi_card_info = respJSON["data"].(map[string]interface{})["busi_card_info"].(string)
  4905. if status == "0" { //读卡成功
  4906. if card_type == "1" {
  4907. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  4908. result, _ := json.Marshal(respJSON)
  4909. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  4910. utils.ErrorLog("解析失败:%v", err)
  4911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4912. return
  4913. }
  4914. res.ErrMsg = res10265.ErrMsg
  4915. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  4916. res.Infcode = infocode
  4917. res.Output = res10265.Output
  4918. res.InfRefmsgid = res10265.InfRefmsgid
  4919. } else {
  4920. //var card_info string //卡信息
  4921. //var busi_card_info string
  4922. token = respJSON["data"].(map[string]interface{})["token"].(string)
  4923. //busi_card_info = respJSON["data"].(map[string]interface{})["busi_card_info"].(string)
  4924. //fmt.Println(card_info)
  4925. //fmt.Println(busi_card_info)
  4926. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  4927. result, _ := json.Marshal(respJSON)
  4928. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  4929. utils.ErrorLog("解析失败:%v", err)
  4930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4931. return
  4932. }
  4933. res.ErrMsg = res10265.ErrMsg
  4934. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  4935. res.Infcode = infocode
  4936. res.Output = res10265.Output
  4937. res.InfRefmsgid = res10265.InfRefmsgid
  4938. }
  4939. if res.Infcode == 0 {
  4940. var insutypes []string
  4941. var insutype string
  4942. var is390 int = 0
  4943. var is310 int = 0
  4944. for _, item := range res.Output.Iinfo {
  4945. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  4946. insutypes = append(insutypes, item.Insutype)
  4947. }
  4948. }
  4949. if len(insutypes) == 1 {
  4950. insutype = insutypes[0]
  4951. } else {
  4952. for _, i := range insutypes {
  4953. if i == "390" {
  4954. is390 = 1
  4955. }
  4956. if i == "310" {
  4957. is310 = 1
  4958. }
  4959. }
  4960. }
  4961. if is390 == 1 {
  4962. insutype = "390"
  4963. }
  4964. if is310 == 1 {
  4965. insutype = "310"
  4966. }
  4967. if len(insutypes) == 0 {
  4968. insutype = "310"
  4969. }
  4970. patient, err := service.GetPatientByIDCard(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  4971. if err == gorm.ErrRecordNotFound {
  4972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  4973. return
  4974. } else if err != nil {
  4975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4976. return
  4977. } else {
  4978. if card_type == "1" {
  4979. bas := strings.Split(card_info, "|")
  4980. basNumber := bas[2]
  4981. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  4982. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  4983. infoStr := string(Iinfos)
  4984. idetinfoStr := string(Idetinfos)
  4985. psn := &models.HisPsn{
  4986. PsnNo: res.Output.Baseinfo.PsnNo,
  4987. Age: res.Output.Baseinfo.Age,
  4988. PatientId: patient.ID,
  4989. Certno: res.Output.Baseinfo.Certno,
  4990. Gend: res.Output.Baseinfo.Gend,
  4991. Naty: res.Output.Baseinfo.Naty,
  4992. PsnCertType: res.Output.Baseinfo.PsnCertType,
  4993. PsnName: res.Output.Baseinfo.PsnName,
  4994. Idetinfo: idetinfoStr,
  4995. Insuinfo: infoStr,
  4996. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4997. CardInfo: card_info,
  4998. VerifyNumber: busi_card_info,
  4999. }
  5000. service.CreateHisPsn(psn)
  5001. c.ServeSuccessJSON(map[string]interface{}{
  5002. "patient": patient,
  5003. "number": basNumber,
  5004. "info": res,
  5005. "insutype": insutype,
  5006. })
  5007. } else {
  5008. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  5009. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  5010. infoStr := string(Iinfos)
  5011. idetinfoStr := string(Idetinfos)
  5012. psn := &models.HisPsn{
  5013. PsnNo: res.Output.Baseinfo.PsnNo,
  5014. Age: res.Output.Baseinfo.Age,
  5015. PatientId: patient.ID,
  5016. Certno: res.Output.Baseinfo.Certno,
  5017. Gend: res.Output.Baseinfo.Gend,
  5018. Naty: res.Output.Baseinfo.Naty,
  5019. PsnCertType: res.Output.Baseinfo.PsnCertType,
  5020. PsnName: res.Output.Baseinfo.PsnName,
  5021. Idetinfo: idetinfoStr,
  5022. Insuinfo: infoStr,
  5023. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5024. CardInfo: card_info,
  5025. VerifyNumber: token,
  5026. }
  5027. service.CreateHisPsn(psn)
  5028. c.ServeSuccessJSON(map[string]interface{}{
  5029. "patient": patient,
  5030. "number": token,
  5031. "info": res,
  5032. "insutype": insutype,
  5033. })
  5034. }
  5035. }
  5036. } else {
  5037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  5038. return
  5039. }
  5040. } else { //读卡失败
  5041. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  5042. return
  5043. }
  5044. } else if miConfig.MdtrtareaAdmvs == "421182" {
  5045. var res ResultTwohb
  5046. api := miConfig.Url + "hbyb/1101?cert_no=" + "" +
  5047. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  5048. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(id_card_type, 10) + "&card_sn=" + "" + "&certificates=1"
  5049. resp, requestErr := http.Get(api)
  5050. if requestErr != nil {
  5051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5052. return
  5053. }
  5054. body, ioErr := ioutil.ReadAll(resp.Body)
  5055. if ioErr != nil {
  5056. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  5057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5058. return
  5059. }
  5060. var respJSON map[string]interface{}
  5061. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  5062. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  5063. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5064. return
  5065. }
  5066. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  5067. result, _ := json.Marshal(respJSON)
  5068. fmt.Println("log")
  5069. fmt.Println(string(result))
  5070. if err := json.Unmarshal([]byte(result), &res); err != nil {
  5071. utils.ErrorLog("解析失败:%v", err)
  5072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5073. return
  5074. }
  5075. if res.Infcode == 0 {
  5076. patient, err := service.GetPatientByIDCard(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  5077. if err == gorm.ErrRecordNotFound {
  5078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  5079. return
  5080. } else if err != nil {
  5081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5082. return
  5083. } else {
  5084. var insuplc_admdvs_temp string
  5085. var insutypes []string
  5086. var insutype string
  5087. var is390 int = 0
  5088. var is310 int = 0
  5089. for _, item := range res.Output.Iinfo {
  5090. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  5091. insutypes = append(insutypes, item.Insutype)
  5092. }
  5093. }
  5094. if len(insutypes) == 1 {
  5095. insutype = insutypes[0]
  5096. } else {
  5097. for _, i := range insutypes {
  5098. if i == "390" {
  5099. is390 = 1
  5100. }
  5101. if i == "310" {
  5102. is310 = 1
  5103. }
  5104. }
  5105. }
  5106. if is390 == 1 {
  5107. insutype = "390"
  5108. }
  5109. if is310 == 1 {
  5110. insutype = "310"
  5111. }
  5112. if len(insutypes) == 0 {
  5113. insutype = "310"
  5114. }
  5115. for _, item := range insutypes {
  5116. if item == insutype {
  5117. insuplc_admdvs_temp = item
  5118. }
  5119. }
  5120. //insuplcAdmdvs := strconv.Itoa(insuplc_admdvs_temp)
  5121. card_info_two := insuplc_admdvs_temp + "|" + res.Output.Baseinfo.Certno + "|" + res.Output.Baseinfo.ExpContent.MdtrtCertNo
  5122. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  5123. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  5124. infoStr := string(Iinfos)
  5125. idetinfoStr := string(Idetinfos)
  5126. psn := &models.HisPsn{
  5127. PsnNo: res.Output.Baseinfo.PsnNo,
  5128. PatientId: patient.ID,
  5129. Certno: res.Output.Baseinfo.Certno,
  5130. Gend: res.Output.Baseinfo.Gend,
  5131. Naty: res.Output.Baseinfo.Naty,
  5132. PsnCertType: res.Output.Baseinfo.PsnCertType,
  5133. PsnName: res.Output.Baseinfo.PsnName,
  5134. Idetinfo: idetinfoStr,
  5135. Insuinfo: infoStr,
  5136. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5137. InsuplcAdmdvs: insuplc_admdvs_temp,
  5138. CardInfo:card_info_two,
  5139. }
  5140. service.CreateHisPsn(psn)
  5141. c.ServeSuccessJSON(map[string]interface{}{
  5142. "patient": patient,
  5143. "number": res.Output.Baseinfo.Certno,
  5144. })
  5145. }
  5146. } else {
  5147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  5148. return
  5149. }
  5150. } else if miConfig.MdtrtareaAdmvs == "360399" {
  5151. fmt.Println(initFlag)
  5152. fmt.Println("initFlag")
  5153. if initFlag == 0 {
  5154. c.TestGetJiangXiBasBaseInit()
  5155. }
  5156. basStr := c.GetBasBaseInfoxxx()
  5157. if len(basStr) == 0 {
  5158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  5159. return
  5160. }
  5161. fmt.Println(basStr)
  5162. bas := strings.Split(basStr, "|")
  5163. basNumber := bas[1]
  5164. fmt.Println(basNumber)
  5165. card_sn := bas[3]
  5166. fmt.Println(card_sn)
  5167. result, _ := service.Jxyb1101(basNumber, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, card_sn, "1", miConfig.Url, miConfig.AccessKey, "")
  5168. //result := service.Jxyb1101(basNumber, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, card_sn, certificates)
  5169. var dat map[string]interface{}
  5170. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5171. fmt.Println(dat)
  5172. } else {
  5173. fmt.Println(err)
  5174. }
  5175. userJSONBytes, _ := json.Marshal(dat)
  5176. var res ResultTwo
  5177. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5178. utils.ErrorLog("解析失败:%v", err)
  5179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5180. return
  5181. }
  5182. if res.Infcode == 0 {
  5183. patient, err := service.GetPatientByNumber(basNumber, c.GetAdminUserInfo().CurrentOrgId)
  5184. if err == gorm.ErrRecordNotFound {
  5185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  5186. return
  5187. } else if err != nil {
  5188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5189. return
  5190. } else {
  5191. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  5192. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  5193. infoStr := string(Iinfos)
  5194. idetinfoStr := string(Idetinfos)
  5195. psn := &models.HisPsn{
  5196. PsnNo: res.Output.Baseinfo.PsnNo,
  5197. Age: res.Output.Baseinfo.Age,
  5198. PatientId: patient.ID,
  5199. Certno: res.Output.Baseinfo.Certno,
  5200. Gend: res.Output.Baseinfo.Gend,
  5201. Naty: res.Output.Baseinfo.Naty,
  5202. PsnCertType: res.Output.Baseinfo.PsnCertType,
  5203. PsnName: res.Output.Baseinfo.PsnName,
  5204. Idetinfo: idetinfoStr,
  5205. Insuinfo: infoStr,
  5206. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5207. CardInfo: basStr,
  5208. VerifyNumber: "",
  5209. }
  5210. service.CreateHisPsn(psn)
  5211. var rf []*ResultFive
  5212. json.Unmarshal([]byte(infoStr), &rf)
  5213. var insutypes []*ResultFive
  5214. var insutype string
  5215. var is390 int = 0
  5216. var is310 int = 0
  5217. for _, item := range rf {
  5218. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  5219. insutypes = append(insutypes, item)
  5220. }
  5221. }
  5222. if len(insutypes) == 1 {
  5223. insutype = insutypes[0].Insutype
  5224. //insuplc_admdvs = insutypes[0].InsuplcAdmdvs
  5225. } else {
  5226. for _, i := range insutypes {
  5227. if i.Insutype == "390" {
  5228. is390 = 1
  5229. }
  5230. if i.Insutype == "310" {
  5231. is310 = 1
  5232. }
  5233. }
  5234. }
  5235. if is390 == 1 {
  5236. insutype = "390"
  5237. }
  5238. if is310 == 1 {
  5239. insutype = "310"
  5240. }
  5241. if len(insutypes) == 0 {
  5242. insutype = "310"
  5243. }
  5244. c.ServeSuccessJSON(map[string]interface{}{
  5245. "patient": patient,
  5246. "number": basNumber,
  5247. "info": res,
  5248. "insutype": insutype,
  5249. })
  5250. }
  5251. } else {
  5252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  5253. return
  5254. }
  5255. } else {
  5256. if initFlagTwo == 0 {
  5257. c.TestGetBasBaseInitTwo()
  5258. }
  5259. basStr := c.GetBasBaseInfoTwo()
  5260. if len(basStr) == 0 {
  5261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  5262. return
  5263. }
  5264. fmt.Println(basStr)
  5265. bas := strings.Split(basStr, "|")
  5266. id_card_no := bas[1]
  5267. result, _ := service.ZHGdyb1101B(id_card_no, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, 1, "", 1, "")
  5268. //result := service.Gdyb1101B(basNumber, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, card_sn, certificates)
  5269. var dat map[string]interface{}
  5270. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5271. fmt.Println(dat)
  5272. } else {
  5273. fmt.Println(err)
  5274. }
  5275. userJSONBytes, _ := json.Marshal(dat)
  5276. var res ResultTwo
  5277. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5278. utils.ErrorLog("解析失败:%v", err)
  5279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5280. return
  5281. }
  5282. if res.Infcode == 0 {
  5283. patient, err := service.GetPatientByNumber(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  5284. if err == gorm.ErrRecordNotFound {
  5285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  5286. return
  5287. } else if err != nil {
  5288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5289. return
  5290. } else {
  5291. var insutypes []string
  5292. var insutype string
  5293. var is390 int = 0
  5294. var is310 int = 0
  5295. for _, item := range res.Output.Iinfo {
  5296. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  5297. insutypes = append(insutypes, item.Insutype)
  5298. }
  5299. }
  5300. if len(insutypes) == 1 {
  5301. insutype = insutypes[0]
  5302. } else {
  5303. for _, i := range insutypes {
  5304. if i == "390" {
  5305. is390 = 1
  5306. }
  5307. if i == "310" {
  5308. is310 = 1
  5309. }
  5310. }
  5311. }
  5312. if is390 == 1 {
  5313. insutype = "390"
  5314. }
  5315. if is310 == 1 {
  5316. insutype = "310"
  5317. }
  5318. if len(insutypes) == 0 {
  5319. insutype = "310"
  5320. }
  5321. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  5322. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  5323. infoStr := string(Iinfos)
  5324. idetinfoStr := string(Idetinfos)
  5325. psn := &models.HisPsn{
  5326. PsnNo: res.Output.Baseinfo.PsnNo,
  5327. Age: res.Output.Baseinfo.Age,
  5328. PatientId: patient.ID,
  5329. Certno: res.Output.Baseinfo.Certno,
  5330. Gend: res.Output.Baseinfo.Gend,
  5331. Naty: res.Output.Baseinfo.Naty,
  5332. PsnCertType: res.Output.Baseinfo.PsnCertType,
  5333. PsnName: res.Output.Baseinfo.PsnName,
  5334. Idetinfo: idetinfoStr,
  5335. Insuinfo: infoStr,
  5336. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5337. CardInfo: basStr,
  5338. VerifyNumber: "",
  5339. }
  5340. service.CreateHisPsn(psn)
  5341. c.ServeSuccessJSON(map[string]interface{}{
  5342. "patient": patient,
  5343. "number": id_card_no,
  5344. "info": res,
  5345. "insutype": insutype,
  5346. })
  5347. }
  5348. } else {
  5349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  5350. return
  5351. }
  5352. }
  5353. break
  5354. case 2:
  5355. if miConfig.MdtrtareaAdmvs == "421182" {
  5356. var res ResultTwohb
  5357. api := miConfig.Url + "hbyb/1101?cert_no=" + "" +
  5358. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  5359. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(id_card_type, 10) + "&card_sn=" + "" + "&certificates=1"
  5360. resp, requestErr := http.Get(api)
  5361. if requestErr != nil {
  5362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5363. return
  5364. }
  5365. body, ioErr := ioutil.ReadAll(resp.Body)
  5366. if ioErr != nil {
  5367. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  5368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5369. return
  5370. }
  5371. var respJSON map[string]interface{}
  5372. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  5373. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  5374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5375. return
  5376. }
  5377. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  5378. result, _ := json.Marshal(respJSON)
  5379. fmt.Println("log")
  5380. fmt.Println(string(result))
  5381. if err := json.Unmarshal([]byte(result), &res); err != nil {
  5382. utils.ErrorLog("解析失败:%v", err)
  5383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5384. return
  5385. }
  5386. if res.Infcode == 0 {
  5387. patient, err := service.GetPatientByIDCard(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  5388. if err == gorm.ErrRecordNotFound {
  5389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  5390. return
  5391. } else if err != nil {
  5392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5393. return
  5394. } else {
  5395. var insuplc_admdvs_temp string
  5396. var insutypes []string
  5397. var insutype string
  5398. var is390 int = 0
  5399. var is310 int = 0
  5400. for _, item := range res.Output.Iinfo {
  5401. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  5402. insutypes = append(insutypes, item.Insutype)
  5403. }
  5404. }
  5405. if len(insutypes) == 1 {
  5406. insutype = insutypes[0]
  5407. } else {
  5408. for _, i := range insutypes {
  5409. if i == "390" {
  5410. is390 = 1
  5411. }
  5412. if i == "310" {
  5413. is310 = 1
  5414. }
  5415. }
  5416. }
  5417. if is390 == 1 {
  5418. insutype = "390"
  5419. }
  5420. if is310 == 1 {
  5421. insutype = "310"
  5422. }
  5423. if len(insutypes) == 0 {
  5424. insutype = "310"
  5425. }
  5426. for _, item := range insutypes {
  5427. if item == insutype {
  5428. insuplc_admdvs_temp = item
  5429. }
  5430. }
  5431. //insuplcAdmdvs := strconv.Itoa(insuplc_admdvs_temp)
  5432. card_info_two := insuplc_admdvs_temp + "|" + res.Output.Baseinfo.Certno + "|" + res.Output.Baseinfo.ExpContent.MdtrtCertNo
  5433. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  5434. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  5435. infoStr := string(Iinfos)
  5436. idetinfoStr := string(Idetinfos)
  5437. psn := &models.HisPsn{
  5438. PsnNo: res.Output.Baseinfo.PsnNo,
  5439. PatientId: patient.ID,
  5440. Certno: res.Output.Baseinfo.Certno,
  5441. Gend: res.Output.Baseinfo.Gend,
  5442. Naty: res.Output.Baseinfo.Naty,
  5443. PsnCertType: res.Output.Baseinfo.PsnCertType,
  5444. PsnName: res.Output.Baseinfo.PsnName,
  5445. Idetinfo: idetinfoStr,
  5446. Insuinfo: infoStr,
  5447. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5448. InsuplcAdmdvs: insuplc_admdvs_temp,
  5449. CardInfo:card_info_two,
  5450. }
  5451. service.CreateHisPsn(psn)
  5452. c.ServeSuccessJSON(map[string]interface{}{
  5453. "patient": patient,
  5454. "number": res.Output.Baseinfo.Certno,
  5455. })
  5456. }
  5457. } else {
  5458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  5459. return
  5460. }
  5461. }
  5462. case 4: //电子凭证
  5463. if miConfig.MdtrtareaAdmvs == "150499" {
  5464. var api string
  5465. api = "http://172.16.13.254:9532/" + "nmyb/readcard?" + "fixmedins_code=" + miConfig.Code + "&secret_key=" + miConfig.SecretKey + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName +
  5466. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&url=" + miConfig.Url + "&cainfo=" + miConfig.Cainfo + "&id_card_type=" + strconv.FormatInt(id_card_type, 10) + "&operator_id=" + strconv.FormatInt(admin_user_id, 10) + "&operator=" + roles.UserName + "&is_settle=" + is_settle
  5467. resp, requestErr := http.Get(api)
  5468. if requestErr != nil {
  5469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5470. return
  5471. }
  5472. body, ioErr := ioutil.ReadAll(resp.Body)
  5473. if ioErr != nil {
  5474. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  5475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5476. return
  5477. }
  5478. var respJSON map[string]interface{}
  5479. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  5480. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  5481. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5482. return
  5483. }
  5484. var status string
  5485. status = respJSON["data"].(map[string]interface{})["status"].(string)
  5486. //card_type := respJSON["data"].(map[string]interface{})["type"].(string)
  5487. var token string
  5488. var res ResultTwo //1101结果
  5489. var res10265 ResultTwo10265 //1101结果
  5490. if status == "0" { //读卡成功
  5491. token = respJSON["data"].(map[string]interface{})["token"].(string)
  5492. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  5493. result, _ := json.Marshal(respJSON)
  5494. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  5495. utils.ErrorLog("解析失败:%v", err)
  5496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5497. return
  5498. }
  5499. res.ErrMsg = res10265.ErrMsg
  5500. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  5501. res.Infcode = infocode
  5502. res.Output = res10265.Output
  5503. res.InfRefmsgid = res10265.InfRefmsgid
  5504. if res.Infcode == 0 {
  5505. patient, err := service.GetPatientByNumber(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  5506. if err == gorm.ErrRecordNotFound {
  5507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  5508. return
  5509. } else if err != nil {
  5510. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5511. return
  5512. } else {
  5513. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  5514. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  5515. infoStr := string(Iinfos)
  5516. idetinfoStr := string(Idetinfos)
  5517. psn := &models.HisPsn{
  5518. PsnNo: res.Output.Baseinfo.PsnNo,
  5519. Age: res.Output.Baseinfo.Age,
  5520. PatientId: patient.ID,
  5521. Certno: res.Output.Baseinfo.Certno,
  5522. Gend: res.Output.Baseinfo.Gend,
  5523. Naty: res.Output.Baseinfo.Naty,
  5524. PsnCertType: res.Output.Baseinfo.PsnCertType,
  5525. PsnName: res.Output.Baseinfo.PsnName,
  5526. Idetinfo: idetinfoStr,
  5527. Insuinfo: infoStr,
  5528. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5529. CardInfo: "",
  5530. VerifyNumber: token,
  5531. }
  5532. service.CreateHisPsn(psn)
  5533. var insutypes []string
  5534. var insutype string
  5535. var is390 int = 0
  5536. var is310 int = 0
  5537. for _, item := range res.Output.Iinfo {
  5538. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  5539. insutypes = append(insutypes, item.Insutype)
  5540. }
  5541. }
  5542. if len(insutypes) == 1 {
  5543. insutype = insutypes[0]
  5544. } else {
  5545. for _, i := range insutypes {
  5546. if i == "390" {
  5547. is390 = 1
  5548. }
  5549. if i == "310" {
  5550. is310 = 1
  5551. }
  5552. }
  5553. }
  5554. if is390 == 1 {
  5555. insutype = "390"
  5556. }
  5557. if is310 == 1 {
  5558. insutype = "310"
  5559. }
  5560. if len(insutypes) == 0 {
  5561. insutype = "390"
  5562. }
  5563. c.ServeSuccessJSON(map[string]interface{}{
  5564. "failed_code": 0,
  5565. "info": res,
  5566. "insutype": insutype,
  5567. "patient": patient,
  5568. })
  5569. }
  5570. } else {
  5571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  5572. return
  5573. }
  5574. }
  5575. } else if miConfig.MdtrtareaAdmvs == "421182" {
  5576. var res ResultTwohb
  5577. api := miConfig.Url + "hbyb/1101?cert_no=" + "" +
  5578. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  5579. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(id_card_type, 10) + "&card_sn=" + "" + "&certificates=1"
  5580. resp, requestErr := http.Get(api)
  5581. if requestErr != nil {
  5582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5583. return
  5584. }
  5585. body, ioErr := ioutil.ReadAll(resp.Body)
  5586. if ioErr != nil {
  5587. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  5588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5589. return
  5590. }
  5591. var respJSON map[string]interface{}
  5592. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  5593. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  5594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5595. return
  5596. }
  5597. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  5598. result, _ := json.Marshal(respJSON)
  5599. fmt.Println("log")
  5600. fmt.Println(string(result))
  5601. if err := json.Unmarshal([]byte(result), &res); err != nil {
  5602. utils.ErrorLog("解析失败:%v", err)
  5603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5604. return
  5605. }
  5606. if res.Infcode == 0 {
  5607. patient, err := service.GetPatientByIDCard(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  5608. if err == gorm.ErrRecordNotFound {
  5609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  5610. return
  5611. } else if err != nil {
  5612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5613. return
  5614. } else {
  5615. var insuplc_admdvs_temp string
  5616. var insutypes []string
  5617. var insutype string
  5618. var is390 int = 0
  5619. var is310 int = 0
  5620. for _, item := range res.Output.Iinfo {
  5621. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  5622. insutypes = append(insutypes, item.Insutype)
  5623. }
  5624. }
  5625. if len(insutypes) == 1 {
  5626. insutype = insutypes[0]
  5627. } else {
  5628. for _, i := range insutypes {
  5629. if i == "390" {
  5630. is390 = 1
  5631. }
  5632. if i == "310" {
  5633. is310 = 1
  5634. }
  5635. }
  5636. }
  5637. if is390 == 1 {
  5638. insutype = "390"
  5639. }
  5640. if is310 == 1 {
  5641. insutype = "310"
  5642. }
  5643. if len(insutypes) == 0 {
  5644. insutype = "310"
  5645. }
  5646. for _, item := range insutypes {
  5647. if item == insutype {
  5648. insuplc_admdvs_temp = item
  5649. }
  5650. }
  5651. //insuplcAdmdvs := strconv.Itoa(insuplc_admdvs_temp)
  5652. card_info_two := insuplc_admdvs_temp + "|" + res.Output.Baseinfo.Certno + "|" + res.Output.Baseinfo.ExpContent.MdtrtCertNo
  5653. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  5654. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  5655. infoStr := string(Iinfos)
  5656. idetinfoStr := string(Idetinfos)
  5657. psn := &models.HisPsn{
  5658. PsnNo: res.Output.Baseinfo.PsnNo,
  5659. PatientId: patient.ID,
  5660. Certno: res.Output.Baseinfo.Certno,
  5661. Gend: res.Output.Baseinfo.Gend,
  5662. Naty: res.Output.Baseinfo.Naty,
  5663. PsnCertType: res.Output.Baseinfo.PsnCertType,
  5664. PsnName: res.Output.Baseinfo.PsnName,
  5665. Idetinfo: idetinfoStr,
  5666. Insuinfo: infoStr,
  5667. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5668. InsuplcAdmdvs: insuplc_admdvs_temp,
  5669. CardInfo:card_info_two,
  5670. }
  5671. service.CreateHisPsn(psn)
  5672. c.ServeSuccessJSON(map[string]interface{}{
  5673. "patient": patient,
  5674. "number": res.Output.Baseinfo.Certno,
  5675. })
  5676. }
  5677. } else {
  5678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  5679. return
  5680. }
  5681. } else if miConfig.MdtrtareaAdmvs =="360399"{
  5682. //if initFlag == 0 {
  5683. //c.TestGetJiangXiBasBaseInit()
  5684. //}
  5685. //if initEleFlag == 0 {
  5686. // GetJxEleBaseInitInfo(c.GetAdminUserInfo().CurrentOrgId)
  5687. //}
  5688. //_, result2 := GetjxELekeyInfo(miConfig.Code, "1", roles.UserName)
  5689. _, result := GetjxELeInfoaaa(miConfig.Code, "1", roles.UserName)
  5690. //json_result := GetJxEleBaseInfo(c.GetAdminUserInfo().CurrentOrgId)
  5691. type ELeData struct {
  5692. Data struct {
  5693. IdNo string `json:"idNo"`
  5694. IdType string `json:"idType"`
  5695. UserName string `json:"userName"`
  5696. EcToken string `json:"ecToken"`
  5697. InsuOrg string `json:"insuOrg"`
  5698. Gender string `json:"gender"`
  5699. Birthday string `json:"birthday"`
  5700. Nationality string `json:"nationality"`
  5701. Email string `json:"email"`
  5702. Extra string `json:"extra"`
  5703. } `json:"data"`
  5704. Code int `json:"code"`
  5705. Message string `json:"message"`
  5706. }
  5707. var ele ELeData
  5708. err := json.Unmarshal([]byte(result), &ele)
  5709. if err != nil {
  5710. utils.ErrorLog("解析失败:%v", err)
  5711. }
  5712. token := ele.Data.EcToken
  5713. token = Remove0000(token)
  5714. result2, requestLog2 := service.Jxyb1101ForEleCert(miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Url, miConfig.AccessKey, token, "", ele.Data.IdNo, ele.Data.UserName)
  5715. saveLog(result2, requestLog2, "1101", "获取人员信息")
  5716. var res ResultTwo
  5717. if err := json.Unmarshal([]byte(result2), &res); err != nil {
  5718. utils.ErrorLog("解析失败:%v", err)
  5719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5720. return
  5721. }
  5722. if res.Infcode == 0 {
  5723. patient, err := service.GetPatientByNumber(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  5724. if err == gorm.ErrRecordNotFound {
  5725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  5726. return
  5727. } else if err != nil {
  5728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5729. return
  5730. } else {
  5731. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  5732. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  5733. infoStr := string(Iinfos)
  5734. idetinfoStr := string(Idetinfos)
  5735. psn := &models.HisPsn{
  5736. PsnNo: res.Output.Baseinfo.PsnNo,
  5737. Age: res.Output.Baseinfo.Age,
  5738. PatientId: patient.ID,
  5739. Certno: res.Output.Baseinfo.Certno,
  5740. Gend: res.Output.Baseinfo.Gend,
  5741. Naty: res.Output.Baseinfo.Naty,
  5742. PsnCertType: res.Output.Baseinfo.PsnCertType,
  5743. PsnName: res.Output.Baseinfo.PsnName,
  5744. Idetinfo: idetinfoStr,
  5745. Insuinfo: infoStr,
  5746. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5747. CardInfo: "",
  5748. VerifyNumber: token,
  5749. }
  5750. service.CreateHisPsn(psn)
  5751. var rf []*ResultFive
  5752. json.Unmarshal([]byte(infoStr), &rf)
  5753. var insutypes []*ResultFive
  5754. var insutype string
  5755. var is390 int = 0
  5756. var is310 int = 0
  5757. for _, item := range rf {
  5758. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  5759. insutypes = append(insutypes, item)
  5760. }
  5761. }
  5762. if len(insutypes) == 1 {
  5763. insutype = insutypes[0].Insutype
  5764. //insuplc_admdvs = insutypes[0].InsuplcAdmdvs
  5765. } else {
  5766. for _, i := range insutypes {
  5767. if i.Insutype == "390" {
  5768. is390 = 1
  5769. }
  5770. if i.Insutype == "310" {
  5771. is310 = 1
  5772. }
  5773. }
  5774. }
  5775. if is390 == 1 {
  5776. insutype = "390"
  5777. }
  5778. if is310 == 1 {
  5779. insutype = "310"
  5780. }
  5781. if len(insutypes) == 0 {
  5782. insutype = "310"
  5783. }
  5784. c.ServeSuccessJSON(map[string]interface{}{
  5785. "patient": patient,
  5786. "number": token,
  5787. "info": res,
  5788. "insutype": insutype,
  5789. })
  5790. }
  5791. } else {
  5792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  5793. return
  5794. }
  5795. }else {
  5796. if initFlagTwo == 0 {
  5797. c.TestGetBasBaseInitTwo()
  5798. }
  5799. token := c.GetEleBaseInfoTwo()
  5800. token = Remove0000(token)
  5801. result2, requestLog2 := service.Gdyb1101ForEleCert(miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, token, "", "")
  5802. saveLog(result2, requestLog2, "1101", "获取人员信息")
  5803. //
  5804. var res ResultTwo
  5805. if err := json.Unmarshal([]byte(result2), &res); err != nil {
  5806. utils.ErrorLog("解析失败:%v", err)
  5807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5808. return
  5809. }
  5810. if res.Infcode == 0 {
  5811. patient, err := service.GetPatientByNumber(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  5812. if err == gorm.ErrRecordNotFound {
  5813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  5814. return
  5815. } else if err != nil {
  5816. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5817. return
  5818. } else {
  5819. var insutypes []string
  5820. var insutype string
  5821. var is390 int = 0
  5822. var is310 int = 0
  5823. for _, item := range res.Output.Iinfo {
  5824. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  5825. insutypes = append(insutypes, item.Insutype)
  5826. }
  5827. }
  5828. if len(insutypes) == 1 {
  5829. insutype = insutypes[0]
  5830. } else {
  5831. for _, i := range insutypes {
  5832. if i == "390" {
  5833. is390 = 1
  5834. }
  5835. if i == "310" {
  5836. is310 = 1
  5837. }
  5838. }
  5839. }
  5840. if is390 == 1 {
  5841. insutype = "390"
  5842. }
  5843. if is310 == 1 {
  5844. insutype = "310"
  5845. }
  5846. if len(insutypes) == 0 {
  5847. insutype = "310"
  5848. }
  5849. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  5850. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  5851. infoStr := string(Iinfos)
  5852. idetinfoStr := string(Idetinfos)
  5853. psn := &models.HisPsn{
  5854. PsnNo: res.Output.Baseinfo.PsnNo,
  5855. Age: res.Output.Baseinfo.Age,
  5856. PatientId: patient.ID,
  5857. Certno: res.Output.Baseinfo.Certno,
  5858. Gend: res.Output.Baseinfo.Gend,
  5859. Naty: res.Output.Baseinfo.Naty,
  5860. PsnCertType: res.Output.Baseinfo.PsnCertType,
  5861. PsnName: res.Output.Baseinfo.PsnName,
  5862. Idetinfo: idetinfoStr,
  5863. Insuinfo: infoStr,
  5864. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5865. CardInfo: "",
  5866. VerifyNumber: token,
  5867. }
  5868. service.CreateHisPsn(psn)
  5869. c.ServeSuccessJSON(map[string]interface{}{
  5870. "patient": patient,
  5871. "number": token,
  5872. "info": res,
  5873. "insutype": insutype,
  5874. })
  5875. }
  5876. } else {
  5877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  5878. return
  5879. }
  5880. }
  5881. break
  5882. }
  5883. }
  5884. func GetjxELekeyInfo(code string, operator_id string, operator_name string) (string, string) {
  5885. // WebSocket服务器地址
  5886. serverURL := "ws://127.0.0.1:8899"
  5887. // 解析WebSocket服务器地址
  5888. u, err := url.Parse(serverURL)
  5889. if err != nil {
  5890. }
  5891. // 建立WebSocket连接
  5892. conn, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
  5893. if err != nil {
  5894. }
  5895. defer conn.Close()
  5896. input2 := make(map[string]interface{})
  5897. input := make(map[string]interface{})
  5898. inputData := make(map[string]interface{})
  5899. inputData["orgId"] = code
  5900. inputData["businessType"] = "01101"
  5901. inputData["operatorId"] = operator_id
  5902. inputData["operatorName"] = operator_name
  5903. inputData["officeId"] = "001"
  5904. inputData["officeName"] = "血透室"
  5905. inputData["deviceType"] = ""
  5906. input["data"] = inputData
  5907. input["orgId"] = code
  5908. input["transType"] = "ec.query"
  5909. //if md == ""
  5910. input2["url"] = "http://10.77.211.236/1.0.0/getEncDynamicKey"
  5911. input2["indata"] = input
  5912. fmt.Println(input2)
  5913. bytesData, _ := json.Marshal(input2)
  5914. err = conn.WriteMessage(websocket.TextMessage, bytesData)
  5915. if err != nil {
  5916. fmt.Println(err)
  5917. }
  5918. // 接收消息
  5919. _, receivedMessage, err := conn.ReadMessage()
  5920. if err != nil {
  5921. fmt.Println(err)
  5922. }
  5923. return "", string(receivedMessage)
  5924. }
  5925. func GetjxELeInfoaaa(code string, operator_id string, operator_name string) (string, string) {
  5926. // WebSocket服务器地址
  5927. serverURL := "ws://127.0.0.1:8899"
  5928. // 解析WebSocket服务器地址
  5929. u, err := url.Parse(serverURL)
  5930. if err != nil {
  5931. }
  5932. // 建立WebSocket连接
  5933. conn, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
  5934. if err != nil {
  5935. }
  5936. defer conn.Close()
  5937. input2 := make(map[string]interface{})
  5938. input := make(map[string]interface{})
  5939. inputData := make(map[string]interface{})
  5940. inputData["orgId"] = code
  5941. inputData["businessType"] = "01103"
  5942. inputData["operatorId"] = operator_id
  5943. inputData["operatorName"] = operator_name
  5944. inputData["officeId"] = "001"
  5945. inputData["officeName"] = "血透室"
  5946. inputData["deviceType"] = ""
  5947. input["data"] = inputData
  5948. input["orgId"] = code
  5949. input["transType"] = "ec.query"
  5950. //if md ==
  5951. input2["url"] = "http://10.77.211.236/1.0.0/localQrCodeQuery"
  5952. input2["indata"] = input
  5953. fmt.Println(input2)
  5954. bytesData, _ := json.Marshal(input2)
  5955. err = conn.WriteMessage(websocket.TextMessage, bytesData)
  5956. if err != nil {
  5957. fmt.Println(err)
  5958. }
  5959. // 接收消息
  5960. _, receivedMessage, err := conn.ReadMessage()
  5961. if err != nil {
  5962. fmt.Println(err)
  5963. }
  5964. return "", string(receivedMessage)
  5965. }
  5966. func (c *ZHHisApiController) GetEleBaseInfoTwo() string {
  5967. DllDef := syscall.MustLoadDLL("SSCard.dll")
  5968. readCard := DllDef.MustFindProc("GetQRBase")
  5969. fmt.Println(readCard)
  5970. if readCard == nil {
  5971. fmt.Println("readcard is nil")
  5972. readCard = DllDef.MustFindProc("GetQRBase")
  5973. }
  5974. str := make([]byte, 1024)
  5975. str1 := make([]byte, 1024)
  5976. ret2, _, _ := readCard.Call(uintptr(180), (uintptr)(unsafe.Pointer(&str[0])), uintptr(1024), (uintptr)(unsafe.Pointer(&str1[0])), uintptr(1024))
  5977. fmt.Println(ret2)
  5978. fmt.Println(string(str1))
  5979. fmt.Println(string(str))
  5980. fmt.Println(":", ConvertToString(string(str1), "gbk", "utf-8"))
  5981. fmt.Println(":", ConvertToString(string(str), "gbk", "utf-8"))
  5982. if ret2 != 0 {
  5983. return ""
  5984. }
  5985. return string(str)
  5986. }
  5987. func (c *ZHHisApiController) TestGetBasBaseInitTwo() {
  5988. DllDef := syscall.MustLoadDLL("SSCard.dll")
  5989. Iinit := DllDef.MustFindProc("Init")
  5990. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  5991. ret, _, err := Iinit.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_api/prd/api/card/initDll"), StrPtr(miConfig.MdtrtareaAdmvs))
  5992. if ret != 0 {
  5993. fmt.Println("SSCard的报错原因:", err)
  5994. fmt.Println("SSCard的运算结果为:", ret)
  5995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  5996. return
  5997. }
  5998. result := int(ret)
  5999. fmt.Println("SSCard的运算结果为1:", result)
  6000. initFlagTwo = 1
  6001. return
  6002. }
  6003. func (c *ZHHisApiController) GetBasBaseInfoTwo() string {
  6004. DllDef := syscall.MustLoadDLL("SSCard.dll")
  6005. readCard := DllDef.MustFindProc("ReadCardBas")
  6006. if readCard == nil {
  6007. fmt.Println("readcard is nil")
  6008. readCard = DllDef.MustFindProc("ReadCardBas")
  6009. }
  6010. str := make([]byte, 1024)
  6011. str1 := make([]byte, 1024)
  6012. ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), uintptr(1024), (uintptr)(unsafe.Pointer(&str1[0])), uintptr(1024))
  6013. fmt.Println(string(str1))
  6014. fmt.Println(string(str))
  6015. fmt.Println(":", ConvertToString(string(str1), "gbk", "utf-8"))
  6016. fmt.Println(":", ConvertToString(string(str), "gbk", "utf-8"))
  6017. if ret2 != 0 {
  6018. return ""
  6019. }
  6020. return string(str)
  6021. }
  6022. var initFlag int64 = 0
  6023. func (c *ZHHisApiController) TestGetBasBaseInit() {
  6024. DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
  6025. Iinit := DllDef.MustFindProc("Init")
  6026. //miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  6027. str := make([]byte, 2048)
  6028. inputData := make(map[string]interface{})
  6029. inputData["IP"] = "10.144.211.75"
  6030. inputData["PORT"] = 7021
  6031. inputData["TIMEOUT"] = 180
  6032. inputData["LOG_PATH"] = "C:\\log\\"
  6033. //inputData["SFZ_DRIVER_TYPE"] = 0
  6034. inputData["URL"] = "/call1"
  6035. bytesData, _ := json.Marshal(inputData)
  6036. fmt.Println(inputData)
  6037. fmt.Println(bytesData)
  6038. ret, _, err := Iinit.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&str[0])))
  6039. if ret != 0 {
  6040. fmt.Println("SSCard的报错原因:", err)
  6041. fmt.Println("SSCard的运算结果为:", ret)
  6042. fmt.Println("SSCard的返回结果为:", string(str))
  6043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  6044. return
  6045. }
  6046. fmt.Println("SSCard的返回结果为:", string(str))
  6047. result := int(ret)
  6048. fmt.Println("SSCard的运算结果为1:", result)
  6049. //initFlag = 1
  6050. return
  6051. }
  6052. func (c *ZHHisApiController) GetSFZBaseInfo() string {
  6053. DllDef := syscall.MustLoadDLL("SSCard.dll")
  6054. readCard := DllDef.MustFindProc("ReadSFZ")
  6055. if readCard == nil {
  6056. fmt.Println("readcard is nil")
  6057. readCard = DllDef.MustFindProc("ReadSFZ")
  6058. }
  6059. str := make([]byte, 256)
  6060. str1 := make([]byte, 256)
  6061. r, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  6062. fmt.Println(r)
  6063. return string(str)
  6064. }
  6065. func (c *ZHHisApiController) GetBasBaseInfo(fixmedins_code string, mdtrtarea_admvs string, opter_name string, opter_id string, fixmedins_name string) string {
  6066. DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
  6067. readCard := DllDef.MustFindProc("ReadCardBas")
  6068. fmt.Println(readCard)
  6069. fmt.Println("!!!!!")
  6070. month := time.Unix(1557042972, 0).Format("1")
  6071. year := time.Now().Format("2006")
  6072. month = time.Now().Format("01")
  6073. day := time.Now().Format("02")
  6074. hour := time.Now().Format("15")
  6075. min := time.Now().Format("04")
  6076. sec := time.Now().Format("05")
  6077. msec := time.Now().Format("000")
  6078. timestamp := time.Now().Unix()
  6079. tempTime := time.Unix(timestamp, 0)
  6080. //timeFormat := tempTime.Format("20060102150405")
  6081. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  6082. //randNum := rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000)
  6083. inputData := make(map[string]interface{})
  6084. inputData["infno"] = "1199"
  6085. //inputData["msgid"] = "7021"
  6086. inputData["msgid"] = fixmedins_code + year + month + day + hour + min + sec + msec + "0" // 发送方报文 ID
  6087. inputData["mdtrtarea_admvs"] = mdtrtarea_admvs // 发送方报文 ID
  6088. inputData["recer_sys_code"] = "01"
  6089. inputData["infver"] = "V1.0"
  6090. inputData["opter_type"] = "1"
  6091. inputData["opter"] = opter_id
  6092. inputData["opter_name"] = opter_name
  6093. inputData["inf_time"] = timeFormatOne
  6094. inputData["fixmedins_code"] = fixmedins_code
  6095. inputData["fixmedins_name"] = fixmedins_name
  6096. inputData["dev_no"] = ""
  6097. inputData["dev_safe_info"] = ""
  6098. inputData["cainfo"] = ""
  6099. inputData["signtype"] = ""
  6100. inputData["sign_no"] = ""
  6101. bytesData, _ := json.Marshal(inputData)
  6102. fmt.Println(string(bytesData))
  6103. pBusiCardInfo := make([]byte, 8192)
  6104. ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&pBusiCardInfo[0])))
  6105. fmt.Println(ret2)
  6106. fmt.Println(DeleteExtraSpace(string(pBusiCardInfo)))
  6107. fmt.Println(":", ConvertToString(DeleteExtraSpace(string(pBusiCardInfo)), "gbk", "utf-8"))
  6108. if ret2 != 0 {
  6109. return ""
  6110. }
  6111. return DeleteExtraSpace(string(pBusiCardInfo))
  6112. }
  6113. func DeleteExtraSpace(s string) string {
  6114. //删除字符串中的多余空格,有多个空格时,仅保留一个空格
  6115. s1 := strings.Replace(s, " ", " ", -1) //替换tab为空格
  6116. regstr := "\\s{2,}" //两个及两个以上空格的正则表达式
  6117. reg, _ := regexp.Compile(regstr) //编译正则表达式
  6118. s2 := make([]byte, len(s1)) //定义字符数组切片
  6119. copy(s2, s1) //将字符串复制到切片
  6120. spc_index := reg.FindStringIndex(string(s2)) //在字符串中搜索
  6121. for len(spc_index) > 0 { //找到适配项
  6122. s2 = append(s2[:spc_index[0]+1], s2[spc_index[1]:]...) //删除多余空格
  6123. spc_index = reg.FindStringIndex(string(s2)) //继续在字符串中搜索
  6124. }
  6125. return string(s2)
  6126. }
  6127. func (c *ZHHisApiController) GetELeInfo(code string, operator_id string, operator_name string) (string, string) {
  6128. DllDef := syscall.MustLoadDLL("NationECCode.dll")
  6129. readCard := DllDef.MustFindProc("NationEcTrans")
  6130. fmt.Println(readCard)
  6131. fmt.Println("!!!!!")
  6132. pBusiCardInfo := make([]byte, 8192)
  6133. input := make(map[string]interface{})
  6134. inputData := make(map[string]interface{})
  6135. inputData["orgId"] = code
  6136. inputData["businessType"] = "01101"
  6137. inputData["operatorId"] = operator_id
  6138. inputData["operatorName"] = operator_name
  6139. inputData["officeId"] = "001"
  6140. inputData["officeName"] = "血透室"
  6141. inputData["deviceType"] = ""
  6142. input["data"] = inputData
  6143. input["orgId"] = code
  6144. input["transType"] = "ec.query"
  6145. bytesData, _ := json.Marshal(input)
  6146. gdyb_url := beego.AppConfig.String("gdyb_url")
  6147. url := gdyb_url + "/localcfc/api/hsecfc/localQrCodeQuery"
  6148. ret2, _, _ := readCard.Call(StrPtr(url), StrPtr(string(bytesData)), (uintptr)(unsafe.Pointer(&pBusiCardInfo[0])))
  6149. fmt.Println(ret2)
  6150. fmt.Println(DeleteExtraSpace(string(pBusiCardInfo)))
  6151. fmt.Println(":", ConvertToString(DeleteExtraSpace(string(pBusiCardInfo)), "gbk", "utf-8"))
  6152. if ret2 != 0 {
  6153. return "", ""
  6154. }
  6155. return DeleteExtraSpace(""), DeleteExtraSpace(string(pBusiCardInfo))
  6156. }
  6157. func StrPtr(s string) uintptr {
  6158. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  6159. }
  6160. func Remove0000(s string) string {
  6161. str := make([]rune, 0, len(s))
  6162. for _, v := range []rune(s) {
  6163. if v == 0 {
  6164. continue
  6165. }
  6166. str = append(str, v)
  6167. }
  6168. return string(str)
  6169. }
  6170. func IntPtr(n int) uintptr {
  6171. return uintptr(n)
  6172. }
  6173. func RemoveRepeatedPurviewElement2(arr []string) (newArr []string) {
  6174. newArr = make([]string, 0)
  6175. for i := 0; i < len(arr); i++ {
  6176. repeat := false
  6177. for j := i + 1; j < len(arr); j++ {
  6178. if arr[i] == arr[j] {
  6179. repeat = true
  6180. break
  6181. }
  6182. }
  6183. if !repeat {
  6184. newArr = append(newArr, arr[i])
  6185. }
  6186. }
  6187. return
  6188. }
  6189. type Result3101 struct {
  6190. Infcode int64 `json:"infcode"`
  6191. InfRefmsgid string `json:"inf_refmsgid"`
  6192. RefmsgTime string `json:"refmsg_time"`
  6193. RespondTime string `json:"respond_time"`
  6194. Enctype string `json:"enctype"`
  6195. Signtype string `json:"signtype"`
  6196. ErrMsg string `json:"err_msg"`
  6197. Output struct {
  6198. Result []struct {
  6199. JudgeResultDetailDtos []struct {
  6200. VolaItemType string `json:"vola_item_type"`
  6201. MdtrtID string `json:"mdtrt_id"`
  6202. JrdID string `json:"jrd_id"`
  6203. PatnID string `json:"patn_id"`
  6204. RxID string `json:"rx_id"`
  6205. VolaAmt interface{} `json:"vola_amt"`
  6206. } `json:"judge_result_detail_dtos"`
  6207. RuleID string `json:"rule_id"`
  6208. VolaEvid string `json:"vola_evid"`
  6209. MdtrtID string `json:"mdtrt_id"`
  6210. RuleName string `json:"rule_name"`
  6211. VolaAmtStas string `json:"vola_amt_stas"`
  6212. JrID string `json:"jr_id"`
  6213. PatnID string `json:"patn_id"`
  6214. SevDeg string `json:"sev_deg"`
  6215. VolaAmt float64 `json:"vola_amt"`
  6216. VolaBhvrType string `json:"vola_bhvr_type"`
  6217. VolaCont string `json:"vola_cont"`
  6218. } `json:"result"`
  6219. } `json:"output"`
  6220. }
  6221. func Check3101ForOne(c *ZHHisApiController, patient_id int64, his service.Struct2401, admin_user_id int64, trig_scen string, record_time string, prescriptions []*models.HisPrescription, ress ResultTwo, record_date int64) (res2 Result3101) {
  6222. var res Result3101
  6223. adminUser := c.GetAdminUserInfo()
  6224. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  6225. //his, _ := service.GetNewHisPatientInfoFour(c.GetAdminUserInfo().CurrentOrgId, his_patient_id)
  6226. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  6227. //record_time := c.GetString("record_time")
  6228. //trig_scen := c.GetString("trig_scen")
  6229. timeLayout := "2006-01-02"
  6230. loc, _ := time.LoadLocation("Local")
  6231. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6232. if err != nil {
  6233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6234. return res
  6235. }
  6236. recordDateTime := theTime.Unix()
  6237. p, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  6238. var patientPrescription models.HisPrescriptionInfo
  6239. //patientPrescription, _ = service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  6240. //if patientPrescription.ID == 0 {
  6241. patientPrescription, _ = service.FindLastPatientPrescriptionInfoTwo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  6242. //}
  6243. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  6244. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  6245. //
  6246. diagnosis_ids := strings.Split(patientPrescription.Diagnosis, ",")
  6247. //prescriptions, _ := service.GetNewHisPrescriptionTen(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  6248. var pp models.PublicParams
  6249. pp.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
  6250. pp.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
  6251. pp.FixmedinsName = miConfig.OrgName
  6252. pp.FixmedinsCode = miConfig.Code
  6253. pp.RequestUrl = miConfig.Url
  6254. pp.Cainfo = miConfig.Cainfo
  6255. pp.SecretKey = miConfig.SecretKey
  6256. pp.AccessKey = miConfig.AccessKey
  6257. pp.OpterName = roles.UserName
  6258. var config []*models.HisXtDiagnoseConfig
  6259. for _, item := range diagnosis_ids {
  6260. id, _ := strconv.ParseInt(item, 10, 64)
  6261. if id > 0 {
  6262. diagnosisConfig, _ := service.FindDiagnoseById(id)
  6263. config = append(config, &diagnosisConfig)
  6264. }
  6265. }
  6266. var pd models.PatientDtos
  6267. pd.PatnID = his.PsnNo
  6268. pd.PatnName = p.Name
  6269. pd.Gend = ress.Output.Baseinfo.Gend
  6270. pd.Poolarea = miConfig.MdtrtareaAdmvs
  6271. pd.CurrMdtrtID = strconv.FormatInt(patientPrescription.ID, 10)
  6272. var fed models.FsiEncounterDtos
  6273. fed.MdtrtID = p.IdCardNo
  6274. fed.MedinsID = miConfig.Code
  6275. fed.MedinsName = miConfig.OrgName
  6276. fed.MedinsAdmdvs = miConfig.MdtrtareaAdmvs
  6277. fed.MedMdtrtType = "1"
  6278. fed.MedinsType = "1"
  6279. fed.MedinsLv = "11"
  6280. tm := time.Unix(record_date, 0)
  6281. s_tm := tm.Format("2006-01-02 15:04:05")
  6282. fed.AdmDate = s_tm
  6283. fed.DscgDate = s_tm
  6284. fed.DscgMainDiseCodg = config[0].CountryCode
  6285. fed.DscgMainDiseName = config[0].CountryContentName
  6286. //诊断信息
  6287. var fdds []*models.FsiDiagnoseDtos
  6288. for index, item := range config {
  6289. if index == 0 {
  6290. var fdd models.FsiDiagnoseDtos
  6291. fdd.DiseID = strconv.FormatInt(item.ID, 10)
  6292. fdd.InoutDiseType = "1"
  6293. fdd.MaindiseFlag = "1"
  6294. fdd.DiseDate = s_tm
  6295. fdd.DiasSrtNo = "1"
  6296. fdd.DiseName = item.CountryContentName
  6297. fdd.DiseCodg = item.CountryCode
  6298. fdds = append(fdds, &fdd)
  6299. } else {
  6300. var fdd models.FsiDiagnoseDtos
  6301. fdd.DiseID = strconv.FormatInt(item.ID, 10)
  6302. fdd.InoutDiseType = "1"
  6303. fdd.MaindiseFlag = "1"
  6304. fdd.DiseDate = s_tm
  6305. fdd.DiasSrtNo = strconv.FormatInt(int64(index), 10)
  6306. fdd.DiseName = item.CountryContentName
  6307. fdd.DiseCodg = item.CountryCode
  6308. fdds = append(fdds, &fdd)
  6309. }
  6310. }
  6311. fed.DrCodg = strconv.FormatInt(doctor_info.ID, 10)
  6312. fed.AdmDeptCodg = strconv.FormatInt(department.ID, 10)
  6313. fed.AdmDeptName = department.Name
  6314. fed.DscgDeptCodg = strconv.FormatInt(department.ID, 10)
  6315. fed.DscgDeptName = department.Name
  6316. fed.MedMdtrtType = "1"
  6317. fed.MedType = "11"
  6318. //if his.Insutype == "390" {
  6319. // fed.MedType = "1402"
  6320. //} else {
  6321. // fed.MedType = "9933"
  6322. //}
  6323. var orders []*models.FsiOrderDtos
  6324. if trig_scen == "4" {
  6325. //处方医嘱信息
  6326. for _, item := range prescriptions {
  6327. for _, subItem := range item.HisDoctorAdviceInfo {
  6328. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 && subItem.BaseDrugLib.IsUser != 1 {
  6329. spec := (subItem.BaseDrugLib.Dose + subItem.BaseDrugLib.DoseUnit) + "*" + strconv.FormatInt(subItem.BaseDrugLib.MinNumber, 10) + subItem.BaseDrugLib.MinUnit + "/" + subItem.BaseDrugLib.MaxUnit
  6330. var order models.FsiOrderDtos
  6331. order.RxID = strconv.FormatInt(item.ID, 10)
  6332. order.Rxno = strconv.FormatInt(item.ID, 10)
  6333. order.LongDrordFlag = "0"
  6334. order.HilistType = "1"
  6335. order.ChrgType = "1"
  6336. order.DrordBhvr = "0"
  6337. order.HilistCode = subItem.BaseDrugLib.MedicalInsuranceNumber
  6338. order.HosplistName = subItem.BaseDrugLib.DrugName
  6339. order.HilistLv = "1"
  6340. order.HilistPric = fmt.Sprintf("%.2f", subItem.Price)
  6341. order.HosplistCode = subItem.BaseDrugLib.MedicalInsuranceNumber
  6342. order.HosplistName = subItem.BaseDrugLib.DrugName
  6343. order.Cnt = fmt.Sprintf("%.2f", subItem.PrescribingNumber)
  6344. order.Pric = fmt.Sprintf("%.2f", subItem.Price)
  6345. order.Sumamt = fmt.Sprintf("%.2f", (subItem.PrescribingNumber * subItem.Price))
  6346. order.OwnpayAmt = ""
  6347. order.SelfpayAmt = ""
  6348. order.Spec = spec
  6349. order.SpecUnt = subItem.PrescribingNumberUnit
  6350. order.DrordBegnDate = s_tm
  6351. order.DrordStopDate = ""
  6352. order.DrordDrCodg = doctor_info.DoctorNumber
  6353. order.DrordDeptName = department.Name
  6354. order.DrordDeptCodg = department.Number
  6355. order.DrordDrName = doctor_info.UserName
  6356. order.DrordDrProfttl = "234"
  6357. order.CurrDrordFlag = "1"
  6358. orders = append(orders, &order)
  6359. }
  6360. }
  6361. for _, subItem := range item.HisPrescriptionProject {
  6362. if len(subItem.HisProject.MedicalCode) > 0 {
  6363. if subItem.Type == 2 {
  6364. var order models.FsiOrderDtos
  6365. order.RxID = strconv.FormatInt(item.ID, 10)
  6366. order.Rxno = strconv.FormatInt(item.ID, 10)
  6367. order.LongDrordFlag = "0"
  6368. order.HilistType = "1"
  6369. order.ChrgType = "1"
  6370. order.DrordBhvr = "0"
  6371. order.HilistCode = subItem.HisProject.MedicalCode
  6372. order.HosplistName = subItem.HisProject.ProjectName
  6373. order.HilistLv = "1"
  6374. order.HilistPric = fmt.Sprintf("%.2f", subItem.Price)
  6375. order.HosplistCode = subItem.HisProject.MedicalCode
  6376. order.HosplistName = subItem.HisProject.ProjectName
  6377. order.Cnt = subItem.Count
  6378. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6379. order.Pric = fmt.Sprintf("%.2f", subItem.Price)
  6380. order.Sumamt = fmt.Sprintf("%.2f", subItem.Price*cnt)
  6381. order.OwnpayAmt = ""
  6382. order.SelfpayAmt = ""
  6383. order.Spec = subItem.Unit
  6384. order.SpecUnt = subItem.Unit
  6385. order.DrordBegnDate = s_tm
  6386. order.DrordStopDate = ""
  6387. order.DrordDrCodg = doctor_info.DoctorNumber
  6388. order.DrordDeptName = department.Name
  6389. order.DrordDeptCodg = department.Number
  6390. order.DrordDrName = doctor_info.UserName
  6391. order.DrordDrProfttl = "234"
  6392. order.CurrDrordFlag = "1"
  6393. orders = append(orders, &order)
  6394. }
  6395. }
  6396. if subItem.Type == 3 {
  6397. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 && subItem.GoodInfo.IsUser != 1 {
  6398. var order models.FsiOrderDtos
  6399. order.RxID = strconv.FormatInt(item.ID, 10)
  6400. order.Rxno = strconv.FormatInt(item.ID, 10)
  6401. order.LongDrordFlag = "0"
  6402. order.HilistType = "1"
  6403. order.ChrgType = "1"
  6404. order.DrordBhvr = "0"
  6405. order.HilistCode = subItem.GoodInfo.MedicalInsuranceNumber
  6406. order.HosplistName = subItem.GoodInfo.GoodName
  6407. order.HilistLv = "1"
  6408. order.HilistPric = fmt.Sprintf("%.2f", subItem.Price)
  6409. order.HosplistCode = subItem.GoodInfo.MedicalInsuranceNumber
  6410. order.HosplistName = subItem.GoodInfo.GoodName
  6411. order.Cnt = subItem.Count
  6412. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6413. order.Pric = fmt.Sprintf("%.2f", subItem.Price)
  6414. order.Sumamt = fmt.Sprintf("%.2f", subItem.Price*cnt)
  6415. order.OwnpayAmt = ""
  6416. order.SelfpayAmt = ""
  6417. order.Spec = subItem.GoodInfo.SpecificationName
  6418. order.SpecUnt = subItem.Unit
  6419. order.DrordBegnDate = s_tm
  6420. order.DrordStopDate = ""
  6421. order.DrordDrCodg = doctor_info.DoctorNumber
  6422. order.DrordDeptName = department.Name
  6423. order.DrordDeptCodg = department.Number
  6424. order.DrordDrName = doctor_info.UserName
  6425. order.DrordDrProfttl = "234"
  6426. order.CurrDrordFlag = "1"
  6427. orders = append(orders, &order)
  6428. }
  6429. }
  6430. }
  6431. }
  6432. //处方医嘱信息
  6433. }
  6434. fed.MatnStas = "0"
  6435. fed.MedfeeSumamt = "0"
  6436. fed.OwnpayAmt = "0"
  6437. fed.SelfpayAmt = "0"
  6438. fed.AcctPayamt = "0"
  6439. fed.MaAmt = "0"
  6440. fed.HifpPayamt = "0"
  6441. fed.SetlTotlnum = "1"
  6442. fed.Insutype = his.Insutype
  6443. fed.ReimFlag = "0"
  6444. fed.OutSetlFlag = "0"
  6445. var fopd []*models.FsiOperationDtosData
  6446. data := make(map[string]interface{})
  6447. data["fed"] = fed
  6448. data["fdd"] = fdds
  6449. data["fod"] = orders
  6450. data["pd"] = pd
  6451. data["pp"] = pp
  6452. data["fopd"] = fopd
  6453. data["trig_scen"] = trig_scen
  6454. fmt.Println(data)
  6455. fmt.Println(fed)
  6456. fmt.Println(fdds)
  6457. fmt.Println(orders)
  6458. fmt.Println(pd)
  6459. fmt.Println(pp)
  6460. fmt.Println(fopd)
  6461. client := &http.Client{}
  6462. bytesData, _ := json.Marshal(data)
  6463. var req *http.Request
  6464. if miConfig.MdtrtareaAdmvs == "320921" || miConfig.MdtrtareaAdmvs == "320982" {
  6465. if miConfig.MdtrtareaAdmvs == "320921" {
  6466. req, _ = http.NewRequest("POST", "http://192.168.2.3:9532/"+"jsyb/3101", bytes.NewReader(bytesData))
  6467. } else {
  6468. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3101", bytes.NewReader(bytesData))
  6469. }
  6470. resp, _ := client.Do(req)
  6471. defer resp.Body.Close()
  6472. body, ioErr := ioutil.ReadAll(resp.Body)
  6473. if ioErr != nil {
  6474. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  6475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6476. return res
  6477. }
  6478. var respJSON map[string]interface{}
  6479. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  6480. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  6481. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6482. return res
  6483. }
  6484. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  6485. fmt.Println(respJSON)
  6486. result, _ := json.Marshal(respJSON)
  6487. fmt.Println(result)
  6488. if err := json.Unmarshal([]byte(result), &res); err != nil {
  6489. utils.ErrorLog("解析失败:%v", err)
  6490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6491. return res
  6492. }
  6493. return res
  6494. } else {
  6495. //if miConfig.MdtrtareaAdmvs == "441202" {
  6496. output, input := service.Gdyb3101(pd, fed, fdds, orders, fopd, pp, trig_scen)
  6497. saveLog(output, input, "3101", "事前")
  6498. if err := json.Unmarshal([]byte(output), &res); err != nil {
  6499. utils.ErrorLog("解析失败:%v", err)
  6500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6501. return
  6502. }
  6503. return res
  6504. //}
  6505. }
  6506. }
  6507. func Check3101(c *ZHHisApiController, patient_id int64, his_patient_id int64, admin_user_id int64, trig_scen string, record_time string, prescriptions []*models.HisPrescription) (res Result3101) {
  6508. adminUser := c.GetAdminUserInfo()
  6509. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  6510. his, _ := service.GetInHospitalRecord(his_patient_id)
  6511. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  6512. //record_time := c.GetString("record_time")
  6513. //trig_scen := c.GetString("trig_scen")
  6514. timeLayout := "2006-01-02"
  6515. loc, _ := time.LoadLocation("Local")
  6516. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6517. if err != nil {
  6518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6519. return res
  6520. }
  6521. recordDateTime := theTime.Unix()
  6522. var patientPrescription models.HisPrescriptionInfo
  6523. patientPrescription, _ = service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  6524. if patientPrescription.ID == 0 {
  6525. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  6526. }
  6527. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  6528. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  6529. //
  6530. diagnosis_ids := strings.Split(patientPrescription.Diagnosis, ",")
  6531. p, _ := service.GetPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  6532. //prescriptions, _ := service.GetNewHisPrescriptionTen(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  6533. var pp models.PublicParams
  6534. pp.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
  6535. pp.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
  6536. pp.FixmedinsName = miConfig.OrgName
  6537. pp.FixmedinsCode = miConfig.Code
  6538. pp.RequestUrl = miConfig.Url
  6539. pp.Cainfo = miConfig.Cainfo
  6540. pp.SecretKey = miConfig.SecretKey
  6541. pp.AccessKey = miConfig.AccessKey
  6542. pp.OpterName = roles.UserName
  6543. var config []*models.HisXtDiagnoseConfig
  6544. for _, item := range diagnosis_ids {
  6545. id, _ := strconv.ParseInt(item, 10, 64)
  6546. if id > 0 {
  6547. diagnosisConfig, _ := service.FindDiagnoseById(id)
  6548. config = append(config, &diagnosisConfig)
  6549. }
  6550. }
  6551. var pd models.PatientDtos
  6552. pd.PatnID = his.PsnNo
  6553. pd.PatnName = his.Name
  6554. pd.Gend = his.Gend
  6555. pd.Poolarea = his.InsuplcAdmdvs
  6556. pd.CurrMdtrtID = his.Number
  6557. birthday := time.Unix(p.Birthday, 0)
  6558. // 格式化为生日字符串
  6559. birthdayStr := birthday.Format("2006-01-02") // 格式化模板为 "年-月-日"
  6560. pd.Brdy = birthdayStr
  6561. var fed models.FsiEncounterDtos
  6562. fed.MdtrtID = his.Number
  6563. fed.MedinsID = miConfig.Code
  6564. fed.MedinsName = miConfig.OrgName
  6565. fed.MedinsAdmdvs = miConfig.MdtrtareaAdmvs
  6566. fed.MedMdtrtType = "1"
  6567. fed.MedinsType = "1"
  6568. fed.MedinsLv = "11"
  6569. tm := time.Unix(his.RecordDate, 0)
  6570. s_tm := tm.Format("2006-01-02 15:04:05")
  6571. fed.AdmDate = s_tm
  6572. fed.DscgDate = s_tm
  6573. fed.DscgMainDiseCodg = config[0].CountryCode
  6574. fed.DscgMainDiseName = config[0].CountryContentName
  6575. //诊断信息
  6576. var fdds []*models.FsiDiagnoseDtos
  6577. for index, item := range config {
  6578. if index == 0 {
  6579. var fdd models.FsiDiagnoseDtos
  6580. fdd.DiseID = strconv.FormatInt(item.ID, 10)
  6581. fdd.InoutDiseType = "1"
  6582. fdd.MaindiseFlag = "1"
  6583. fdd.DiseDate = s_tm
  6584. fdd.DiasSrtNo = "1"
  6585. fdd.DiseName = item.CountryContentName
  6586. fdd.DiseCodg = item.CountryCode
  6587. fdds = append(fdds, &fdd)
  6588. } else {
  6589. var fdd models.FsiDiagnoseDtos
  6590. fdd.DiseID = strconv.FormatInt(item.ID, 10)
  6591. fdd.InoutDiseType = "1"
  6592. fdd.MaindiseFlag = "1"
  6593. fdd.DiseDate = s_tm
  6594. fdd.DiasSrtNo = strconv.FormatInt(int64(index), 10)
  6595. fdd.DiseName = item.CountryContentName
  6596. fdd.DiseCodg = item.CountryCode
  6597. fdds = append(fdds, &fdd)
  6598. }
  6599. }
  6600. fed.DrCodg = strconv.FormatInt(doctor_info.ID, 10)
  6601. fed.AdmDeptCodg = strconv.FormatInt(department.ID, 10)
  6602. fed.AdmDeptName = department.Name
  6603. fed.DscgDeptCodg = strconv.FormatInt(department.ID, 10)
  6604. fed.DscgDeptName = department.Name
  6605. fed.MedMdtrtType = "1"
  6606. fed.MedType = "11"
  6607. //if his.Insutype == "390" {
  6608. // fed.MedType = "1402"
  6609. //} else {
  6610. // fed.MedType = "9933"
  6611. //}
  6612. var orders []*models.FsiOrderDtos
  6613. if trig_scen == "4" {
  6614. //处方医嘱信息
  6615. for _, item := range prescriptions {
  6616. for _, subItem := range item.HisDoctorAdviceInfo {
  6617. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 && subItem.BaseDrugLib.IsUser != 1 {
  6618. spec := (subItem.BaseDrugLib.Dose + subItem.BaseDrugLib.DoseUnit) + "*" + strconv.FormatInt(subItem.BaseDrugLib.MinNumber, 10) + subItem.BaseDrugLib.MinUnit + "/" + subItem.BaseDrugLib.MaxUnit
  6619. var order models.FsiOrderDtos
  6620. order.RxID = strconv.FormatInt(item.ID, 10)
  6621. order.Rxno = strconv.FormatInt(item.ID, 10)
  6622. order.LongDrordFlag = "0"
  6623. order.HilistType = "1"
  6624. order.ChrgType = "1"
  6625. order.DrordBhvr = "0"
  6626. order.HilistCode = subItem.BaseDrugLib.MedicalInsuranceNumber
  6627. order.HosplistName = subItem.BaseDrugLib.DrugName
  6628. order.HilistLv = "1"
  6629. order.HilistPric = fmt.Sprintf("%.2f", subItem.Price)
  6630. order.HosplistCode = subItem.BaseDrugLib.MedicalInsuranceNumber
  6631. order.HosplistName = subItem.BaseDrugLib.DrugName
  6632. order.Cnt = fmt.Sprintf("%.2f", subItem.PrescribingNumber)
  6633. order.Pric = fmt.Sprintf("%.2f", subItem.Price)
  6634. order.Sumamt = fmt.Sprintf("%.2f", (subItem.PrescribingNumber * subItem.Price))
  6635. order.OwnpayAmt = ""
  6636. order.SelfpayAmt = ""
  6637. order.Spec = spec
  6638. order.SpecUnt = subItem.PrescribingNumberUnit
  6639. order.DrordBegnDate = s_tm
  6640. order.DrordStopDate = ""
  6641. order.DrordDrCodg = doctor_info.DoctorNumber
  6642. order.DrordDeptName = department.Name
  6643. order.DrordDeptCodg = department.Number
  6644. order.DrordDrName = doctor_info.UserName
  6645. order.DrordDrProfttl = "234"
  6646. order.CurrDrordFlag = "1"
  6647. orders = append(orders, &order)
  6648. }
  6649. }
  6650. for _, subItem := range item.HisPrescriptionProject {
  6651. if len(subItem.HisProject.MedicalCode) > 0 {
  6652. if subItem.Type == 2 {
  6653. var order models.FsiOrderDtos
  6654. order.RxID = strconv.FormatInt(item.ID, 10)
  6655. order.Rxno = strconv.FormatInt(item.ID, 10)
  6656. order.LongDrordFlag = "0"
  6657. order.HilistType = "1"
  6658. order.ChrgType = "1"
  6659. order.DrordBhvr = "0"
  6660. order.HilistCode = subItem.HisProject.MedicalCode
  6661. order.HosplistName = subItem.HisProject.ProjectName
  6662. order.HilistLv = "1"
  6663. order.HilistPric = fmt.Sprintf("%.2f", subItem.Price)
  6664. order.HosplistCode = subItem.HisProject.MedicalCode
  6665. order.HosplistName = subItem.HisProject.ProjectName
  6666. order.Cnt = subItem.Count
  6667. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6668. order.Pric = fmt.Sprintf("%.2f", subItem.Price)
  6669. order.Sumamt = fmt.Sprintf("%.2f", subItem.Price*cnt)
  6670. order.OwnpayAmt = ""
  6671. order.SelfpayAmt = ""
  6672. order.Spec = subItem.Unit
  6673. order.SpecUnt = subItem.Unit
  6674. order.DrordBegnDate = s_tm
  6675. order.DrordStopDate = ""
  6676. order.DrordDrCodg = doctor_info.DoctorNumber
  6677. order.DrordDeptName = department.Name
  6678. order.DrordDeptCodg = department.Number
  6679. order.DrordDrName = doctor_info.UserName
  6680. order.DrordDrProfttl = "234"
  6681. order.CurrDrordFlag = "1"
  6682. orders = append(orders, &order)
  6683. }
  6684. }
  6685. if subItem.Type == 3 {
  6686. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 && subItem.GoodInfo.IsUser != 1 {
  6687. var order models.FsiOrderDtos
  6688. order.RxID = strconv.FormatInt(item.ID, 10)
  6689. order.Rxno = strconv.FormatInt(item.ID, 10)
  6690. order.LongDrordFlag = "0"
  6691. order.HilistType = "1"
  6692. order.ChrgType = "1"
  6693. order.DrordBhvr = "0"
  6694. order.HilistCode = subItem.GoodInfo.MedicalInsuranceNumber
  6695. order.HosplistName = subItem.GoodInfo.GoodName
  6696. order.HilistLv = "1"
  6697. order.HilistPric = fmt.Sprintf("%.2f", subItem.Price)
  6698. order.HosplistCode = subItem.GoodInfo.MedicalInsuranceNumber
  6699. order.HosplistName = subItem.GoodInfo.GoodName
  6700. order.Cnt = subItem.Count
  6701. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6702. order.Pric = fmt.Sprintf("%.2f", subItem.Price)
  6703. order.Sumamt = fmt.Sprintf("%.2f", subItem.Price*cnt)
  6704. order.OwnpayAmt = ""
  6705. order.SelfpayAmt = ""
  6706. order.Spec = subItem.GoodInfo.SpecificationName
  6707. order.SpecUnt = subItem.Unit
  6708. order.DrordBegnDate = s_tm
  6709. order.DrordStopDate = ""
  6710. order.DrordDrCodg = doctor_info.DoctorNumber
  6711. order.DrordDeptName = department.Name
  6712. order.DrordDeptCodg = department.Number
  6713. order.DrordDrName = doctor_info.UserName
  6714. order.DrordDrProfttl = "234"
  6715. order.CurrDrordFlag = "1"
  6716. orders = append(orders, &order)
  6717. }
  6718. }
  6719. }
  6720. }
  6721. //处方医嘱信息
  6722. }
  6723. fed.MatnStas = "0"
  6724. fed.MedfeeSumamt = "0"
  6725. fed.OwnpayAmt = "0"
  6726. fed.SelfpayAmt = "0"
  6727. fed.AcctPayamt = "0"
  6728. fed.MaAmt = "0"
  6729. fed.HifpPayamt = "0"
  6730. fed.SetlTotlnum = "1"
  6731. fed.Insutype = his.InsutypeType
  6732. fed.ReimFlag = "0"
  6733. fed.OutSetlFlag = "0"
  6734. var fopd []*models.FsiOperationDtosData
  6735. data := make(map[string]interface{})
  6736. data["fed"] = fed
  6737. data["fdd"] = fdds
  6738. data["fod"] = orders
  6739. data["pd"] = pd
  6740. data["pp"] = pp
  6741. data["fopd"] = fopd
  6742. data["trig_scen"] = trig_scen
  6743. fmt.Println(data)
  6744. fmt.Println(fed)
  6745. fmt.Println(fdds)
  6746. fmt.Println(orders)
  6747. fmt.Println(pd)
  6748. fmt.Println(pp)
  6749. fmt.Println(fopd)
  6750. client := &http.Client{}
  6751. bytesData, _ := json.Marshal(data)
  6752. var req *http.Request
  6753. if miConfig.MdtrtareaAdmvs == "320921" || miConfig.MdtrtareaAdmvs == "320982" {
  6754. if miConfig.MdtrtareaAdmvs == "320921" {
  6755. req, _ = http.NewRequest("POST", "http://192.168.2.3:9532/"+"jsyb/3101", bytes.NewReader(bytesData))
  6756. } else {
  6757. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3101", bytes.NewReader(bytesData))
  6758. }
  6759. resp, _ := client.Do(req)
  6760. defer resp.Body.Close()
  6761. body, ioErr := ioutil.ReadAll(resp.Body)
  6762. if ioErr != nil {
  6763. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  6764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6765. return res
  6766. }
  6767. var respJSON map[string]interface{}
  6768. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  6769. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  6770. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6771. return res
  6772. }
  6773. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  6774. fmt.Println(respJSON)
  6775. result, _ := json.Marshal(respJSON)
  6776. fmt.Println(result)
  6777. if err := json.Unmarshal([]byte(result), &res); err != nil {
  6778. utils.ErrorLog("解析失败:%v", err)
  6779. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6780. return res
  6781. }
  6782. return res
  6783. } else {
  6784. output, input := service.Gdyb3101(pd, fed, fdds, orders, fopd, pp, trig_scen)
  6785. saveLog(output, input, "3101", "事前")
  6786. if err := json.Unmarshal([]byte(output), &res); err != nil {
  6787. utils.ErrorLog("解析失败:%v", err)
  6788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6789. return
  6790. }
  6791. return res
  6792. }
  6793. return res
  6794. }
  6795. func Check3102(c *ZHHisApiController, patient_id int64, his_patient_id int64, admin_user_id int64, trig_scen string, order_id int64) (res Result3101) {
  6796. ////patient_id, _ := c.GetInt64("patient_id")
  6797. //order_id, _ := c.GetInt64("order_id")
  6798. ////his_patient_id, _ := c.GetInt64("his_patient_id")
  6799. ////admin_user_id, _ := c.GetInt64("admin_user_id")
  6800. //trig_scen := c.GetString("trig_scen")
  6801. adminUser := c.GetAdminUserInfo()
  6802. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  6803. //his, _ := service.GetNewHisPatientInfoFour(c.GetAdminUserInfo().CurrentOrgId, his_patient_id)
  6804. his, _ := service.GetInHospitalRecord(his_patient_id)
  6805. p, _ := service.GetPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  6806. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  6807. record_time := c.GetString("record_time")
  6808. order, _ := service.GetHisOrderByID(order_id)
  6809. timeLayout := "2006-01-02"
  6810. loc, _ := time.LoadLocation("Local")
  6811. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6812. if err != nil {
  6813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6814. return
  6815. }
  6816. recordDateTime := theTime.Unix()
  6817. var patientPrescription models.HisPrescriptionInfo
  6818. patientPrescription, _ = service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  6819. if patientPrescription.ID == 0 {
  6820. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  6821. }
  6822. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  6823. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  6824. //
  6825. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  6826. prescriptions, _ := service.GetNewHisPrescriptionTenone(adminUser.CurrentOrgId, his.Number)
  6827. var pp models.PublicParams
  6828. pp.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
  6829. pp.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
  6830. pp.FixmedinsName = miConfig.OrgName
  6831. pp.FixmedinsCode = miConfig.Code
  6832. pp.RequestUrl = miConfig.Url
  6833. pp.Cainfo = miConfig.Cainfo
  6834. pp.SecretKey = miConfig.SecretKey
  6835. pp.AccessKey = miConfig.AccessKey
  6836. pp.OpterName = roles.UserName
  6837. var config []*models.HisXtDiagnoseConfig
  6838. for _, item := range diagnosis_ids {
  6839. id, _ := strconv.ParseInt(item, 10, 64)
  6840. if id > 0 {
  6841. diagnosisConfig, _ := service.FindDiagnoseById(id)
  6842. config = append(config, &diagnosisConfig)
  6843. }
  6844. }
  6845. var pd models.PatientDtos
  6846. pd.PatnID = his.PsnNo
  6847. pd.PatnName = his.Name
  6848. pd.Gend = his.Gend
  6849. pd.Poolarea = his.InsuplcAdmdvs
  6850. pd.CurrMdtrtID = his.Number
  6851. // 将时间戳转换为 time.Time 类型
  6852. birthday := time.Unix(p.Birthday, 0)
  6853. // 格式化为生日字符串
  6854. birthdayStr := birthday.Format("2006-01-02") // 格式化模板为 "年-月-日"
  6855. pd.Brdy = birthdayStr
  6856. var fed models.FsiEncounterDtos
  6857. fed.MdtrtID = his.Number
  6858. fed.MedinsID = miConfig.Code
  6859. fed.MedinsName = miConfig.OrgName
  6860. fed.MedinsAdmdvs = miConfig.MdtrtareaAdmvs
  6861. fed.MedMdtrtType = "1"
  6862. fed.MedinsType = "1"
  6863. fed.MedinsLv = "11"
  6864. tm := time.Unix(his.RecordDate, 0)
  6865. s_tm := tm.Format("2006-01-02 15:04:05")
  6866. fed.AdmDate = s_tm
  6867. fed.DscgDate = s_tm
  6868. fed.DscgMainDiseCodg = config[0].CountryCode
  6869. fed.DscgMainDiseName = config[0].CountryContentName
  6870. //诊断信息
  6871. var fdds []*models.FsiDiagnoseDtos
  6872. for index, item := range config {
  6873. if index == 0 {
  6874. var fdd models.FsiDiagnoseDtos
  6875. fdd.DiseID = strconv.FormatInt(item.ID, 10)
  6876. fdd.InoutDiseType = "1"
  6877. fdd.MaindiseFlag = "1"
  6878. fdd.DiseDate = s_tm
  6879. fdd.DiasSrtNo = "1"
  6880. fdd.DiseName = item.CountryContentName
  6881. fdd.DiseCodg = item.CountryCode
  6882. fdds = append(fdds, &fdd)
  6883. } else {
  6884. var fdd models.FsiDiagnoseDtos
  6885. fdd.DiseID = strconv.FormatInt(item.ID, 10)
  6886. fdd.InoutDiseType = "1"
  6887. fdd.MaindiseFlag = "1"
  6888. fdd.DiseDate = s_tm
  6889. fdd.DiasSrtNo = strconv.FormatInt(int64(index), 10)
  6890. fdd.DiseName = item.CountryContentName
  6891. fdd.DiseCodg = item.CountryCode
  6892. fdds = append(fdds, &fdd)
  6893. }
  6894. }
  6895. fed.DrCodg = strconv.FormatInt(doctor_info.ID, 10)
  6896. fed.AdmDeptCodg = strconv.FormatInt(department.ID, 10)
  6897. fed.AdmDeptName = department.Name
  6898. fed.DscgDeptCodg = strconv.FormatInt(department.ID, 10)
  6899. fed.DscgDeptName = department.Name
  6900. fed.MedType = "14"
  6901. //处方医嘱信息
  6902. var orders []*models.FsiOrderDtos
  6903. //for _, item := range prescriptions {
  6904. // for _, subItem := range item.HisDoctorAdviceInfo {
  6905. // var order models.FsiOrderDtos
  6906. // order.RxID = strconv.FormatInt(item.ID, 10)
  6907. // order.Rxno = strconv.FormatInt(item.ID, 10)
  6908. // order.LongDrordFlag = "0"
  6909. // order.HilistType = "1"
  6910. // order.ChrgType = "1"
  6911. // order.DrordBhvr = "-"
  6912. // order.HilistCode = subItem.BaseDrugLib.MedicalInsuranceNumber
  6913. // order.HosplistName = subItem.BaseDrugLib.DrugName
  6914. // order.HilistLv = "1"
  6915. // order.HilistPric = strconv.FormatFloat(subItem.Price, 'E', -1, 64)
  6916. // order.HosplistCode = subItem.BaseDrugLib.MedicalInsuranceNumber
  6917. // order.HosplistName = subItem.BaseDrugLib.DrugName
  6918. // order.Cnt = strconv.FormatFloat(subItem.PrescribingNumber, 'E', -1, 64)
  6919. // order.Pric = strconv.FormatFloat(subItem.Price, 'E', -1, 64)
  6920. // order.Sumamt = strconv.FormatFloat((subItem.Price * subItem.PrescribingNumber), 'E', -1, 64)
  6921. // order.OwnpayAmt = ""
  6922. // order.SelfpayAmt = ""
  6923. // order.Spec = ""
  6924. // order.SpecUnt = ""
  6925. // order.DrordBegnDate = s_tm
  6926. // order.DrordStopDate = ""
  6927. // order.DrordDrCodg = "1"
  6928. // order.DrordDeptName = department.Name
  6929. // order.DrordDrCodg = "1"
  6930. // order.DrordDrName = doctor_info.UserName
  6931. // order.DrordDrProfttl = ""
  6932. // order.CurrDrordFlag = "1"
  6933. // orders = append(orders, &order)
  6934. // }
  6935. // for _, subItem := range item.HisPrescriptionProject {
  6936. // if subItem.Type == 2 {
  6937. // var order models.FsiOrderDtos
  6938. // order.RxID = strconv.FormatInt(item.ID, 10)
  6939. // order.Rxno = strconv.FormatInt(item.ID, 10)
  6940. // order.LongDrordFlag = "0"
  6941. // order.HilistType = "1"
  6942. // order.ChrgType = "1"
  6943. // order.DrordBhvr = "-"
  6944. // order.HilistCode = subItem.HisProject.MedicalCode
  6945. // order.HosplistName = subItem.HisProject.ProjectName
  6946. // order.HilistLv = "1"
  6947. // order.HilistPric = strconv.FormatFloat(subItem.Price, 'E', -1, 64)
  6948. // order.HosplistCode = subItem.HisProject.MedicalCode
  6949. // order.HosplistName = subItem.HisProject.ProjectName
  6950. // order.Cnt = subItem.Count
  6951. // cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6952. //
  6953. // order.Pric = strconv.FormatFloat(subItem.Price, 'E', -1, 64)
  6954. // order.Sumamt = strconv.FormatFloat((subItem.Price * cnt), 'E', -1, 64)
  6955. // order.OwnpayAmt = ""
  6956. // order.SelfpayAmt = ""
  6957. // order.Spec = ""
  6958. // order.SpecUnt = ""
  6959. // order.DrordBegnDate = s_tm
  6960. // order.DrordStopDate = ""
  6961. // order.DrordDrCodg = "1"
  6962. // order.DrordDeptName = department.Name
  6963. // order.DrordDrCodg = "1"
  6964. // order.DrordDrName = doctor_info.UserName
  6965. // order.DrordDrProfttl = ""
  6966. // order.CurrDrordFlag = "1"
  6967. // orders = append(orders, &order)
  6968. //
  6969. // }
  6970. // if subItem.Type == 3 {
  6971. //
  6972. // var order models.FsiOrderDtos
  6973. // order.RxID = strconv.FormatInt(item.ID, 10)
  6974. // order.Rxno = strconv.FormatInt(item.ID, 10)
  6975. // order.LongDrordFlag = "0"
  6976. // order.HilistType = "1"
  6977. // order.ChrgType = "1"
  6978. // order.DrordBhvr = "-"
  6979. // order.HilistCode = subItem.GoodInfo.MedicalInsuranceNumber
  6980. // order.HosplistName = subItem.GoodInfo.GoodName
  6981. // order.HilistLv = "1"
  6982. // order.HilistPric = strconv.FormatFloat(subItem.Price, 'E', -1, 64)
  6983. // order.HosplistCode = subItem.GoodInfo.MedicalInsuranceNumber
  6984. // order.HosplistName = subItem.GoodInfo.GoodName
  6985. // order.Cnt = subItem.Count
  6986. // cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6987. // order.Pric = strconv.FormatFloat(subItem.Price, 'E', -1, 64)
  6988. // order.Sumamt = strconv.FormatFloat((subItem.Price * cnt), 'E', -1, 64)
  6989. // order.OwnpayAmt = ""
  6990. // order.SelfpayAmt = ""
  6991. // order.Spec = ""
  6992. // order.SpecUnt = ""
  6993. // order.DrordBegnDate = s_tm
  6994. // order.DrordStopDate = ""
  6995. // order.DrordDrCodg = "1"
  6996. // order.DrordDeptName = department.Name
  6997. // order.DrordDrCodg = "1"
  6998. // order.DrordDrName = doctor_info.UserName
  6999. // order.DrordDrProfttl = ""
  7000. // order.CurrDrordFlag = "1"
  7001. // orders = append(orders, &order)
  7002. //
  7003. // }
  7004. // }
  7005. //}
  7006. for _, item := range prescriptions {
  7007. for _, subItem := range item.HisDoctorAdviceInfo {
  7008. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 && subItem.BaseDrugLib.IsUser != 1 {
  7009. spec := (subItem.BaseDrugLib.Dose + subItem.BaseDrugLib.DoseUnit) + "*" + strconv.FormatInt(subItem.BaseDrugLib.MinNumber, 10) + subItem.BaseDrugLib.MinUnit + "/" + subItem.BaseDrugLib.MaxUnit
  7010. var order models.FsiOrderDtos
  7011. order.RxID = strconv.FormatInt(item.ID, 10)
  7012. order.Rxno = strconv.FormatInt(item.ID, 10)
  7013. order.LongDrordFlag = "0"
  7014. order.HilistType = "1"
  7015. order.ChrgType = "1"
  7016. order.DrordBhvr = "0"
  7017. order.HilistCode = subItem.BaseDrugLib.MedicalInsuranceNumber
  7018. order.HosplistName = subItem.BaseDrugLib.DrugName
  7019. order.HilistLv = "1"
  7020. order.HilistPric = fmt.Sprintf("%.2f", subItem.Price)
  7021. order.HosplistCode = subItem.BaseDrugLib.MedicalInsuranceNumber
  7022. order.HosplistName = subItem.BaseDrugLib.DrugName
  7023. order.Cnt = fmt.Sprintf("%.2f", subItem.PrescribingNumber)
  7024. order.Pric = fmt.Sprintf("%.2f", subItem.Price)
  7025. order.Sumamt = fmt.Sprintf("%.2f", (subItem.PrescribingNumber * subItem.Price))
  7026. order.OwnpayAmt = ""
  7027. order.SelfpayAmt = ""
  7028. order.Spec = spec
  7029. order.SpecUnt = subItem.PrescribingNumberUnit
  7030. order.DrordBegnDate = s_tm
  7031. order.DrordStopDate = ""
  7032. order.DrordDrCodg = doctor_info.DoctorNumber
  7033. order.DrordDeptName = department.Name
  7034. order.DrordDeptCodg = department.Number
  7035. order.DrordDrName = doctor_info.UserName
  7036. order.DrordDrProfttl = "234"
  7037. order.CurrDrordFlag = "1"
  7038. orders = append(orders, &order)
  7039. }
  7040. }
  7041. for _, subItem := range item.HisPrescriptionProject {
  7042. if len(subItem.HisProject.MedicalCode) > 0 {
  7043. if subItem.Type == 2 {
  7044. var order models.FsiOrderDtos
  7045. order.RxID = strconv.FormatInt(item.ID, 10)
  7046. order.Rxno = strconv.FormatInt(item.ID, 10)
  7047. order.LongDrordFlag = "0"
  7048. order.HilistType = "1"
  7049. order.ChrgType = "1"
  7050. order.DrordBhvr = "0"
  7051. order.HilistCode = subItem.HisProject.MedicalCode
  7052. order.HosplistName = subItem.HisProject.ProjectName
  7053. order.HilistLv = "1"
  7054. order.HilistPric = fmt.Sprintf("%.2f", subItem.Price)
  7055. order.HosplistCode = subItem.HisProject.MedicalCode
  7056. order.HosplistName = subItem.HisProject.ProjectName
  7057. order.Cnt = subItem.Count
  7058. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7059. order.Pric = fmt.Sprintf("%.2f", subItem.Price)
  7060. order.Sumamt = fmt.Sprintf("%.2f", subItem.Price*cnt)
  7061. order.OwnpayAmt = ""
  7062. order.SelfpayAmt = ""
  7063. order.Spec = subItem.Unit
  7064. order.SpecUnt = subItem.Unit
  7065. order.DrordBegnDate = s_tm
  7066. order.DrordStopDate = ""
  7067. order.DrordDrCodg = doctor_info.DoctorNumber
  7068. order.DrordDeptName = department.Name
  7069. order.DrordDeptCodg = department.Number
  7070. order.DrordDrName = doctor_info.UserName
  7071. order.DrordDrProfttl = "234"
  7072. order.CurrDrordFlag = "1"
  7073. orders = append(orders, &order)
  7074. }
  7075. }
  7076. if subItem.Type == 3 {
  7077. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 && subItem.GoodInfo.IsUser != 1 {
  7078. var order models.FsiOrderDtos
  7079. order.RxID = strconv.FormatInt(item.ID, 10)
  7080. order.Rxno = strconv.FormatInt(item.ID, 10)
  7081. order.LongDrordFlag = "0"
  7082. order.HilistType = "1"
  7083. order.ChrgType = "1"
  7084. order.DrordBhvr = "0"
  7085. order.HilistCode = subItem.GoodInfo.MedicalInsuranceNumber
  7086. order.HosplistName = subItem.GoodInfo.GoodName
  7087. order.HilistLv = "1"
  7088. order.HilistPric = fmt.Sprintf("%.2f", subItem.Price)
  7089. order.HosplistCode = subItem.GoodInfo.MedicalInsuranceNumber
  7090. order.HosplistName = subItem.GoodInfo.GoodName
  7091. order.Cnt = subItem.Count
  7092. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7093. order.Pric = fmt.Sprintf("%.2f", subItem.Price)
  7094. order.Sumamt = fmt.Sprintf("%.2f", subItem.Price*cnt)
  7095. order.OwnpayAmt = ""
  7096. order.SelfpayAmt = ""
  7097. order.Spec = subItem.GoodInfo.SpecificationName
  7098. order.SpecUnt = subItem.Unit
  7099. order.DrordBegnDate = s_tm
  7100. order.DrordStopDate = ""
  7101. order.DrordDrCodg = doctor_info.DoctorNumber
  7102. order.DrordDeptName = department.Name
  7103. order.DrordDeptCodg = department.Number
  7104. order.DrordDrName = doctor_info.UserName
  7105. order.DrordDrProfttl = "234"
  7106. order.CurrDrordFlag = "1"
  7107. orders = append(orders, &order)
  7108. }
  7109. }
  7110. }
  7111. }
  7112. //for _, item := range prescriptions {
  7113. // for _, subItem := range item.HisDoctorAdviceInfo {
  7114. // spec := (subItem.BaseDrugLib.Dose + subItem.BaseDrugLib.DoseUnit) + "*" + strconv.FormatInt(subItem.BaseDrugLib.MinNumber, 10) + subItem.BaseDrugLib.MinUnit + "/" + subItem.BaseDrugLib.MaxUnit
  7115. //
  7116. // var order models.FsiOrderDtos
  7117. // order.RxID = strconv.FormatInt(item.ID, 10)
  7118. // order.Rxno = strconv.FormatInt(item.ID, 10)
  7119. // order.LongDrordFlag = "0"
  7120. // order.HilistType = "1"
  7121. // order.ChrgType = "1"
  7122. // order.DrordBhvr = "0"
  7123. // order.HilistCode = subItem.BaseDrugLib.MedicalInsuranceNumber
  7124. // order.HosplistName = subItem.BaseDrugLib.DrugName
  7125. // order.HilistLv = "1"
  7126. // order.HilistPric = fmt.Sprintf("%.2f", subItem.Price)
  7127. // order.HosplistCode = subItem.BaseDrugLib.MedicalInsuranceNumber
  7128. // order.HosplistName = subItem.BaseDrugLib.DrugName
  7129. // order.Cnt = fmt.Sprintf("%.2f", subItem.PrescribingNumber)
  7130. // order.Pric = fmt.Sprintf("%.2f", subItem.Price)
  7131. // order.Sumamt = fmt.Sprintf("%.2f", (subItem.PrescribingNumber * subItem.Price))
  7132. // order.OwnpayAmt = ""
  7133. // order.SelfpayAmt = ""
  7134. // order.Spec = spec
  7135. // order.SpecUnt = subItem.PrescribingNumberUnit
  7136. // order.DrordBegnDate = s_tm
  7137. // order.DrordStopDate = ""
  7138. // order.DrordDrCodg = doctor_info.DoctorNumber
  7139. // order.DrordDeptName = department.Name
  7140. // order.DrordDeptCodg = department.Number
  7141. // order.DrordDrName = doctor_info.UserName
  7142. // order.DrordDrProfttl = "234"
  7143. // order.CurrDrordFlag = "1"
  7144. // orders = append(orders, &order)
  7145. // }
  7146. // for _, subItem := range item.HisPrescriptionProject {
  7147. // if subItem.Type == 2 {
  7148. // var order models.FsiOrderDtos
  7149. // order.RxID = strconv.FormatInt(item.ID, 10)
  7150. // order.Rxno = strconv.FormatInt(item.ID, 10)
  7151. // order.LongDrordFlag = "0"
  7152. // order.HilistType = "1"
  7153. // order.ChrgType = "1"
  7154. // order.DrordBhvr = "0"
  7155. // order.HilistCode = subItem.HisProject.MedicalCode
  7156. // order.HosplistName = subItem.HisProject.ProjectName
  7157. // order.HilistLv = "1"
  7158. // order.HilistPric = fmt.Sprintf("%.2f", subItem.Price)
  7159. // order.HosplistCode = subItem.HisProject.MedicalCode
  7160. // order.HosplistName = subItem.HisProject.ProjectName
  7161. // order.Cnt = subItem.Count
  7162. // cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7163. // order.Pric = fmt.Sprintf("%.2f", subItem.Price)
  7164. // order.Sumamt = fmt.Sprintf("%.2f", subItem.Price*cnt)
  7165. // order.OwnpayAmt = ""
  7166. // order.SelfpayAmt = ""
  7167. // order.Spec = subItem.Unit
  7168. // order.SpecUnt = subItem.Unit
  7169. // order.DrordBegnDate = s_tm
  7170. // order.DrordStopDate = ""
  7171. // order.DrordDrCodg = doctor_info.DoctorNumber
  7172. // order.DrordDeptName = department.Name
  7173. // order.DrordDeptCodg = department.Number
  7174. // order.DrordDrName = doctor_info.UserName
  7175. // order.DrordDrProfttl = "234"
  7176. // order.CurrDrordFlag = "1"
  7177. // orders = append(orders, &order)
  7178. //
  7179. // }
  7180. // if subItem.Type == 3 {
  7181. //
  7182. // var order models.FsiOrderDtos
  7183. // order.RxID = strconv.FormatInt(item.ID, 10)
  7184. // order.Rxno = strconv.FormatInt(item.ID, 10)
  7185. // order.LongDrordFlag = "0"
  7186. // order.HilistType = "1"
  7187. // order.ChrgType = "1"
  7188. // order.DrordBhvr = "0"
  7189. // order.HilistCode = subItem.GoodInfo.MedicalInsuranceNumber
  7190. // order.HosplistName = subItem.GoodInfo.GoodName
  7191. // order.HilistLv = "1"
  7192. // order.HilistPric = fmt.Sprintf("%.2f", subItem.Price)
  7193. // order.HosplistCode = subItem.GoodInfo.MedicalInsuranceNumber
  7194. // order.HosplistName = subItem.GoodInfo.GoodName
  7195. // order.Cnt = subItem.Count
  7196. // cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7197. // order.Pric = fmt.Sprintf("%.2f", subItem.Price)
  7198. // order.Sumamt = fmt.Sprintf("%.2f", subItem.Price*cnt)
  7199. // order.OwnpayAmt = ""
  7200. // order.SelfpayAmt = ""
  7201. // order.Spec = subItem.GoodInfo.SpecificationName
  7202. // order.SpecUnt = subItem.Unit
  7203. // order.DrordBegnDate = s_tm
  7204. // order.DrordStopDate = ""
  7205. // order.DrordDrCodg = doctor_info.DoctorNumber
  7206. // order.DrordDeptName = department.Name
  7207. // order.DrordDeptCodg = department.Number
  7208. // order.DrordDrName = doctor_info.UserName
  7209. // order.DrordDrProfttl = "234"
  7210. // order.CurrDrordFlag = "1"
  7211. // orders = append(orders, &order)
  7212. //
  7213. // }
  7214. // }
  7215. //}
  7216. //处方医嘱信息
  7217. fed.MatnStas = "0"
  7218. fed.MedfeeSumamt = fmt.Sprintf("%.2f", order.MedfeeSumamt)
  7219. fed.OwnpayAmt = fmt.Sprintf("%.2f", order.FulamtOwnpayAmt)
  7220. fed.SelfpayAmt = fmt.Sprintf("%.2f", order.PreselfpayAmt)
  7221. fed.AcctPayamt = fmt.Sprintf("%.2f", order.AcctPay)
  7222. fed.MaAmt = fmt.Sprintf("%.2f", order.MafPay)
  7223. fed.HifpPayamt = fmt.Sprintf("%.2f", order.HifpPay)
  7224. fed.SetlTotlnum = "1"
  7225. fed.Insutype = his.InsutypeType
  7226. fed.ReimFlag = "0"
  7227. fed.OutSetlFlag = "0"
  7228. var fopd []*models.FsiOperationDtosData
  7229. data := make(map[string]interface{})
  7230. data["fed"] = fed
  7231. data["fdd"] = fdds
  7232. data["fod"] = orders
  7233. data["pd"] = pd
  7234. data["pp"] = pp
  7235. data["fopd"] = fopd
  7236. data["trig_scen"] = trig_scen
  7237. client := &http.Client{}
  7238. bytesData, _ := json.Marshal(data)
  7239. var req *http.Request
  7240. if miConfig.MdtrtareaAdmvs == "320921" || miConfig.MdtrtareaAdmvs == "320982" {
  7241. if miConfig.MdtrtareaAdmvs == "320921" {
  7242. req, _ = http.NewRequest("POST", "http://192.168.2.3:9532/"+"jsyb/3102", bytes.NewReader(bytesData))
  7243. } else {
  7244. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3102", bytes.NewReader(bytesData))
  7245. }
  7246. resp, _ := client.Do(req)
  7247. defer resp.Body.Close()
  7248. body, ioErr := ioutil.ReadAll(resp.Body)
  7249. if ioErr != nil {
  7250. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  7251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7252. return res
  7253. }
  7254. var respJSON map[string]interface{}
  7255. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  7256. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  7257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7258. return res
  7259. }
  7260. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  7261. result, _ := json.Marshal(respJSON)
  7262. if err := json.Unmarshal([]byte(result), &res); err != nil {
  7263. utils.ErrorLog("解析失败:%v", err)
  7264. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7265. return res
  7266. }
  7267. return res
  7268. } else {
  7269. output, input := service.Gdyb3102(pd, fed, fdds, orders, fopd, pp, trig_scen)
  7270. saveLog(output, input, "3102", "事中")
  7271. if err := json.Unmarshal([]byte(output), &res); err != nil {
  7272. utils.ErrorLog("解析失败:%v", err)
  7273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7274. return
  7275. }
  7276. return res
  7277. }
  7278. return res
  7279. }