his_api_controller.go 233KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707
  1. package sg
  2. import (
  3. "archive/zip"
  4. "bytes"
  5. "encoding/json"
  6. "fmt"
  7. "gdyb/controllers"
  8. "gdyb/enums"
  9. "gdyb/models"
  10. "gdyb/service"
  11. "gdyb/utils"
  12. "github.com/astaxie/beego"
  13. "github.com/jinzhu/gorm"
  14. "github.com/shopspring/decimal"
  15. "io"
  16. "io/ioutil"
  17. "math/rand"
  18. "net/http"
  19. "os"
  20. "path/filepath"
  21. "strconv"
  22. "strings"
  23. "syscall"
  24. "time"
  25. "unsafe"
  26. )
  27. type HisApiController struct {
  28. controllers.BaseAuthAPIController
  29. }
  30. func HisManagerApiRegistRouters() {
  31. fmt.Println("----------")
  32. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  33. beego.Router("/api/diag/upload", &HisApiController{}, "get:GetUploadDiag")
  34. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  35. beego.Router("/api/settle/query", &HisApiController{}, "get:GetSettleAccounts")
  36. beego.Router("/api/checkaccount/get", &HisApiController{}, "get:GetCheckAccount")
  37. beego.Router("/api/checkdetailaccount/get", &HisApiController{}, "get:GetCheckDetailAccount")
  38. beego.Router("/api/refund/post", &HisApiController{}, "get:Refund")
  39. //beego.Router("/api/sscard", &HisApiController{}, "get:Sscard")
  40. beego.Router("/api/refundnumber/post", &HisApiController{}, "get:RefundNumber")
  41. beego.Router("/api/refunddetail/post", &HisApiController{}, "get:RefundDetail")
  42. beego.Router("/api/treatment/check", &HisApiController{}, "get:CheckTreatment")
  43. beego.Router("/api/record/put", &HisApiController{}, "get:PutRecord")
  44. //beego.Router("/api/patient/info", &HisApiController{}, "get:GetHisPatientInfo")
  45. beego.Router("/api/org/info", &HisApiController{}, "get:GetOrgInfo")
  46. //beego.Router("/api/testcard", &HisApiController{}, "get:TestGetBasBaseInfo")
  47. beego.Router("/api/readcard", &HisApiController{}, "get:ReadCard")
  48. //beego.Router("/api/testpay", &HisApiController{}, "get:TestPay")
  49. beego.Router("/api/presettle/get", &HisApiController{}, "get:GetPreUploadInfo")
  50. //beego.Router("/api/settle/get", &HisApiController{}, "get:GetSettleInfo")
  51. beego.Router("/api/310", &HisApiController{}, "get:Check310")
  52. beego.Router("/api/390", &HisApiController{}, "get:Check390")
  53. beego.Router("/api/patient/info", &HisApiController{}, "get:GetPatientInfo")
  54. //备案撤销相关接口
  55. beego.Router("/api/checkcode/get", &HisApiController{}, "get:GetCheckCode")
  56. beego.Router("/api/uncheckcode/get", &HisApiController{}, "get:UnCheckCode")
  57. beego.Router("/api/psn/putonrecord", &HisApiController{}, "get:PsnPutOnRecord")
  58. beego.Router("/api/psn/unputonrecord", &HisApiController{}, "get:PsnUnPutOnRecord")
  59. beego.Router("/api/psn/ncds/putonrecord", &HisApiController{}, "get:PsnPutNCDSOnRecord")
  60. beego.Router("/api/psn/ncds/unputonrecord", &HisApiController{}, "get:PsnPutUnNCDSOnRecord")
  61. beego.Router("/api/reversal", &HisApiController{}, "get:ReversalData")
  62. beego.Router("/api/reversal/other", &HisApiController{}, "get:ReversalOtherData")
  63. //beego.Router("/api/reversal/one", &HisApiController{}, "get:ReversalOtherOneData")
  64. beego.Router("/api/settlelist/get", &HisApiController{}, "get:GetSettleList")
  65. beego.Router("/api/pwd/check", &HisApiController{}, "get:CheckCardPWD")
  66. beego.Router("/api/insutype/check", &HisApiController{}, "get:CheckInsutype")
  67. //beego.Router("/api/settlelist/get", &HisApiController{}, "get:GetSettleList")
  68. //beego.Router("/api/testinit", &HisApiController{}, "get:TestGetBasBaseInit")
  69. //beego.Router("/api/test", &HisApiController{}, "get:TestGetBasBaseInfo")
  70. }
  71. func (c *HisApiController) CheckInsutype() {
  72. his_patient_id, _ := c.GetInt64("his_patient_id")
  73. admin_user_id, _ := c.GetInt64("admin_user_id")
  74. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  75. his, _ := service.GetNewHisPatientInfoFour(c.GetAdminUserInfo().CurrentOrgId, his_patient_id)
  76. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  77. result := service.Gdyb90100(his.PsnNo, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  78. var dat map[string]interface{}
  79. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  80. fmt.Println(dat)
  81. } else {
  82. fmt.Println(err)
  83. }
  84. userJSONBytes, _ := json.Marshal(dat)
  85. var res Result90100
  86. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  87. utils.ErrorLog("解析失败:%v", err)
  88. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  89. return
  90. }
  91. if res.Infcode != 0 {
  92. c.ServeSuccessJSON(map[string]interface{}{
  93. "failed_code": -10,
  94. "msg": res.ErrMsg,
  95. })
  96. return
  97. } else {
  98. fmt.Println(res)
  99. }
  100. }
  101. func (c *HisApiController) CheckCardPWD() {
  102. card_pwd := c.GetString("card_pwd")
  103. his_patient_id, _ := c.GetInt64("his_patient_id")
  104. admin_user_id, _ := c.GetInt64("admin_user_id")
  105. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  106. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  107. his, _ := service.GetNewHisPatientInfoFour(c.GetAdminUserInfo().CurrentOrgId, his_patient_id)
  108. result := service.Gdyb90991(his.PsnNo, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, card_pwd)
  109. var dat map[string]interface{}
  110. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  111. fmt.Println(dat)
  112. } else {
  113. fmt.Println(err)
  114. }
  115. userJSONBytes, _ := json.Marshal(dat)
  116. var res Result90991
  117. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  118. utils.ErrorLog("解析失败:%v", err)
  119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  120. return
  121. }
  122. if res.Infcode != 0 {
  123. c.ServeSuccessJSON(map[string]interface{}{
  124. "failed_code": -10,
  125. "msg": res.ErrMsg,
  126. })
  127. return
  128. } else {
  129. if res.Output.Result.CheckStat == "0" {
  130. var msg string
  131. switch res.Output.Result.CardStat {
  132. case "00":
  133. msg = "未激活"
  134. break
  135. case "10":
  136. msg = "激活"
  137. break
  138. case "20":
  139. msg = "窗口挂失"
  140. break
  141. case "21":
  142. msg = "电话挂失"
  143. break
  144. case "22":
  145. msg = "单位网上申报挂失"
  146. break
  147. case "23":
  148. msg = "保健办挂失"
  149. break
  150. case "24":
  151. msg = "个人网上挂失"
  152. break
  153. case "25":
  154. msg = "网上服务大厅挂失"
  155. break
  156. case "30":
  157. msg = "注销"
  158. break
  159. case "40":
  160. msg = "回收"
  161. break
  162. case "99":
  163. msg = "制卡中(无效卡)"
  164. break
  165. }
  166. c.ServeSuccessJSON(map[string]interface{}{
  167. "failed_code": -10,
  168. "msg": msg,
  169. })
  170. return
  171. } else {
  172. c.ServeSuccessJSON(map[string]interface{}{
  173. "msg": "校验成功",
  174. })
  175. return
  176. }
  177. }
  178. }
  179. func (c *HisApiController) ReadCard() {
  180. id_card_type, _ := c.GetInt64("id_card_type")
  181. admin_user_id, _ := c.GetInt64("admin_user_id")
  182. certificates, _ := c.GetInt64("certificates")
  183. fmt.Println(c.GetAdminUserInfo().CurrentOrgId)
  184. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  185. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  186. switch id_card_type {
  187. case 1:
  188. if miConfig.MdtrtareaAdmvs == "421300" {
  189. var res ResultTwo
  190. api := "http://192.168.124.4:9532/" + "hbyb/1101?cert_no=" + "" +
  191. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  192. "&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)
  193. resp, requestErr := http.Get(api)
  194. if requestErr != nil {
  195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  196. return
  197. }
  198. body, ioErr := ioutil.ReadAll(resp.Body)
  199. if ioErr != nil {
  200. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  202. return
  203. }
  204. var respJSON map[string]interface{}
  205. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  206. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  208. return
  209. }
  210. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  211. result, _ := json.Marshal(respJSON)
  212. fmt.Println("log")
  213. fmt.Println(string(result))
  214. if err := json.Unmarshal([]byte(result), &res); err != nil {
  215. utils.ErrorLog("解析失败:%v", err)
  216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  217. return
  218. }
  219. if res.Infcode == 0 {
  220. patient, err := service.GetPatientByIDCard(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  221. if err == gorm.ErrRecordNotFound {
  222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  223. return
  224. } else if err != nil {
  225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  226. return
  227. } else {
  228. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  229. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  230. infoStr := string(Iinfos)
  231. idetinfoStr := string(Idetinfos)
  232. psn := &models.HisPsn{
  233. PsnNo: res.Output.Baseinfo.PsnNo,
  234. Age: res.Output.Baseinfo.Age,
  235. PatientId: patient.ID,
  236. Certno: res.Output.Baseinfo.Certno,
  237. Brdy: res.Output.Baseinfo.Brdy,
  238. Gend: res.Output.Baseinfo.Gend,
  239. Naty: res.Output.Baseinfo.Naty,
  240. PsnCertType: res.Output.Baseinfo.PsnCertType,
  241. PsnName: res.Output.Baseinfo.PsnName,
  242. Idetinfo: idetinfoStr,
  243. Insuinfo: infoStr,
  244. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  245. }
  246. service.CreateHisPsn(psn)
  247. c.ServeSuccessJSON(map[string]interface{}{
  248. "patient": patient,
  249. "number": res.Output.Baseinfo.Certno,
  250. })
  251. }
  252. } else {
  253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  254. return
  255. }
  256. } else {
  257. if initFlag == 0 {
  258. c.TestGetBasBaseInit()
  259. }
  260. basStr := c.GetBasBaseInfo()
  261. if len(basStr) == 0 {
  262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  263. return
  264. }
  265. fmt.Println(basStr)
  266. bas := strings.Split(basStr, "|")
  267. basNumber := bas[1]
  268. fmt.Println(basNumber)
  269. card_sn := bas[3]
  270. fmt.Println(card_sn)
  271. result := service.Gdyb1101B(basNumber, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, card_sn, certificates)
  272. var dat map[string]interface{}
  273. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  274. fmt.Println(dat)
  275. } else {
  276. fmt.Println(err)
  277. }
  278. userJSONBytes, _ := json.Marshal(dat)
  279. var res ResultTwo
  280. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  281. utils.ErrorLog("解析失败:%v", err)
  282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  283. return
  284. }
  285. if res.Infcode == 0 {
  286. patient, err := service.GetPatientByNumber(basNumber, c.GetAdminUserInfo().CurrentOrgId)
  287. if err == gorm.ErrRecordNotFound {
  288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  289. return
  290. } else if err != nil {
  291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  292. return
  293. } else {
  294. c.ServeSuccessJSON(map[string]interface{}{
  295. "patient": patient,
  296. "number": basNumber,
  297. })
  298. }
  299. } else {
  300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  301. return
  302. }
  303. break
  304. }
  305. case 2:
  306. SFZStr := c.GetSFZBaseInfo()
  307. id_card_str := strings.Split(SFZStr, "^")
  308. id_card_number := id_card_str[0]
  309. card_sn := ""
  310. result := service.Gdyb1101B(id_card_number, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, card_sn, certificates)
  311. var dat map[string]interface{}
  312. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  313. fmt.Println(dat)
  314. } else {
  315. fmt.Println(err)
  316. }
  317. userJSONBytes, _ := json.Marshal(dat)
  318. var res ResultTwo
  319. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  320. utils.ErrorLog("解析失败:%v", err)
  321. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  322. return
  323. }
  324. if res.Infcode == 0 {
  325. patient, err := service.GetPatientByNumber(id_card_number, c.GetAdminUserInfo().CurrentOrgId)
  326. if err == gorm.ErrRecordNotFound {
  327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  328. return
  329. } else if err != nil {
  330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  331. return
  332. } else {
  333. c.ServeSuccessJSON(map[string]interface{}{
  334. "patient": patient,
  335. "number": id_card_number,
  336. })
  337. }
  338. } else {
  339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  340. return
  341. }
  342. break
  343. case 3:
  344. break
  345. }
  346. }
  347. var initFlag int64 = 0
  348. func (c *HisApiController) TestGetBasBaseInit() {
  349. DllDef := syscall.MustLoadDLL("SSCard.dll")
  350. Iinit := DllDef.MustFindProc("Init")
  351. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  352. ret, _, err := Iinit.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr(miConfig.InsuplcAdmdvs))
  353. if ret != 0 {
  354. fmt.Println("SSCard的报错原因:", err)
  355. fmt.Println("SSCard的运算结果为:", ret)
  356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  357. return
  358. }
  359. result := int(ret)
  360. fmt.Println("SSCard的运算结果为1:", result)
  361. initFlag = 1
  362. return
  363. }
  364. func (c *HisApiController) GetSFZBaseInfo() string {
  365. DllDef := syscall.MustLoadDLL("SSCard.dll")
  366. readCard := DllDef.MustFindProc("ReadSFZ")
  367. if readCard == nil {
  368. fmt.Println("readcard is nil")
  369. readCard = DllDef.MustFindProc("ReadSFZ")
  370. }
  371. str := make([]byte, 256)
  372. str1 := make([]byte, 256)
  373. r, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  374. fmt.Println(r)
  375. return string(str)
  376. }
  377. func (c *HisApiController) GetBasBaseInfo() string {
  378. DllDef := syscall.MustLoadDLL("SSCard.dll")
  379. readCard := DllDef.MustFindProc("ReadCardBas")
  380. if readCard == nil {
  381. fmt.Println("readcard is nil")
  382. readCard = DllDef.MustFindProc("ReadCardBas")
  383. }
  384. str := make([]byte, 1024)
  385. str1 := make([]byte, 1024)
  386. ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), uintptr(1024), (uintptr)(unsafe.Pointer(&str1[0])), uintptr(1024))
  387. fmt.Println(string(str1))
  388. fmt.Println(string(str))
  389. if ret2 != 0 {
  390. return ""
  391. }
  392. return string(str)
  393. }
  394. func prttostr(vcode uintptr) string {
  395. var vbyte []byte
  396. for i := 0; i < 10; i++ {
  397. sbyte := *((*byte)(unsafe.Pointer(vcode)))
  398. if sbyte == 0 {
  399. break
  400. }
  401. vbyte = append(vbyte, sbyte)
  402. vcode += 1
  403. }
  404. return string(vbyte)
  405. }
  406. type CustomFundPay struct {
  407. FundPayType string `json:"fund_pay_type"`
  408. FundPayamt float64 `json:"fund_payamt"`
  409. }
  410. func (c *HisApiController) GetSettleList() {
  411. order_id, _ := c.GetInt64("order_id")
  412. admin_user_id, _ := c.GetInt64("admin_user_id")
  413. order, _ := service.GetHisOrderByIDTwo(order_id)
  414. roles, _ := service.GetDoctorListTwo(c.GetAdminUserInfo().CurrentOrgId)
  415. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  416. admin, _ := service.GetAdminUserByUserID(roles[0].AdminUserId)
  417. curRoles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  418. depart, _ := service.GetDepartMentDetail(curRoles.DepartmentId)
  419. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  420. if order.ID == 0 {
  421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  422. return
  423. }
  424. struct4101 := service.Struct4101{
  425. PsnNo: order.PsnNo,
  426. MdtrtId: order.MdtrtId,
  427. SetlId: order.SetlId,
  428. PsnName: order.PsnName,
  429. Gend: order.Gend,
  430. Brdy: his.Brdy,
  431. Age: his.Age,
  432. Naty: order.Naty,
  433. PatnCertType: "01",
  434. Certno: order.Certno,
  435. Prfs: "90",
  436. ConerName: roles[0].UserName,
  437. PatnRlts: "99",
  438. ConerAddr: miConfig.OrgName,
  439. ConerTel: admin.Mobile,
  440. HiType: order.Insutype,
  441. Insuplc: miConfig.InsuplcAdmdvs,
  442. MaindiagFlag: "1",
  443. BillCode: order.FaPiaoCode,
  444. BillNo: order.FaPiaoNumber,
  445. BizSn: order.Number,
  446. PsnSelfPay: order.PsnPartAmt,
  447. PsnOwnPay: order.PsnPartAmt,
  448. AcctPay: order.AcctPay,
  449. PsnCashpay: order.PsnCashPay,
  450. HiPaymtd: "1",
  451. Hsorg: miConfig.InsuplcAdmdvs,
  452. HsorgOpter: miConfig.InsuplcAdmdvs,
  453. MedinsFillPsn: curRoles.UserName,
  454. MedinsFillDept: depart.Name,
  455. IptMedType: "2",
  456. }
  457. if order.SettleType == 1 {
  458. t := time.Unix(int64(order.SettleAccountsDate), 0)
  459. dateStr := t.Format("2006-01-02")
  460. struct4101.SetlBegnDate = dateStr
  461. struct4101.SetlEndDate = dateStr
  462. } else {
  463. t := time.Unix(int64(order.SettleStartTime), 0)
  464. t2 := time.Unix(int64(order.SettleEndTime), 0)
  465. dateStartStr := t.Format("2006-01-02")
  466. dateEndStr := t2.Format("2006-01-02")
  467. struct4101.SetlBegnDate = dateStartStr
  468. struct4101.SetlEndDate = dateEndStr
  469. }
  470. var rf []CustomFundPay
  471. json.Unmarshal([]byte(order.SetlDetail), &rf)
  472. var tempFunPays []service.CustomStruct
  473. for _, item := range rf {
  474. var tempFunPay service.CustomStruct
  475. tempFunPay.FundPayamt = item.FundPayamt
  476. tempFunPay.FundPayType = item.FundPayType
  477. tempFunPays = append(tempFunPays, tempFunPay)
  478. }
  479. struct4101.CustomStruct = tempFunPays
  480. var tempOpspdiseinfos []service.OpspdiseinfoStruct
  481. var tempOpspdiseinfo2 service.OpspdiseinfoStruct
  482. //sickConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  483. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  484. var config []*models.HisXtDiagnoseConfig
  485. for _, item := range diagnosis_ids {
  486. id, _ := strconv.ParseInt(item, 10, 64)
  487. diagnosisConfig, _ := service.FindDiagnoseById(id)
  488. config = append(config, &diagnosisConfig)
  489. }
  490. for _, item := range config {
  491. var tempOpspdiseinfo service.OpspdiseinfoStruct
  492. tempOpspdiseinfo.DiagCode = item.CountryCode
  493. tempOpspdiseinfo.DiagName = item.CountryContentName
  494. tempOpspdiseinfo.MaindiagFlag = "1"
  495. tempOpspdiseinfo.OprnOprtCode = ""
  496. tempOpspdiseinfo.OprnOprtName = ""
  497. tempOpspdiseinfos = append(tempOpspdiseinfos, tempOpspdiseinfo)
  498. }
  499. sickConfigTwo, _ := service.FindSickById(his.SickType)
  500. tempOpspdiseinfo2.DiagCode = sickConfigTwo.ContentCode
  501. tempOpspdiseinfo2.DiagName = sickConfigTwo.CountryContentName
  502. tempOpspdiseinfo2.MaindiagFlag = "2"
  503. tempOpspdiseinfo2.OprnOprtCode = ""
  504. tempOpspdiseinfo2.OprnOprtName = ""
  505. tempOpspdiseinfos = append(tempOpspdiseinfos, tempOpspdiseinfo2)
  506. struct4101.OpspdiseinfoStruct = tempOpspdiseinfos
  507. var iteminfo service.IteminfoStruct
  508. var bedCostTotal float64 = 0 //床位总费
  509. var bedCostSelfTotal float64 = 0 //床位自费
  510. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  511. var operationCostTotal float64 = 0 //手术费
  512. var operationCostSelfTotal float64 = 0 //手术费
  513. var operationCostPartSelfTotal float64 = 0 //手术费
  514. var otherCostTotal float64 = 0 //其他费用
  515. var otherCostSelfTotal float64 = 0 //其他费用
  516. var otherCostPartSelfTotal float64 = 0 //其他费用
  517. var materialCostTotal float64 = 0 //材料费
  518. var materialCostSelfTotal float64 = 0 //材料费
  519. var materialCostPartSelfTotal float64 = 0 //材料费
  520. var westernMedicineCostTotal float64 = 0 //西药费
  521. var westernMedicineCostSelfTotal float64 = 0 //西药费
  522. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  523. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  524. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  525. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  526. var checkCostTotal float64 = 0 //检查费
  527. var checkCostSelfTotal float64 = 0 //检查费
  528. var checkCostPartSelfTotal float64 = 0 //检查费
  529. var laboratoryCostTotal float64 = 0 //化验费
  530. var laboratoryCostSelfTotal float64 = 0 //化验费
  531. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  532. var treatCostTotal float64 = 0 //治疗费用
  533. var treatCostSelfTotal float64 = 0 //治疗费用
  534. var treatCostPartSelfTotal float64 = 0 //治疗费用
  535. decimal.DivisionPrecision = 2
  536. var bed_fulamt_ownpay_amt float64 = 0
  537. var operation_fulamt_ownpay_amt float64 = 0
  538. var other_fulamt_ownpay_amt float64 = 0
  539. var westernMedicine_fulamt_ownpay_amt float64 = 0
  540. var chineseTraditional_fulamt_ownpay_amt float64 = 0
  541. var check_fulamt_ownpay_amt float64 = 0
  542. var material_fulamt_ownpay_amt float64 = 0
  543. var laboratory_fulamt_ownpay_amt float64 = 0
  544. var treat_fulamt_ownpay_amt float64 = 0
  545. var bed_claa_sunmfee float64 = 0
  546. var bed_clab_amt float64 = 0
  547. var bed_other_amt float64 = 0
  548. var operation_claa_sunmfee float64 = 0
  549. var operation_clab_amt float64 = 0
  550. var operation_other_amt float64 = 0
  551. var other_claa_sunmfee float64 = 0
  552. var other_clab_amt float64 = 0
  553. var other_other_amt float64 = 0
  554. var westernMedicine_claa_sunmfee float64 = 0
  555. var westernMedicine_clab_amt float64 = 0
  556. var westernMedicine_other_amt float64 = 0
  557. var chineseTraditional_claa_sunmfee float64 = 0
  558. var chineseTraditional_clab_amt float64 = 0
  559. var chineseTraditional_other_amt float64 = 0
  560. var check_claa_sunmfee float64 = 0
  561. var check_clab_amt float64 = 0
  562. var check_other_amt float64 = 0
  563. var material_claa_sunmfee float64 = 0
  564. var material_clab_amt float64 = 0
  565. var material_other_amt float64 = 0
  566. var laboratory_claa_sunmfee float64 = 0
  567. var laboratory_clab_amt float64 = 0
  568. var laboratory_other_amt float64 = 0
  569. var treat_claa_sunmfee float64 = 0
  570. var treat_clab_amt float64 = 0
  571. var treat_other_amt float64 = 0
  572. for _, item := range order.HisOrderInfo {
  573. if item.MedChrgitmType == "01" { //床位费
  574. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  575. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  576. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  577. bed_fulamt_ownpay_amt, _ = decimal.NewFromFloat(bed_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  578. if item.ChrgitmLv == "1" {
  579. bed_claa_sunmfee, _ = decimal.NewFromFloat(bed_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  580. }
  581. if item.ChrgitmLv == "2" {
  582. bed_clab_amt, _ = decimal.NewFromFloat(bed_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  583. }
  584. if item.ChrgitmLv == "3" {
  585. bed_other_amt, _ = decimal.NewFromFloat(bed_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  586. }
  587. }
  588. if item.MedChrgitmType == "03" { //检查费
  589. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  590. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  591. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  592. check_fulamt_ownpay_amt, _ = decimal.NewFromFloat(check_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  593. if item.ChrgitmLv == "1" {
  594. check_claa_sunmfee, _ = decimal.NewFromFloat(check_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  595. }
  596. if item.ChrgitmLv == "2" {
  597. check_clab_amt, _ = decimal.NewFromFloat(check_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  598. }
  599. if item.ChrgitmLv == "3" {
  600. check_other_amt, _ = decimal.NewFromFloat(check_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  601. }
  602. }
  603. if item.MedChrgitmType == "04" { //化验费
  604. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  605. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  606. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  607. laboratory_fulamt_ownpay_amt, _ = decimal.NewFromFloat(laboratory_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  608. if item.ChrgitmLv == "1" {
  609. laboratory_claa_sunmfee, _ = decimal.NewFromFloat(laboratory_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  610. }
  611. if item.ChrgitmLv == "2" {
  612. laboratory_clab_amt, _ = decimal.NewFromFloat(laboratory_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  613. }
  614. if item.ChrgitmLv == "3" {
  615. laboratory_other_amt, _ = decimal.NewFromFloat(laboratory_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  616. }
  617. }
  618. if item.MedChrgitmType == "05" { //治疗费
  619. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  620. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  621. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  622. treat_fulamt_ownpay_amt, _ = decimal.NewFromFloat(treat_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  623. if item.ChrgitmLv == "1" {
  624. treat_claa_sunmfee, _ = decimal.NewFromFloat(treat_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  625. }
  626. if item.ChrgitmLv == "2" {
  627. treat_clab_amt, _ = decimal.NewFromFloat(treat_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  628. }
  629. if item.ChrgitmLv == "3" {
  630. treat_other_amt, _ = decimal.NewFromFloat(treat_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  631. }
  632. }
  633. if item.MedChrgitmType == "06" { //手术费
  634. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  635. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  636. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  637. operation_fulamt_ownpay_amt, _ = decimal.NewFromFloat(operation_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  638. if item.ChrgitmLv == "1" {
  639. operation_claa_sunmfee, _ = decimal.NewFromFloat(operation_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  640. }
  641. if item.ChrgitmLv == "2" {
  642. operation_clab_amt, _ = decimal.NewFromFloat(operation_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  643. }
  644. if item.ChrgitmLv == "3" {
  645. operation_other_amt, _ = decimal.NewFromFloat(operation_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  646. }
  647. }
  648. if item.MedChrgitmType == "08" { //材料费
  649. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  650. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  651. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  652. material_fulamt_ownpay_amt, _ = decimal.NewFromFloat(material_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  653. if item.ChrgitmLv == "1" {
  654. material_claa_sunmfee, _ = decimal.NewFromFloat(material_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  655. }
  656. if item.ChrgitmLv == "2" {
  657. material_clab_amt, _ = decimal.NewFromFloat(material_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  658. }
  659. if item.ChrgitmLv == "3" {
  660. material_other_amt, _ = decimal.NewFromFloat(material_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  661. }
  662. }
  663. if item.MedChrgitmType == "09" { //西药费
  664. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  665. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  666. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  667. westernMedicine_fulamt_ownpay_amt, _ = decimal.NewFromFloat(westernMedicine_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  668. if item.ChrgitmLv == "1" {
  669. westernMedicine_claa_sunmfee, _ = decimal.NewFromFloat(westernMedicine_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  670. }
  671. if item.ChrgitmLv == "2" {
  672. westernMedicine_clab_amt, _ = decimal.NewFromFloat(westernMedicine_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  673. }
  674. if item.ChrgitmLv == "3" {
  675. westernMedicine_other_amt, _ = decimal.NewFromFloat(westernMedicine_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  676. }
  677. }
  678. if item.MedChrgitmType == "11" { //中成费
  679. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  680. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  681. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  682. chineseTraditional_fulamt_ownpay_amt, _ = decimal.NewFromFloat(chineseTraditional_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  683. if item.ChrgitmLv == "1" {
  684. chineseTraditional_claa_sunmfee, _ = decimal.NewFromFloat(chineseTraditional_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  685. }
  686. if item.ChrgitmLv == "2" {
  687. chineseTraditional_clab_amt, _ = decimal.NewFromFloat(chineseTraditional_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  688. }
  689. if item.ChrgitmLv == "3" {
  690. chineseTraditional_other_amt, _ = decimal.NewFromFloat(chineseTraditional_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  691. }
  692. }
  693. if item.MedChrgitmType == "14" { //其他费
  694. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  695. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  696. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  697. other_fulamt_ownpay_amt, _ = decimal.NewFromFloat(other_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  698. if item.ChrgitmLv == "1" {
  699. other_claa_sunmfee, _ = decimal.NewFromFloat(other_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  700. }
  701. if item.ChrgitmLv == "2" {
  702. other_clab_amt, _ = decimal.NewFromFloat(other_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  703. }
  704. if item.ChrgitmLv == "3" {
  705. other_other_amt, _ = decimal.NewFromFloat(other_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  706. }
  707. }
  708. }
  709. var iteminfoStructs []service.IteminfoStruct
  710. if bedCostTotal != 0 {
  711. iteminfo.MedChrgitm = "01"
  712. iteminfo.FulamtOwnpayAmt = bed_fulamt_ownpay_amt
  713. iteminfo.Amt = bedCostTotal
  714. iteminfo.ClaaSumfee = bed_claa_sunmfee
  715. iteminfo.ClabAmt = bed_clab_amt
  716. iteminfo.OthAmt = bed_other_amt
  717. iteminfoStructs = append(iteminfoStructs, iteminfo)
  718. }
  719. if checkCostTotal != 0 {
  720. iteminfo.MedChrgitm = "03"
  721. iteminfo.FulamtOwnpayAmt = check_fulamt_ownpay_amt
  722. iteminfo.Amt = checkCostTotal
  723. iteminfo.ClaaSumfee = check_claa_sunmfee
  724. iteminfo.ClabAmt = check_clab_amt
  725. iteminfo.OthAmt = check_other_amt
  726. iteminfoStructs = append(iteminfoStructs, iteminfo)
  727. }
  728. if laboratoryCostTotal != 0 {
  729. iteminfo.MedChrgitm = "04"
  730. iteminfo.FulamtOwnpayAmt = laboratory_fulamt_ownpay_amt
  731. iteminfo.Amt = laboratoryCostTotal
  732. iteminfo.ClaaSumfee = laboratory_claa_sunmfee
  733. iteminfo.ClabAmt = laboratory_clab_amt
  734. iteminfo.OthAmt = laboratory_other_amt
  735. iteminfoStructs = append(iteminfoStructs, iteminfo)
  736. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  737. }
  738. if treatCostTotal != 0 {
  739. iteminfo.MedChrgitm = "05"
  740. iteminfo.FulamtOwnpayAmt = treat_fulamt_ownpay_amt
  741. iteminfo.Amt = treatCostTotal
  742. iteminfo.ClaaSumfee = treat_claa_sunmfee
  743. iteminfo.ClabAmt = treat_clab_amt
  744. iteminfo.OthAmt = treat_other_amt
  745. iteminfoStructs = append(iteminfoStructs, iteminfo)
  746. // (struct4101.IteminfoStruct, iteminfo)
  747. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  748. }
  749. if operationCostTotal != 0 {
  750. iteminfo.MedChrgitm = "06"
  751. iteminfo.FulamtOwnpayAmt = bed_fulamt_ownpay_amt
  752. iteminfo.Amt = operationCostTotal
  753. iteminfo.ClaaSumfee = operation_claa_sunmfee
  754. iteminfo.ClabAmt = operation_clab_amt
  755. iteminfo.OthAmt = operation_other_amt
  756. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  757. iteminfoStructs = append(iteminfoStructs, iteminfo)
  758. }
  759. if materialCostTotal != 0 {
  760. iteminfo.MedChrgitm = "08"
  761. iteminfo.FulamtOwnpayAmt = material_fulamt_ownpay_amt
  762. iteminfo.Amt = materialCostTotal
  763. iteminfo.ClaaSumfee = material_claa_sunmfee
  764. iteminfo.ClabAmt = material_clab_amt
  765. iteminfo.OthAmt = material_other_amt
  766. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  767. iteminfoStructs = append(iteminfoStructs, iteminfo)
  768. }
  769. if westernMedicineCostTotal != 0 {
  770. iteminfo.MedChrgitm = "09"
  771. iteminfo.FulamtOwnpayAmt = westernMedicine_fulamt_ownpay_amt
  772. iteminfo.Amt = westernMedicineCostTotal
  773. iteminfo.ClaaSumfee = westernMedicine_claa_sunmfee
  774. iteminfo.ClabAmt = westernMedicine_clab_amt
  775. iteminfo.OthAmt = westernMedicine_other_amt
  776. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  777. iteminfoStructs = append(iteminfoStructs, iteminfo)
  778. }
  779. if chineseTraditionalMedicineCostTotal != 0 {
  780. iteminfo.MedChrgitm = "11"
  781. iteminfo.FulamtOwnpayAmt = westernMedicine_fulamt_ownpay_amt
  782. iteminfo.Amt = westernMedicineCostTotal
  783. iteminfo.ClaaSumfee = westernMedicine_claa_sunmfee
  784. iteminfo.ClabAmt = westernMedicine_clab_amt
  785. iteminfo.OthAmt = westernMedicine_other_amt
  786. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  787. iteminfoStructs = append(iteminfoStructs, iteminfo)
  788. }
  789. if otherCostTotal != 0 {
  790. iteminfo.MedChrgitm = "14"
  791. iteminfo.FulamtOwnpayAmt = other_fulamt_ownpay_amt
  792. iteminfo.Amt = otherCostTotal
  793. iteminfo.ClaaSumfee = other_claa_sunmfee
  794. iteminfo.ClabAmt = other_clab_amt
  795. iteminfo.OthAmt = other_other_amt
  796. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  797. iteminfoStructs = append(iteminfoStructs, iteminfo)
  798. }
  799. struct4101.IteminfoStruct = iteminfoStructs
  800. struct4101.Ntly = "中国"
  801. struct4101.AdmCaty = "A03.06"
  802. result := service.Gdyb4101(struct4101, miConfig.SecretKey, miConfig.OrgName, curRoles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  803. fmt.Println(result)
  804. var dat map[string]interface{}
  805. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  806. fmt.Println(dat)
  807. } else {
  808. fmt.Println(err)
  809. }
  810. userJSONBytes, _ := json.Marshal(dat)
  811. var res ResultSeventeen
  812. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  813. utils.ErrorLog("解析失败:%v", err)
  814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  815. return
  816. }
  817. if res.Infcode != 0 {
  818. c.ServeSuccessJSON(map[string]interface{}{
  819. "failed_code": -10,
  820. "msg": res.ErrMsg,
  821. })
  822. return
  823. } else {
  824. hisFundSettleListResult := &models.HisFundSettleListResult{
  825. Number: res.Output.SetlListId,
  826. Status: 1,
  827. Ctime: time.Now().Unix(),
  828. Mtime: time.Now().Unix(),
  829. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  830. IsUpload: 1,
  831. OrderId: order_id,
  832. }
  833. service.CreateUploadRecord(hisFundSettleListResult)
  834. c.ServeSuccessJSON(map[string]interface{}{
  835. "msg": "上传成功",
  836. "result": hisFundSettleListResult,
  837. })
  838. return
  839. }
  840. }
  841. //func (c *HisApiController) TestPay() {
  842. // DllDef2 := syscall.MustLoadDLL("SSSE32.dll")
  843. // readCards := DllDef2.MustFindProc("BankTrans")
  844. // inputData := make(map[string]interface{})
  845. // inputData["transId"] = "05"
  846. // inputData["amount"] = "0.01"
  847. // inputData["traceNo"] = "20210227093601325405377"
  848. // inputData["cardNo"] = "F36084348"
  849. // inputData["id"] = "44022919620927046X"
  850. // //jsonStr := `
  851. // // {
  852. // // "transId": "05",
  853. // // "amount":"1.00",
  854. // // "traceNo":"20210227093601325405377",
  855. // // "cardNo":"F36084348",
  856. // // "id":"44022919620927046X"
  857. // //
  858. // // }
  859. // //`
  860. //
  861. // bytes_arr, _ := json.Marshal(inputData)
  862. // str3 := make([]byte, 256)
  863. // ret4, _, err4 := readCards.Call(StrPtr(string(bytes_arr)), (uintptr)(unsafe.Pointer(&str3[0])))
  864. // fmt.Println(":", string(str3))
  865. //
  866. // if err4 != nil {
  867. // fmt.Println("SSCard的运算结果为:", ret4)
  868. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  869. // return
  870. // }
  871. //
  872. //}
  873. //func (c *HisApiController) TestGetBasBaseInfo() {
  874. //
  875. // //result := C.Init(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  876. // //fmt.Println(result)
  877. // //cs1 := C.CString("")
  878. // //cs2 := C.CString("")
  879. // //C.ReadCardBas(cs1, IntPtr(1024), cs2, IntPtr(1024))
  880. // //fmt.Println(cs1)
  881. // //fmt.Println(cs2)
  882. // //C.free(unsafe.Pointer(cs1))
  883. // //C.free(unsafe.Pointer(cs2))
  884. //
  885. // //
  886. //
  887. // DllDef := syscall.MustLoadDLL("SSCard.dll")
  888. // Iinit := DllDef.MustFindProc("Init")
  889. // readCard := DllDef.MustFindProc("ReadCardBas")
  890. // ret, _, err := Iinit.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  891. // if ret != 0 {
  892. // fmt.Println("SSCard的报错原因:", err)
  893. // fmt.Println("SSCard的运算结果为:", ret)
  894. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  895. // return
  896. // }
  897. //
  898. // result := int(ret)
  899. // fmt.Println("SSCard的运算结果为1:", result)
  900. //
  901. // //path := ""
  902. // //bytePath := []byte( "\x00")
  903. // //bytePath2 := []byte( "\x00")
  904. // //ssss
  905. //
  906. // str := make([]byte, 256)
  907. // str1 := make([]byte, 256)
  908. // s2 := []byte(string(str))
  909. // s3 := []byte(string(str1))
  910. // ret2, _, err2 := readCard.Call((uintptr)(unsafe.Pointer(&s2[0])), IntPtr(256), (uintptr)(unsafe.Pointer(&s3[0])), IntPtr(256))
  911. // fmt.Println(" Add(4,5)的结果为:", ret2)
  912. // fmt.Println(" str:", s2)
  913. // fmt.Println(" str1:", s3)
  914. // if err2 != nil {
  915. // fmt.Println("SSCard的运算结果为:", ret2)
  916. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  917. // return
  918. // }
  919. //
  920. // //DllDef := syscall.MustLoadDLL("SSCard.dll")
  921. //
  922. //}
  923. func (c *HisApiController) GetOrgInfo() {
  924. miConfig, _ := service.FindMedicalInsuranceInfo(4)
  925. service.Gdyb1201("", miConfig.OrgName, "1122", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, 1, "")
  926. }
  927. func (c *HisApiController) GetHisPatientInfo() {
  928. medical_insurance_card := c.GetString("medical_insurance_card")
  929. id_card_type, _ := c.GetInt64("id_card_type")
  930. id_card := c.GetString("id_card")
  931. adminInfo := c.GetAdminUserInfo()
  932. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  933. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  934. appRole, _ := service.GetAppRole(adminInfo.CurrentOrgId)
  935. IdCardNo := ""
  936. if id_card_type == 1 {
  937. IdCardNo = medical_insurance_card
  938. } else if id_card_type == 2 {
  939. IdCardNo = id_card
  940. }
  941. if config.IsOpen == 1 {
  942. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  943. resp, requestErr := http.Get(api)
  944. if requestErr != nil {
  945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  946. return
  947. }
  948. defer resp.Body.Close()
  949. body, ioErr := ioutil.ReadAll(resp.Body)
  950. if ioErr != nil {
  951. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  953. return
  954. }
  955. var respJSON map[string]interface{}
  956. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  957. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  959. return
  960. }
  961. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  962. userJSONBytes, _ := json.Marshal(userJSON)
  963. var res ResultTwo
  964. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  965. utils.ErrorLog("解析失败:%v", err)
  966. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  967. return
  968. }
  969. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  970. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  971. infoStr := string(Iinfos)
  972. idetinfoStr := string(Idetinfos)
  973. if res.Infcode == 0 {
  974. his := models.VMHisPatient{
  975. Status: 1,
  976. Ctime: time.Now().Unix(),
  977. Mtime: time.Now().Unix(),
  978. PsnNo: res.Output.Baseinfo.PsnNo,
  979. PsnCertType: res.Output.Baseinfo.PsnCertType,
  980. Certno: res.Output.Baseinfo.Certno,
  981. PsnName: res.Output.Baseinfo.PsnName,
  982. Gend: res.Output.Baseinfo.Gend,
  983. Naty: res.Output.Baseinfo.Naty,
  984. Brdy: res.Output.Baseinfo.Brdy,
  985. Age: res.Output.Baseinfo.Age,
  986. Iinfo: infoStr,
  987. Idetinfo: idetinfoStr,
  988. UserOrgId: adminInfo.CurrentOrgId,
  989. IsReturn: 1,
  990. IdCardType: id_card_type,
  991. }
  992. c.ServeSuccessJSON(map[string]interface{}{
  993. "info": his,
  994. })
  995. } else {
  996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  997. return
  998. }
  999. }
  1000. }
  1001. //func GetBasBaseInfo() (jsonStr string, err error) {
  1002. //
  1003. // handle := syscall.NewLazyDLL("SSCard.dll")
  1004. // add := handle.NewProc("ReadCardBas")
  1005. // str := make([]byte, 1024)
  1006. // str1 := make([]byte, 1024)
  1007. // ret, _, _ := add.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1008. // fmt.Println(ConvertToString(string(str), "gbk", "utf-8"))
  1009. //
  1010. // fmt.Println(ConvertToString(string(str1), "gbk", "utf-8"))
  1011. //
  1012. // fmt.Println("> Add(4,5)的结果为:", ret)
  1013. // handle.Release()
  1014. //
  1015. // return "", nil
  1016. //
  1017. //}
  1018. //func GetQRBaseInfo() (jsonStr string, err error) {
  1019. // handle := syscall.LoadDLL("SSCard.dll")
  1020. // ReadCardBas := handle.FindProc("GetQRBase")
  1021. //
  1022. // str := make([]byte, 256)
  1023. // str1 := make([]byte, 256)
  1024. // r, _, _ := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1025. //
  1026. // fmt.Println(string(str))
  1027. // fmt.Println(r)
  1028. // return string(str), nil
  1029. //}
  1030. //func CardInit() int {
  1031. // DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1032. // add := DllTestDef.MustFindProc("Init")
  1033. // ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1034. // if err != nil {
  1035. // fmt.Println("SSCard的运算结果为:", ret)
  1036. // }
  1037. // result := int(ret)
  1038. // return result
  1039. //}
  1040. //func CardInit() int {
  1041. // ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1042. // if err != nil {
  1043. // fmt.Println("SSCard的运算结果为:", ret)
  1044. // }
  1045. // fmt.Println(err)
  1046. // result := int(ret)
  1047. // return result
  1048. //}
  1049. func IntPtr(n int) uintptr {
  1050. return uintptr(n)
  1051. }
  1052. func StrPtr(s string) uintptr {
  1053. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1054. }
  1055. type ResultTwo struct {
  1056. ErrMsg string `json:"err_msg"`
  1057. InfRefmsgid string `json:"inf_refmsgid"`
  1058. Infcode int64 `json:"infcode"`
  1059. Output struct {
  1060. Baseinfo struct {
  1061. Age float64 `json:"age"`
  1062. Brdy string `json:"brdy"`
  1063. Certno string `json:"certno"`
  1064. Gend string `json:"gend"`
  1065. Naty string `json:"naty"`
  1066. PsnCertType string `json:"psn_cert_type"`
  1067. PsnName string `json:"psn_name"`
  1068. PsnNo string `json:"psn_no"`
  1069. } `json:"baseinfo"`
  1070. Idetinfo []interface{} `json:"idetinfo"`
  1071. Iinfo []struct {
  1072. Balc float64 `json:"balc"`
  1073. CvlservFlag string `json:"cvlserv_flag"`
  1074. EmpName string `json:"emp_name"`
  1075. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  1076. Insutype string `json:"insutype"`
  1077. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  1078. PausInsuDate string `json:"paus_insu_date"`
  1079. PsnInsuDate string `json:"psn_insu_date"`
  1080. PsnInsuStas string `json:"psn_insu_stas"`
  1081. PsnType string `json:"psn_type"`
  1082. } `json:"insuinfo"`
  1083. } `json:"output"`
  1084. RefmsgTime string `json:"refmsg_time"`
  1085. RespondTime string `json:"respond_time"`
  1086. Signtype interface{} `json:"signtype"`
  1087. WarnInfo interface{} `json:"warn_info"`
  1088. }
  1089. type ResultThree struct {
  1090. Cainfo interface{} `json:"cainfo"`
  1091. ErrMsg string `json:"err_msg"`
  1092. InfRefmsgid string `json:"inf_refmsgid"`
  1093. Infcode int64 `json:"infcode"`
  1094. Output struct {
  1095. Data struct {
  1096. IptOtpNo string `json:"ipt_otp_no"`
  1097. MdtrtID string `json:"mdtrt_id"`
  1098. PsnNo string `json:"psn_no"`
  1099. } `json:"data"`
  1100. } `json:"output"`
  1101. RefmsgTime string `json:"refmsg_time"`
  1102. RespondTime string `json:"respond_time"`
  1103. Signtype interface{} `json:"signtype"`
  1104. WarnMsg interface{} `json:"warn_msg"`
  1105. }
  1106. type ResultFour struct {
  1107. Cainfo string `json:"cainfo"`
  1108. ErrMsg string `json:"err_msg"`
  1109. InfRefmsgid string `json:"inf_refmsgid"`
  1110. Infcode int64 `json:"infcode"`
  1111. Output struct {
  1112. Result []struct {
  1113. BasMednFlag string `json:"bas_medn_flag"`
  1114. ChldMedcFlag string `json:"chld_medc_flag"`
  1115. ChrgitmLv string `json:"chrgitm_lv"`
  1116. Cnt float64 `json:"cnt"`
  1117. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  1118. DrtReimFlag string `json:"drt_reim_flag"`
  1119. FeedetlSn string `json:"feedetl_sn"`
  1120. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1121. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  1122. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1123. ListSpItemFlag string `json:"list_sp_item_flag"`
  1124. LmtUsedFlag string `json:"lmt_used_flag"`
  1125. MedChrgitmType string `json:"med_chrgitm_type"`
  1126. Memo string `json:"memo"`
  1127. OverlmtAmt float64 `json:"overlmt_amt"`
  1128. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1129. Pric float64 `json:"pric"`
  1130. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  1131. SelfpayProp float64 `json:"selfpay_prop"`
  1132. } `json:"result"`
  1133. } `json:"output"`
  1134. RefmsgTime string `json:"refmsg_time"`
  1135. RespondTime string `json:"respond_time"`
  1136. Signtype string `json:"signtype"`
  1137. WarnMsg string `json:"warn_msg"`
  1138. }
  1139. type ResultFive struct {
  1140. Balc float64 `json:"balc"`
  1141. CvlservFlag string `json:"cvlserv_flag"`
  1142. EmpName string `json:"emp_name"`
  1143. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  1144. Insutype string `json:"insutype"`
  1145. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  1146. PausInsuDate string `json:"paus_insu_date"`
  1147. PsnInsuDate string `json:"psn_insu_date"`
  1148. PsnInsuStas string `json:"psn_insu_stas"`
  1149. PsnType string `json:"psn_type"`
  1150. }
  1151. type ResultSix struct {
  1152. Cainfo interface{} `json:"cainfo"`
  1153. ErrMsg string `json:"err_msg"`
  1154. InfRefmsgid string `json:"inf_refmsgid"`
  1155. Infcode int64 `json:"infcode"`
  1156. Output struct {
  1157. } `json:"output"`
  1158. RefmsgTime string `json:"refmsg_time"`
  1159. RespondTime string `json:"respond_time"`
  1160. Signtype interface{} `json:"signtype"`
  1161. WarnMsg interface{} `json:"warn_msg"`
  1162. }
  1163. type ResultSeven struct {
  1164. Cainfo string `json:"cainfo"`
  1165. ErrMsg string `json:"err_msg"`
  1166. InfRefmsgid string `json:"inf_refmsgid"`
  1167. Infcode int64 `json:"infcode"`
  1168. Output struct {
  1169. Setldetail []interface{} `json:"setldetail"`
  1170. Setlinfo struct {
  1171. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  1172. AcctPay float64 `json:"acct_pay"`
  1173. ActPayDedc float64 `json:"act_pay_dedc"`
  1174. Age float64 `json:"age"`
  1175. Balc float64 `json:"balc"`
  1176. Brdy string `json:"brdy"`
  1177. Certno string `json:"certno"`
  1178. ClrOptins string `json:"clr_optins"`
  1179. ClrType string `json:"clr_type"`
  1180. ClrWay string `json:"clr_way"`
  1181. CvlservFlag string `json:"cvlserv_flag"`
  1182. CvlservPay float64 `json:"cvlserv_pay"`
  1183. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1184. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1185. Gend string `json:"gend"`
  1186. HifesPay float64 `json:"hifes_pay"`
  1187. HifmiPay float64 `json:"hifmi_pay"`
  1188. HifpPay float64 `json:"hifp_pay"`
  1189. HospPartAmt float64 `json:"hosp_part_amt"`
  1190. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1191. Insutype string `json:"insutype"`
  1192. MafPay float64 `json:"maf_pay"`
  1193. MdtrtCertType string `json:"mdtrt_cert_type"`
  1194. HifobPay float64 `json:"hifob_pay"`
  1195. MdtrtID string `json:"mdtrt_id"`
  1196. MedType string `json:"med_type"`
  1197. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1198. MedinsSetlID string `json:"medins_setl_id"`
  1199. Naty string `json:"naty"`
  1200. OthPay float64 `json:"oth_pay"`
  1201. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1202. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  1203. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1204. PsnCashPay float64 `json:"psn_cash_pay"`
  1205. PsnCertType string `json:"psn_cert_type"`
  1206. PsnName string `json:"psn_name"`
  1207. PsnNo string `json:"psn_no"`
  1208. PsnPartAmt float64 `json:"psn_part_amt"`
  1209. PsnType string `json:"psn_type"`
  1210. SetlID string `json:"setl_id"`
  1211. SetlTime string `json:"setl_time"`
  1212. } `json:"setlinfo"`
  1213. } `json:"output"`
  1214. RefmsgTime string `json:"refmsg_time"`
  1215. RespondTime string `json:"respond_time"`
  1216. Signtype interface{} `json:"signtype"`
  1217. WarnMsg interface{} `json:"warn_msg"`
  1218. }
  1219. type ResultEight struct {
  1220. Cainfo string `json:"cainfo"`
  1221. ErrMsg string `json:"err_msg"`
  1222. InfRefmsgid string `json:"inf_refmsgid"`
  1223. Infcode int64 `json:"infcode"`
  1224. Output struct {
  1225. Stmtinfo struct {
  1226. SetlOptins string `json:"setl_optins"`
  1227. StmtRslt string `json:"stmt_rslt"`
  1228. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  1229. } `json:"stmtinfo"`
  1230. } `json:"output"`
  1231. RefmsgTime string `json:"refmsg_time"`
  1232. RespondTime string `json:"respond_time"`
  1233. Signtype interface{} `json:"signtype"`
  1234. WarnMsg interface{} `json:"warn_msg"`
  1235. }
  1236. type ResultNine struct {
  1237. Cainfo string `json:"cainfo"`
  1238. ErrMsg string `json:"err_msg"`
  1239. InfRefmsgid string `json:"inf_refmsgid"`
  1240. Infcode int64 `json:"infcode"`
  1241. Output struct {
  1242. FileQuryNo string `json:"file_qury_no"`
  1243. } `json:"output"`
  1244. RefmsgTime string `json:"refmsg_time"`
  1245. RespondTime string `json:"respond_time"`
  1246. Signtype interface{} `json:"signtype"`
  1247. WarnMsg interface{} `json:"warn_msg"`
  1248. }
  1249. type ResultTen struct {
  1250. Cainfo string `json:"cainfo"`
  1251. ErrMsg string `json:"err_msg"`
  1252. InfRefmsgid string `json:"inf_refmsgid"`
  1253. Infcode int64 `json:"infcode"`
  1254. Output struct {
  1255. DldEndtime string `json:"dld_endtime"`
  1256. FileQuryNo string `json:"file_qury_no"`
  1257. Filename string `json:"filename"`
  1258. } `json:"output"`
  1259. RefmsgTime string `json:"refmsg_time"`
  1260. RespondTime string `json:"respond_time"`
  1261. Signtype interface{} `json:"signtype"`
  1262. WarnMsg interface{} `json:"warn_msg"`
  1263. }
  1264. //type Autogenerated struct {
  1265. // Output struct {
  1266. // Setlinfo struct {
  1267. // SetlTime string `json:"setl_time"`
  1268. // CvlservPay float64 `json:"cvlserv_pay"`
  1269. // Year string `json:"year"`
  1270. // MedType string `json:"med_type"`
  1271. // PsnPay float64 `json:"psn_pay"`
  1272. // OpterID string `json:"opter_id"`
  1273. // Begndate string `json:"begndate"`
  1274. // FlxempeFlag string `json:"flxempe_flag"`
  1275. // HifmiPay float64 `json:"hifmi_pay"`
  1276. // PsnNo string `json:"psn_no"`
  1277. // ActPayDedc float64 `json:"act_pay_dedc"`
  1278. // MedinsSetlID interface{} `json:"medins_setl_id"`
  1279. // AcctMulaidPay interface{} `json:"acct_mulaid_pay"`
  1280. // ClrWay string `json:"clr_way"`
  1281. // OthPay float64 `json:"oth_pay"`
  1282. // Gend string `json:"gend"`
  1283. // MdtrtID string `json:"mdtrt_id"`
  1284. // AcctPay float64 `json:"acct_pay"`
  1285. // InscpScpAmt float64 `json:"inscp_scp_amt"`
  1286. // Insutype string `json:"insutype"`
  1287. // Invono interface{} `json:"invono"`
  1288. // Enddate string `json:"enddate"`
  1289. // CashPayamt float64 `json:"cash_payamt"`
  1290. // PsnType string `json:"psn_type"`
  1291. // FixmedinsName string `json:"fixmedins_name"`
  1292. // HifpPay float64 `json:"hifp_pay"`
  1293. // NewFlag interface{} `json:"new_flag"`
  1294. // OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1295. // PreselfpayAmt float64 `json:"preselfpay_amt"`
  1296. // PayLoc string `json:"pay_loc"`
  1297. // ClrType string `json:"clr_type"`
  1298. // RefdSetlFlag string `json:"refd_setl_flag"`
  1299. // CvlservFlag string `json:"cvlserv_flag"`
  1300. // EmpName string `json:"emp_name"`
  1301. // Brdy string `json:"brdy"`
  1302. // Naty string `json:"naty"`
  1303. // Certno string `json:"certno"`
  1304. // DiseCode string `json:"dise_code"`
  1305. // FixmedinsCode string `json:"fixmedins_code"`
  1306. // DedcHospLv string `json:"dedc_hosp_lv"`
  1307. // OpterName string `json:"opter_name"`
  1308. // Balc float64 `json:"balc"`
  1309. // FixmedinsPoolarea string `json:"fixmedins_poolarea"`
  1310. // PsnCertType string `json:"psn_cert_type"`
  1311. // HifobPay float64 `json:"hifob_pay"`
  1312. // MedfeeSumamt float64 `json:"medfee_sumamt"`
  1313. // HifesPay float64 `json:"hifes_pay"`
  1314. // FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1315. // OptTime string `json:"opt_time"`
  1316. // FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1317. // SetlID string `json:"setl_id"`
  1318. // MafPay float64 `json:"maf_pay"`
  1319. // PsnName string `json:"psn_name"`
  1320. // InsuOptins interface{} `json:"insu_optins"`
  1321. // PrefFundPay interface{} `json:"pref_fund_pay"`
  1322. // ClrOptins string `json:"clr_optins"`
  1323. // PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  1324. // DiseName string `json:"dise_name"`
  1325. // LmtpricHospLv string `json:"lmtpric_hosp_lv"`
  1326. // Age float64 `json:"age"`
  1327. // DtrtCertType string `json:"dtrt_cert_type"`
  1328. // HospLv string `json:"hosp_lv"`
  1329. // } `json:"setlinfo"`
  1330. // Setldetail []struct {
  1331. // FundPayType string `json:"fund_pay_type"`
  1332. // FundPayamt float64 `json:"fund_payamt"`
  1333. // SetlProcInfo interface{} `json:"setl_proc_info"`
  1334. // CrtPaybLmtAmt interface{} `json:"crt_payb_lmt_amt"`
  1335. // InscpScpAmt interface{} `json:"inscp_scp_amt"`
  1336. // FundPayTypeName interface{} `json:"fund_pay_type_name"`
  1337. // PrefFundPay interface{} `json:"pref_fund_pay"`
  1338. // } `json:"setldetail"`
  1339. // } `json:"output"`
  1340. // Infcode int `json:"infcode"`
  1341. // WarnMsg interface{} `json:"warn_msg"`
  1342. // Cainfo interface{} `json:"cainfo"`
  1343. // ErrMsg interface{} `json:"err_msg"`
  1344. // RefmsgTime string `json:"refmsg_time"`
  1345. // Signtype interface{} `json:"signtype"`
  1346. // RespondTime string `json:"respond_time"`
  1347. // InfRefmsgid string `json:"inf_refmsgid"`
  1348. //}
  1349. type ResultEleven struct {
  1350. Cainfo string `json:"cainfo"`
  1351. ErrMsg string `json:"err_msg"`
  1352. InfRefmsgid string `json:"inf_refmsgid"`
  1353. Infcode int64 `json:"infcode"`
  1354. Output struct {
  1355. Setlinfo struct {
  1356. SetlTime string `json:"setl_time"`
  1357. CvlservPay float64 `json:"cvlserv_pay"`
  1358. Year string `json:"year"`
  1359. MedType string `json:"med_type"`
  1360. PsnPay float64 `json:"psn_pay"`
  1361. OpterID string `json:"opter_id"`
  1362. Begndate string `json:"begndate"`
  1363. FlxempeFlag string `json:"flxempe_flag"`
  1364. HifmiPay float64 `json:"hifmi_pay"`
  1365. PsnNo string `json:"psn_no"`
  1366. ActPayDedc float64 `json:"act_pay_dedc"`
  1367. MedinsSetlID interface{} `json:"medins_setl_id"`
  1368. AcctMulaidPay interface{} `json:"acct_mulaid_pay"`
  1369. ClrWay string `json:"clr_way"`
  1370. OthPay float64 `json:"oth_pay"`
  1371. Gend string `json:"gend"`
  1372. MdtrtID string `json:"mdtrt_id"`
  1373. AcctPay float64 `json:"acct_pay"`
  1374. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1375. Insutype string `json:"insutype"`
  1376. Invono interface{} `json:"invono"`
  1377. Enddate string `json:"enddate"`
  1378. CashPayamt float64 `json:"cash_payamt"`
  1379. PsnType string `json:"psn_type"`
  1380. FixmedinsName string `json:"fixmedins_name"`
  1381. HifpPay float64 `json:"hifp_pay"`
  1382. NewFlag interface{} `json:"new_flag"`
  1383. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1384. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1385. PayLoc string `json:"pay_loc"`
  1386. ClrType string `json:"clr_type"`
  1387. RefdSetlFlag string `json:"refd_setl_flag"`
  1388. CvlservFlag string `json:"cvlserv_flag"`
  1389. EmpName string `json:"emp_name"`
  1390. Brdy string `json:"brdy"`
  1391. Naty string `json:"naty"`
  1392. Certno string `json:"certno"`
  1393. DiseCode string `json:"dise_code"`
  1394. FixmedinsCode string `json:"fixmedins_code"`
  1395. DedcHospLv string `json:"dedc_hosp_lv"`
  1396. OpterName string `json:"opter_name"`
  1397. Balc float64 `json:"balc"`
  1398. FixmedinsPoolarea string `json:"fixmedins_poolarea"`
  1399. PsnCertType string `json:"psn_cert_type"`
  1400. HifobPay float64 `json:"hifob_pay"`
  1401. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1402. HifesPay float64 `json:"hifes_pay"`
  1403. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1404. OptTime string `json:"opt_time"`
  1405. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1406. SetlID string `json:"setl_id"`
  1407. MafPay float64 `json:"maf_pay"`
  1408. PsnName string `json:"psn_name"`
  1409. InsuOptins interface{} `json:"insu_optins"`
  1410. PrefFundPay interface{} `json:"pref_fund_pay"`
  1411. ClrOptins string `json:"clr_optins"`
  1412. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  1413. DiseName string `json:"dise_name"`
  1414. LmtpricHospLv string `json:"lmtpric_hosp_lv"`
  1415. Age float64 `json:"age"`
  1416. DtrtCertType string `json:"dtrt_cert_type"`
  1417. HospLv string `json:"hosp_lv"`
  1418. } `json:"setlinfo"`
  1419. } `json:"output"`
  1420. RefmsgTime string `json:"refmsg_time"`
  1421. RespondTime string `json:"respond_time"`
  1422. Signtype interface{} `json:"signtype"`
  1423. WarnMsg interface{} `json:"warn_msg"`
  1424. }
  1425. type ResultTwelve struct {
  1426. Cainfo string `json:"cainfo"`
  1427. ErrMsg string `json:"err_msg"`
  1428. InfRefmsgid string `json:"inf_refmsgid"`
  1429. Infcode int64 `json:"infcode"`
  1430. Output struct {
  1431. MdtrtId string `json:"mdtrt_id"`
  1432. ChrgBchno string `json:"chrg_bchno"`
  1433. PsnNo string `json:"psn_no"`
  1434. } `json:"output"`
  1435. RefmsgTime string `json:"refmsg_time"`
  1436. RespondTime string `json:"respond_time"`
  1437. Signtype interface{} `json:"signtype"`
  1438. WarnMsg interface{} `json:"warn_msg"`
  1439. }
  1440. type ResultThirteen struct {
  1441. ErrMsg string `json:"err_msg"`
  1442. InfRefmsgid string `json:"inf_refmsgid"`
  1443. Infcode int64 `json:"infcode"`
  1444. Output struct {
  1445. Result struct {
  1446. TrtDclaDetlSn string `json:"trt_dcla_detl_sn"`
  1447. } `json:"result"`
  1448. } `json:"output"`
  1449. RefmsgTime string `json:"refmsg_time"`
  1450. RespondTime string `json:"respond_time"`
  1451. Signtype interface{} `json:"signtype"`
  1452. WarnInfo interface{} `json:"warn_info"`
  1453. }
  1454. type ResultFourteen struct {
  1455. ErrMsg string `json:"err_msg"`
  1456. InfRefmsgid string `json:"inf_refmsgid"`
  1457. Infcode int64 `json:"infcode"`
  1458. Output struct {
  1459. } `json:"output"`
  1460. RefmsgTime string `json:"refmsg_time"`
  1461. RespondTime string `json:"respond_time"`
  1462. Signtype interface{} `json:"signtype"`
  1463. WarnInfo interface{} `json:"warn_info"`
  1464. }
  1465. type ResultSixteen struct {
  1466. Cainfo string `json:"cainfo"`
  1467. ErrMsg string `json:"err_msg"`
  1468. InfRefmsgid string `json:"inf_refmsgid"`
  1469. Infcode int64 `json:"infcode"`
  1470. Output struct {
  1471. Setldetail []interface{} `json:"setldetail"`
  1472. Setlinfo struct {
  1473. MdtrtID string `json:"mdtrt_id"`
  1474. SetlID string `json:"setl_id"`
  1475. ClrOptins string `json:"clr_optins"`
  1476. SetlTime string `json:"setl_time"`
  1477. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1478. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1479. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1480. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1481. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1482. ActPayDedc float64 `json:"act_pay_dedc"`
  1483. HifpPay float64 `json:"hifp_pay"`
  1484. PoolPropSe float64 `json:"pool_prop_selfpay"`
  1485. Lfpay float64 `json:"selfpay"`
  1486. CvlservPay float64 `json:"cvlserv_pay"`
  1487. HifesPay float64 `json:"hifes_pay"`
  1488. HifmiPay float64 `json:"hifmi_pay"`
  1489. HifobPay float64 `json:"hifob_pay"`
  1490. MafPay float64 `json:"maf_pay"`
  1491. OthPay float64 `json:"oth_pay"`
  1492. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1493. PsnPartAmt float64 `json:"psn_part_amt"`
  1494. AcctPay float64 `json:"acct_pay"`
  1495. Balc float64 `json:"balc"`
  1496. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  1497. HospPartAmt float64 `json:"hosp_part_amt"`
  1498. MedinsSetlID string `json:"medins_setl_id"`
  1499. PdnCashPay string `json:"pdn_cash_pay"`
  1500. } `json:"setlinfo"`
  1501. } `json:"output"`
  1502. RefmsgTime string `json:"refmsg_time"`
  1503. RespondTime string `json:"respond_time"`
  1504. Signtype interface{} `json:"signtype"`
  1505. WarnMsg interface{} `json:"warn_msg"`
  1506. }
  1507. type ResultSeventeen struct {
  1508. ErrMsg string `json:"err_msg"`
  1509. InfRefmsgid string `json:"inf_refmsgid"`
  1510. Infcode int64 `json:"infcode"`
  1511. Output struct {
  1512. SetlListId string `json:"setl_list_id"`
  1513. } `json:"output"`
  1514. RefmsgTime string `json:"refmsg_time"`
  1515. RespondTime string `json:"respond_time"`
  1516. Signtype string `json:"signtype"`
  1517. WarnInfo string `json:"warn_info"`
  1518. }
  1519. type Result90991 struct {
  1520. ErrMsg string `json:"err_msg"`
  1521. InfRefmsgid string `json:"inf_refmsgid"`
  1522. Infcode int64 `json:"infcode"`
  1523. Output struct {
  1524. Result struct {
  1525. PsnNo string `json:"psn_no"`
  1526. CardStat string `json:"card_stat"`
  1527. Certno string `json:"certno"`
  1528. PsnName string `json:"psn_name"`
  1529. CheckStat string `json:"check_stat"`
  1530. } `json:"result"`
  1531. } `json:"output"`
  1532. RefmsgTime string `json:"refmsg_time"`
  1533. RespondTime string `json:"respond_time"`
  1534. Signtype interface{} `json:"signtype"`
  1535. WarnInfo interface{} `json:"warn_info"`
  1536. }
  1537. type Result90100 struct {
  1538. ErrMsg string `json:"err_msg"`
  1539. InfRefmsgid string `json:"inf_refmsgid"`
  1540. Infcode int64 `json:"infcode"`
  1541. Output struct {
  1542. PoolareaNo string `json:"poolarea_no"`
  1543. PoolareaNoName string `json:"poolarea_no_name"`
  1544. Insutype string `json:"insutype"`
  1545. InsutypeName string `json:"insutype_name"`
  1546. ClctType string `json:"clct_type"`
  1547. ClctTypeName string `json:"clct_type_name"`
  1548. ClctFlag string `json:"clct_flag"`
  1549. ClctFlagName string `json:"clct_flag_name"`
  1550. AccrymBegn string `json:"accrym_begn"`
  1551. AccrymEnd string `json:"accrym_end"`
  1552. ClctTime string `json:"clct_time"`
  1553. ClctstdCrtfRuleCodg string `json:"clctstd_crtf_rule_codg"`
  1554. } `json:"output"`
  1555. RefmsgTime string `json:"refmsg_time"`
  1556. RespondTime string `json:"respond_time"`
  1557. Signtype interface{} `json:"signtype"`
  1558. WarnInfo interface{} `json:"warn_info"`
  1559. }
  1560. type Custom struct {
  1561. DetItemFeeSumamt string
  1562. Cut string
  1563. FeedetlSn string
  1564. Price string
  1565. MedListCodg string
  1566. Type int64
  1567. AdviceId int64
  1568. ProjectId int64
  1569. ItemId int64
  1570. }
  1571. //获取个人信息----挂号-----上传就诊信息
  1572. func (c *HisApiController) GetRegisterInfo() {
  1573. fmt.Println("~~~~~~~~")
  1574. id, _ := c.GetInt64("id")
  1575. record_time := c.GetString("record_time")
  1576. settlementValue, _ := c.GetInt64("settlement_value")
  1577. medical_insurance_card := c.GetString("medical_insurance_card")
  1578. name := c.GetString("name")
  1579. id_card_type, _ := c.GetInt64("id_card_type")
  1580. certificates, _ := c.GetInt64("certificates")
  1581. medical_care, _ := c.GetInt64("medical_care")
  1582. birthday := c.GetString("birthday")
  1583. //age, _ := c.GetInt64("age")
  1584. id_card := c.GetString("id_card")
  1585. register_type, _ := c.GetInt64("register")
  1586. doctor, _ := c.GetInt64("doctor")
  1587. department, _ := c.GetInt64("department")
  1588. gender, _ := c.GetInt64("sex")
  1589. //phone := c.GetString("phone")
  1590. registration_fee, _ := c.GetFloat("registration_fee")
  1591. medical_expenses, _ := c.GetFloat("medical_expenses")
  1592. social_type, _ := c.GetInt64("social_type")
  1593. admin_user_id, _ := c.GetInt64("admin_user_id")
  1594. timeLayout := "2006-01-02"
  1595. loc, _ := time.LoadLocation("Local")
  1596. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  1597. birthUnix := birthdays.Unix()
  1598. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1599. if err != nil {
  1600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1601. return
  1602. }
  1603. recordDateTime := theTime.Unix()
  1604. adminInfo := c.GetAdminUserInfo()
  1605. var patient service.Patients
  1606. if id == 0 {
  1607. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  1608. } else {
  1609. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  1610. }
  1611. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  1612. if patientPrescription.ID == 0 {
  1613. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  1614. }
  1615. //adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1616. //diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  1617. //sickConfig, _ := service.FindSickById(sick_type)
  1618. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1619. if patient.ID == 0 {
  1620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1621. return
  1622. }
  1623. if len(patient.IdCardNo) == 0 {
  1624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  1625. return
  1626. }
  1627. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  1628. roles, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1629. doctor_info, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor)
  1630. //就诊结算未完成,不能进行二次挂号
  1631. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  1632. if len(his) >= 1 {
  1633. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  1634. if len(his) >= 1 && order.ID == 0 {
  1635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  1636. return
  1637. }
  1638. }
  1639. //var register_log string
  1640. if config.IsOpen == 1 {
  1641. var res ResultTwo
  1642. var PsnNo string
  1643. var PsnCertType string
  1644. var Certno string
  1645. var PsnName string
  1646. var Gend string
  1647. var Naty string
  1648. var Brdy string
  1649. var Age float64
  1650. var infoStr string
  1651. var idetinfoStr string
  1652. if miConfig.MdtrtareaAdmvs == "421300" {
  1653. psn_info, _ := service.GetPsnByPatientId(id)
  1654. PsnNo = psn_info.PsnNo
  1655. PsnCertType = psn_info.PsnCertType
  1656. Certno = psn_info.Certno
  1657. PsnName = psn_info.PsnName
  1658. Gend = psn_info.Gend
  1659. Naty = psn_info.Naty
  1660. Brdy = psn_info.Brdy
  1661. Age = psn_info.Age
  1662. infoStr = psn_info.Insuinfo
  1663. idetinfoStr = psn_info.Idetinfo
  1664. } else {
  1665. result, requestLog := service.Gdyb1101(patient.IdCardNo, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, "", strconv.FormatInt(certificates, 10))
  1666. saveLog(result, requestLog, "1101", "人员基本信息获取")
  1667. if err := json.Unmarshal([]byte(result), &res); err != nil {
  1668. utils.ErrorLog("解析失败:%v", err)
  1669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1670. return
  1671. }
  1672. PsnNo = res.Output.Baseinfo.PsnNo
  1673. PsnCertType = res.Output.Baseinfo.PsnCertType
  1674. Certno = res.Output.Baseinfo.Certno
  1675. PsnName = res.Output.Baseinfo.PsnName
  1676. Gend = res.Output.Baseinfo.Gend
  1677. Naty = res.Output.Baseinfo.Naty
  1678. Brdy = res.Output.Baseinfo.Brdy
  1679. Age = res.Output.Baseinfo.Age
  1680. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  1681. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  1682. infoStr = string(Iinfos)
  1683. idetinfoStr = string(Idetinfos)
  1684. }
  1685. if res.Infcode == 0 {
  1686. his := models.VMHisPatient{
  1687. Name: name,
  1688. Gender: gender,
  1689. Birthday: birthUnix,
  1690. MedicalTreatmentType: medical_care,
  1691. IdType: certificates,
  1692. IdCardNo: id_card,
  1693. BalanceAccountsType: settlementValue,
  1694. SocialType: social_type,
  1695. MedicalInsuranceNumber: medical_insurance_card,
  1696. RegisterType: register_type,
  1697. RegisterCost: registration_fee,
  1698. TreatmentCost: medical_expenses,
  1699. Status: 1,
  1700. Ctime: time.Now().Unix(),
  1701. Mtime: time.Now().Unix(),
  1702. PsnNo: PsnNo,
  1703. PsnCertType: PsnCertType,
  1704. Certno: Certno,
  1705. PsnName: PsnName,
  1706. Gend: Gend,
  1707. Naty: Naty,
  1708. Brdy: Brdy,
  1709. Age: Age,
  1710. Iinfo: infoStr,
  1711. Idetinfo: idetinfoStr,
  1712. PatientId: patient.ID,
  1713. RecordDate: theTime.Unix(),
  1714. UserOrgId: adminInfo.CurrentOrgId,
  1715. AdminUserId: admin_user_id,
  1716. IsReturn: 1,
  1717. IdCardType: id_card_type,
  1718. Doctor: doctor,
  1719. Departments: department,
  1720. }
  1721. timestamp := time.Now().Unix()
  1722. tempTime := time.Unix(timestamp, 0)
  1723. timeFormat := tempTime.Format("20060102150405")
  1724. chrgBchno := rand.Intn(100000) + 10000
  1725. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1726. //count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  1727. department, _ := service.GetDepartMentDetail(department)
  1728. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  1729. IdCardNo := ""
  1730. if id_card_type == 1 {
  1731. // IdCardNo = medical_insurance_card
  1732. IdCardNo = patient.IdCardNo
  1733. } else {
  1734. IdCardNo = patient.IdCardNo
  1735. }
  1736. var insutypes []string
  1737. var insutype string
  1738. var is390 int = 0
  1739. var is310 int = 0
  1740. for _, item := range res.Output.Iinfo {
  1741. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1742. insutypes = append(insutypes, item.Insutype)
  1743. }
  1744. }
  1745. if len(insutypes) == 1 {
  1746. insutype = insutypes[0]
  1747. } else {
  1748. for _, i := range insutypes {
  1749. if i == "390" {
  1750. is390 = 1
  1751. }
  1752. if i == "310" {
  1753. is310 = 1
  1754. }
  1755. }
  1756. }
  1757. if is390 == 1 {
  1758. insutype = "390"
  1759. }
  1760. if is310 == 1 {
  1761. insutype = "310"
  1762. }
  1763. if len(insutypes) == 0 {
  1764. insutype = "310"
  1765. }
  1766. //insutype = "390"
  1767. var resThree ResultThree
  1768. if miConfig.MdtrtareaAdmvs == "421300" {
  1769. api := "http://192.168.124.4:9532/" + "hbyb/2201?psn_no=" + res.Output.Baseinfo.PsnNo + "&insutype=" + insutype + "&cert_no=" + res.Output.Baseinfo.Certno + "&ipt_otp_no=" + ipt_otp_no +
  1770. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  1771. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(id_card_type, 10) + "&dept_code=" + department.Number + "&dept=" + department.Name + "&doctor_id=" + doctor_id
  1772. resp, requestErr := http.Get(api)
  1773. if requestErr != nil {
  1774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1775. return
  1776. }
  1777. body, ioErr := ioutil.ReadAll(resp.Body)
  1778. if ioErr != nil {
  1779. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1781. return
  1782. }
  1783. var respJSON map[string]interface{}
  1784. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1785. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1787. return
  1788. }
  1789. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1790. result, _ := json.Marshal(respJSON)
  1791. fmt.Println("log")
  1792. fmt.Println(string(result))
  1793. if err := json.Unmarshal([]byte(result), &resThree); err != nil {
  1794. utils.ErrorLog("解析失败:%v", err)
  1795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1796. return
  1797. }
  1798. } else {
  1799. fmt.Println(roles.UserName)
  1800. result, requestLog := service.Gdyb2201(res.Output.Baseinfo.PsnNo, insutype, IdCardNo, miConfig.OrgName, roles.UserName, ipt_otp_no, department.Name, miConfig.Code, department.Number, doctor_id, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, doctor_info.UserName)
  1801. saveLog(result, requestLog, "2201", "挂号")
  1802. if err := json.Unmarshal([]byte(result), &resThree); err != nil {
  1803. utils.ErrorLog("解析失败:%v", err)
  1804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1805. return
  1806. }
  1807. }
  1808. if resThree.Infcode != 0 {
  1809. adminUser := c.GetAdminUserInfo()
  1810. errlog := &models.HisOrderError{
  1811. UserOrgId: adminUser.CurrentOrgId,
  1812. Ctime: time.Now().Unix(),
  1813. Mtime: time.Now().Unix(),
  1814. ErrMsg: resThree.ErrMsg,
  1815. Status: 1,
  1816. PatientId: id,
  1817. RecordTime: recordDateTime,
  1818. Stage: 2,
  1819. }
  1820. service.CreateErrMsgLog(errlog)
  1821. c.ServeSuccessJSON(map[string]interface{}{
  1822. "failed_code": -10,
  1823. "msg": resThree.ErrMsg,
  1824. })
  1825. return
  1826. }
  1827. his.Number = resThree.Output.Data.MdtrtID
  1828. his.PsnNo = resThree.Output.Data.PsnNo
  1829. his.IptOtpNo = resThree.Output.Data.IptOtpNo
  1830. his.IdCardNo = patient.IdCardNo
  1831. his.PhoneNumber = patient.Phone
  1832. his.UserOrgId = adminInfo.CurrentOrgId
  1833. his.Ctime = time.Now().Unix()
  1834. his.Mtime = time.Now().Unix()
  1835. his.Status = 1
  1836. service.UpdateHisPatientStatus(&his)
  1837. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  1838. c.ServeSuccessJSON(map[string]interface{}{
  1839. "his_info": his,
  1840. })
  1841. } else {
  1842. adminUser := c.GetAdminUserInfo()
  1843. errlog := &models.HisOrderError{
  1844. UserOrgId: adminUser.CurrentOrgId,
  1845. Ctime: time.Now().Unix(),
  1846. Mtime: time.Now().Unix(),
  1847. ErrMsg: res.ErrMsg,
  1848. Status: 1,
  1849. PatientId: id,
  1850. RecordTime: recordDateTime,
  1851. Stage: 1,
  1852. }
  1853. service.CreateErrMsgLog(errlog)
  1854. c.ServeSuccessJSON(map[string]interface{}{
  1855. "failed_code": -10,
  1856. "msg": res.ErrMsg,
  1857. })
  1858. return
  1859. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  1860. }
  1861. }
  1862. }
  1863. //上传明细----预结算----确认订单
  1864. func (c *HisApiController) GetUploadInfo() {
  1865. id, _ := c.GetInt64("id")
  1866. record_time := c.GetString("record_time")
  1867. his_patient_id, _ := c.GetInt64("his_patient_id")
  1868. order_id, _ := c.GetInt64("order_id")
  1869. pay_way, _ := c.GetInt64("pay_way")
  1870. pay_price, _ := c.GetFloat("pay_price")
  1871. pay_card_no := c.GetString("pay_card_no")
  1872. discount_price, _ := c.GetFloat("discount_price")
  1873. preferential_price, _ := c.GetFloat("preferential_price")
  1874. reality_price, _ := c.GetFloat("reality_price")
  1875. found_price, _ := c.GetFloat("found_price")
  1876. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1877. private_price, _ := c.GetFloat("private_price")
  1878. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1879. admin_user_id, _ := c.GetInt64("admin_user_id")
  1880. fapiao_code := c.GetString("fapiao_code")
  1881. fapiao_number := c.GetString("fapiao_number")
  1882. diagnosis_id := c.GetString("diagnosis")
  1883. sick_type, _ := c.GetInt64("sick_type")
  1884. reg_type, _ := c.GetInt64("p_type")
  1885. id_str := c.GetString("ids")
  1886. ids_arr := strings.Split(id_str, ",")
  1887. timeLayout := "2006-01-02"
  1888. loc, _ := time.LoadLocation("Local")
  1889. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1890. if err != nil {
  1891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1892. return
  1893. }
  1894. recordDateTime := theTime.Unix()
  1895. adminUser := c.GetAdminUserInfo()
  1896. var tempOrder models.HisOrder
  1897. tempOrder, _ = service.GetHisOrderByID(order_id)
  1898. var prescriptions []*models.HisPrescription
  1899. var start_time int64
  1900. var end_time int64
  1901. //if adminUser.CurrentOrgId == 10106{
  1902. // if len(fapiao_code) == 0{
  1903. // fapiao_code = "144072080589"
  1904. // }
  1905. // if len(fapiao_number) == 0{
  1906. // order, _ := service.GetLastHisOrder(adminUser.CurrentOrgId)
  1907. // if order.ID == 0{
  1908. // fapiao_number = "00001520"
  1909. // }else{
  1910. // //fapiao_code = "00001520"
  1911. // fpNumber, _ := strconv.Atoi(order.FaPiaoNumber)
  1912. // var zero string
  1913. // if fpNumber >= 1000{
  1914. // zero = "0000" + strconv.Itoa(fpNumber)
  1915. // }else if fpNumber >= 10000{
  1916. // zero = "000" + strconv.Itoa(fpNumber)
  1917. // } else if fpNumber >= 100000{
  1918. // zero = "00" + strconv.Itoa(fpNumber)
  1919. // } else if fpNumber >= 1000000{
  1920. // zero = "0" + strconv.Itoa(fpNumber)
  1921. // }else {
  1922. // zero = strconv.Itoa(fpNumber)
  1923. // }
  1924. // fapiao_number = zero
  1925. // }
  1926. // }
  1927. //}
  1928. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1929. his, _ := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  1930. var patientPrescription models.HisPrescriptionInfo
  1931. patientPrescription, _ = service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  1932. if patientPrescription.ID == 0 {
  1933. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1934. }
  1935. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1936. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1937. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  1938. diagnosis_ids := strings.Split(diagnosis_id, ",")
  1939. var config []*models.HisXtDiagnoseConfig
  1940. for _, item := range diagnosis_ids {
  1941. id, _ := strconv.ParseInt(item, 10, 64)
  1942. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1943. config = append(config, &diagnosisConfig)
  1944. }
  1945. sickConfig, _ := service.FindSickById(sick_type)
  1946. if tempOrder.ID == 0 {
  1947. tempOrder, _ = service.GetTodayHisOrder(adminUser.CurrentOrgId, id, recordDateTime, his.Number)
  1948. }
  1949. if tempOrder.ID == 0 {
  1950. var result string
  1951. var requestLog string
  1952. var res2 ResultSix
  1953. if miConfig.InsuplcAdmdvs == "421300" {
  1954. data := make(map[string]interface{})
  1955. client := &http.Client{}
  1956. data["psn_no"] = his.PsnNo
  1957. data["mdtrt_id"] = his.Number
  1958. data["doctor"] = roles.UserName
  1959. data["department"] = department.Name
  1960. data["org_name"] = miConfig.OrgName
  1961. data["med_type"] = strconv.FormatInt(reg_type, 10)
  1962. data["doctor_id"] = strconv.FormatInt(doctor_info.AdminUserId, 10)
  1963. data["fixmedins_code"] = miConfig.Code
  1964. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1965. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1966. data["secret_key"] = miConfig.SecretKey
  1967. data["sick_code"] = sickConfig.CountryCode
  1968. data["sick_name"] = sickConfig.ClassName
  1969. data["dept"] = strconv.FormatInt(department.ID, 10)
  1970. data["config"] = config
  1971. bytesData, _ := json.Marshal(data)
  1972. req, _ := http.NewRequest("POST", "http://192.168.124.4:9532/"+"hbyb/2203", bytes.NewReader(bytesData))
  1973. resp, _ := client.Do(req)
  1974. defer resp.Body.Close()
  1975. body, ioErr := ioutil.ReadAll(resp.Body)
  1976. if ioErr != nil {
  1977. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1979. return
  1980. }
  1981. var respJSON map[string]interface{}
  1982. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1983. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1985. return
  1986. }
  1987. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1988. userJSONBytes, _ := json.Marshal(respJSON)
  1989. fmt.Println("log")
  1990. fmt.Println(string(userJSONBytes))
  1991. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  1992. utils.ErrorLog("解析失败:%v", err)
  1993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1994. return
  1995. }
  1996. } else {
  1997. if miConfig.InsuplcAdmdvs == "440781" { //
  1998. result, requestLog = service.Gdyb2203A(his.PsnNo, his.Number, doctor_info.UserName, department.Name, miConfig.OrgName, strconv.FormatInt(reg_type, 10), doctor_info.AdminUserId, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sickConfig.ContentCode, sickConfig.ClassName, roles.UserName, config)
  1999. } else {
  2000. result, requestLog = service.Gdyb2203(his.PsnNo, his.Number, doctor_info.UserName, department.Name, miConfig.OrgName, strconv.FormatInt(reg_type, 10), doctor_info.AdminUserId, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sickConfig.ContentCode, sickConfig.ClassName, roles.UserName, config)
  2001. }
  2002. saveLog(result, requestLog, "2203", "上传就诊信息")
  2003. var respJSON2 map[string]interface{}
  2004. if err := json.Unmarshal([]byte(string(result)), &respJSON2); err != nil {
  2005. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2007. return
  2008. }
  2009. userJSONBytes2, _ := json.Marshal(respJSON2)
  2010. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  2011. utils.ErrorLog("解析失败:%v", err)
  2012. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2013. return
  2014. }
  2015. }
  2016. if res2.Infcode != 0 {
  2017. adminUser := c.GetAdminUserInfo()
  2018. errlog := &models.HisOrderError{
  2019. UserOrgId: adminUser.CurrentOrgId,
  2020. Ctime: time.Now().Unix(),
  2021. Mtime: time.Now().Unix(),
  2022. ErrMsg: res2.ErrMsg,
  2023. Status: 1,
  2024. PatientId: id,
  2025. RecordTime: recordDateTime,
  2026. Stage: 3,
  2027. }
  2028. service.CreateErrMsgLog(errlog)
  2029. c.ServeSuccessJSON(map[string]interface{}{
  2030. "failed_code": -10,
  2031. "msg": res2.ErrMsg,
  2032. })
  2033. return
  2034. } else {
  2035. his.Diagnosis = diagnosis_id
  2036. his.SickType = sickConfig.ID
  2037. his.PType = fmt.Sprintf("%d", reg_type)
  2038. service.UpdateHisPatientThree(&his)
  2039. data := make(map[string]interface{})
  2040. if settle_accounts_type == 1 { //日结
  2041. if reg_type == 11 {
  2042. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  2043. } else {
  2044. prescriptions, _ = service.GetNewHisPrescription(adminUser.CurrentOrgId, his_patient_id, recordDateTime, strconv.Itoa(int(reg_type)))
  2045. }
  2046. //prescriptions, _ = service.GetNewHisPrescriptionTwo(adminUser.CurrentOrgId, his_patient_id, recordDateTime, reg_type)
  2047. data["pre"] = prescriptions
  2048. } else { //月结
  2049. start_time_str := c.GetString("start_time")
  2050. end_time_str := c.GetString("end_time")
  2051. timeLayout := "2006-01-02"
  2052. loc, _ := time.LoadLocation("Local")
  2053. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2054. if err != nil {
  2055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2056. return
  2057. }
  2058. recordStartTime := theStartTime.Unix()
  2059. start_time = recordStartTime
  2060. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2061. if err != nil {
  2062. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2063. return
  2064. }
  2065. recordEndTime := theEndTime.Unix()
  2066. end_time = recordEndTime
  2067. prescriptions, _ = service.GetMonthHisPrescriptionTwo(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  2068. data["pre"] = prescriptions
  2069. }
  2070. if reg_type == 1111 || reg_type == 1112 {
  2071. reg_type = 11
  2072. }
  2073. timestamp := time.Now().Unix()
  2074. tempTime := time.Unix(timestamp, 0)
  2075. timeFormat := tempTime.Format("20060102150405")
  2076. chrgBchno := rand.Intn(100000) + 10000
  2077. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  2078. strconv.FormatInt(his.PatientId, 10)
  2079. client := &http.Client{}
  2080. data["psn_no"] = his.PsnNo
  2081. data["mdtrt_id"] = his.Number
  2082. data["chrg_bchno"] = chrg_bchno
  2083. data["org_name"] = miConfig.OrgName
  2084. data["doctor"] = roles.UserName
  2085. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  2086. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  2087. data["fixmedins_code"] = miConfig.Code
  2088. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  2089. data["dept_code"] = "15"
  2090. } else {
  2091. data["dept_code"] = department.Number
  2092. }
  2093. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  2094. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  2095. data["secret_key"] = miConfig.SecretKey
  2096. data["balance_accounts_type"] = strconv.FormatInt(his.BalanceAccountsType, 10)
  2097. var ids []int64
  2098. for _, item := range prescriptions {
  2099. ids = append(ids, item.ID)
  2100. }
  2101. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2102. if config.IsOpen == 1 { //对接了医保,走医保流程
  2103. var res ResultFour
  2104. if miConfig.MdtrtareaAdmvs == "421300" {
  2105. bytesData, _ := json.Marshal(data)
  2106. req, _ := http.NewRequest("POST", "http://192.168.124.4:9532/"+"hbyb/2204", bytes.NewReader(bytesData))
  2107. resp, _ := client.Do(req)
  2108. defer resp.Body.Close()
  2109. body, ioErr := ioutil.ReadAll(resp.Body)
  2110. if ioErr != nil {
  2111. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2113. return
  2114. }
  2115. var respJSON map[string]interface{}
  2116. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  2117. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2119. return
  2120. }
  2121. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2122. userJSONBytes, _ := json.Marshal(respJSON)
  2123. fmt.Println("log")
  2124. fmt.Println(string(userJSONBytes))
  2125. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2126. utils.ErrorLog("解析失败:%v", err)
  2127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2128. return
  2129. }
  2130. } else {
  2131. result, request_log := service.Gdyb2204(his.PsnNo, his.Number, prescriptions, chrg_bchno, miConfig.OrgName, roles.UserName, data["dept"].(string), data["fixmedins_code"].(string), data["dept_code"].(string), data["doctor_id"].(string), miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, data["balance_accounts_type"].(string))
  2132. var dat map[string]interface{}
  2133. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2134. fmt.Println(dat)
  2135. } else {
  2136. fmt.Println(err)
  2137. }
  2138. saveLog(result, request_log, "2204", "上传费用明细")
  2139. userJSONBytes, _ := json.Marshal(dat)
  2140. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2141. utils.ErrorLog("解析失败:%v", err)
  2142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2143. return
  2144. }
  2145. }
  2146. if res.Infcode == 0 {
  2147. order := &models.HisOrder{
  2148. UserOrgId: adminUser.CurrentOrgId,
  2149. HisPatientId: his.ID,
  2150. PatientId: his.PatientId,
  2151. SettleAccountsDate: recordDateTime,
  2152. Ctime: time.Now().Unix(),
  2153. Mtime: time.Now().Unix(),
  2154. Status: 1,
  2155. Number: chrg_bchno,
  2156. Infcode: res.Infcode,
  2157. WarnMsg: res.WarnMsg,
  2158. Cainfo: res.Cainfo,
  2159. ErrMsg: res.ErrMsg,
  2160. RespondTime: res.RefmsgTime,
  2161. InfRefmsgid: res.InfRefmsgid,
  2162. OrderStatus: 1,
  2163. PayWay: pay_way,
  2164. PayPrice: pay_price,
  2165. PayCardNo: pay_card_no,
  2166. DiscountPrice: discount_price,
  2167. PreferentialPrice: preferential_price,
  2168. RealityPrice: reality_price,
  2169. FoundPrice: found_price,
  2170. MedicalInsurancePrice: medical_insurance_price,
  2171. PrivatePrice: private_price,
  2172. IsMedicineInsurance: 1,
  2173. SettleType: settle_accounts_type,
  2174. SettleStartTime: start_time,
  2175. SettleEndTime: end_time,
  2176. Creator: roles.AdminUserId,
  2177. Modify: roles.AdminUserId,
  2178. FaPiaoNumber: fapiao_number,
  2179. FaPiaoCode: fapiao_code,
  2180. PType: 2,
  2181. Diagnosis: diagnosis_id,
  2182. }
  2183. err = service.CreateOrder(order)
  2184. if err != nil {
  2185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2186. return
  2187. }
  2188. for _, item := range res.Output.Result {
  2189. temp := strings.Split(item.FeedetlSn, "-")
  2190. var advice_id int64 = 0
  2191. var project_id int64 = 0
  2192. var types int64 = 0
  2193. id, _ := strconv.ParseInt(temp[2], 10, 64)
  2194. types, _ = strconv.ParseInt(temp[1], 10, 64)
  2195. if temp[1] == "1" {
  2196. advice_id = id
  2197. project_id = 0
  2198. } else if temp[1] == "2" {
  2199. advice_id = 0
  2200. project_id = id
  2201. }
  2202. info := &models.HisOrderInfo{
  2203. OrderNumber: order.Number,
  2204. FeedetlSn: item.FeedetlSn,
  2205. UploadDate: time.Now().Unix(),
  2206. AdviceId: advice_id,
  2207. DetItemFeeSumamt: item.DetItemFeeSumamt,
  2208. Cnt: item.Cnt,
  2209. Pric: float64(item.Pric),
  2210. PatientId: his.PatientId,
  2211. PricUplmtAmt: item.PricUplmtAmt,
  2212. SelfpayProp: item.SelfpayProp,
  2213. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2214. OverlmtAmt: item.OverlmtAmt,
  2215. PreselfpayAmt: item.PreselfpayAmt,
  2216. BasMednFlag: item.BasMednFlag,
  2217. MedChrgitmType: item.MedChrgitmType,
  2218. HiNegoDrugFlag: item.HiNegoDrugFlag,
  2219. Status: 1,
  2220. Memo: item.Memo,
  2221. Mtime: time.Now().Unix(),
  2222. InscpScpAmt: item.InscpScpAmt,
  2223. DrtReimFlag: item.DrtReimFlag,
  2224. Ctime: time.Now().Unix(),
  2225. ListSpItemFlag: item.ListSpItemFlag,
  2226. ChldMedcFlag: item.ChldMedcFlag,
  2227. LmtUsedFlag: item.LmtUsedFlag,
  2228. ChrgitmLv: item.ChrgitmLv,
  2229. UserOrgId: adminUser.CurrentOrgId,
  2230. HisPatientId: his.ID,
  2231. OrderId: order.ID,
  2232. ProjectId: project_id,
  2233. Type: types,
  2234. }
  2235. service.CreateOrderInfo(info)
  2236. }
  2237. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2238. service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, his_patient_id, chrg_bchno, recordDateTime)
  2239. var total float64
  2240. for _, item := range prescriptions {
  2241. if item.Type == 1 { //药品
  2242. for _, subItem := range item.HisDoctorAdviceInfo {
  2243. total = total + (subItem.Price * subItem.PrescribingNumber)
  2244. }
  2245. }
  2246. if item.Type == 2 { //项目
  2247. for _, subItem := range item.HisPrescriptionProject {
  2248. total = total + (subItem.Price * float64(subItem.Count))
  2249. }
  2250. }
  2251. }
  2252. for _, item := range prescriptions {
  2253. for _, subItem := range item.HisAdditionalCharge {
  2254. total = total + (subItem.Price * float64(subItem.Count))
  2255. }
  2256. }
  2257. allTotal := fmt.Sprintf("%.2f", total)
  2258. if res.Infcode == 0 {
  2259. var rf []*ResultFive
  2260. json.Unmarshal([]byte(his.Iinfo), &rf)
  2261. chrg_bchno := chrg_bchno
  2262. cert_no := his.Certno
  2263. var insutypes []string
  2264. var insutype string
  2265. var is390 int = 0
  2266. var is310 int = 0
  2267. for _, item := range rf {
  2268. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  2269. insutypes = append(insutypes, item.Insutype)
  2270. }
  2271. }
  2272. if len(insutypes) == 1 {
  2273. insutype = insutypes[0]
  2274. } else {
  2275. for _, i := range insutypes {
  2276. if i == "390" {
  2277. is390 = 1
  2278. }
  2279. if i == "310" {
  2280. is310 = 1
  2281. }
  2282. }
  2283. }
  2284. if is390 == 1 {
  2285. insutype = "390"
  2286. }
  2287. if is310 == 1 {
  2288. insutype = "310"
  2289. }
  2290. if len(insutypes) == 0 {
  2291. insutype = "310"
  2292. }
  2293. //insutype = "390"
  2294. if his.IdCardType == 1 {
  2295. // cert_no = his.MedicalInsuranceNumber
  2296. cert_no = his.Certno
  2297. } else {
  2298. cert_no = his.Certno
  2299. }
  2300. var res ResultSeven
  2301. var src_resquest string
  2302. var result2 string
  2303. if miConfig.MdtrtareaAdmvs == "421300" {
  2304. api := "http://192.168.124.4:9532/" + "hbyb/2207?psn_no=" + his.PsnNo + "&mdtrt_id=" +
  2305. his.Number + "&chrg_bchno=" + chrg_bchno + "&org_name=" + miConfig.OrgName +
  2306. "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2307. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2308. "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(his.IdCardType, 10) +
  2309. "&certificates=" + strconv.FormatInt(his.IdType, 10) + "&cert_no=" + cert_no +
  2310. "&insutype=" + insutype + "&total=" + allTotal + "&med_type=" + strconv.FormatInt(reg_type, 10)
  2311. resp, requestErr := http.Get(api)
  2312. if requestErr != nil {
  2313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2314. return
  2315. }
  2316. body, ioErr := ioutil.ReadAll(resp.Body)
  2317. if ioErr != nil {
  2318. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2320. return
  2321. }
  2322. var respJSON map[string]interface{}
  2323. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2324. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2326. return
  2327. }
  2328. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2329. result, _ := json.Marshal(respJSON)
  2330. if err := json.Unmarshal([]byte(result), &res); err != nil {
  2331. utils.ErrorLog("解析失败:%v", err)
  2332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2333. return
  2334. }
  2335. } else {
  2336. result2, src_resquest = service.Gdyb2207(his.PsnNo, his.Number, chrg_bchno, cert_no, insutype, allTotal, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, strconv.FormatInt(reg_type, 10), his.IdCardType, 0, 0, 0, 0, his.IdType)
  2337. var dat map[string]interface{}
  2338. if err := json.Unmarshal([]byte(result2), &dat); err == nil {
  2339. fmt.Println(dat)
  2340. } else {
  2341. fmt.Println(err)
  2342. }
  2343. saveLog(result2, src_resquest, "2207", "结算")
  2344. userJSONBytes, _ := json.Marshal(dat)
  2345. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2346. utils.ErrorLog("解析失败:%v", err)
  2347. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2348. return
  2349. }
  2350. }
  2351. if res.Infcode != 0 {
  2352. errlog := &models.HisOrderError{
  2353. UserOrgId: adminUser.CurrentOrgId,
  2354. Ctime: time.Now().Unix(),
  2355. Mtime: time.Now().Unix(),
  2356. Number: chrg_bchno,
  2357. ErrMsg: res.ErrMsg,
  2358. Status: 1,
  2359. PatientId: id,
  2360. RecordTime: recordDateTime,
  2361. Stage: 6,
  2362. }
  2363. service.CreateErrMsgLog(errlog)
  2364. c.ServeSuccessJSON(map[string]interface{}{
  2365. "failed_code": -10,
  2366. "msg": res.ErrMsg,
  2367. })
  2368. return
  2369. } else {
  2370. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2371. order.OrderStatus = 2
  2372. order.Status = 1
  2373. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2374. order.SetlId = res.Output.Setlinfo.SetlID
  2375. order.PsnNo = res.Output.Setlinfo.PsnNo
  2376. order.PsnName = res.Output.Setlinfo.PsnName
  2377. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2378. order.Certno = res.Output.Setlinfo.Certno
  2379. order.Gend = res.Output.Setlinfo.Gend
  2380. order.Naty = res.Output.Setlinfo.Naty
  2381. order.Age = res.Output.Setlinfo.Age
  2382. order.Insutype = res.Output.Setlinfo.Insutype
  2383. order.PsnType = res.Output.Setlinfo.PsnType
  2384. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2385. order.SetlTime = res.Output.Setlinfo.SetlTime
  2386. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2387. order.MedType = res.Output.Setlinfo.MedType
  2388. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2389. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2390. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2391. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2392. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2393. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2394. order.HifpPay = res.Output.Setlinfo.HifpPay
  2395. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2396. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2397. order.HifesPay = res.Output.Setlinfo.HifesPay
  2398. order.HifobPay = res.Output.Setlinfo.HifobPay
  2399. order.MafPay = res.Output.Setlinfo.MafPay
  2400. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  2401. order.OthPay = res.Output.Setlinfo.OthPay
  2402. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2403. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2404. order.AcctPay = res.Output.Setlinfo.AcctPay
  2405. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2406. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2407. order.Balc = res.Output.Setlinfo.Balc
  2408. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2409. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2410. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2411. order.ClrWay = res.Output.Setlinfo.ClrWay
  2412. order.Creator = order.Creator
  2413. order.Modify = roles.AdminUserId
  2414. order.RequestLog = src_resquest
  2415. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2416. detailStr := string(setlDetail)
  2417. order.SetlDetail = detailStr
  2418. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2419. err = service.UpDateOrder(order)
  2420. if err == nil {
  2421. c.ServeSuccessJSON(map[string]interface{}{
  2422. "msg": "结算成功",
  2423. })
  2424. } else {
  2425. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2426. return
  2427. }
  2428. }
  2429. } else {
  2430. adminUser := c.GetAdminUserInfo()
  2431. errlog := &models.HisOrderError{
  2432. UserOrgId: adminUser.CurrentOrgId,
  2433. Ctime: time.Now().Unix(),
  2434. Mtime: time.Now().Unix(),
  2435. ErrMsg: res.ErrMsg,
  2436. Status: 1,
  2437. PatientId: id,
  2438. RecordTime: recordDateTime,
  2439. Stage: 4,
  2440. }
  2441. service.CreateErrMsgLog(errlog)
  2442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2443. return
  2444. }
  2445. } else {
  2446. adminUser := c.GetAdminUserInfo()
  2447. errlog := &models.HisOrderError{
  2448. UserOrgId: adminUser.CurrentOrgId,
  2449. Ctime: time.Now().Unix(),
  2450. Mtime: time.Now().Unix(),
  2451. ErrMsg: res.ErrMsg,
  2452. Status: 1,
  2453. PatientId: id,
  2454. RecordTime: recordDateTime,
  2455. Stage: 4,
  2456. }
  2457. service.CreateErrMsgLog(errlog)
  2458. c.ServeSuccessJSON(map[string]interface{}{
  2459. "failed_code": -10,
  2460. "msg": res.ErrMsg,
  2461. })
  2462. return
  2463. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  2464. //return
  2465. }
  2466. }
  2467. }
  2468. } else if tempOrder.ID > 0 {
  2469. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  2470. var rf []*ResultFive
  2471. json.Unmarshal([]byte(his.Iinfo), &rf)
  2472. chrg_bchno := tempOrder.Number
  2473. cert_no := his.Certno
  2474. var insutypes []string
  2475. var insutype string
  2476. var is390 int = 0
  2477. var is310 int = 0
  2478. for _, item := range rf {
  2479. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  2480. insutypes = append(insutypes, item.Insutype)
  2481. }
  2482. }
  2483. if len(insutypes) == 1 {
  2484. insutype = insutypes[0]
  2485. } else {
  2486. for _, i := range insutypes {
  2487. if i == "390" {
  2488. is390 = 1
  2489. }
  2490. if i == "310" {
  2491. is310 = 1
  2492. }
  2493. }
  2494. }
  2495. if is390 == 1 {
  2496. insutype = "390"
  2497. }
  2498. if is310 == 1 {
  2499. insutype = "310"
  2500. }
  2501. if len(insutypes) == 0 {
  2502. insutype = "310"
  2503. }
  2504. //insutype = "390"
  2505. if his.IdCardType == 1 {
  2506. // cert_no = his.MedicalInsuranceNumber
  2507. cert_no = his.Certno
  2508. } else {
  2509. cert_no = his.Certno
  2510. }
  2511. var res ResultSeven
  2512. var src_resquest string
  2513. var result2 string
  2514. if miConfig.MdtrtareaAdmvs == "421300" {
  2515. api := "http://192.168.124.4:9532/" + "hbyb/2207?psn_no=" + his.PsnNo + "&mdtrt_id=" +
  2516. his.Number + "&chrg_bchno=" + chrg_bchno + "&org_name=" + miConfig.OrgName +
  2517. "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2518. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2519. "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(his.IdCardType, 10) +
  2520. "&certificates=" + strconv.FormatInt(his.IdType, 10) + "&cert_no=" + cert_no +
  2521. "&insutype=" + insutype + "&total=" + allTotal + "&med_type=" + strconv.FormatInt(reg_type, 10)
  2522. resp, requestErr := http.Get(api)
  2523. if requestErr != nil {
  2524. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2525. return
  2526. }
  2527. body, ioErr := ioutil.ReadAll(resp.Body)
  2528. if ioErr != nil {
  2529. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2531. return
  2532. }
  2533. var respJSON map[string]interface{}
  2534. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2535. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2537. return
  2538. }
  2539. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2540. result, _ := json.Marshal(respJSON)
  2541. fmt.Println("log")
  2542. fmt.Println(string(result))
  2543. if err := json.Unmarshal([]byte(result), &res); err != nil {
  2544. utils.ErrorLog("解析失败:%v", err)
  2545. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2546. return
  2547. }
  2548. } else {
  2549. result2, src_resquest = service.Gdyb2207(his.PsnNo, his.Number, chrg_bchno, cert_no, insutype, allTotal, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, strconv.FormatInt(reg_type, 10), his.IdCardType, tempOrder.FulamtOwnpayAmt, tempOrder.OverlmtSelfPay, tempOrder.PreselfpayAmt, tempOrder.InscpScpAmt, his.IdType)
  2550. var dat map[string]interface{}
  2551. if err := json.Unmarshal([]byte(result2), &dat); err == nil {
  2552. fmt.Println(dat)
  2553. } else {
  2554. fmt.Println(err)
  2555. }
  2556. saveLog(result2, src_resquest, "2207", "结算")
  2557. userJSONBytes, _ := json.Marshal(dat)
  2558. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2559. utils.ErrorLog("解析失败:%v", err)
  2560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2561. return
  2562. }
  2563. }
  2564. if res.Infcode != 0 {
  2565. errlog := &models.HisOrderError{
  2566. UserOrgId: adminUser.CurrentOrgId,
  2567. Ctime: time.Now().Unix(),
  2568. Mtime: time.Now().Unix(),
  2569. Number: chrg_bchno,
  2570. ErrMsg: res.ErrMsg,
  2571. Status: 1,
  2572. PatientId: id,
  2573. RecordTime: recordDateTime,
  2574. Stage: 6,
  2575. }
  2576. service.CreateErrMsgLog(errlog)
  2577. c.ServeSuccessJSON(map[string]interface{}{
  2578. "failed_code": -10,
  2579. "msg": res.ErrMsg,
  2580. })
  2581. return
  2582. } else {
  2583. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2584. order.OrderStatus = 2
  2585. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2586. order.SetlId = res.Output.Setlinfo.SetlID
  2587. order.PsnNo = res.Output.Setlinfo.PsnNo
  2588. order.PsnName = res.Output.Setlinfo.PsnName
  2589. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2590. order.Certno = res.Output.Setlinfo.Certno
  2591. order.Gend = res.Output.Setlinfo.Gend
  2592. order.Naty = res.Output.Setlinfo.Naty
  2593. order.Age = res.Output.Setlinfo.Age
  2594. order.Insutype = res.Output.Setlinfo.Insutype
  2595. order.PsnType = res.Output.Setlinfo.PsnType
  2596. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2597. order.SetlTime = res.Output.Setlinfo.SetlTime
  2598. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2599. order.MedType = res.Output.Setlinfo.MedType
  2600. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2601. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2602. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2603. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2604. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2605. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2606. order.HifpPay = res.Output.Setlinfo.HifpPay
  2607. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2608. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2609. order.HifesPay = res.Output.Setlinfo.HifesPay
  2610. order.HifobPay = res.Output.Setlinfo.HifobPay
  2611. order.MafPay = res.Output.Setlinfo.MafPay
  2612. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  2613. order.OthPay = res.Output.Setlinfo.OthPay
  2614. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2615. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2616. order.AcctPay = res.Output.Setlinfo.AcctPay
  2617. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2618. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2619. order.Balc = res.Output.Setlinfo.Balc
  2620. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2621. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2622. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2623. order.ClrWay = res.Output.Setlinfo.ClrWay
  2624. order.Creator = order.Creator
  2625. order.Modify = roles.AdminUserId
  2626. order.RequestLog = src_resquest
  2627. order.Diagnosis = diagnosis_id
  2628. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2629. detailStr := string(setlDetail)
  2630. order.SetlDetail = detailStr
  2631. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2632. err = service.UpDateOrder(order)
  2633. if err == nil {
  2634. c.ServeSuccessJSON(map[string]interface{}{
  2635. "msg": "结算成功",
  2636. })
  2637. } else {
  2638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2639. return
  2640. }
  2641. }
  2642. }
  2643. }
  2644. //func (c *HisApiController) GetPreUploadInfo() {
  2645. // id, _ := c.GetInt64("id")
  2646. // record_time := c.GetString("record_time")
  2647. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2648. // admin_user_id, _ := c.GetInt64("admin_user_id")
  2649. //
  2650. // timeLayout := "2006-01-02"
  2651. // loc, _ := time.LoadLocation("Local")
  2652. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2653. // if err != nil {
  2654. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2655. // return
  2656. // }
  2657. // recordDateTime := theTime.Unix()
  2658. // adminUser := c.GetAdminUserInfo()
  2659. //
  2660. // var prescriptions []*models.HisPrescription
  2661. //
  2662. // var start_time int64
  2663. // var end_time int64
  2664. //
  2665. // data := make(map[string]interface{})
  2666. // if settle_accounts_type == 1 { //日结
  2667. // prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  2668. // data["pre"] = prescriptions
  2669. //
  2670. // } else { //月结
  2671. // start_time_str := c.GetString("start_time")
  2672. // end_time_str := c.GetString("end_time")
  2673. // timeLayout := "2006-01-02"
  2674. // loc, _ := time.LoadLocation("Local")
  2675. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2676. // if err != nil {
  2677. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2678. // return
  2679. // }
  2680. // recordStartTime := theStartTime.Unix()
  2681. // start_time = recordStartTime
  2682. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2683. // if err != nil {
  2684. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2685. // return
  2686. // }
  2687. // recordEndTime := theEndTime.Unix()
  2688. // end_time = recordEndTime
  2689. // prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  2690. // data["pre"] = prescriptions
  2691. //
  2692. // }
  2693. //
  2694. // roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2695. //
  2696. // his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2697. // timestamp := time.Now().Unix()
  2698. // tempTime := time.Unix(timestamp, 0)
  2699. // timeFormat := tempTime.Format("20060102150405")
  2700. // chrgBchno := rand.Intn(100000) + 10000
  2701. // chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  2702. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2703. // patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2704. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  2705. // strconv.FormatInt(his.PatientId, 10)
  2706. // client := &http.Client{}
  2707. // data["psn_no"] = his.PsnNo
  2708. // data["mdtrt_id"] = his.Number
  2709. // data["chrg_bchno"] = chrg_bchno
  2710. // data["org_name"] = miConfig.OrgName
  2711. // data["doctor"] = roles.UserName
  2712. // data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  2713. // data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  2714. // data["fixmedins_code"] = miConfig.Code
  2715. // data["dept_code"] = department.Number
  2716. // data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  2717. // data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  2718. // data["secret_key"] = miConfig.SecretKey
  2719. // var ids []int64
  2720. //
  2721. // for _, item := range prescriptions {
  2722. // ids = append(ids, item.ID)
  2723. // }
  2724. // config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2725. // if config.IsOpen == 1 { //对接了医保,走医保流程
  2726. // bytesData, _ := json.Marshal(data)
  2727. // req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  2728. // resp, _ := client.Do(req)
  2729. // defer resp.Body.Close()
  2730. // body, ioErr := ioutil.ReadAll(resp.Body)
  2731. // if ioErr != nil {
  2732. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2733. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2734. // return
  2735. // }
  2736. // var respJSON map[string]interface{}
  2737. // if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  2738. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2739. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2740. // return
  2741. // }
  2742. //
  2743. // respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2744. // userJSONBytes, _ := json.Marshal(respJSON)
  2745. // var res ResultFour
  2746. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2747. // utils.ErrorLog("解析失败:%v", err)
  2748. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2749. // return
  2750. // }
  2751. //
  2752. // if res.Infcode == 0 {
  2753. // order := &models.HisOrder{
  2754. // UserOrgId: adminUser.CurrentOrgId,
  2755. // HisPatientId: his.ID,
  2756. // PatientId: his.PatientId,
  2757. // SettleAccountsDate: recordDateTime,
  2758. // Ctime: time.Now().Unix(),
  2759. // Mtime: time.Now().Unix(),
  2760. // Status: 1,
  2761. // Number: chrg_bchno,
  2762. // Infcode: res.Infcode,
  2763. // WarnMsg: res.WarnMsg,
  2764. // Cainfo: res.Cainfo,
  2765. // ErrMsg: res.ErrMsg,
  2766. // RespondTime: res.RefmsgTime,
  2767. // InfRefmsgid: res.InfRefmsgid,
  2768. // OrderStatus: 1,
  2769. // IsMedicineInsurance: 1,
  2770. // SettleType: settle_accounts_type,
  2771. // SettleStartTime: start_time,
  2772. // SettleEndTime: end_time,
  2773. // Creator: roles.ID,
  2774. // Modify: roles.ID,
  2775. // PType: 2,
  2776. // }
  2777. // err = service.CreateOrder(order)
  2778. // if err != nil {
  2779. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2780. // return
  2781. // }
  2782. //
  2783. // for _, item := range res.Output.Result {
  2784. // temp := strings.Split(item.FeedetlSn, "-")
  2785. // var advice_id int64 = 0
  2786. // var project_id int64 = 0
  2787. // var types int64 = 0
  2788. //
  2789. // id, _ := strconv.ParseInt(temp[2], 10, 64)
  2790. // types, _ = strconv.ParseInt(temp[1], 10, 64)
  2791. //
  2792. // if temp[1] == "1" {
  2793. // advice_id = id
  2794. // project_id = 0
  2795. // } else if temp[1] == "2" {
  2796. // advice_id = 0
  2797. // project_id = id
  2798. // }
  2799. //
  2800. // info := &models.HisOrderInfo{
  2801. // OrderNumber: order.Number,
  2802. // FeedetlSn: item.FeedetlSn,
  2803. // UploadDate: time.Now().Unix(),
  2804. // AdviceId: advice_id,
  2805. // DetItemFeeSumamt: item.DetItemFeeSumamt,
  2806. // Cnt: item.Cnt,
  2807. // Pric: float64(item.Pric),
  2808. // PatientId: his.PatientId,
  2809. // PricUplmtAmt: item.PricUplmtAmt,
  2810. // SelfpayProp: item.SelfpayProp,
  2811. // FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2812. // OverlmtAmt: item.OverlmtAmt,
  2813. // PreselfpayAmt: item.PreselfpayAmt,
  2814. // BasMednFlag: item.BasMednFlag,
  2815. // MedChrgitmType: item.MedChrgitmType,
  2816. // HiNegoDrugFlag: item.HiNegoDrugFlag,
  2817. // Status: 1,
  2818. // Memo: item.Memo,
  2819. // Mtime: time.Now().Unix(),
  2820. // InscpScpAmt: item.InscpScpAmt,
  2821. // DrtReimFlag: item.DrtReimFlag,
  2822. // Ctime: time.Now().Unix(),
  2823. // ListSpItemFlag: item.ListSpItemFlag,
  2824. // ChldMedcFlag: item.ChldMedcFlag,
  2825. // LmtUsedFlag: item.LmtUsedFlag,
  2826. // ChrgitmLv: item.ChrgitmLv,
  2827. // UserOrgId: adminUser.CurrentOrgId,
  2828. // HisPatientId: his.ID,
  2829. // OrderId: order.ID,
  2830. // ProjectId: project_id,
  2831. // Type: types,
  2832. // }
  2833. // service.CreateOrderInfo(info)
  2834. //
  2835. // }
  2836. // service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2837. // service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  2838. //
  2839. // var total float64
  2840. // for _, item := range prescriptions {
  2841. // if item.Type == 1 { //药品
  2842. // for _, subItem := range item.HisDoctorAdviceInfo {
  2843. // total = total + (subItem.Price * subItem.PrescribingNumber)
  2844. // }
  2845. // }
  2846. // if item.Type == 2 { //项目
  2847. // for _, subItem := range item.HisPrescriptionProject {
  2848. // total = total + (subItem.Price * float64(subItem.Count))
  2849. // }
  2850. // }
  2851. // }
  2852. //
  2853. // for _, item := range prescriptions {
  2854. // for _, subItem := range item.HisAdditionalCharge {
  2855. // total = total + (subItem.Price * float64(subItem.Count))
  2856. // }
  2857. // }
  2858. //
  2859. // allTotal := fmt.Sprintf("%.2f", total)
  2860. // if res.Infcode == 0 {
  2861. // var rf []*ResultFive
  2862. // json.Unmarshal([]byte(his.Iinfo), &rf)
  2863. // psn_no := his.PsnNo
  2864. // mdtrt_id := his.Number
  2865. // chrg_bchno := chrg_bchno
  2866. // cert_no := his.Certno
  2867. // insutype := rf[0].Insutype
  2868. //
  2869. // if his.IdCardType == 1 {
  2870. // cert_no = his.MedicalInsuranceNumber
  2871. //
  2872. // } else {
  2873. //
  2874. // cert_no = his.Certno
  2875. //
  2876. // }
  2877. //
  2878. // api := "http://127.0.0.1:9532/" + "gdyb/seven?cert_no=" + cert_no + "&insutype=" +
  2879. // insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  2880. // "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  2881. // miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10)
  2882. // resp, requestErr := http.Get(api)
  2883. // if requestErr != nil {
  2884. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2885. // return
  2886. // }
  2887. // defer resp.Body.Close()
  2888. // body, ioErr := ioutil.ReadAll(resp.Body)
  2889. // if ioErr != nil {
  2890. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2891. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2892. // return
  2893. // }
  2894. // var respJSON map[string]interface{}
  2895. // if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2896. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2897. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2898. // return
  2899. // }
  2900. // fmt.Println(respJSON)
  2901. // respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2902. // userJSONBytes, _ := json.Marshal(respJSON)
  2903. // var res ResultSeven
  2904. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2905. // utils.ErrorLog("解析失败:%v", err)
  2906. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2907. // return
  2908. // }
  2909. // if res.Infcode != 0 {
  2910. // errlog := &models.HisOrderError{
  2911. // UserOrgId: adminUser.CurrentOrgId,
  2912. // Ctime: time.Now().Unix(),
  2913. // Mtime: time.Now().Unix(),
  2914. // Number: chrg_bchno,
  2915. // ErrMsg: res.ErrMsg,
  2916. // Status: 1,
  2917. // PatientId: id,
  2918. // RecordTime: recordDateTime,
  2919. // Stage: 7,
  2920. // }
  2921. // service.CreateErrMsgLog(errlog)
  2922. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2923. // return
  2924. // } else {
  2925. // order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2926. // order.OrderStatus = 1
  2927. // order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2928. // order.SetlId = res.Output.Setlinfo.SetlID
  2929. // order.PsnNo = res.Output.Setlinfo.PsnNo
  2930. // order.PsnName = res.Output.Setlinfo.PsnName
  2931. // order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2932. // order.Certno = res.Output.Setlinfo.Certno
  2933. // order.Gend = res.Output.Setlinfo.Gend
  2934. // order.Naty = res.Output.Setlinfo.Naty
  2935. // order.Age = res.Output.Setlinfo.Age
  2936. // order.Insutype = res.Output.Setlinfo.Insutype
  2937. // order.PsnType = res.Output.Setlinfo.PsnType
  2938. // order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2939. // order.SetlTime = res.Output.Setlinfo.SetlTime
  2940. // order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2941. // order.MedType = res.Output.Setlinfo.MedType
  2942. // order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2943. // order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2944. // order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2945. // order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2946. // order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2947. // order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2948. // order.HifpPay = res.Output.Setlinfo.HifpPay
  2949. // order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2950. // order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2951. // order.HifesPay = res.Output.Setlinfo.HifesPay
  2952. // order.HifobPay = res.Output.Setlinfo.HifobPay
  2953. // order.MafPay = res.Output.Setlinfo.MafPay
  2954. // order.OthPay = res.Output.Setlinfo.OthPay
  2955. // order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2956. // order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2957. // order.AcctPay = res.Output.Setlinfo.AcctPay
  2958. // order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2959. // order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2960. // order.Balc = res.Output.Setlinfo.Balc
  2961. // order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2962. // order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2963. // order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2964. // order.ClrWay = res.Output.Setlinfo.ClrWay
  2965. // order.Creator = order.Creator
  2966. // order.Modify = roles.ID
  2967. // setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2968. // detailStr := string(setlDetail)
  2969. // order.SetlDetail = detailStr
  2970. // //err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2971. // err = service.UpDateOrder(order)
  2972. // if err == nil {
  2973. // c.ServeSuccessJSON(map[string]interface{}{
  2974. // "msg": "预结算成功",
  2975. // })
  2976. // } else {
  2977. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2978. // return
  2979. // }
  2980. // }
  2981. // } else {
  2982. // adminUser := c.GetAdminUserInfo()
  2983. // errlog := &models.HisOrderError{
  2984. // UserOrgId: adminUser.CurrentOrgId,
  2985. // Ctime: time.Now().Unix(),
  2986. // Mtime: time.Now().Unix(),
  2987. // ErrMsg: res.ErrMsg,
  2988. // Status: 1,
  2989. // PatientId: id,
  2990. // RecordTime: recordDateTime,
  2991. // Stage: 4,
  2992. // }
  2993. // service.CreateErrMsgLog(errlog)
  2994. //
  2995. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2996. // return
  2997. // }
  2998. // } else {
  2999. // adminUser := c.GetAdminUserInfo()
  3000. // errlog := &models.HisOrderError{
  3001. // UserOrgId: adminUser.CurrentOrgId,
  3002. // Ctime: time.Now().Unix(),
  3003. // Mtime: time.Now().Unix(),
  3004. // ErrMsg: res.ErrMsg,
  3005. // Status: 1,
  3006. // PatientId: id,
  3007. // RecordTime: recordDateTime,
  3008. // Stage: 4,
  3009. // }
  3010. // service.CreateErrMsgLog(errlog)
  3011. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  3012. // return
  3013. // }
  3014. //
  3015. // } else {
  3016. // var total float64
  3017. // for _, item := range prescriptions {
  3018. // if item.Type == 1 { //药品
  3019. // for _, subItem := range item.HisDoctorAdviceInfo {
  3020. // total = total + (subItem.Price * subItem.PrescribingNumber)
  3021. // }
  3022. // }
  3023. // if item.Type == 2 { //项目
  3024. // for _, subItem := range item.HisPrescriptionProject {
  3025. // total = total + (subItem.Price * float64(subItem.Count))
  3026. // }
  3027. // }
  3028. //
  3029. // for _, subItem := range item.HisAdditionalCharge {
  3030. // total = total + (subItem.Price * float64(subItem.Count))
  3031. // }
  3032. // }
  3033. //
  3034. // allTotal := fmt.Sprintf("%.2f", total)
  3035. // totals, _ := strconv.ParseFloat(allTotal, 64)
  3036. // order := &models.HisOrder{
  3037. // UserOrgId: adminUser.CurrentOrgId,
  3038. // HisPatientId: his.ID,
  3039. // PatientId: id,
  3040. // SettleAccountsDate: recordDateTime,
  3041. // Ctime: time.Now().Unix(),
  3042. // Mtime: time.Now().Unix(),
  3043. // Status: 1,
  3044. // OrderStatus: 2,
  3045. // Number: chrg_bchno,
  3046. // MedfeeSumamt: totals,
  3047. // }
  3048. // err = service.CreateOrder(order)
  3049. // if err != nil {
  3050. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  3051. // return
  3052. // }
  3053. //
  3054. // var customs []*Custom
  3055. // for _, item := range prescriptions {
  3056. //
  3057. // if item.Type == 1 { //药品
  3058. // for _, subItem := range item.HisDoctorAdviceInfo {
  3059. // cus := &Custom{
  3060. // AdviceId: subItem.ID,
  3061. // ProjectId: 0,
  3062. // DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  3063. // Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  3064. // FeedetlSn: subItem.FeedetlSn,
  3065. // Price: fmt.Sprintf("%.2f", subItem.Price),
  3066. // MedListCodg: subItem.MedListCodg,
  3067. // Type: 1,
  3068. // }
  3069. // customs = append(customs, cus)
  3070. // }
  3071. // }
  3072. //
  3073. // if item.Type == 2 { //项目
  3074. // for _, subItem := range item.HisPrescriptionProject {
  3075. //
  3076. // cus := &Custom{
  3077. // AdviceId: 0,
  3078. // ProjectId: subItem.ID,
  3079. // DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  3080. // Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  3081. // FeedetlSn: subItem.FeedetlSn,
  3082. // Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  3083. // MedListCodg: subItem.MedListCodg,
  3084. // Type: 2,
  3085. // }
  3086. //
  3087. // customs = append(customs, cus)
  3088. // }
  3089. // }
  3090. //
  3091. // for _, item := range item.HisAdditionalCharge {
  3092. // cus := &Custom{
  3093. // ItemId: item.ID,
  3094. // AdviceId: 0,
  3095. // ProjectId: 0,
  3096. // DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  3097. // Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  3098. // FeedetlSn: item.FeedetlSn,
  3099. // Price: fmt.Sprintf("%.2f", float64(item.Price)),
  3100. // MedListCodg: item.XtHisAddtionConfig.Code,
  3101. // Type: 3,
  3102. // }
  3103. //
  3104. // customs = append(customs, cus)
  3105. // }
  3106. //
  3107. // }
  3108. //
  3109. // for _, item := range customs {
  3110. // var advice_id int64 = 0
  3111. // var project_id int64 = 0
  3112. // var item_id int64 = 0
  3113. //
  3114. // var types int64 = 0
  3115. //
  3116. // if item.Type == 1 {
  3117. // advice_id = item.AdviceId
  3118. // project_id = 0
  3119. // item_id = 0
  3120. // } else if item.Type == 2 {
  3121. // advice_id = 0
  3122. // item_id = 0
  3123. //
  3124. // project_id = item.ProjectId
  3125. // } else if item.Type == 3 {
  3126. // advice_id = 0
  3127. // item_id = item.ItemId
  3128. // project_id = 0
  3129. // }
  3130. //
  3131. // detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  3132. // cut, _ := strconv.ParseFloat(item.Cut, 32)
  3133. // pric, _ := strconv.ParseFloat(item.Price, 32)
  3134. //
  3135. // info := &models.HisOrderInfo{
  3136. // OrderNumber: order.Number,
  3137. // UploadDate: time.Now().Unix(),
  3138. // AdviceId: advice_id,
  3139. // DetItemFeeSumamt: detItemFeeSumamt,
  3140. // Cnt: cut,
  3141. // Pric: pric,
  3142. // PatientId: id,
  3143. // Status: 1,
  3144. // Mtime: time.Now().Unix(),
  3145. // Ctime: time.Now().Unix(),
  3146. // UserOrgId: adminUser.CurrentOrgId,
  3147. // HisPatientId: his.ID,
  3148. // OrderId: order.ID,
  3149. // ProjectId: project_id,
  3150. // Type: types,
  3151. // ItemId: item_id,
  3152. // }
  3153. // service.CreateOrderInfo(info)
  3154. // }
  3155. // //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  3156. // err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  3157. // err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  3158. // err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  3159. // if err == nil {
  3160. // c.ServeSuccessJSON(map[string]interface{}{
  3161. // "msg": "结算成功",
  3162. // })
  3163. // } else {
  3164. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  3165. // return
  3166. // }
  3167. // }
  3168. //}
  3169. //上传明细-预结算-
  3170. func (c *HisApiController) GetPreUploadInfo() {
  3171. id, _ := c.GetInt64("id")
  3172. record_time := c.GetString("record_time")
  3173. his_patient_id, _ := c.GetInt64("his_patient_id")
  3174. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  3175. admin_user_id, _ := c.GetInt64("admin_user_id")
  3176. diagnosis_id := c.GetString("diagnosis")
  3177. sick_type, _ := c.GetInt64("sick_type")
  3178. reg_type, _ := c.GetInt64("p_type")
  3179. id_str := c.GetString("ids")
  3180. ids_arr := strings.Split(id_str, ",")
  3181. timeLayout := "2006-01-02"
  3182. loc, _ := time.LoadLocation("Local")
  3183. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3184. if err != nil {
  3185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3186. return
  3187. }
  3188. recordDateTime := theTime.Unix()
  3189. adminUser := c.GetAdminUserInfo()
  3190. diagnosis_ids := strings.Split(diagnosis_id, ",")
  3191. var config []*models.HisXtDiagnoseConfig
  3192. for _, item := range diagnosis_ids {
  3193. id, _ := strconv.ParseInt(item, 10, 64)
  3194. diagnosisConfig, _ := service.FindDiagnoseById(id)
  3195. config = append(config, &diagnosisConfig)
  3196. }
  3197. //diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  3198. sickConfig, _ := service.FindSickById(sick_type)
  3199. var prescriptions []*models.HisPrescription
  3200. var start_time int64
  3201. var end_time int64
  3202. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3203. fmt.Println(his_patient_id)
  3204. his, _ := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  3205. timestamp := time.Now().Unix()
  3206. tempTime := time.Unix(timestamp, 0)
  3207. timeFormat := tempTime.Format("20060102150405")
  3208. chrgBchno := rand.Intn(100000) + 10000
  3209. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  3210. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3211. var patientPrescription models.HisPrescriptionInfo
  3212. patientPrescription, _ = service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  3213. if patientPrescription.ID == 0 {
  3214. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  3215. }
  3216. //miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3217. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  3218. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  3219. strconv.FormatInt(his.PatientId, 10)
  3220. var res2 ResultSix
  3221. if miConfig.InsuplcAdmdvs == "421300" {
  3222. data := make(map[string]interface{})
  3223. client := &http.Client{}
  3224. data["psn_no"] = his.PsnNo
  3225. data["mdtrt_id"] = his.Number
  3226. data["doctor"] = roles.UserName
  3227. data["department"] = department.Name
  3228. data["org_name"] = miConfig.OrgName
  3229. data["med_type"] = strconv.FormatInt(reg_type, 10)
  3230. data["doctor_id"] = strconv.FormatInt(doctor_info.AdminUserId, 10)
  3231. data["fixmedins_code"] = miConfig.Code
  3232. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  3233. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  3234. data["secret_key"] = miConfig.SecretKey
  3235. data["sick_code"] = sickConfig.CountryCode
  3236. data["sick_name"] = sickConfig.ClassName
  3237. data["dept"] = strconv.FormatInt(department.ID, 10)
  3238. data["config"] = config
  3239. fmt.Println(data)
  3240. bytesData, _ := json.Marshal(data)
  3241. req, _ := http.NewRequest("POST", "http://192.168.124.4:9532/"+"hbyb/2203", bytes.NewReader(bytesData))
  3242. resp, _ := client.Do(req)
  3243. defer resp.Body.Close()
  3244. body, ioErr := ioutil.ReadAll(resp.Body)
  3245. if ioErr != nil {
  3246. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3247. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3248. return
  3249. }
  3250. var respJSON map[string]interface{}
  3251. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  3252. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3254. return
  3255. }
  3256. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3257. userJSONBytes, _ := json.Marshal(respJSON)
  3258. fmt.Println("log")
  3259. fmt.Println(string(userJSONBytes))
  3260. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  3261. utils.ErrorLog("解析失败:%v", err)
  3262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3263. return
  3264. }
  3265. } else {
  3266. var result string
  3267. var requestLog string
  3268. if miConfig.InsuplcAdmdvs == "440781" { //
  3269. result, requestLog = service.Gdyb2203A(his.PsnNo, his.Number, doctor_info.UserName, department.Name, miConfig.OrgName, strconv.FormatInt(reg_type, 10), doctor_info.AdminUserId, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sickConfig.ContentCode, sickConfig.ClassName, roles.UserName, config)
  3270. } else {
  3271. result, requestLog = service.Gdyb2203(his.PsnNo, his.Number, doctor_info.UserName, department.Name, miConfig.OrgName, strconv.FormatInt(reg_type, 10), doctor_info.AdminUserId, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sickConfig.CountryCode, sickConfig.ClassName, roles.UserName, config)
  3272. saveLog(result, requestLog, "2203", "上传就诊信息")
  3273. var respJSON2 map[string]interface{}
  3274. if err := json.Unmarshal([]byte(string(result)), &respJSON2); err != nil {
  3275. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3276. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3277. return
  3278. }
  3279. userJSONBytes2, _ := json.Marshal(respJSON2)
  3280. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  3281. utils.ErrorLog("解析失败:%v", err)
  3282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3283. return
  3284. }
  3285. }
  3286. }
  3287. if res2.Infcode != 0 {
  3288. adminUser := c.GetAdminUserInfo()
  3289. errlog := &models.HisOrderError{
  3290. UserOrgId: adminUser.CurrentOrgId,
  3291. Ctime: time.Now().Unix(),
  3292. Mtime: time.Now().Unix(),
  3293. ErrMsg: res2.ErrMsg,
  3294. Status: 1,
  3295. PatientId: id,
  3296. RecordTime: recordDateTime,
  3297. Stage: 3,
  3298. }
  3299. service.CreateErrMsgLog(errlog)
  3300. c.ServeSuccessJSON(map[string]interface{}{
  3301. "failed_code": -10,
  3302. "msg": res2.ErrMsg,
  3303. })
  3304. return
  3305. } else {
  3306. his.Diagnosis = diagnosis_id
  3307. his.SickType = sickConfig.ID
  3308. his.PType = fmt.Sprintf("%d", reg_type)
  3309. service.UpdateHisPatientThree(&his)
  3310. data := make(map[string]interface{})
  3311. if settle_accounts_type == 1 { //日结
  3312. if reg_type == 11 {
  3313. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  3314. } else {
  3315. prescriptions, _ = service.GetNewHisPrescription(adminUser.CurrentOrgId, his_patient_id, recordDateTime, strconv.Itoa(int(reg_type)))
  3316. }
  3317. data["pre"] = prescriptions
  3318. } else { //月结
  3319. start_time_str := c.GetString("start_time")
  3320. end_time_str := c.GetString("end_time")
  3321. timeLayout := "2006-01-02"
  3322. loc, _ := time.LoadLocation("Local")
  3323. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  3324. if err != nil {
  3325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3326. return
  3327. }
  3328. recordStartTime := theStartTime.Unix()
  3329. start_time = recordStartTime
  3330. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3331. if err != nil {
  3332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3333. return
  3334. }
  3335. recordEndTime := theEndTime.Unix()
  3336. end_time = recordEndTime
  3337. prescriptions, _ = service.GetMonthHisPrescriptionTwo(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  3338. data["pre"] = prescriptions
  3339. }
  3340. if reg_type == 1111 || reg_type == 1112 {
  3341. reg_type = 11
  3342. }
  3343. client := &http.Client{}
  3344. data["psn_no"] = his.PsnNo
  3345. data["mdtrt_id"] = his.Number
  3346. data["chrg_bchno"] = chrg_bchno
  3347. data["org_name"] = miConfig.OrgName
  3348. data["doctor"] = roles.UserName
  3349. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  3350. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  3351. data["fixmedins_code"] = miConfig.Code
  3352. data["balance_accounts_type"] = strconv.FormatInt(his.BalanceAccountsType, 10)
  3353. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  3354. data["dept_code"] = "15"
  3355. } else {
  3356. data["dept_code"] = department.Number
  3357. }
  3358. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  3359. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  3360. data["secret_key"] = miConfig.SecretKey
  3361. var ids []int64
  3362. for _, item := range prescriptions {
  3363. ids = append(ids, item.ID)
  3364. }
  3365. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3366. if config.IsOpen == 1 { //对接了医保,走医保流程
  3367. var res ResultFour
  3368. if miConfig.MdtrtareaAdmvs == "421300" {
  3369. bytesData, _ := json.Marshal(data)
  3370. req, _ := http.NewRequest("POST", "http://192.168.124.4:9532/"+"hbyb/2204", bytes.NewReader(bytesData))
  3371. resp, _ := client.Do(req)
  3372. defer resp.Body.Close()
  3373. body, ioErr := ioutil.ReadAll(resp.Body)
  3374. if ioErr != nil {
  3375. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3377. return
  3378. }
  3379. var respJSON map[string]interface{}
  3380. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  3381. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3383. return
  3384. }
  3385. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3386. userJSONBytes, _ := json.Marshal(respJSON)
  3387. fmt.Println("log")
  3388. fmt.Println(string(userJSONBytes))
  3389. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3390. utils.ErrorLog("解析失败:%v", err)
  3391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3392. return
  3393. }
  3394. } else {
  3395. result, request_log := service.Gdyb2204(his.PsnNo, his.Number, prescriptions, chrg_bchno, miConfig.OrgName, roles.UserName, data["dept"].(string), data["fixmedins_code"].(string), data["dept_code"].(string), data["doctor_id"].(string), miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, data["balance_accounts_type"].(string))
  3396. var dat map[string]interface{}
  3397. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3398. fmt.Println(dat)
  3399. } else {
  3400. fmt.Println(err)
  3401. }
  3402. saveLog(result, request_log, "2204", "上传费用明细")
  3403. userJSONBytes, _ := json.Marshal(dat)
  3404. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3405. utils.ErrorLog("解析失败:%v", err)
  3406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3407. return
  3408. }
  3409. }
  3410. if res.Infcode == 0 {
  3411. order := &models.HisOrder{
  3412. UserOrgId: adminUser.CurrentOrgId,
  3413. HisPatientId: his.ID,
  3414. PatientId: his.PatientId,
  3415. SettleAccountsDate: recordDateTime,
  3416. Ctime: time.Now().Unix(),
  3417. Mtime: time.Now().Unix(),
  3418. Status: 1,
  3419. Number: chrg_bchno,
  3420. Infcode: res.Infcode,
  3421. WarnMsg: res.WarnMsg,
  3422. Cainfo: res.Cainfo,
  3423. ErrMsg: res.ErrMsg,
  3424. RespondTime: res.RefmsgTime,
  3425. InfRefmsgid: res.InfRefmsgid,
  3426. OrderStatus: 1,
  3427. IsMedicineInsurance: 1,
  3428. SettleType: settle_accounts_type,
  3429. SettleStartTime: start_time,
  3430. SettleEndTime: end_time,
  3431. Creator: roles.AdminUserId,
  3432. Modify: roles.AdminUserId,
  3433. PType: 2,
  3434. Diagnosis: diagnosis_id,
  3435. }
  3436. err = service.CreateOrder(order)
  3437. if err != nil {
  3438. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  3439. return
  3440. }
  3441. for _, item := range res.Output.Result {
  3442. temp := strings.Split(item.FeedetlSn, "-")
  3443. var advice_id int64 = 0
  3444. var project_id int64 = 0
  3445. var types int64 = 0
  3446. id, _ := strconv.ParseInt(temp[2], 10, 64)
  3447. types, _ = strconv.ParseInt(temp[1], 10, 64)
  3448. if temp[1] == "1" {
  3449. advice_id = id
  3450. project_id = 0
  3451. } else if temp[1] == "2" {
  3452. advice_id = 0
  3453. project_id = id
  3454. }
  3455. info := &models.HisOrderInfo{
  3456. OrderNumber: order.Number,
  3457. FeedetlSn: item.FeedetlSn,
  3458. UploadDate: time.Now().Unix(),
  3459. AdviceId: advice_id,
  3460. DetItemFeeSumamt: item.DetItemFeeSumamt,
  3461. Cnt: item.Cnt,
  3462. Pric: float64(item.Pric),
  3463. PatientId: his.PatientId,
  3464. PricUplmtAmt: item.PricUplmtAmt,
  3465. SelfpayProp: item.SelfpayProp,
  3466. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  3467. OverlmtAmt: item.OverlmtAmt,
  3468. PreselfpayAmt: item.PreselfpayAmt,
  3469. BasMednFlag: item.BasMednFlag,
  3470. MedChrgitmType: item.MedChrgitmType,
  3471. HiNegoDrugFlag: item.HiNegoDrugFlag,
  3472. Status: 1,
  3473. Memo: item.Memo,
  3474. Mtime: time.Now().Unix(),
  3475. InscpScpAmt: item.InscpScpAmt,
  3476. DrtReimFlag: item.DrtReimFlag,
  3477. Ctime: time.Now().Unix(),
  3478. ListSpItemFlag: item.ListSpItemFlag,
  3479. ChldMedcFlag: item.ChldMedcFlag,
  3480. LmtUsedFlag: item.LmtUsedFlag,
  3481. ChrgitmLv: item.ChrgitmLv,
  3482. UserOrgId: adminUser.CurrentOrgId,
  3483. HisPatientId: his.ID,
  3484. OrderId: order.ID,
  3485. ProjectId: project_id,
  3486. Type: types,
  3487. }
  3488. service.CreateOrderInfo(info)
  3489. }
  3490. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  3491. service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, his_patient_id, chrg_bchno, recordDateTime)
  3492. var total float64
  3493. for _, item := range prescriptions {
  3494. if item.Type == 1 { //药品
  3495. for _, subItem := range item.HisDoctorAdviceInfo {
  3496. total = total + (subItem.Price * subItem.PrescribingNumber)
  3497. }
  3498. }
  3499. if item.Type == 2 { //项目
  3500. for _, subItem := range item.HisPrescriptionProject {
  3501. total = total + (subItem.Price * float64(subItem.Count))
  3502. }
  3503. }
  3504. }
  3505. for _, item := range prescriptions {
  3506. for _, subItem := range item.HisAdditionalCharge {
  3507. total = total + (subItem.Price * float64(subItem.Count))
  3508. }
  3509. }
  3510. allTotal := fmt.Sprintf("%.2f", total)
  3511. if res.Infcode == 0 {
  3512. var rf []*ResultFive
  3513. json.Unmarshal([]byte(his.Iinfo), &rf)
  3514. chrg_bchno := chrg_bchno
  3515. cert_no := his.Certno
  3516. var insutypes []string
  3517. var insutype string
  3518. var is390 int = 0
  3519. var is310 int = 0
  3520. for _, item := range rf {
  3521. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  3522. insutypes = append(insutypes, item.Insutype)
  3523. }
  3524. }
  3525. if len(insutypes) == 1 {
  3526. insutype = insutypes[0]
  3527. } else {
  3528. for _, i := range insutypes {
  3529. if i == "390" {
  3530. is390 = 1
  3531. }
  3532. if i == "310" {
  3533. is310 = 1
  3534. }
  3535. }
  3536. }
  3537. if is390 == 1 {
  3538. insutype = "390"
  3539. }
  3540. if is310 == 1 {
  3541. insutype = "310"
  3542. }
  3543. if len(insutypes) == 0 {
  3544. insutype = "310"
  3545. }
  3546. //insutype = "390"
  3547. if his.IdCardType == 1 {
  3548. cert_no = his.MedicalInsuranceNumber
  3549. } else {
  3550. cert_no = his.Certno
  3551. }
  3552. var res ResultSeven
  3553. if miConfig.MdtrtareaAdmvs == "421300" {
  3554. api := "http://192.168.124.4:9532/" + "hbyb/2206?psn_no=" + his.PsnNo + "&mdtrt_id=" +
  3555. his.Number + "&chrg_bchno=" + chrg_bchno + "&org_name=" + miConfig.OrgName +
  3556. "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  3557. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3558. "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(his.IdCardType, 10) +
  3559. "&certificates=" + strconv.FormatInt(his.IdType, 10) + "&cert_no=" + cert_no +
  3560. "&insutype=" + insutype + "&total=" + allTotal + "&med_type=" + strconv.FormatInt(reg_type, 10)
  3561. resp, requestErr := http.Get(api)
  3562. if requestErr != nil {
  3563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3564. return
  3565. }
  3566. body, ioErr := ioutil.ReadAll(resp.Body)
  3567. if ioErr != nil {
  3568. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3570. return
  3571. }
  3572. var respJSON map[string]interface{}
  3573. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3574. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3576. return
  3577. }
  3578. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3579. result, _ := json.Marshal(respJSON)
  3580. fmt.Println("log")
  3581. fmt.Println(string(result))
  3582. if err := json.Unmarshal([]byte(result), &res); err != nil {
  3583. utils.ErrorLog("解析失败:%v", err)
  3584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3585. return
  3586. }
  3587. } else {
  3588. result, request_log := service.Gdyb2206(his.PsnNo, his.Number, chrg_bchno, cert_no, insutype, allTotal, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, strconv.FormatInt(reg_type, 10), his.IdCardType, 0, 0, 0, 0, his.IdType)
  3589. var dat map[string]interface{}
  3590. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3591. fmt.Println(dat)
  3592. } else {
  3593. fmt.Println(err)
  3594. }
  3595. saveLog(result, request_log, "2206", "预结算")
  3596. userJSONBytes, _ := json.Marshal(dat)
  3597. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3598. utils.ErrorLog("解析失败:%v", err)
  3599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3600. return
  3601. }
  3602. }
  3603. if res.Infcode != 0 {
  3604. errlog := &models.HisOrderError{
  3605. UserOrgId: adminUser.CurrentOrgId,
  3606. Ctime: time.Now().Unix(),
  3607. Mtime: time.Now().Unix(),
  3608. Number: chrg_bchno,
  3609. ErrMsg: res.ErrMsg,
  3610. Status: 1,
  3611. PatientId: id,
  3612. RecordTime: recordDateTime,
  3613. Stage: 20,
  3614. }
  3615. service.CreateErrMsgLog(errlog)
  3616. c.ServeSuccessJSON(map[string]interface{}{
  3617. "failed_code": -10,
  3618. "msg": res.ErrMsg,
  3619. })
  3620. return
  3621. } else {
  3622. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  3623. order.OrderStatus = 1
  3624. order.IsPre = 1
  3625. order.Status = 1
  3626. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  3627. order.SetlId = res.Output.Setlinfo.SetlID
  3628. order.PsnNo = res.Output.Setlinfo.PsnNo
  3629. order.PsnName = res.Output.Setlinfo.PsnName
  3630. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  3631. order.Certno = res.Output.Setlinfo.Certno
  3632. order.Gend = res.Output.Setlinfo.Gend
  3633. order.Naty = res.Output.Setlinfo.Naty
  3634. order.Age = res.Output.Setlinfo.Age
  3635. order.Insutype = res.Output.Setlinfo.Insutype
  3636. order.PsnType = res.Output.Setlinfo.PsnType
  3637. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  3638. order.SetlTime = res.Output.Setlinfo.SetlTime
  3639. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  3640. order.MedType = res.Output.Setlinfo.MedType
  3641. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  3642. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  3643. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  3644. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  3645. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  3646. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  3647. order.HifpPay = res.Output.Setlinfo.HifpPay
  3648. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  3649. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  3650. order.HifesPay = res.Output.Setlinfo.HifesPay
  3651. order.HifobPay = res.Output.Setlinfo.HifobPay
  3652. order.MafPay = res.Output.Setlinfo.MafPay
  3653. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  3654. order.OthPay = res.Output.Setlinfo.OthPay
  3655. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  3656. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  3657. order.AcctPay = res.Output.Setlinfo.AcctPay
  3658. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  3659. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  3660. order.Balc = res.Output.Setlinfo.Balc
  3661. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  3662. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  3663. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  3664. order.ClrWay = res.Output.Setlinfo.ClrWay
  3665. order.Creator = order.Creator
  3666. order.Modify = roles.AdminUserId
  3667. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  3668. detailStr := string(setlDetail)
  3669. order.SetlDetail = detailStr
  3670. //err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  3671. err = service.UpDateOrder(order)
  3672. if err == nil {
  3673. c.ServeSuccessJSON(map[string]interface{}{
  3674. "msg": "预结算成功",
  3675. })
  3676. } else {
  3677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  3678. return
  3679. }
  3680. }
  3681. } else {
  3682. adminUser := c.GetAdminUserInfo()
  3683. errlog := &models.HisOrderError{
  3684. UserOrgId: adminUser.CurrentOrgId,
  3685. Ctime: time.Now().Unix(),
  3686. Mtime: time.Now().Unix(),
  3687. ErrMsg: res.ErrMsg,
  3688. Status: 1,
  3689. PatientId: id,
  3690. RecordTime: recordDateTime,
  3691. Stage: 4,
  3692. }
  3693. service.CreateErrMsgLog(errlog)
  3694. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  3695. return
  3696. }
  3697. } else {
  3698. adminUser := c.GetAdminUserInfo()
  3699. errlog := &models.HisOrderError{
  3700. UserOrgId: adminUser.CurrentOrgId,
  3701. Ctime: time.Now().Unix(),
  3702. Mtime: time.Now().Unix(),
  3703. ErrMsg: res.ErrMsg,
  3704. Status: 1,
  3705. PatientId: id,
  3706. RecordTime: recordDateTime,
  3707. Stage: 4,
  3708. }
  3709. service.CreateErrMsgLog(errlog)
  3710. c.ServeSuccessJSON(map[string]interface{}{
  3711. "failed_code": -10,
  3712. "msg": res.ErrMsg,
  3713. })
  3714. return
  3715. }
  3716. }
  3717. }
  3718. }
  3719. //func (c *HisApiController) GetSettleInfo() {
  3720. // id, _ := c.GetInt64("id")
  3721. // order_id, _ := c.GetInt64("order_id")
  3722. //
  3723. // record_time := c.GetString("record_time")
  3724. // pay_way, _ := c.GetInt64("pay_way")
  3725. // pay_price, _ := c.GetFloat("pay_price")
  3726. // pay_card_no := c.GetString("pay_card_no")
  3727. // discount_price, _ := c.GetFloat("discount_price")
  3728. // preferential_price, _ := c.GetFloat("preferential_price")
  3729. // reality_price, _ := c.GetFloat("reality_price")
  3730. // found_price, _ := c.GetFloat("found_price")
  3731. // medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  3732. // private_price, _ := c.GetFloat("private_price")
  3733. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  3734. // admin_user_id, _ := c.GetInt64("admin_user_id")
  3735. //
  3736. // timeLayout := "2006-01-02"
  3737. // loc, _ := time.LoadLocation("Local")
  3738. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3739. // if err != nil {
  3740. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3741. // return
  3742. // }
  3743. // recordDateTime := theTime.Unix()
  3744. // adminUser := c.GetAdminUserInfo()
  3745. //
  3746. // var prescriptions []*models.HisPrescription
  3747. //
  3748. // data := make(map[string]interface{})
  3749. // if settle_accounts_type == 1 { //日结
  3750. // prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  3751. // data["pre"] = prescriptions
  3752. //
  3753. // } else { //月结
  3754. // start_time_str := c.GetString("start_time")
  3755. // end_time_str := c.GetString("end_time")
  3756. // timeLayout := "2006-01-02"
  3757. // loc, _ := time.LoadLocation("Local")
  3758. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  3759. // if err != nil {
  3760. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3761. // return
  3762. // }
  3763. // recordStartTime := theStartTime.Unix()
  3764. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3765. // if err != nil {
  3766. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3767. // return
  3768. // }
  3769. // recordEndTime := theEndTime.Unix()
  3770. // prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  3771. // data["pre"] = prescriptions
  3772. //
  3773. // }
  3774. //
  3775. // roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3776. //
  3777. // his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  3778. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3779. // patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  3780. // strconv.FormatInt(his.PatientId, 10)
  3781. //
  3782. // order_src, _ := service.GetHisOrderByID(order_id)
  3783. //
  3784. // config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3785. // if config.IsOpen == 1 { //对接了医保,走医保流程
  3786. //
  3787. // var total float64
  3788. // for _, item := range prescriptions {
  3789. // if item.Type == 1 { //药品
  3790. // for _, subItem := range item.HisDoctorAdviceInfo {
  3791. // total = total + (subItem.Price * subItem.PrescribingNumber)
  3792. // }
  3793. // }
  3794. // if item.Type == 2 { //项目
  3795. // for _, subItem := range item.HisPrescriptionProject {
  3796. // total = total + (subItem.Price * float64(subItem.Count))
  3797. // }
  3798. // }
  3799. // }
  3800. //
  3801. // for _, item := range prescriptions {
  3802. // for _, subItem := range item.HisAdditionalCharge {
  3803. // total = total + (subItem.Price * float64(subItem.Count))
  3804. // }
  3805. // }
  3806. //
  3807. // allTotal := fmt.Sprintf("%.2f", total)
  3808. // var rf []*ResultFive
  3809. // json.Unmarshal([]byte(his.Iinfo), &rf)
  3810. // psn_no := order_src.PsnNo
  3811. // mdtrt_id := order_src.MdtrtId
  3812. // chrg_bchno := order_src.Number
  3813. // cert_no := order_src.Certno
  3814. // insutype := rf[0].Insutype
  3815. //
  3816. // if his.IdCardType == 1 {
  3817. // cert_no = his.MedicalInsuranceNumber
  3818. // } else {
  3819. // cert_no = his.Certno
  3820. // }
  3821. //
  3822. // result, src_resquest := service.Gdyb2207(his.PsnNo, his.Number, chrg_bchno, cert_no, insutype, strconv.FormatFloat(total, 'E', -1, 64) ,miConfig.OrgName,roles.UserName,miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, strconv.FormatInt(patientPrescription.RegisterType, 10),his.IdCardType, order_src.FulamtOwnpayAmt,order_src.OverlmtSelfPay,order_src.PreselfpayAmt,order_src.InscpScpAmt)
  3823. // var dat map[string]interface{}
  3824. // if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3825. // fmt.Println(dat)
  3826. // } else {
  3827. // fmt.Println(err)
  3828. // }
  3829. //
  3830. // userJSONBytes, _ := json.Marshal(dat)
  3831. //
  3832. //
  3833. //
  3834. // var res ResultSeven
  3835. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3836. // utils.ErrorLog("解析失败:%v", err)
  3837. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3838. // return
  3839. // }
  3840. // if res.Infcode == -1 {
  3841. // errlog := &models.HisOrderError{
  3842. // UserOrgId: adminUser.CurrentOrgId,
  3843. // Ctime: time.Now().Unix(),
  3844. // Mtime: time.Now().Unix(),
  3845. // Number: chrg_bchno,
  3846. // ErrMsg: res.ErrMsg,
  3847. // Status: 1,
  3848. // PatientId: id,
  3849. // RecordTime: recordDateTime,
  3850. // Stage: 6,
  3851. // }
  3852. // service.CreateErrMsgLog(errlog)
  3853. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  3854. // return
  3855. // } else {
  3856. // order_src.OrderStatus = 2
  3857. // order_src.PayWay = pay_way
  3858. // order_src.PayPrice = pay_price
  3859. // order_src.PayCardNo = pay_card_no
  3860. // order_src.DiscountPrice = discount_price
  3861. // order_src.PreferentialPrice = preferential_price
  3862. // order_src.RealityPrice = reality_price
  3863. // order_src.FoundPrice = found_price
  3864. // order_src.MedicalInsurancePrice = medical_insurance_price
  3865. // order_src.PrivatePrice = private_price
  3866. // order_src.MdtrtId = res.Output.Setlinfo.MdtrtID
  3867. // order_src.SetlId = res.Output.Setlinfo.SetlID
  3868. // order_src.PsnNo = res.Output.Setlinfo.PsnNo
  3869. // order_src.PsnName = res.Output.Setlinfo.PsnName
  3870. // order_src.PsnCertType = res.Output.Setlinfo.PsnCertType
  3871. // order_src.Certno = res.Output.Setlinfo.Certno
  3872. // order_src.Gend = res.Output.Setlinfo.Gend
  3873. // order_src.Naty = res.Output.Setlinfo.Naty
  3874. // order_src.Age = res.Output.Setlinfo.Age
  3875. // order_src.Insutype = res.Output.Setlinfo.Insutype
  3876. // order_src.PsnType = res.Output.Setlinfo.PsnType
  3877. // order_src.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  3878. // order_src.SetlTime = res.Output.Setlinfo.SetlTime
  3879. // order_src.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  3880. // order_src.MedType = res.Output.Setlinfo.MedType
  3881. // order_src.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  3882. // order_src.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  3883. // order_src.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  3884. // order_src.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  3885. // order_src.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  3886. // order_src.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  3887. // order_src.HifpPay = res.Output.Setlinfo.HifpPay
  3888. // order_src.CvlservPay = res.Output.Setlinfo.CvlservPay
  3889. // order_src.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  3890. // order_src.HifesPay = res.Output.Setlinfo.HifesPay
  3891. // order_src.HifobPay = res.Output.Setlinfo.HifobPay
  3892. // order_src.MafPay = res.Output.Setlinfo.MafPay
  3893. // order_src.OthPay = res.Output.Setlinfo.OthPay
  3894. // order_src.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  3895. // order_src.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  3896. // order_src.AcctPay = res.Output.Setlinfo.AcctPay
  3897. // order_src.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  3898. // order_src.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  3899. // order_src.Balc = res.Output.Setlinfo.Balc
  3900. // order_src.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  3901. // order_src.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  3902. // order_src.ClrOptins = res.Output.Setlinfo.ClrOptins
  3903. // order_src.ClrWay = res.Output.Setlinfo.ClrWay
  3904. // order_src.Creator = order_src.Creator
  3905. // order_src.Modify = roles.ID
  3906. // order_src.RequestLog = src_resquest
  3907. // setlDetail, _ := json.Marshal(res.Output.Setldetail)
  3908. // detailStr := string(setlDetail)
  3909. // order_src.SetlDetail = detailStr
  3910. // err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  3911. // err = service.UpDateOrder(order_src)
  3912. //
  3913. // if err == nil {
  3914. // c.ServeSuccessJSON(map[string]interface{}{
  3915. // "msg": "结算成功",
  3916. // })
  3917. // } else {
  3918. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  3919. // return
  3920. // }
  3921. // }
  3922. // }
  3923. //}
  3924. //退款
  3925. func (c *HisApiController) Refund() {
  3926. order_id, _ := c.GetInt64("order_id")
  3927. admin_user_id, _ := c.GetInt64("admin_user_id")
  3928. //record_time := c.GetString("record_time")
  3929. //patient_id, _ := c.GetInt64("patient_id")
  3930. //timeLayout := "2006-01-02"
  3931. //loc, _ := time.LoadLocation("Local")
  3932. adminUser := c.GetAdminUserInfo()
  3933. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3934. //if err != nil {
  3935. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3936. // return
  3937. //}
  3938. //recordDateTime := theTime.Unix()
  3939. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3940. var order models.HisOrder
  3941. order, _ = service.GetHisOrderByID(order_id)
  3942. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3943. if order.ID == 0 {
  3944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3945. return
  3946. //order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  3947. }
  3948. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3949. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3950. if config.IsOpen == 1 { //对接了医保,走医保流程
  3951. var res ResultSixteen
  3952. var src_resquest string
  3953. var result string
  3954. if miConfig.MdtrtareaAdmvs == "421300" {
  3955. api3 := "http://192.168.124.4:9532/" + "hbyb/2208?psn_no=" + order.PsnNo +
  3956. "&mdtrt_id=" + order.Number + "&setl_id=" + order.SetlId + "&doctor=" + roles.UserName + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  3957. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3958. resp3, requestErr3 := http.Get(api3)
  3959. if requestErr3 != nil {
  3960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3961. return
  3962. }
  3963. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  3964. if ioErr3 != nil {
  3965. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  3966. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3967. return
  3968. }
  3969. var respJSON3 map[string]interface{}
  3970. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  3971. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3973. return
  3974. }
  3975. respJSON3 = respJSON3["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3976. userJSONBytes3, _ := json.Marshal(respJSON3)
  3977. fmt.Println("log")
  3978. fmt.Println(string(userJSONBytes3))
  3979. if err := json.Unmarshal(userJSONBytes3, &res); err != nil {
  3980. utils.ErrorLog("解析失败:%v", err)
  3981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3982. return
  3983. }
  3984. } else {
  3985. result, src_resquest = service.Gdyb2208(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  3986. var dat map[string]interface{}
  3987. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3988. fmt.Println(dat)
  3989. } else {
  3990. fmt.Println(err)
  3991. }
  3992. saveLog(result, src_resquest, "2208", "退费")
  3993. userJSONBytes, _ := json.Marshal(dat)
  3994. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3995. utils.ErrorLog("解析失败:%v", err)
  3996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3997. return
  3998. }
  3999. }
  4000. if res.Infcode == 0 {
  4001. var res2 ResultSix
  4002. if miConfig.MdtrtareaAdmvs == "421300" {
  4003. api3 := "http://192.168.124.4:9532/" + "hbyb/2205?psn_no=" + order.PsnNo +
  4004. "&mdtrt_id=" + order.Number + "&chrg_bchno=" + order.Number + "&doctor=" + roles.UserName + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  4005. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4006. resp3, requestErr3 := http.Get(api3)
  4007. if requestErr3 != nil {
  4008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4009. return
  4010. }
  4011. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  4012. if ioErr3 != nil {
  4013. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  4014. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4015. return
  4016. }
  4017. var respJSON3 map[string]interface{}
  4018. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  4019. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4021. return
  4022. }
  4023. respJSON3 = respJSON3["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4024. userJSONBytes3, _ := json.Marshal(respJSON3)
  4025. fmt.Println("log")
  4026. fmt.Println(string(userJSONBytes3))
  4027. if err := json.Unmarshal(userJSONBytes3, &res2); err != nil {
  4028. utils.ErrorLog("解析失败:%v", err)
  4029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4030. return
  4031. }
  4032. } else {
  4033. result2, src_request := service.Gdyb2205(order.PsnNo, order.MdtrtId, order.Number, miConfig.OrgName, roles.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  4034. var dat map[string]interface{}
  4035. if err := json.Unmarshal([]byte(result2), &dat); err == nil {
  4036. fmt.Println(dat)
  4037. } else {
  4038. fmt.Println(err)
  4039. }
  4040. saveLog(result2, src_request, "2205", "撤销明细")
  4041. userJSONBytes, _ := json.Marshal(dat)
  4042. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  4043. utils.ErrorLog("解析失败:%v", err)
  4044. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4045. return
  4046. }
  4047. }
  4048. if res2.Infcode == 0 {
  4049. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, src_resquest, result)
  4050. if err == nil {
  4051. c.ServeSuccessJSON(map[string]interface{}{
  4052. "msg": "退费成功",
  4053. })
  4054. } else {
  4055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4056. return
  4057. }
  4058. } else {
  4059. c.ServeSuccessJSON(map[string]interface{}{
  4060. "code": -10,
  4061. "msg": res2.ErrMsg,
  4062. })
  4063. }
  4064. } else {
  4065. c.ServeSuccessJSON(map[string]interface{}{
  4066. "code": -10,
  4067. "msg": res.ErrMsg,
  4068. })
  4069. }
  4070. }
  4071. }
  4072. func (c *HisApiController) RefundNumber() {
  4073. record_time := c.GetString("record_time")
  4074. //patient_id, _ := c.GetInt64("patient_id")
  4075. admin_user_id, _ := c.GetInt64("admin_user_id")
  4076. his_patient_id, _ := c.GetInt64("id")
  4077. timeLayout := "2006-01-02"
  4078. loc, _ := time.LoadLocation("Local")
  4079. adminUser := c.GetAdminUserInfo()
  4080. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4081. fmt.Println(err)
  4082. if err != nil {
  4083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4084. return
  4085. }
  4086. recordDateTime := theTime.Unix()
  4087. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  4088. his, _ := service.GetHisPatientRecord(adminUser.CurrentOrgId, his_patient_id)
  4089. //patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  4090. //order, _ := service.GetHisOrderByID(order_id)
  4091. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4092. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4093. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4094. count, _ := service.GetOrderCountByNumber(adminUser.CurrentOrgId, his.PatientId, recordDateTime, his.Number)
  4095. if count > 0 {
  4096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4097. return
  4098. }
  4099. if config.IsOpen == 1 { //对接了医保,走医保流程
  4100. var res2 ResultSix
  4101. if miConfig.MdtrtareaAdmvs == "421300" {
  4102. api3 := "http://192.168.124.4:9532/" + "hbyb/2202?psn_no=" + his.PsnNo +
  4103. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + roles.UserName + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  4104. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4105. resp3, requestErr3 := http.Get(api3)
  4106. if requestErr3 != nil {
  4107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4108. return
  4109. }
  4110. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  4111. if ioErr3 != nil {
  4112. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  4113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4114. return
  4115. }
  4116. var respJSON3 map[string]interface{}
  4117. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  4118. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4120. return
  4121. }
  4122. respJSON3 = respJSON3["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4123. userJSONBytes3, _ := json.Marshal(respJSON3)
  4124. fmt.Println("log")
  4125. fmt.Println(string(userJSONBytes3))
  4126. if err := json.Unmarshal(userJSONBytes3, &res2); err != nil {
  4127. utils.ErrorLog("解析失败:%v", err)
  4128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4129. return
  4130. }
  4131. } else {
  4132. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  4133. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + roles.UserName + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  4134. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4135. resp3, requestErr3 := http.Get(api3)
  4136. if requestErr3 != nil {
  4137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4138. return
  4139. }
  4140. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  4141. if ioErr3 != nil {
  4142. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  4143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4144. return
  4145. }
  4146. var respJSON3 map[string]interface{}
  4147. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  4148. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4150. return
  4151. }
  4152. respJSON3 = respJSON3["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4153. userJSONBytes3, _ := json.Marshal(respJSON3)
  4154. if err := json.Unmarshal(userJSONBytes3, &res2); err != nil {
  4155. utils.ErrorLog("解析失败:%v", err)
  4156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4157. return
  4158. }
  4159. }
  4160. if res2.Infcode == 0 {
  4161. if err == nil {
  4162. c.ServeSuccessJSON(map[string]interface{}{
  4163. "msg": "退号成功",
  4164. })
  4165. service.UpdataRegStatusTwo(his_patient_id, recordDateTime, adminUser.CurrentOrgId)
  4166. } else {
  4167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4168. return
  4169. }
  4170. } else {
  4171. c.ServeSuccessJSON(map[string]interface{}{
  4172. "code": -10,
  4173. "msg": res2.ErrMsg,
  4174. })
  4175. }
  4176. } else {
  4177. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  4178. //if err == nil {
  4179. // c.ServeSuccessJSON(map[string]interface{}{
  4180. // "msg": "退费成功",
  4181. // })
  4182. //} else {
  4183. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4184. // return
  4185. //}
  4186. }
  4187. }
  4188. func (c *HisApiController) RefundDetail() {
  4189. order_id, _ := c.GetInt64("order_id")
  4190. his_patient_id, _ := c.GetInt64("his_patient_id")
  4191. number := c.GetString("number")
  4192. record_time := c.GetString("record_time")
  4193. patient_id, _ := c.GetInt64("patient_id")
  4194. timeLayout := "2006-01-02"
  4195. loc, _ := time.LoadLocation("Local")
  4196. adminUser := c.GetAdminUserInfo()
  4197. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4198. fmt.Println(err)
  4199. if err != nil {
  4200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4201. return
  4202. }
  4203. recordDateTime := theTime.Unix()
  4204. his, _ := service.GetNewVMHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  4205. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  4206. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4207. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4208. var order models.HisOrder
  4209. order, _ = service.GetHisOrderByID(order_id)
  4210. if order.ID == 0 {
  4211. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  4212. }
  4213. if config.IsOpen == 1 { //对接了医保,走医保流程
  4214. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  4215. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  4216. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4217. resp2, requestErr2 := http.Get(api2)
  4218. if requestErr2 != nil {
  4219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4220. return
  4221. }
  4222. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  4223. if ioErr2 != nil {
  4224. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  4225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4226. return
  4227. }
  4228. var respJSON2 map[string]interface{}
  4229. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  4230. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4232. return
  4233. }
  4234. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId, "", "")
  4235. if err == nil {
  4236. c.ServeSuccessJSON(map[string]interface{}{
  4237. "msg": "退费成功",
  4238. })
  4239. } else {
  4240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4241. return
  4242. }
  4243. } else {
  4244. err := service.UpdataOrderStatus(order_id, 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. }
  4254. }
  4255. //对账
  4256. func (c *HisApiController) GetCheckAccount() {
  4257. start_time := c.GetString("start_time")
  4258. end_time := c.GetString("end_time")
  4259. insutype := c.GetString("insutype")
  4260. clr_type := c.GetString("clr_type")
  4261. admin_user_id, _ := c.GetInt64("admin_user_id")
  4262. adminUser := c.GetAdminUserInfo()
  4263. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4264. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4265. timeLayout := "2006-01-02"
  4266. loc, _ := time.LoadLocation("Local")
  4267. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4268. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4269. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  4270. //orders_two, _ := service.GetOrderByTimeThree(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  4271. fixmedins_setl_cnt := int64(len(orders))
  4272. //
  4273. ////撤销的算2条数据为一笔
  4274. //for _, item := range orders_two {
  4275. // if item.OrderStatus == 3 {
  4276. // fixmedins_setl_cnt = fixmedins_setl_cnt + 1
  4277. // }
  4278. //}
  4279. var medfee_sumamt float64
  4280. var acct_pay float64
  4281. var fund_pay_sumamt float64
  4282. for _, item := range orders {
  4283. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  4284. acct_pay = acct_pay + item.AcctPay
  4285. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  4286. }
  4287. var user_name string
  4288. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4289. if role.ID == 0 {
  4290. user_name = "xxx"
  4291. } else {
  4292. user_name = role.UserName
  4293. }
  4294. if config.IsOpen == 1 {
  4295. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  4296. "insutype=" + insutype +
  4297. "&clr_type=" + clr_type +
  4298. "&setl_optins=" + "定点医保中心" +
  4299. "&stmt_begndate=" + start_time +
  4300. "&stm_enddate=" + end_time +
  4301. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  4302. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  4303. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  4304. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  4305. "&fixmedins_code=" + miConfig.Code +
  4306. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  4307. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  4308. "&secret_key=" + miConfig.SecretKey +
  4309. "&org_name=" + miConfig.OrgName +
  4310. "&doctor=" + user_name
  4311. fmt.Println(api)
  4312. resp, requestErr := http.Get(api)
  4313. if requestErr != nil {
  4314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4315. return
  4316. }
  4317. body, ioErr := ioutil.ReadAll(resp.Body)
  4318. fmt.Println(body)
  4319. if ioErr != nil {
  4320. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4321. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4322. return
  4323. }
  4324. var respJSON map[string]interface{}
  4325. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4326. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4328. return
  4329. }
  4330. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4331. userJSONBytes, _ := json.Marshal(respJSON)
  4332. var res ResultEight
  4333. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4334. utils.ErrorLog("解析失败:%v", err)
  4335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4336. return
  4337. }
  4338. if res.Infcode == 0 {
  4339. if res.Output.Stmtinfo.StmtRslt == "0" {
  4340. micc := &models.MedicalInsuranceCostCompare{
  4341. StartTime: startime.Unix(),
  4342. EndTime: endtime.Unix(),
  4343. Insutype: insutype,
  4344. CheckType: 1,
  4345. Num: fixmedins_setl_cnt,
  4346. Mtime: time.Now().Unix(),
  4347. Status: 1,
  4348. UserOrgId: adminUser.CurrentOrgId,
  4349. CostTotal: medfee_sumamt,
  4350. FuncTotal: fund_pay_sumamt,
  4351. PsnPay: acct_pay,
  4352. Creator: admin_user_id,
  4353. Ctime: time.Now().Unix(),
  4354. }
  4355. err := service.CreateMedicalInsuranceCostCompareRecord(micc)
  4356. if err == nil {
  4357. c.ServeSuccessJSON(map[string]interface{}{
  4358. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  4359. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  4360. })
  4361. } else {
  4362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4363. }
  4364. } else {
  4365. c.ServeSuccessJSON(map[string]interface{}{
  4366. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  4367. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  4368. })
  4369. }
  4370. } else {
  4371. c.ServeSuccessJSON(map[string]interface{}{
  4372. "code": -10,
  4373. "msg": res.ErrMsg,
  4374. })
  4375. }
  4376. }
  4377. }
  4378. func (c *HisApiController) Check310() {
  4379. adminUser := c.GetAdminUserInfo()
  4380. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4381. var user_name string
  4382. user_name = "xxx"
  4383. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  4384. "insutype=" + "310" +
  4385. "&clr_type=" + "11" +
  4386. "&setl_optins=" + "定点医保中心" +
  4387. "&stmt_begndate=" + "2021-03-01" +
  4388. "&stm_enddate=" + "2021-03-31" +
  4389. "&medfee_sumamt=" + "11521" +
  4390. "&fund_pay_sumamt=" + "10166.66" +
  4391. "&acct_pay=" + "0" +
  4392. "&fixmedins_setl_cnt=" + "7" +
  4393. "&fixmedins_code=" + miConfig.Code +
  4394. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  4395. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  4396. "&secret_key=" + miConfig.SecretKey +
  4397. "&org_name=" + miConfig.OrgName +
  4398. "&doctor=" + user_name
  4399. fmt.Println(api)
  4400. resp, requestErr := http.Get(api)
  4401. if requestErr != nil {
  4402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4403. return
  4404. }
  4405. body, ioErr := ioutil.ReadAll(resp.Body)
  4406. fmt.Println(body)
  4407. if ioErr != nil {
  4408. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4410. return
  4411. }
  4412. var respJSON map[string]interface{}
  4413. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4414. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4416. return
  4417. }
  4418. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4419. userJSONBytes, _ := json.Marshal(respJSON)
  4420. var res ResultEight
  4421. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4422. utils.ErrorLog("解析失败:%v", err)
  4423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4424. return
  4425. }
  4426. }
  4427. func (c *HisApiController) Check390() {
  4428. adminUser := c.GetAdminUserInfo()
  4429. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4430. var user_name string
  4431. user_name = "张俊杰"
  4432. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  4433. "insutype=" + "390" +
  4434. "&clr_type=" + "11" +
  4435. "&setl_optins=" + "定点医保中心" +
  4436. "&stmt_begndate=" + "2021-03-01" +
  4437. "&stm_enddate=" + "2021-03-31" +
  4438. "&medfee_sumamt=" + "209318.43" +
  4439. "&fund_pay_sumamt=" + "188029.12" +
  4440. "&acct_pay=" + "0" +
  4441. "&fixmedins_setl_cnt=" + "48" +
  4442. "&fixmedins_code=" + miConfig.Code +
  4443. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  4444. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  4445. "&secret_key=" + miConfig.SecretKey +
  4446. "&org_name=" + miConfig.OrgName +
  4447. "&doctor=" + user_name
  4448. fmt.Println(api)
  4449. resp, requestErr := http.Get(api)
  4450. if requestErr != nil {
  4451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4452. return
  4453. }
  4454. body, ioErr := ioutil.ReadAll(resp.Body)
  4455. fmt.Println(body)
  4456. if ioErr != nil {
  4457. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4459. return
  4460. }
  4461. var respJSON map[string]interface{}
  4462. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4463. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4465. return
  4466. }
  4467. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4468. userJSONBytes, _ := json.Marshal(respJSON)
  4469. var res ResultEight
  4470. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4471. utils.ErrorLog("解析失败:%v", err)
  4472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4473. return
  4474. }
  4475. }
  4476. //对账明细
  4477. func (c *HisApiController) GetCheckDetailAccount() {
  4478. start_time := c.GetString("start_time")
  4479. end_time := c.GetString("end_time")
  4480. admin_user_id, _ := c.GetInt64("admin_user_id")
  4481. adminUser := c.GetAdminUserInfo()
  4482. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4483. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4484. timeLayout := "2006-01-02"
  4485. loc, _ := time.LoadLocation("Local")
  4486. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4487. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4488. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  4489. Mkdir(miConfig.OrgName)
  4490. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  4491. file_name := file + ".txt"
  4492. zip_name := file + ".zip"
  4493. zip_path := miConfig.OrgName + "/" + zip_name
  4494. file_path := miConfig.OrgName + "/" + file_name
  4495. decimal.DivisionPrecision = 2
  4496. var medfee_sumamt float64
  4497. var psn_cash_pay float64
  4498. var fund_pay_sumamt float64
  4499. fixmedins_setl_cnt := int64(len(orders))
  4500. for _, item := range orders {
  4501. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  4502. psn_cash_pay = psn_cash_pay + item.PsnCashPay
  4503. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  4504. }
  4505. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  4506. defer f.Close()
  4507. if err != nil {
  4508. fmt.Println(err.Error())
  4509. } else {
  4510. for _, item := range orders {
  4511. var refd_setl_flag string
  4512. if item.OrderStatus == 2 {
  4513. refd_setl_flag = "0"
  4514. var str string
  4515. str = item.SetlId + " " +
  4516. item.MdtrtId + " " +
  4517. item.PsnNo + " " +
  4518. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  4519. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  4520. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\r\n"
  4521. _, err = f.Write([]byte(str))
  4522. }
  4523. if item.OrderStatus == 3 {
  4524. var str string
  4525. str = item.SetlId + " " +
  4526. item.MdtrtId + " " +
  4527. item.PsnNo + " " +
  4528. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  4529. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  4530. fmt.Sprintf("%.2f", item.AcctPay) + " " + "1" + "\r\n"
  4531. _, err = f.Write([]byte(str))
  4532. var str2 string
  4533. str2 = item.SetlId + " " +
  4534. item.MdtrtId + " " +
  4535. item.PsnNo + " " +
  4536. fmt.Sprintf("%.2f", 0-item.MedfeeSumamt) + " " +
  4537. fmt.Sprintf("%.2f", 0-item.FundPaySumamt) + " " +
  4538. fmt.Sprintf("%.2f", 0-item.AcctPay) + " " + "1" + "\r\n"
  4539. _, err = f.Write([]byte(str2))
  4540. }
  4541. }
  4542. }
  4543. Zip(file_path, zip_path)
  4544. fmt.Println(ReadFile(zip_path))
  4545. fmt.Println(string(ReadFile(zip_path)))
  4546. if config.IsOpen == 1 {
  4547. var user_name string
  4548. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4549. if role.ID == 0 {
  4550. user_name = "管理员"
  4551. } else {
  4552. user_name = role.UserName
  4553. }
  4554. baseParams := models.BaseParams{
  4555. SecretKey: miConfig.SecretKey,
  4556. FixmedinsCode: miConfig.Code,
  4557. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4558. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4559. OrgName: miConfig.OrgName,
  4560. Doctor: user_name,
  4561. }
  4562. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  4563. var dat map[string]interface{}
  4564. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4565. fmt.Println(dat)
  4566. } else {
  4567. fmt.Println(err)
  4568. }
  4569. userJSONBytes, _ := json.Marshal(dat)
  4570. var res ResultNine
  4571. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4572. utils.ErrorLog("解析失败:%v", err)
  4573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4574. return
  4575. }
  4576. if res.Infcode == 0 {
  4577. fileNo := res.Output.FileQuryNo
  4578. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  4579. "file_qury_no=" + fileNo +
  4580. "&setl_optins=" + "定点医保中心" +
  4581. "&stmt_begndate=" + start_time +
  4582. "&stm_enddate=" + end_time +
  4583. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  4584. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  4585. "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) +
  4586. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  4587. "&fixmedins_code=" + miConfig.Code +
  4588. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  4589. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  4590. "&secret_key=" + miConfig.SecretKey +
  4591. "&org_name=" + miConfig.OrgName +
  4592. "&doctor=" + user_name
  4593. resp, requestErr := http.Get(api)
  4594. if requestErr != nil {
  4595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4596. return
  4597. }
  4598. body, ioErr := ioutil.ReadAll(resp.Body)
  4599. if ioErr != nil {
  4600. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4601. c.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. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4608. return
  4609. }
  4610. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4611. userJSONBytes, _ := json.Marshal(respJSON)
  4612. var res ResultTen
  4613. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4614. utils.ErrorLog("解析失败:%v", err)
  4615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4616. return
  4617. }
  4618. if res.Infcode == 0 {
  4619. service.Gdyb9102(baseParams, zip_name, fileNo)
  4620. micc := &models.MedicalInsuranceCostCompare{
  4621. StartTime: startime.Unix(),
  4622. EndTime: endtime.Unix(),
  4623. Insutype: "0",
  4624. CheckType: 2,
  4625. Num: fixmedins_setl_cnt,
  4626. Mtime: time.Now().Unix(),
  4627. Status: 1,
  4628. UserOrgId: adminUser.CurrentOrgId,
  4629. CostTotal: medfee_sumamt,
  4630. FuncTotal: fund_pay_sumamt,
  4631. PsnPay: psn_cash_pay,
  4632. Creator: admin_user_id,
  4633. Ctime: time.Now().Unix(),
  4634. }
  4635. service.CreateMedicalInsuranceCostCompareRecord(micc)
  4636. c.ServeSuccessJSON(map[string]interface{}{
  4637. "msg": "明细对账成功",
  4638. })
  4639. }
  4640. } else {
  4641. }
  4642. }
  4643. }
  4644. func (c *HisApiController) GetSettleAccounts() {
  4645. //id, _ := c.GetInt64("id")
  4646. //record_time := c.GetString("record_time")
  4647. order_id, _ := c.GetInt64("order_id")
  4648. admin_user_id, _ := c.GetInt64("admin_user_id")
  4649. //timeLayout := "2006-01-02"
  4650. //loc, _ := time.LoadLocation("Local")
  4651. //
  4652. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4653. //if err != nil {
  4654. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4655. // return
  4656. //}
  4657. //recordDateTime := theTime.Unix()
  4658. adminUser := c.GetAdminUserInfo()
  4659. order, _ := service.GetHisOrderByID(order_id)
  4660. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  4661. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  4662. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  4663. orderInfos = append(orderInfos, orderInfos_two...)
  4664. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  4665. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  4666. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  4667. //var config []*models.HisXtDiagnoseConfig
  4668. var name string
  4669. for _, item := range diagnosis_ids {
  4670. id, _ := strconv.ParseInt(item, 10, 64)
  4671. diagnosisConfig, _ := service.FindDiagnoseById(id)
  4672. if len(name) == 0 {
  4673. name = diagnosisConfig.ClassName
  4674. } else {
  4675. name = name + "," + diagnosisConfig.ClassName
  4676. }
  4677. }
  4678. var bedCostTotal float64 = 0 //床位总费
  4679. var bedCostSelfTotal float64 = 0 //床位自费
  4680. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  4681. var operationCostTotal float64 = 0 //手术费
  4682. var operationCostSelfTotal float64 = 0 //手术费
  4683. var operationCostPartSelfTotal float64 = 0 //手术费
  4684. var otherCostTotal float64 = 0 //其他费用
  4685. var otherCostSelfTotal float64 = 0 //其他费用
  4686. var otherCostPartSelfTotal float64 = 0 //其他费用
  4687. var materialCostTotal float64 = 0 //材料费
  4688. var materialCostSelfTotal float64 = 0 //材料费
  4689. var materialCostPartSelfTotal float64 = 0 //材料费
  4690. var westernMedicineCostTotal float64 = 0 //西药费
  4691. var westernMedicineCostSelfTotal float64 = 0 //西药费
  4692. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  4693. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  4694. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  4695. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  4696. var checkCostTotal float64 = 0 //检查费
  4697. var checkCostSelfTotal float64 = 0 //检查费
  4698. var checkCostPartSelfTotal float64 = 0 //检查费
  4699. var laboratoryCostTotal float64 = 0 //化验费
  4700. var laboratoryCostSelfTotal float64 = 0 //化验费
  4701. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  4702. var treatCostTotal float64 = 0 //治疗费用
  4703. var treatCostSelfTotal float64 = 0 //治疗费用
  4704. var treatCostPartSelfTotal float64 = 0 //治疗费用
  4705. decimal.DivisionPrecision = 2
  4706. for _, item := range orderInfos {
  4707. if item.MedChrgitmType == "01" { //床位费
  4708. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4709. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4710. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4711. }
  4712. if item.MedChrgitmType == "03" { //检查费
  4713. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4714. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4715. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4716. }
  4717. if item.MedChrgitmType == "04" { //化验费
  4718. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4719. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4720. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4721. }
  4722. if item.MedChrgitmType == "05" { //治疗费
  4723. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4724. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4725. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4726. }
  4727. if item.MedChrgitmType == "06" { //手术费
  4728. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4729. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4730. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4731. }
  4732. if item.MedChrgitmType == "08" { //材料费
  4733. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4734. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4735. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4736. }
  4737. if item.MedChrgitmType == "09" { //西药费
  4738. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4739. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4740. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4741. }
  4742. if item.MedChrgitmType == "11" { //中成费
  4743. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4744. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4745. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4746. }
  4747. if item.MedChrgitmType == "14" { //其他费
  4748. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4749. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4750. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4751. }
  4752. }
  4753. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4754. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4755. var user_name string
  4756. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4757. if role.ID == 0 {
  4758. user_name = "管理员"
  4759. } else {
  4760. user_name = role.UserName
  4761. }
  4762. baseParams := models.BaseParams{
  4763. SecretKey: miConfig.SecretKey,
  4764. FixmedinsCode: miConfig.Code,
  4765. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4766. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4767. OrgName: miConfig.OrgName,
  4768. Doctor: user_name,
  4769. }
  4770. businessParams := models.BusinessParams{
  4771. PsnNo: order.PsnNo,
  4772. MdtrtId: order.MdtrtId,
  4773. SetlId: order.SetlId,
  4774. }
  4775. var res ResultEleven
  4776. if config.IsOpen == 1 {
  4777. if miConfig.MdtrtareaAdmvs == "421300" {
  4778. api := "http://192.168.124.4:9532/" + "hbyb/5203?psn_no=" + businessParams.PsnNo + "&mdtrt_id=" + businessParams.MdtrtId + "&setl_id=" + businessParams.SetlId +
  4779. "&org_name=" + miConfig.OrgName + "&doctor=" + baseParams.Doctor + "&fixmedins_code=" + miConfig.Code +
  4780. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&med_type=" + order.MedType
  4781. resp, requestErr := http.Get(api)
  4782. if requestErr != nil {
  4783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4784. return
  4785. }
  4786. body, ioErr := ioutil.ReadAll(resp.Body)
  4787. if ioErr != nil {
  4788. //utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4789. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4790. return
  4791. }
  4792. var respJSON map[string]interface{}
  4793. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4794. //utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4795. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4796. return
  4797. }
  4798. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4799. result, _ := json.Marshal(respJSON)
  4800. fmt.Println("log")
  4801. fmt.Println(string(result))
  4802. if err := json.Unmarshal([]byte(result), &res); err != nil {
  4803. //utils.ErrorLog("解析失败:%v", err)
  4804. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4805. return
  4806. }
  4807. c.ServeSuccessJSON(map[string]interface{}{
  4808. "msg": "成功",
  4809. })
  4810. } else {
  4811. result := service.Gdyb5203(baseParams, businessParams)
  4812. var dat map[string]interface{}
  4813. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4814. fmt.Println(dat)
  4815. } else {
  4816. fmt.Println(err)
  4817. }
  4818. userJSONBytes, _ := json.Marshal(dat)
  4819. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4820. utils.ErrorLog("解析失败:%v", err)
  4821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4822. return
  4823. }
  4824. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4825. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  4826. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, order.PatientId, order.SettleAccountsDate)
  4827. adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  4828. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4829. var doctor_name string
  4830. if roles.ID == 0 {
  4831. doctor_name = "管理员"
  4832. } else {
  4833. doctor_name = roles.UserName
  4834. }
  4835. yiliao_leibie := ""
  4836. switch order.MedType {
  4837. case "11":
  4838. yiliao_leibie = "普通门诊"
  4839. break
  4840. case "12":
  4841. yiliao_leibie = "门诊挂号"
  4842. break
  4843. case "13":
  4844. yiliao_leibie = "急诊"
  4845. break
  4846. case "14":
  4847. yiliao_leibie = "门诊特殊病"
  4848. break
  4849. case "15":
  4850. yiliao_leibie = "门诊统筹"
  4851. break
  4852. case "16":
  4853. yiliao_leibie = "门诊慢性病"
  4854. break
  4855. case "21":
  4856. yiliao_leibie = "普通住院"
  4857. break
  4858. }
  4859. departments, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  4860. if res.Infcode == 0 {
  4861. c.ServeSuccessJSON(map[string]interface{}{
  4862. "diagnosis": name,
  4863. "order_infos": orderInfos,
  4864. "number": order.MdtrtId,
  4865. "date": order.SettleAccountsDate,
  4866. "charge_admin": charge_admin,
  4867. "printor_admin": printor_admin,
  4868. "info": res.Output.Setlinfo,
  4869. "bedCostTotal": bedCostTotal,
  4870. "bedCostSelfTotal": bedCostSelfTotal,
  4871. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  4872. "operationCostTotal": operationCostTotal,
  4873. "operationCostSelfTotal": operationCostSelfTotal,
  4874. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  4875. "otherCostTotal": otherCostTotal,
  4876. "otherCostSelfTotal": otherCostSelfTotal,
  4877. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  4878. "materialCostTotal": materialCostTotal,
  4879. "materialCostSelfTotal": materialCostSelfTotal,
  4880. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  4881. "westernMedicineCostTotal": westernMedicineCostTotal,
  4882. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  4883. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  4884. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  4885. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  4886. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  4887. "checkCostTotal": checkCostTotal,
  4888. "checkCostSelfTotal": checkCostSelfTotal,
  4889. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  4890. "laboratoryCostTotal": laboratoryCostTotal,
  4891. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  4892. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  4893. "treatCostTotal": treatCostTotal,
  4894. "treatCostSelfTotal": treatCostSelfTotal,
  4895. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  4896. "doctor_code": adminRole_two.DoctorCode,
  4897. "doctor_name": doctor_name,
  4898. "health_card_no": order.PsnNo,
  4899. "department": departments.Name,
  4900. "yiliao_leibie": yiliao_leibie,
  4901. "after_money": order.AccountPrice,
  4902. "patient": patient,
  4903. "org_name": miConfig.OrgName,
  4904. "org_code": miConfig.Code,
  4905. "order_number": order.Number,
  4906. })
  4907. }
  4908. }
  4909. }
  4910. }
  4911. func (c *HisApiController) CheckTreatment() {
  4912. patient_id, _ := c.GetInt64("patient_id", 0)
  4913. record_time := c.GetString("record_time")
  4914. insutype := c.GetString("insutype")
  4915. timeLayout := "2006-01-02"
  4916. loc, _ := time.LoadLocation("Local")
  4917. adminUser := c.GetAdminUserInfo()
  4918. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4919. fmt.Println(err)
  4920. if err != nil {
  4921. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4922. return
  4923. }
  4924. recordDateTime := theTime.Unix()
  4925. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  4926. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  4927. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4928. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4929. var user_name string
  4930. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  4931. if role.ID == 0 {
  4932. user_name = "xxx"
  4933. } else {
  4934. user_name = role.UserName
  4935. }
  4936. baseParams := models.BaseParams{
  4937. SecretKey: miConfig.SecretKey,
  4938. FixmedinsCode: miConfig.Code,
  4939. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4940. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4941. OrgName: miConfig.OrgName,
  4942. Doctor: user_name,
  4943. }
  4944. if config.IsOpen == 1 {
  4945. result := service.Gdyb2001(baseParams, his.PsnNo, insutype, strconv.FormatInt(patientPrescription.RegisterType, 10))
  4946. var dat map[string]interface{}
  4947. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4948. fmt.Println(dat)
  4949. } else {
  4950. fmt.Println(err)
  4951. }
  4952. }
  4953. }
  4954. func (c *HisApiController) PutRecord() {
  4955. id, _ := c.GetInt64("id")
  4956. record_time := c.GetString("record_time")
  4957. timeLayout := "2006-01-02"
  4958. loc, _ := time.LoadLocation("Local")
  4959. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4960. if err != nil {
  4961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4962. return
  4963. }
  4964. recordDateTime := theTime.Unix()
  4965. adminInfo := c.GetAdminUserInfo()
  4966. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  4967. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  4968. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  4969. fmt.Println(miConfig.SecretKey)
  4970. if patient == nil {
  4971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4972. return
  4973. }
  4974. if len(patient.IdCardNo) == 0 {
  4975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  4976. return
  4977. }
  4978. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  4979. if config.IsOpen == 1 {
  4980. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4981. resp, requestErr := http.Get(api)
  4982. if requestErr != nil {
  4983. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4984. return
  4985. }
  4986. defer resp.Body.Close()
  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. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  5000. userJSONBytes, _ := json.Marshal(userJSON)
  5001. var res ResultTwo
  5002. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5003. utils.ErrorLog("解析失败:%v", err)
  5004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5005. return
  5006. }
  5007. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  5008. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  5009. infoStr := string(Iinfos)
  5010. idetinfoStr := string(Idetinfos)
  5011. if res.Infcode == 0 {
  5012. his := models.VMHisPatient{
  5013. Status: 1,
  5014. Ctime: time.Now().Unix(),
  5015. Mtime: time.Now().Unix(),
  5016. PsnNo: res.Output.Baseinfo.PsnNo,
  5017. PsnCertType: res.Output.Baseinfo.PsnCertType,
  5018. Certno: res.Output.Baseinfo.Certno,
  5019. PsnName: res.Output.Baseinfo.PsnName,
  5020. Gend: res.Output.Baseinfo.Gend,
  5021. Naty: res.Output.Baseinfo.Naty,
  5022. Brdy: res.Output.Baseinfo.Brdy,
  5023. Age: res.Output.Baseinfo.Age,
  5024. Iinfo: infoStr,
  5025. Idetinfo: idetinfoStr,
  5026. PatientId: patient.ID,
  5027. RecordDate: theTime.Unix(),
  5028. UserOrgId: adminInfo.CurrentOrgId,
  5029. AdminUserId: adminInfo.AdminUser.Id,
  5030. IsReturn: 1,
  5031. }
  5032. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  5033. result := service.Gdyb2503(his.PsnNo, res.Output.Iinfo[0].Insutype, miConfig.OrgName, patientPrescription.Doctor, miConfig.Code, doctor_id, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "重症尿毒症透析(血透)", "M07801")
  5034. result2 := service.Gdyb5301(his.PsnNo, res.Output.Iinfo[0].Insutype, miConfig.OrgName, patientPrescription.Doctor, miConfig.Code, doctor_id, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "重症尿毒症透析(血透)", "M07801")
  5035. var dat map[string]interface{}
  5036. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5037. fmt.Println(dat)
  5038. } else {
  5039. fmt.Println(err)
  5040. }
  5041. var dat2 map[string]interface{}
  5042. if err := json.Unmarshal([]byte(result2), &dat2); err == nil {
  5043. fmt.Println(dat2)
  5044. } else {
  5045. fmt.Println(err)
  5046. }
  5047. } else {
  5048. adminUser := c.GetAdminUserInfo()
  5049. errlog := &models.HisOrderError{
  5050. UserOrgId: adminUser.CurrentOrgId,
  5051. Ctime: time.Now().Unix(),
  5052. Mtime: time.Now().Unix(),
  5053. ErrMsg: res.ErrMsg,
  5054. Status: 1,
  5055. PatientId: id,
  5056. RecordTime: recordDateTime,
  5057. Stage: 1,
  5058. }
  5059. service.CreateErrMsgLog(errlog)
  5060. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  5061. return
  5062. }
  5063. }
  5064. }
  5065. func (c *HisApiController) GetUploadDiag() {
  5066. id, _ := c.GetInt64("id")
  5067. record_time := c.GetString("record_time")
  5068. diagnosis_id, _ := c.GetInt64("diagnosis")
  5069. sick_type, _ := c.GetInt64("sick_type")
  5070. reg_type, _ := c.GetInt64("reg_type")
  5071. timeLayout := "2006-01-02"
  5072. loc, _ := time.LoadLocation("Local")
  5073. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5074. if err != nil {
  5075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5076. return
  5077. }
  5078. var patientPrescription models.HisPrescriptionInfo
  5079. recordDateTime := theTime.Unix()
  5080. adminInfo := c.GetAdminUserInfo()
  5081. patientPrescription, _ = service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  5082. if patientPrescription.ID == 0 {
  5083. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  5084. }
  5085. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  5086. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  5087. his, _ := service.GetVMHisPatientInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  5088. sickConfig, _ := service.FindSickById(sick_type)
  5089. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  5090. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  5091. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  5092. "&diag=" + diagnosisConfig.ClassName + "&org_name=" + miConfig.OrgName + "&med_type=" + strconv.FormatInt(reg_type, 10) + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code + "&diag_code=" + diagnosisConfig.CountryCode +
  5093. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.ContentCode + "&sick_name=" + sickConfig.ClassName
  5094. resp2, requestErr2 := http.Get(api2)
  5095. if requestErr2 != nil {
  5096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5097. return
  5098. }
  5099. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  5100. if ioErr2 != nil {
  5101. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  5102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5103. return
  5104. }
  5105. var respJSON2 map[string]interface{}
  5106. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  5107. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  5108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5109. return
  5110. }
  5111. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  5112. userJSONBytes2, _ := json.Marshal(respJSON2)
  5113. var res2 ResultSix
  5114. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  5115. utils.ErrorLog("解析失败:%v", err)
  5116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5117. return
  5118. }
  5119. if res2.Infcode != 0 {
  5120. adminUser := c.GetAdminUserInfo()
  5121. errlog := &models.HisOrderError{
  5122. UserOrgId: adminUser.CurrentOrgId,
  5123. Ctime: time.Now().Unix(),
  5124. Mtime: time.Now().Unix(),
  5125. ErrMsg: res2.ErrMsg,
  5126. Status: 1,
  5127. PatientId: id,
  5128. RecordTime: recordDateTime,
  5129. Stage: 3,
  5130. }
  5131. service.CreateErrMsgLog(errlog)
  5132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  5133. return
  5134. }
  5135. c.ServeSuccessJSON(map[string]interface{}{
  5136. "msg": "上传成功",
  5137. })
  5138. }
  5139. type QueryResult struct {
  5140. ID int64
  5141. Name string
  5142. Code string
  5143. List_type_code string
  5144. }
  5145. func (c *HisApiController) GetCheckCode() {
  5146. ids_str := c.GetString("ids")
  5147. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  5148. ids_arr := strings.Split(ids_str, ",")
  5149. var queryResult []QueryResult
  5150. ids := make([]int64, 0)
  5151. for _, item := range ids_arr {
  5152. id, _ := strconv.ParseInt(item, 10, 64)
  5153. ids = append(ids, id)
  5154. }
  5155. if record_type == 1 {
  5156. drugs, _ := service.GetBatchDrugList(ids)
  5157. for _, item := range drugs {
  5158. result := QueryResult{
  5159. ID: item.ID,
  5160. Name: item.DrugName,
  5161. Code: item.MedicalInsuranceNumber,
  5162. List_type_code: "101",
  5163. }
  5164. queryResult = append(queryResult, result)
  5165. }
  5166. } else if record_type == 2 {
  5167. goods, _ := service.GetBatchGoodInformationList(ids)
  5168. for _, item := range goods {
  5169. result := QueryResult{
  5170. ID: item.ID,
  5171. Name: item.GoodName,
  5172. Code: item.MedicalInsuranceNumber,
  5173. List_type_code: "301",
  5174. }
  5175. queryResult = append(queryResult, result)
  5176. }
  5177. } else if record_type == 3 {
  5178. projects, _ := service.GetBathchMyPorjecgList(ids)
  5179. for _, item := range projects {
  5180. result := QueryResult{
  5181. ID: item.ID,
  5182. Name: item.ProjectName,
  5183. Code: item.MedicalCode,
  5184. List_type_code: "201",
  5185. }
  5186. queryResult = append(queryResult, result)
  5187. }
  5188. }
  5189. admin_user_id, _ := c.GetInt64("admin_user_id")
  5190. adminUser := c.GetAdminUserInfo()
  5191. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5192. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5193. var user_name string
  5194. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  5195. if role.ID == 0 {
  5196. user_name = "xxx"
  5197. } else {
  5198. user_name = role.UserName
  5199. }
  5200. baseParams := &models.BaseParams{
  5201. SecretKey: miConfig.SecretKey,
  5202. FixmedinsCode: miConfig.Code,
  5203. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  5204. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  5205. OrgName: miConfig.OrgName,
  5206. Doctor: user_name,
  5207. }
  5208. if config.IsOpen == 1 {
  5209. for _, item := range queryResult {
  5210. var result string
  5211. if record_type == 1 {
  5212. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  5213. } else if record_type == 2 {
  5214. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  5215. } else if record_type == 3 {
  5216. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  5217. }
  5218. var dat map[string]interface{}
  5219. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5220. fmt.Println(dat)
  5221. } else {
  5222. fmt.Println(err)
  5223. }
  5224. userJSONBytes, _ := json.Marshal(dat)
  5225. var res ResultSix
  5226. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5227. utils.ErrorLog("解析失败:%v", err)
  5228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5229. return
  5230. }
  5231. if res.Infcode == 0 {
  5232. if record_type == 1 {
  5233. service.UpdateBaseDrugById(item.ID)
  5234. } else if record_type == 2 {
  5235. service.UpdateGoodInformaitonByDetail(item.ID)
  5236. } else if record_type == 3 {
  5237. service.UpdateProjectById(item.ID)
  5238. }
  5239. c.ServeSuccessJSON(map[string]interface{}{
  5240. "failed_code": 0,
  5241. "msg": "目录对照成功",
  5242. })
  5243. } else {
  5244. c.ServeSuccessJSON(map[string]interface{}{
  5245. "failed_code": -10,
  5246. "msg": res.ErrMsg,
  5247. })
  5248. }
  5249. }
  5250. }
  5251. }
  5252. func (c *HisApiController) UnCheckCode() {
  5253. ids_str := c.GetString("ids")
  5254. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  5255. admin_user_id, _ := c.GetInt64("admin_user_id")
  5256. ids_arr := strings.Split(ids_str, ",")
  5257. var queryResult []QueryResult
  5258. ids := make([]int64, 0)
  5259. for _, item := range ids_arr {
  5260. id, _ := strconv.ParseInt(item, 10, 64)
  5261. ids = append(ids, id)
  5262. }
  5263. if record_type == 1 {
  5264. drugs, _ := service.GetBatchDrugList(ids)
  5265. for _, item := range drugs {
  5266. result := QueryResult{
  5267. ID: item.ID,
  5268. Name: item.DrugName,
  5269. Code: item.MedicalInsuranceNumber,
  5270. List_type_code: "101",
  5271. }
  5272. queryResult = append(queryResult, result)
  5273. }
  5274. } else if record_type == 2 {
  5275. goods, _ := service.GetBatchGoodInformationList(ids)
  5276. for _, item := range goods {
  5277. result := QueryResult{
  5278. ID: item.ID,
  5279. Name: item.GoodName,
  5280. Code: item.MedicalInsuranceNumber,
  5281. List_type_code: "301",
  5282. }
  5283. queryResult = append(queryResult, result)
  5284. }
  5285. } else if record_type == 3 {
  5286. projects, _ := service.GetBathchMyPorjecgList(ids)
  5287. for _, item := range projects {
  5288. result := QueryResult{
  5289. ID: item.ID,
  5290. Name: item.ProjectName,
  5291. Code: item.MedicalCode,
  5292. List_type_code: "201",
  5293. }
  5294. queryResult = append(queryResult, result)
  5295. }
  5296. }
  5297. adminUser := c.GetAdminUserInfo()
  5298. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5299. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5300. var user_name string
  5301. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  5302. if role.ID == 0 {
  5303. user_name = "xxx"
  5304. } else {
  5305. user_name = role.UserName
  5306. }
  5307. baseParams := &models.BaseParams{
  5308. SecretKey: miConfig.SecretKey,
  5309. FixmedinsCode: miConfig.Code,
  5310. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  5311. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  5312. OrgName: miConfig.OrgName,
  5313. Doctor: user_name,
  5314. }
  5315. if config.IsOpen == 1 {
  5316. for _, item := range queryResult {
  5317. var result string
  5318. if record_type == 1 {
  5319. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  5320. } else if record_type == 2 {
  5321. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  5322. } else if record_type == 3 {
  5323. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  5324. }
  5325. var dat2 map[string]interface{}
  5326. if err := json.Unmarshal([]byte(result), &dat2); err == nil {
  5327. fmt.Println(dat2)
  5328. } else {
  5329. fmt.Println(err)
  5330. }
  5331. userJSONBytes, _ := json.Marshal(dat2)
  5332. var res ResultSix
  5333. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5334. utils.ErrorLog("解析失败:%v", err)
  5335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5336. return
  5337. }
  5338. if res.Infcode == 0 {
  5339. if record_type == 1 {
  5340. service.UpdateDrugByIdDetail(item.ID)
  5341. } else if record_type == 2 {
  5342. service.UpdateGoodInfoById(item.ID)
  5343. } else if record_type == 3 {
  5344. service.UpdateMyProjectById(item.ID)
  5345. }
  5346. c.ServeSuccessJSON(map[string]interface{}{
  5347. "failed_code": 0,
  5348. "msg": "撤销目录对照成功",
  5349. })
  5350. } else {
  5351. c.ServeSuccessJSON(map[string]interface{}{
  5352. "failed_code": -10,
  5353. "msg": res.ErrMsg,
  5354. })
  5355. }
  5356. }
  5357. }
  5358. }
  5359. func (c *HisApiController) GetPatientInfo() {
  5360. id_card_no := c.GetString("id_card_no")
  5361. admin_user_id, _ := c.GetInt64("admin_user_id")
  5362. patient, _ := service.GetPatientByIDCard(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  5363. if patient.ID == 0 {
  5364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5365. return
  5366. }
  5367. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  5368. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  5369. config, _ := service.GetMedicalInsuranceConfig(c.GetAdminUserInfo().CurrentOrgId)
  5370. if config.IsOpen == 1 {
  5371. result := service.Gdyb1101A(id_card_no, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  5372. var dat map[string]interface{}
  5373. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5374. fmt.Println(dat)
  5375. } else {
  5376. fmt.Println(err)
  5377. }
  5378. userJSONBytes, _ := json.Marshal(dat)
  5379. var res ResultTwo
  5380. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5381. utils.ErrorLog("解析失败:%v", err)
  5382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5383. return
  5384. }
  5385. if res.Infcode != 0 {
  5386. c.ServeSuccessJSON(map[string]interface{}{
  5387. "failed_code": -10,
  5388. "msg": res.ErrMsg,
  5389. })
  5390. } else {
  5391. c.ServeSuccessJSON(map[string]interface{}{
  5392. "failed_code": 0,
  5393. "info": res,
  5394. })
  5395. }
  5396. }
  5397. }
  5398. func (c *HisApiController) PsnPutOnRecord() {
  5399. record_type, _ := c.GetInt64("type")
  5400. patient_id, _ := c.GetInt64("patient_id")
  5401. admin_user_id, _ := c.GetInt64("admin_user_id")
  5402. start_time := c.GetString("start_time")
  5403. end_time := c.GetString("end_time")
  5404. adminUser := c.GetAdminUserInfo()
  5405. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5406. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5407. var patients []*models.Patients
  5408. if record_type == 1 { //全部备案
  5409. patient, _ := service.GetAllPatient(adminUser.CurrentOrgId)
  5410. patients = append(patients, patient...)
  5411. } else { //单个备案
  5412. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  5413. patients = append(patients, patient)
  5414. }
  5415. var user_name string
  5416. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  5417. if role.ID == 0 {
  5418. user_name = "xxx"
  5419. } else {
  5420. user_name = role.UserName
  5421. }
  5422. if config.IsOpen == 1 {
  5423. for _, item := range patients {
  5424. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + item.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + user_name + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  5425. resp, requestErr := http.Get(api)
  5426. if requestErr != nil {
  5427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5428. return
  5429. }
  5430. defer resp.Body.Close()
  5431. body, ioErr := ioutil.ReadAll(resp.Body)
  5432. if ioErr != nil {
  5433. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  5434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5435. return
  5436. }
  5437. var respJSON map[string]interface{}
  5438. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  5439. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  5440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5441. return
  5442. }
  5443. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  5444. userJSONBytes, _ := json.Marshal(userJSON)
  5445. var res ResultTwo
  5446. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5447. utils.ErrorLog("解析失败:%v", err)
  5448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5449. return
  5450. }
  5451. if res.Infcode == 0 {
  5452. result := service.Gdyb2505(res.Output.Baseinfo.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, start_time, end_time)
  5453. var dat map[string]interface{}
  5454. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5455. fmt.Println(dat)
  5456. } else {
  5457. fmt.Println(err)
  5458. }
  5459. userJSONBytes, _ := json.Marshal(dat)
  5460. var res2 ResultThirteen
  5461. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  5462. utils.ErrorLog("解析失败:%v", err)
  5463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5464. return
  5465. }
  5466. if res2.Infcode == 0 {
  5467. psnResult := &models.GdybPsnRecord{
  5468. UserOrgId: adminUser.CurrentOrgId,
  5469. PatientId: item.ID,
  5470. PsnNo: res.Output.Baseinfo.PsnNo,
  5471. Ctime: time.Now().Unix(),
  5472. Mtime: time.Now().Unix(),
  5473. Status: 1,
  5474. IsCancel: 1,
  5475. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  5476. }
  5477. service.CreatePsnRecord(psnResult)
  5478. } else {
  5479. c.ServeSuccessJSON(map[string]interface{}{
  5480. "failed_code": -10,
  5481. "msg": res2.ErrMsg,
  5482. })
  5483. return
  5484. }
  5485. }
  5486. }
  5487. }
  5488. }
  5489. func (c *HisApiController) PsnUnPutOnRecord() {
  5490. id, _ := c.GetInt64("id")
  5491. //record_type, _ := c.GetInt64("type")
  5492. admin_user_id, _ := c.GetInt64("admin_user_id")
  5493. adminUser := c.GetAdminUserInfo()
  5494. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5495. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5496. var user_name string
  5497. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  5498. if role.ID == 0 {
  5499. user_name = "xxx"
  5500. } else {
  5501. user_name = role.UserName
  5502. }
  5503. psn_record, _ := service.GetPsnRecordById(id)
  5504. if psn_record.ID == 0 {
  5505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  5506. return
  5507. }
  5508. if config.IsOpen == 1 {
  5509. result := service.Gdyb2506(psn_record.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  5510. var dat map[string]interface{}
  5511. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5512. fmt.Println(dat)
  5513. } else {
  5514. fmt.Println(err)
  5515. }
  5516. userJSONBytes, _ := json.Marshal(dat)
  5517. var res ResultFourteen
  5518. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5519. utils.ErrorLog("解析失败:%v", err)
  5520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5521. return
  5522. }
  5523. if res.Infcode == 0 {
  5524. psn_record.IsCancel = 2
  5525. service.CreatePsnRecord(&psn_record)
  5526. } else {
  5527. c.ServeSuccessJSON(map[string]interface{}{
  5528. "failed_code": -10,
  5529. "msg": res.ErrMsg,
  5530. })
  5531. return
  5532. }
  5533. }
  5534. }
  5535. func (c *HisApiController) PsnPutNCDSOnRecord() {
  5536. patient_id, _ := c.GetInt64("patient_id")
  5537. insutype := c.GetString("insutype")
  5538. psn_no := c.GetString("psn_no")
  5539. doctor_id, _ := c.GetInt64("doctor_id")
  5540. sick_id, _ := c.GetInt64("sick_id")
  5541. department_id, _ := c.GetInt64("department_id")
  5542. adminUser := c.GetAdminUserInfo()
  5543. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  5544. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5545. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5546. sick, _ := service.FindSickById(sick_id)
  5547. doctor, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, doctor_id)
  5548. if config.IsOpen == 1 {
  5549. result := service.Gdyb2503(psn_no, insutype, miConfig.OrgName, doctor.UserName, miConfig.Code, strconv.FormatInt(doctor.ID, 10), miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sick.ClassName, sick.ContentCode)
  5550. var dat map[string]interface{}
  5551. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5552. fmt.Println(dat)
  5553. } else {
  5554. fmt.Println(err)
  5555. }
  5556. userJSONBytes, _ := json.Marshal(dat)
  5557. var res2 ResultThirteen
  5558. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  5559. utils.ErrorLog("解析失败:%v", err)
  5560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5561. return
  5562. }
  5563. if res2.Infcode == 0 {
  5564. psnResult := &models.GdybPsnNcdsRecord{
  5565. UserOrgId: adminUser.CurrentOrgId,
  5566. PatientId: patient.ID,
  5567. PsnNo: psn_no,
  5568. DoctorId: doctor.AdminUserId,
  5569. DepartmentId: department_id,
  5570. SickType: sick_id,
  5571. Insutype: insutype,
  5572. Ctime: time.Now().Unix(),
  5573. Mtime: time.Now().Unix(),
  5574. Status: 1,
  5575. IsCancel: 1,
  5576. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  5577. }
  5578. service.CreatePsnNCDSRecord(psnResult)
  5579. c.ServeSuccessJSON(map[string]interface{}{
  5580. "failed_code": 0,
  5581. "msg": "备案成功",
  5582. "result": psnResult,
  5583. })
  5584. } else {
  5585. c.ServeSuccessJSON(map[string]interface{}{
  5586. "failed_code": -10,
  5587. "msg": res2.ErrMsg,
  5588. })
  5589. return
  5590. }
  5591. }
  5592. }
  5593. func (c *HisApiController) PsnPutUnNCDSOnRecord() {
  5594. id, _ := c.GetInt64("id")
  5595. admin_user_id, _ := c.GetInt64("admin_user_id")
  5596. adminUser := c.GetAdminUserInfo()
  5597. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5598. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5599. var user_name string
  5600. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  5601. if role.ID == 0 {
  5602. user_name = "xxx"
  5603. } else {
  5604. user_name = role.UserName
  5605. }
  5606. psn_record, _ := service.GetPsnNCDSRecordById(id)
  5607. if psn_record.ID == 0 {
  5608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  5609. return
  5610. }
  5611. if config.IsOpen == 1 {
  5612. result := service.Gdyb2504(psn_record.PsnNo, miConfig.OrgName, user_name, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  5613. var dat map[string]interface{}
  5614. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5615. fmt.Println(dat)
  5616. } else {
  5617. fmt.Println(err)
  5618. }
  5619. userJSONBytes, _ := json.Marshal(dat)
  5620. var res ResultFourteen
  5621. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5622. utils.ErrorLog("解析失败:%v", err)
  5623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5624. return
  5625. }
  5626. if res.Infcode == 0 {
  5627. psn_record.IsCancel = 2
  5628. service.CreatePsnNCDSRecord(&psn_record)
  5629. c.ServeSuccessJSON(map[string]interface{}{
  5630. "failed_code": 0,
  5631. "msg": "撤销备案成功",
  5632. })
  5633. } else {
  5634. c.ServeSuccessJSON(map[string]interface{}{
  5635. "failed_code": -10,
  5636. "msg": res.ErrMsg,
  5637. })
  5638. return
  5639. }
  5640. }
  5641. }
  5642. func (c *HisApiController) TestTest() {
  5643. patient, _ := service.GetHisPatientInfo(4, 456, 1619712000)
  5644. fmt.Println(patient.Iinfo)
  5645. }
  5646. type CustomData struct {
  5647. MsgId string
  5648. PsnNo string
  5649. Info string
  5650. }
  5651. func (c *HisApiController) ReversalData() {
  5652. var customData []*CustomData
  5653. custom := &CustomData{
  5654. MsgId: "H44022900158202103301714472004",
  5655. PsnNo: "44020000001101329945",
  5656. Info: "2207",
  5657. }
  5658. customData = append(customData, custom)
  5659. custom1 := &CustomData{
  5660. MsgId: "H4402290015820210330172057803",
  5661. PsnNo: "44020000001101161813",
  5662. Info: "2207",
  5663. }
  5664. customData = append(customData, custom1)
  5665. custom2 := &CustomData{
  5666. MsgId: "H44022900158202103301705198813",
  5667. PsnNo: "44190000133097375417",
  5668. Info: "2207",
  5669. }
  5670. customData = append(customData, custom2)
  5671. custom3 := &CustomData{
  5672. MsgId: "H44022900158202103301715524756",
  5673. PsnNo: "44020000001100187221",
  5674. Info: "2207",
  5675. }
  5676. customData = append(customData, custom3)
  5677. custom4 := &CustomData{
  5678. MsgId: "H44022900158202103301730376224",
  5679. PsnNo: "44020000001101959155",
  5680. Info: "2207",
  5681. }
  5682. customData = append(customData, custom4)
  5683. custom5 := &CustomData{
  5684. MsgId: "H44022900158202103301748008725",
  5685. PsnNo: "44020000001104246641",
  5686. Info: "2207",
  5687. }
  5688. customData = append(customData, custom5)
  5689. custom6 := &CustomData{
  5690. MsgId: "H44022900158202103301718096755",
  5691. PsnNo: "44020000001102211860",
  5692. Info: "2207",
  5693. }
  5694. customData = append(customData, custom6)
  5695. custom7 := &CustomData{
  5696. MsgId: "H44022900158202103301736551640",
  5697. PsnNo: "44020000001102687718",
  5698. Info: "2207",
  5699. }
  5700. customData = append(customData, custom7)
  5701. custom8 := &CustomData{
  5702. MsgId: "H44022900158202103301743097676",
  5703. PsnNo: "44020000001102127785",
  5704. Info: "2207",
  5705. }
  5706. customData = append(customData, custom8)
  5707. custom9 := &CustomData{
  5708. MsgId: "H44022900158202103301712304203",
  5709. PsnNo: "44020000001101518097",
  5710. Info: "2207",
  5711. }
  5712. customData = append(customData, custom9)
  5713. custom10 := &CustomData{
  5714. MsgId: "H44022900158202103301738448785",
  5715. PsnNo: "44020000001100500813",
  5716. Info: "2207",
  5717. }
  5718. customData = append(customData, custom10)
  5719. custom11 := &CustomData{
  5720. MsgId: "H44022900158202103301732455843",
  5721. PsnNo: "44020000001102690557",
  5722. Info: "2207",
  5723. }
  5724. customData = append(customData, custom11)
  5725. custom12 := &CustomData{
  5726. MsgId: "H44022900158202103301745421708",
  5727. PsnNo: "44020000001102211928",
  5728. Info: "2207",
  5729. }
  5730. customData = append(customData, custom12)
  5731. custom1212 := &CustomData{
  5732. MsgId: "H440229001582021033017351627",
  5733. PsnNo: "44020000001102481733",
  5734. Info: "2207",
  5735. }
  5736. customData = append(customData, custom1212)
  5737. custom13 := &CustomData{
  5738. MsgId: "H44022900158202103301740327951",
  5739. PsnNo: "44020000001103174866",
  5740. Info: "2207",
  5741. }
  5742. customData = append(customData, custom13)
  5743. custom14 := &CustomData{
  5744. MsgId: "H4402290015820210330174922668",
  5745. PsnNo: "44020000001102927272",
  5746. Info: "2207",
  5747. }
  5748. customData = append(customData, custom14)
  5749. custom15 := &CustomData{
  5750. MsgId: "H44022900158202103301752362273",
  5751. PsnNo: "44020000001102942890",
  5752. Info: "2207",
  5753. }
  5754. customData = append(customData, custom15)
  5755. custom16 := &CustomData{
  5756. MsgId: "H44022900158202103301751082917",
  5757. PsnNo: "44020000001101662162",
  5758. Info: "2207",
  5759. }
  5760. customData = append(customData, custom16)
  5761. custom17 := &CustomData{
  5762. MsgId: "H44022900158202103301754147728",
  5763. PsnNo: "44020000000229014511",
  5764. Info: "2207",
  5765. }
  5766. customData = append(customData, custom17)
  5767. adminUser := c.GetAdminUserInfo()
  5768. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5769. for _, item := range customData {
  5770. result := service.Gdyb2601(item.PsnNo, item.MsgId, item.Info, miConfig.OrgName, "张俊杰", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  5771. fmt.Println(result)
  5772. }
  5773. }
  5774. func (c *HisApiController) ReversalOtherData() {
  5775. var customData []*CustomData
  5776. custom := &CustomData{
  5777. MsgId: "H44022900158202103301714472004",
  5778. PsnNo: "44020000001101329945",
  5779. Info: "2208",
  5780. }
  5781. customData = append(customData, custom)
  5782. custom1 := &CustomData{
  5783. MsgId: "H4402290015820210330172057803",
  5784. PsnNo: "44020000001101161813",
  5785. Info: "2208",
  5786. }
  5787. customData = append(customData, custom1)
  5788. custom2 := &CustomData{
  5789. MsgId: "H44022900158202103301705198813",
  5790. PsnNo: "44190000133097375417",
  5791. Info: "2208",
  5792. }
  5793. customData = append(customData, custom2)
  5794. custom3 := &CustomData{
  5795. MsgId: "H44022900158202103301715524756",
  5796. PsnNo: "44020000001100187221",
  5797. Info: "2208",
  5798. }
  5799. customData = append(customData, custom3)
  5800. custom4 := &CustomData{
  5801. MsgId: "H44022900158202103301730376224",
  5802. PsnNo: "44020000001101959155",
  5803. Info: "2208",
  5804. }
  5805. customData = append(customData, custom4)
  5806. custom5 := &CustomData{
  5807. MsgId: "H44022900158202103301748008725",
  5808. PsnNo: "44020000001104246641",
  5809. Info: "2208",
  5810. }
  5811. customData = append(customData, custom5)
  5812. custom6 := &CustomData{
  5813. MsgId: "H44022900158202103301718096755",
  5814. PsnNo: "44020000001102211860",
  5815. Info: "2208",
  5816. }
  5817. customData = append(customData, custom6)
  5818. custom7 := &CustomData{
  5819. MsgId: "H44022900158202103301736551640",
  5820. PsnNo: "44020000001102687718",
  5821. Info: "2208",
  5822. }
  5823. customData = append(customData, custom7)
  5824. custom8 := &CustomData{
  5825. MsgId: "H44022900158202103301743097676",
  5826. PsnNo: "44020000001102127785",
  5827. Info: "2208",
  5828. }
  5829. customData = append(customData, custom8)
  5830. custom9 := &CustomData{
  5831. MsgId: "H44022900158202103301712304203",
  5832. PsnNo: "44020000001101518097",
  5833. Info: "2208",
  5834. }
  5835. customData = append(customData, custom9)
  5836. custom10 := &CustomData{
  5837. MsgId: "H44022900158202103301738448785",
  5838. PsnNo: "44020000001100500813",
  5839. Info: "2208",
  5840. }
  5841. customData = append(customData, custom10)
  5842. custom11 := &CustomData{
  5843. MsgId: "H44022900158202103301732455843",
  5844. PsnNo: "44020000001102690557",
  5845. Info: "2208",
  5846. }
  5847. customData = append(customData, custom11)
  5848. custom12 := &CustomData{
  5849. MsgId: "H44022900158202103301745421708",
  5850. PsnNo: "44020000001102211928",
  5851. Info: "2208",
  5852. }
  5853. customData = append(customData, custom12)
  5854. custom1212 := &CustomData{
  5855. MsgId: "H440229001582021033017351627",
  5856. PsnNo: "44020000001102481733",
  5857. Info: "2208",
  5858. }
  5859. customData = append(customData, custom1212)
  5860. custom13 := &CustomData{
  5861. MsgId: "H44022900158202103301740327951",
  5862. PsnNo: "44020000001103174866",
  5863. Info: "2208",
  5864. }
  5865. customData = append(customData, custom13)
  5866. custom14 := &CustomData{
  5867. MsgId: "H4402290015820210330174922668",
  5868. PsnNo: "44020000001102927272",
  5869. Info: "2208",
  5870. }
  5871. customData = append(customData, custom14)
  5872. custom15 := &CustomData{
  5873. MsgId: "H44022900158202103301752362273",
  5874. PsnNo: "44020000001102942890",
  5875. Info: "2208",
  5876. }
  5877. customData = append(customData, custom15)
  5878. custom16 := &CustomData{
  5879. MsgId: "H44022900158202103301751082917",
  5880. PsnNo: "44020000001101662162",
  5881. Info: "2208",
  5882. }
  5883. customData = append(customData, custom16)
  5884. custom17 := &CustomData{
  5885. MsgId: "H44022900158202103301754147728",
  5886. PsnNo: "44020000000229014511",
  5887. Info: "2208",
  5888. }
  5889. customData = append(customData, custom17)
  5890. adminUser := c.GetAdminUserInfo()
  5891. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5892. for _, item := range customData {
  5893. result := service.Gdyb2601(item.PsnNo, item.MsgId, item.Info, miConfig.OrgName, "张俊杰", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  5894. fmt.Println(result)
  5895. }
  5896. }
  5897. func PathExists(path string) (bool, error) {
  5898. _, err := os.Stat(path)
  5899. if err == nil {
  5900. return true, nil
  5901. }
  5902. if os.IsNotExist(err) {
  5903. return false, nil
  5904. }
  5905. return false, err
  5906. }
  5907. //创建文件夹
  5908. func Mkdir(dir string) {
  5909. // 创建文件夹
  5910. exist, err := PathExists(dir)
  5911. if err != nil {
  5912. fmt.Println(err.Error())
  5913. } else {
  5914. if exist {
  5915. fmt.Println(dir + "文件夹已存在!")
  5916. } else {
  5917. // 文件夹名称,权限
  5918. err := os.Mkdir(dir, os.ModePerm)
  5919. if err != nil {
  5920. fmt.Println(dir+"文件夹创建失败:", err.Error())
  5921. } else {
  5922. fmt.Println(dir + "文件夹创建成功!")
  5923. }
  5924. }
  5925. }
  5926. }
  5927. //压缩文件
  5928. func Zip(srcFile string, destZip string) error {
  5929. zipfile, err := os.Create(destZip)
  5930. if err != nil {
  5931. return err
  5932. }
  5933. defer zipfile.Close()
  5934. archive := zip.NewWriter(zipfile)
  5935. defer archive.Close()
  5936. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  5937. if err != nil {
  5938. return err
  5939. }
  5940. header, err := zip.FileInfoHeader(info)
  5941. if err != nil {
  5942. return err
  5943. }
  5944. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  5945. // header.Name = path
  5946. if info.IsDir() {
  5947. header.Name += "/"
  5948. } else {
  5949. header.Method = zip.Deflate
  5950. }
  5951. writer, err := archive.CreateHeader(header)
  5952. if err != nil {
  5953. return err
  5954. }
  5955. if !info.IsDir() {
  5956. file, err := os.Open(path)
  5957. if err != nil {
  5958. return err
  5959. }
  5960. defer file.Close()
  5961. _, err = io.Copy(writer, file)
  5962. }
  5963. return err
  5964. })
  5965. return err
  5966. }
  5967. func ReadFile(filePath string) []byte {
  5968. f, err := os.Open(filePath)
  5969. if err != nil {
  5970. fmt.Println("read file fail", err)
  5971. return nil
  5972. }
  5973. defer f.Close()
  5974. fd, err := ioutil.ReadAll(f)
  5975. if err != nil {
  5976. fmt.Println("read to fd fail", err)
  5977. return nil
  5978. }
  5979. return fd
  5980. }
  5981. func RemoveRepeatedCode(arr []string) (newArr []string) {
  5982. newArr = make([]string, 0)
  5983. for i := 0; i < len(arr); i++ {
  5984. repeat := false
  5985. for j := i + 1; j < len(arr); j++ {
  5986. if arr[i] == arr[j] {
  5987. repeat = true
  5988. break
  5989. }
  5990. }
  5991. if !repeat {
  5992. newArr = append(newArr, arr[i])
  5993. }
  5994. }
  5995. return
  5996. }
  5997. func saveRegisterLog(result string) {
  5998. org_id, _ := beego.AppConfig.Int64("org_id")
  5999. miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  6000. dir := miConfig.OrgName + "日志"
  6001. utils.Mkdir(dir)
  6002. month := time.Unix(1557042972, 0).Format("1")
  6003. year := time.Now().Format("2006")
  6004. month = time.Now().Format("01")
  6005. day := time.Now().Format("02")
  6006. file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  6007. file_name := file + ".txt"
  6008. file_path := miConfig.OrgName + "日志" + "/" + file_name
  6009. exist, _ := utils.PathExists(file_path)
  6010. if exist { //存在
  6011. fmt.Println("存在")
  6012. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  6013. if err != nil {
  6014. fmt.Println("read fail")
  6015. }
  6016. content := "\r\n" + result
  6017. n, _ := f.Seek(0, 2)
  6018. _, err = f.WriteAt([]byte(content), n)
  6019. } else { //不存在
  6020. fmt.Println("文件不存在,创建文件")
  6021. f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  6022. defer f.Close()
  6023. if err != nil {
  6024. } else {
  6025. _, err = f.Write([]byte("记录日志"))
  6026. }
  6027. }
  6028. }
  6029. func saveLog(result string, request string, infno string, desc string) {
  6030. org_id, _ := beego.AppConfig.Int64("org_id")
  6031. miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  6032. dir := miConfig.OrgName + "日志"
  6033. utils.Mkdir(dir)
  6034. month := time.Unix(1557042972, 0).Format("1")
  6035. year := time.Now().Format("2006")
  6036. month = time.Now().Format("01")
  6037. day := time.Now().Format("02")
  6038. hour := time.Now().Format("15")
  6039. min := time.Now().Format("04")
  6040. sec := time.Now().Format("05")
  6041. result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  6042. file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  6043. file_name := file + ".txt"
  6044. file_path := miConfig.OrgName + "日志" + "/" + file_name
  6045. exist, _ := utils.PathExists(file_path)
  6046. if exist { //存在
  6047. fmt.Println("存在")
  6048. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  6049. if err != nil {
  6050. fmt.Println("read fail")
  6051. }
  6052. content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  6053. n, _ := f.Seek(0, 2)
  6054. _, err = f.WriteAt([]byte(content), n)
  6055. } else { //不存在
  6056. fmt.Println("文件不存在,创建文件")
  6057. f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  6058. defer f.Close()
  6059. if err != nil {
  6060. } else {
  6061. _, err = f.Write([]byte("记录日志"))
  6062. }
  6063. }
  6064. }