his_api_controller.go 271KB

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