zh_his_api_controller.go 279KB

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