his_api_controller.go 233KB

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