his_api_controller.go 232KB

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