zh_his_api_controller.go 277KB

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