his_api_controller.go 233KB

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