his_api_controller.go 235KB

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