his_api_controller.go 268KB

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