zh_his_api_controller.go 277KB

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