zh_his_api_controller.go 279KB

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