his_api_controller.go 233KB

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