auto_create_week_schedules_service.go 247KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914
  1. package city
  2. //
  3. import (
  4. "Data_Upload_Api/models/sz"
  5. "Data_Upload_Api/service"
  6. "Data_Upload_Api/utils"
  7. "fmt"
  8. _ "github.com/astaxie/beego"
  9. "github.com/jinzhu/gorm"
  10. "github.com/robfig/cron/v3"
  11. "github.com/shopspring/decimal"
  12. "math"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. var createUploadDataCronJob *cron.Cron
  18. func init() {
  19. // createUploadDataCronJob.AddFunc(spec2, func() {
  20. // SyncToSmzy() //深圳市数据上报
  21. // })
  22. }
  23. // 返回一个支持至 秒 级别的 cron
  24. func newWithSeconds() *cron.Cron {
  25. secondParser := cron.NewParser(cron.Second | cron.Minute |
  26. cron.Hour | cron.Dom | cron.Month | cron.DowOptional | cron.Descriptor)
  27. return cron.New(cron.WithParser(secondParser), cron.WithChain())
  28. }
  29. //
  30. // func BeginAutoJob() {
  31. // utils.InfoLog("开启定时任务")
  32. // // createUploadDataCronJob = cron.New()
  33. // createUploadDataCronJob := newWithSeconds()
  34. // spec := "0 30 1 * * ?" // 每天凌晨0点检测数据上报情况
  35. // spec1 := "0 45 1 * * ?" // 每天凌晨0点检测数据上报情况
  36. // // spec2 := "0 20 0 * * ?" // 每天凌晨0点检测数据上报情况
  37. // createUploadDataCronJob.AddFunc(spec, func() {
  38. // SyncToSzbl() //深圳市数据上报
  39. // })
  40. // createUploadDataCronJob.AddFunc(spec1, func() {
  41. // SyncToSzblbr() //深圳市数据上报
  42. // })
  43. // createUploadDataCronJob.Start()
  44. // }
  45. func BeginAutoJob() {
  46. utils.InfoLog("开启定时任务")
  47. // createUploadDataCronJob = cron.New()
  48. createUploadDataCronJob := newWithSeconds()
  49. //spec := "0 0 1 * * ?" // 每天凌晨0点检测数据上报情况
  50. spec1 := "0 30 1 * * ?" // 每天凌晨0点检测数据上报情况
  51. //spec2 := "0 0 2 * * ?" // 每天凌晨0点检测数据上报情况
  52. //spec3 := "0 30 2 * * ?" // 每天凌晨0点检测数据上报情况
  53. //spec4 := "0 30 3 * * ?" // 每天凌晨0点检测数据上报情况
  54. //spec5 := "0 10 1 * * ?" // 每天凌晨0点检测数据上报情况
  55. //spec6 := "0 20 1 * * ?" // 每天凌晨0点检测数据上报情况
  56. //spec7 := "0 40 1 * * ?" // 每天凌晨0点检测数据上报情况
  57. //spec8 := "0 40 1 * * ?" // 每天凌晨0点检测数据上报情况
  58. //createUploadDataCronJob.AddFunc(spec, func() {
  59. // SyncToSzbl() //深圳市数据上报
  60. //})
  61. //
  62. createUploadDataCronJob.AddFunc(spec1, func() {
  63. SyncToLhblYxxxzx() //深圳市数据上报
  64. })
  65. //
  66. //createUploadDataCronJob.AddFunc(spec2, func() {
  67. // SyncToSzblbr() //深圳市数据上报
  68. //})
  69. //
  70. //createUploadDataCronJob.AddFunc(spec3, func() {
  71. // SyncToSzblbrYxxxzx() //深圳市数据上报
  72. //})
  73. //
  74. //createUploadDataCronJob.AddFunc(spec4, func() {
  75. // SyncToSzblgpYxxxzx() //深圳市数据上报
  76. //})
  77. //createUploadDataCronJob.AddFunc(spec5, func() {
  78. // SyncToWzyy() //深圳市数据上报
  79. //})
  80. //createUploadDataCronJob.AddFunc(spec6, func() {
  81. // SyncToSmzy() //深圳市数据上报
  82. //})
  83. //
  84. //createUploadDataCronJob.AddFunc(spec7, func() {
  85. // SyncToSmzyYxxxzx() //深圳市数据上报
  86. //})
  87. //createUploadDataCronJob.AddFunc(spec8, func() {
  88. // SyncToLg2h() //深圳市数据上报
  89. //})
  90. createUploadDataCronJob.Start()
  91. }
  92. // 龙华百伦
  93. func SyncToLhblYxxxzx() {
  94. org := &sz.DataUploadConfig{
  95. OrgId: 19504,
  96. ProvinceId: 19,
  97. CityId: 291,
  98. DepartmentName: "深圳市龙骅百伦血液透析中心",
  99. HospitalId: "MA5HTGMX3",
  100. InstType: 1,
  101. DbHost: "127.0.0.1",
  102. DbPort: "1433",
  103. DbPass: "1Q2W3e4r!@#$",
  104. DbUser: "adapter",
  105. DbName: "adapter_2019",
  106. }
  107. // for _, org := range configs {
  108. // 第二步:跟进配置,创建数据库连接
  109. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  110. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  111. if err != nil {
  112. utils.ErrorLog("创建数据库连接失败:%v", err)
  113. return
  114. }
  115. // 第三步:开始同步数据
  116. SyncTBDICPractitioner_pg(orgDb, org.OrgId, org.HospitalId)
  117. // 药品目录字典表
  118. SyncTBDICMedicines_pg(orgDb, org.OrgId, org.HospitalId)
  119. // 药品对照字典
  120. SyncTBDICYpdzzd_pg(orgDb, org.OrgId, org.HospitalId)
  121. // 诊疗项目目录字典表
  122. SyncTBDICZlxmml_pg(orgDb, org.OrgId, org.HospitalId)
  123. // 诊疗项目目录字典表
  124. SyncTBDICZlxmdzzd_pg(orgDb, org.OrgId, org.HospitalId)
  125. // 机构床位 t_hd_wm
  126. SyncTMDICTBED_pg(orgDb, org.OrgId, org.HospitalId)
  127. // 门诊患者信息表
  128. SyncTBMZPatientInformation_pg(orgDb, org.OrgId, org.HospitalId)
  129. // 挂号表
  130. SyncTBHISMZReg_pg(orgDb, org.OrgId, org.HospitalId)
  131. // 门诊就诊记录表
  132. SyncTB_YL_MZ_Medical_Record_pg(orgDb, org.OrgId, org.HospitalId)
  133. // 门诊处方主表
  134. SyncTB_CIS_Prescription_pg(orgDb, org.OrgId, org.HospitalId)
  135. // 18. 门诊处方明细表
  136. SyncTB_CIS_Prescription_Detail_pg(orgDb, org.OrgId, org.HospitalId)
  137. // 19. 门诊收费表
  138. SyncTB_HIS_MZ_Charge_pg(orgDb, org.OrgId, org.HospitalId)
  139. // 20. 门诊收费明细表
  140. SyncTB_HIS_MZ_Fee_Detail_pg(orgDb, org.OrgId, org.HospitalId)
  141. // 业务量收入统计表
  142. SyncTB_STAT_YWL_Report_pg(orgDb, org.OrgId, org.HospitalId)
  143. SyncDM_pg(orgDb, org.OrgId, org.HospitalId)
  144. SyncTB_Diagnosis_Detail_pg(orgDb, org.OrgId, org.HospitalId)
  145. // 第四步:关闭数据库连接
  146. service.CloseDB(orgDb)
  147. }
  148. // }
  149. return
  150. }
  151. func SyncToWzyy() {
  152. org := &sz.DataUploadConfig{
  153. OrgId: 10580,
  154. ProvinceId: 19,
  155. CityId: 291,
  156. DepartmentName: "深圳五洲中医院",
  157. HospitalId: "783910835",
  158. InstType: 2,
  159. DbHost: "172.8.110.22",
  160. DbPort: "1433",
  161. DbPass: "12361myd!@#",
  162. DbUser: "sa",
  163. DbName: "adapter_2019",
  164. }
  165. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  166. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  167. if err != nil {
  168. utils.ErrorLog("创建数据库连接失败:%v", err)
  169. return
  170. }
  171. // 第三步:开始同步数据
  172. // 同步医院信息 t_hd_hospital
  173. //SyncHospital(orgDb, org.OrgId, org.HospitalId, org.InstType, org.DepartmentName)
  174. // 同步员工 t_hd_staff
  175. SyncStaff(orgDb, org.OrgId, org.HospitalId)
  176. // 布局表(T_HD_LAYOUT)
  177. SyncLayout(orgDb, org.OrgId, org.HospitalId)
  178. // 同步设备 t_hd_dm
  179. SyncDM(orgDb, org.OrgId, org.HospitalId)
  180. // 同步水处理器 t_hd_wm
  181. SyncWMS(orgDb, org.OrgId, org.HospitalId)
  182. // 同步维修 t_hd_maintain
  183. SyncMachineRepair(orgDb, org.OrgId, org.HospitalId)
  184. // 同步设备消毒方法表(T_HD_DISINFECT_METHOD
  185. SyncDisinfectMethod(orgDb, org.OrgId, org.HospitalId)
  186. // 同步其它设备信息表(T_HD_OTHER_MACHINE)
  187. SyncOtherMachine(orgDb, org.OrgId, org.HospitalId)
  188. // 同步透析机消毒检测记录表(T_HD_DM_DISINFECT)
  189. SyncDmDisinfect(orgDb, org.OrgId, org.HospitalId)
  190. // 透析机透析液细菌培养检测记录表(t_hd_dm_dialysate_bc)
  191. SyncLisCulture(orgDb, org.OrgId, org.HospitalId)
  192. // 透析机透析液内毒素检测记录表(T_HD_DM_DIALYSATE_EN)
  193. SyncDialysate(orgDb, org.OrgId, org.HospitalId)
  194. // 水处理机消毒记录表(T_HD_WM_DISINFECT)
  195. SyncWmDisinfect(orgDb, org.OrgId, org.HospitalId)
  196. //透析用水PH值检测表(T_HD_WATER_PH)
  197. SynLisWaterPh(orgDb, org.OrgId, org.HospitalId)
  198. //透析用水细菌培养检测表(T_HD_WATER_BC)
  199. SyncLisWaterBc(orgDb, org.OrgId, org.HospitalId)
  200. //透析用水内毒素检测表(T_HD_WATER_EN)
  201. SyncLisWaterEn(orgDb, org.OrgId, org.HospitalId)
  202. //透析用水有毒化学物检测表(T_HD_WATER_NC)
  203. SynLisWaterNc(orgDb, org.OrgId, org.HospitalId)
  204. //透析用水水硬度检测表(T_HD_WATER_WH)
  205. SynListHadWater(orgDb, org.OrgId, org.HospitalId)
  206. //透析用水游离氯检测表(T_HD_WATER_FC)
  207. SyncLisWaterFc(orgDb, org.OrgId, org.HospitalId)
  208. //透析用水电解质检测表(T_HD_WATER_EL)
  209. SyncLisWaterEl(orgDb, org.OrgId, org.HospitalId)
  210. //透析用水微量元素检测表(T_HD_WATER_TE)
  211. SyncLisWaterTe(orgDb, org.OrgId, org.HospitalId)
  212. //透析室空气消毒记录表(T_HD_AIR_DISINFECT)
  213. SyncLisAirDetection(orgDb, org.OrgId, org.HospitalId)
  214. //物表消毒记录表(T_HD_SURFACE_DISINFECT)
  215. SyncLisBodyDetection(orgDb, org.OrgId, org.HospitalId)
  216. // 同步血透患者基本信息表(T_HD_PATIENT)
  217. SyncPatient(orgDb, org.OrgId, org.HospitalId)
  218. // 同步患者退出信息表(T_HD_PATIENT_QUIT)
  219. SyncPatientOut(orgDb, org.OrgId, org.HospitalId)
  220. // 同步处方 t_hd_ps
  221. SyncPs(orgDb, org.OrgId, org.HospitalId)
  222. // 同步处方药品 t_hd_ps
  223. SyncPsMedicine(orgDb, org.OrgId, org.HospitalId)
  224. // 患者诊断信息表(T_HD_DIAGNOSIS)
  225. SyncDiagnosis(orgDb, org.OrgId, org.HospitalId)
  226. // 患者通路信息表(T_HD_ACCESS)
  227. SyncAccess(orgDb, org.OrgId, org.HospitalId)
  228. //导管感染记录表(T_HD_CI)
  229. SynListHdCi(orgDb, org.OrgId, org.HospitalId)
  230. //导管感染转归记录表(T_HD_CI_OUTCOME)
  231. SynLisHdCiOutCome(orgDb, org.OrgId, org.HospitalId)
  232. // UpdatePatient(orgDb, org.OrgId, org.HospitalId)
  233. // 患者传染病检查记录表(T_HD_INFECTION
  234. SyncInfection(orgDb, org.OrgId, org.HospitalId)
  235. // 同步排班 t_hd_shift
  236. SyncShift(orgDb, org.OrgId, org.HospitalId)
  237. // 同步透析医嘱表(T_HD_DOCTORS_ADVICE)
  238. SyncDoctorAdvice(orgDb, org.OrgId, org.HospitalId)
  239. // 同步患者透析记录 t_hd_dialysis
  240. SyncDialysis(orgDb, org.OrgId, org.HospitalId)
  241. // 同步透中信息 t_hd_middle
  242. SyncMiddle(orgDb, org.OrgId, org.HospitalId)
  243. // 透析并发症记录表(T_HD_COMPLICATION)
  244. SyncComplication(orgDb, org.OrgId, org.HospitalId)
  245. // 透析床位表(T_HD_SICKBED)
  246. SyncSickbed(orgDb, org.OrgId, org.HospitalId)
  247. // 同步透析床位分区 t_hd_division
  248. SyncDivision(orgDb, org.OrgId, org.HospitalId)
  249. // 血透患者检测结果表(T_HD_LIS_REPORT)
  250. SyncLisReport(orgDb, org.OrgId, org.HospitalId)
  251. // 血透患者检验结果指标表(T_HD_LIS_INDICATORS)
  252. SyncLisIndicators(orgDb, org.OrgId, org.HospitalId)
  253. SyncLisIndicatorsBc(orgDb, org.OrgId, org.HospitalId)
  254. SyncLisReportBc(orgDb, org.OrgId, org.HospitalId)
  255. // 第四步:关闭数据库连接
  256. service.CloseDB(orgDb)
  257. }
  258. // }
  259. return
  260. }
  261. func SyncToSzbl() {
  262. org := &sz.DataUploadConfig{
  263. OrgId: 10138,
  264. ProvinceId: 19,
  265. CityId: 291,
  266. DepartmentName: "深圳市百霖血液透析中心",
  267. HospitalId: "MA5DB4KB6",
  268. InstType: 1,
  269. DbHost: "127.0.0.1",
  270. DbPort: "1433",
  271. DbPass: "1Q2W3e4r!@#$",
  272. DbUser: "adapter",
  273. DbName: "adapter_2019",
  274. }
  275. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  276. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  277. if err != nil {
  278. utils.ErrorLog("创建数据库连接失败:%v", err)
  279. return
  280. }
  281. // 第三步:开始同步数据
  282. // 同步医院信息 t_hd_hospital
  283. SyncHospital(orgDb, org.OrgId, org.HospitalId, org.InstType, org.DepartmentName)
  284. // 同步员工 t_hd_staff
  285. SyncStaff(orgDb, org.OrgId, org.HospitalId)
  286. // 布局表(T_HD_LAYOUT)
  287. SyncLayout(orgDb, org.OrgId, org.HospitalId)
  288. // 同步设备 t_hd_dm
  289. SyncDM(orgDb, org.OrgId, org.HospitalId)
  290. // 同步水处理器 t_hd_wm
  291. SyncWMS(orgDb, org.OrgId, org.HospitalId)
  292. // 同步维修 t_hd_maintain
  293. SyncMachineRepair(orgDb, org.OrgId, org.HospitalId)
  294. // 同步设备消毒方法表(T_HD_DISINFECT_METHOD
  295. SyncDisinfectMethod(orgDb, org.OrgId, org.HospitalId)
  296. // 同步其它设备信息表(T_HD_OTHER_MACHINE)
  297. SyncOtherMachine(orgDb, org.OrgId, org.HospitalId)
  298. // 同步透析机消毒检测记录表(T_HD_DM_DISINFECT)
  299. SyncDmDisinfect(orgDb, org.OrgId, org.HospitalId)
  300. // 透析机透析液细菌培养检测记录表(t_hd_dm_dialysate_bc)
  301. SyncLisCulture(orgDb, org.OrgId, org.HospitalId)
  302. // 透析机透析液内毒素检测记录表(T_HD_DM_DIALYSATE_EN)
  303. SyncDialysate(orgDb, org.OrgId, org.HospitalId)
  304. // 水处理机消毒记录表(T_HD_WM_DISINFECT)
  305. SyncWmDisinfect(orgDb, org.OrgId, org.HospitalId)
  306. //透析用水PH值检测表(T_HD_WATER_PH)
  307. SynLisWaterPh(orgDb, org.OrgId, org.HospitalId)
  308. //透析用水细菌培养检测表(T_HD_WATER_BC)
  309. SyncLisWaterBc(orgDb, org.OrgId, org.HospitalId)
  310. //透析用水内毒素检测表(T_HD_WATER_EN)
  311. SyncLisWaterEn(orgDb, org.OrgId, org.HospitalId)
  312. //透析用水有毒化学物检测表(T_HD_WATER_NC)
  313. SynLisWaterNc(orgDb, org.OrgId, org.HospitalId)
  314. //透析用水水硬度检测表(T_HD_WATER_WH)
  315. SynListHadWater(orgDb, org.OrgId, org.HospitalId)
  316. //透析用水游离氯检测表(T_HD_WATER_FC)
  317. SyncLisWaterFc(orgDb, org.OrgId, org.HospitalId)
  318. //透析用水电解质检测表(T_HD_WATER_EL)
  319. SyncLisWaterEl(orgDb, org.OrgId, org.HospitalId)
  320. //透析用水微量元素检测表(T_HD_WATER_TE)
  321. SyncLisWaterTe(orgDb, org.OrgId, org.HospitalId)
  322. //透析室空气消毒记录表(T_HD_AIR_DISINFECT)
  323. SyncLisAirDetection(orgDb, org.OrgId, org.HospitalId)
  324. //物表消毒记录表(T_HD_SURFACE_DISINFECT)
  325. SyncLisBodyDetection(orgDb, org.OrgId, org.HospitalId)
  326. // 同步血透患者基本信息表(T_HD_PATIENT)
  327. SyncPatient(orgDb, org.OrgId, org.HospitalId)
  328. // 同步患者退出信息表(T_HD_PATIENT_QUIT)
  329. SyncPatientOut(orgDb, org.OrgId, org.HospitalId)
  330. // 同步处方 t_hd_ps
  331. SyncPs(orgDb, org.OrgId, org.HospitalId)
  332. // 同步处方药品 t_hd_ps
  333. SyncPsMedicine(orgDb, org.OrgId, org.HospitalId)
  334. // 患者诊断信息表(T_HD_DIAGNOSIS)
  335. SyncDiagnosis(orgDb, org.OrgId, org.HospitalId)
  336. // 患者通路信息表(T_HD_ACCESS)
  337. SyncAccess(orgDb, org.OrgId, org.HospitalId)
  338. //导管感染记录表(T_HD_CI)
  339. SynListHdCi(orgDb, org.OrgId, org.HospitalId)
  340. //导管感染转归记录表(T_HD_CI_OUTCOME)
  341. SynLisHdCiOutCome(orgDb, org.OrgId, org.HospitalId)
  342. // UpdatePatient(orgDb, org.OrgId, org.HospitalId)
  343. // 患者传染病检查记录表(T_HD_INFECTION
  344. SyncInfection(orgDb, org.OrgId, org.HospitalId)
  345. // 同步排班 t_hd_shift
  346. SyncShift(orgDb, org.OrgId, org.HospitalId)
  347. // 同步透析医嘱表(T_HD_DOCTORS_ADVICE)
  348. SyncDoctorAdvice(orgDb, org.OrgId, org.HospitalId)
  349. // 同步患者透析记录 t_hd_dialysis
  350. SyncDialysis(orgDb, org.OrgId, org.HospitalId)
  351. // 同步透中信息 t_hd_middle
  352. SyncMiddle(orgDb, org.OrgId, org.HospitalId)
  353. // 透析并发症记录表(T_HD_COMPLICATION)
  354. SyncComplication(orgDb, org.OrgId, org.HospitalId)
  355. // 透析床位表(T_HD_SICKBED)
  356. SyncSickbed(orgDb, org.OrgId, org.HospitalId)
  357. // 同步透析床位分区 t_hd_division
  358. SyncDivision(orgDb, org.OrgId, org.HospitalId)
  359. // 血透患者检测结果表(T_HD_LIS_REPORT)
  360. SyncLisReport(orgDb, org.OrgId, org.HospitalId)
  361. // 血透患者检验结果指标表(T_HD_LIS_INDICATORS)
  362. SyncLisIndicators(orgDb, org.OrgId, org.HospitalId)
  363. SyncLisIndicatorsBc(orgDb, org.OrgId, org.HospitalId)
  364. SyncLisReportBc(orgDb, org.OrgId, org.HospitalId)
  365. // 第四步:关闭数据库连接
  366. service.CloseDB(orgDb)
  367. }
  368. // }
  369. return
  370. }
  371. func SyncToSzblYxxxzx() {
  372. org := &sz.DataUploadConfig{
  373. OrgId: 10138,
  374. ProvinceId: 19,
  375. CityId: 291,
  376. DepartmentName: "深圳市百霖血液透析中心",
  377. HospitalId: "MA5DB4KB6",
  378. InstType: 1,
  379. DbHost: "127.0.0.1",
  380. DbPort: "1433",
  381. DbPass: "1Q2W3e4r!@#$",
  382. DbUser: "adapter",
  383. DbName: "adapter_2019",
  384. }
  385. // for _, org := range configs {
  386. // 第二步:跟进配置,创建数据库连接
  387. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  388. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  389. if err != nil {
  390. utils.ErrorLog("创建数据库连接失败:%v", err)
  391. return
  392. }
  393. // 第三步:开始同步数据
  394. // 机构人员字典表 t_hd_hospital
  395. SyncTBDICPractitioner(orgDb, org.OrgId, org.HospitalId)
  396. // 药品目录字典表
  397. SyncTBDICMedicines(orgDb, org.OrgId, org.HospitalId)
  398. // 药品对照字典
  399. SyncTBDICYpdzzd(orgDb, org.OrgId, org.HospitalId)
  400. // 诊疗项目目录字典表
  401. SyncTBDICZlxmml(orgDb, org.OrgId, org.HospitalId)
  402. // 诊疗项目目录字典表
  403. SyncTBDICZlxmdzzd(orgDb, org.OrgId, org.HospitalId)
  404. // 机构床位 t_hd_wm
  405. SyncTMDICTBED(orgDb, org.OrgId, org.HospitalId)
  406. // 门诊患者信息表
  407. SyncTBMZPatientInformation(orgDb, org.OrgId, org.HospitalId)
  408. // 挂号表
  409. SyncTBHISMZReg(orgDb, org.OrgId, org.HospitalId)
  410. // 门诊就诊记录表
  411. SyncTB_YL_MZ_Medical_Record(orgDb, org.OrgId, org.HospitalId)
  412. // 门诊处方主表
  413. SyncTB_CIS_Prescription(orgDb, org.OrgId, org.HospitalId)
  414. // 18. 门诊处方明细表
  415. SyncTB_CIS_Prescription_Detail(orgDb, org.OrgId, org.HospitalId)
  416. // 19. 门诊收费表
  417. SyncTB_HIS_MZ_Charge(orgDb, org.OrgId, org.HospitalId)
  418. // 20. 门诊收费明细表
  419. SyncTB_HIS_MZ_Fee_Detail(orgDb, org.OrgId, org.HospitalId)
  420. // 业务量收入统计表
  421. SyncTB_STAT_YWL_Report(orgDb, org.OrgId, org.HospitalId)
  422. SyncTB_Diagnosis_Detail(orgDb, org.OrgId, org.HospitalId)
  423. // 第四步:关闭数据库连接
  424. service.CloseDB(orgDb)
  425. }
  426. // }
  427. return
  428. }
  429. func SyncToSzblYxxxzxtmp() {
  430. org := &sz.DataUploadConfig{
  431. OrgId: 10138,
  432. ProvinceId: 19,
  433. CityId: 291,
  434. DepartmentName: "深圳市百霖血液透析中心",
  435. HospitalId: "MA5DB4KB6",
  436. InstType: 1,
  437. DbHost: "127.0.0.1",
  438. DbPort: "1433",
  439. DbPass: "1Q2W3e4r!@#$",
  440. DbUser: "adapter",
  441. DbName: "adapter_2019",
  442. }
  443. // for _, org := range configs {
  444. // 第二步:跟进配置,创建数据库连接
  445. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  446. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  447. if err != nil {
  448. utils.ErrorLog("创建数据库连接失败:%v", err)
  449. return
  450. }
  451. // 第三步:开始同步数据
  452. // 机构人员字典表 t_hd_hospital
  453. SyncTBDICPractitioner(orgDb, org.OrgId, org.HospitalId)
  454. // 药品目录字典表
  455. SyncTBDICMedicines(orgDb, org.OrgId, org.HospitalId)
  456. // 药品对照字典
  457. SyncTBDICYpdzzd(orgDb, org.OrgId, org.HospitalId)
  458. // 诊疗项目目录字典表
  459. SyncTBDICZlxmml(orgDb, org.OrgId, org.HospitalId)
  460. // 诊疗项目目录字典表
  461. SyncTBDICZlxmdzzd(orgDb, org.OrgId, org.HospitalId)
  462. // 机构床位 t_hd_wm
  463. SyncTMDICTBED(orgDb, org.OrgId, org.HospitalId)
  464. // 门诊患者信息表
  465. SyncTBMZPatientInformation(orgDb, org.OrgId, org.HospitalId)
  466. // 挂号表
  467. SyncTBHISMZReg(orgDb, org.OrgId, org.HospitalId)
  468. // 门诊就诊记录表
  469. SyncTB_YL_MZ_Medical_Record(orgDb, org.OrgId, org.HospitalId)
  470. // 门诊处方主表
  471. SyncTB_CIS_Prescription(orgDb, org.OrgId, org.HospitalId)
  472. // 18. 门诊处方明细表
  473. SyncTB_CIS_Prescription_Detail(orgDb, org.OrgId, org.HospitalId)
  474. // 19. 门诊收费表
  475. SyncTB_HIS_MZ_Charge(orgDb, org.OrgId, org.HospitalId)
  476. // 20. 门诊收费明细表
  477. SyncTB_HIS_MZ_Fee_Detail(orgDb, org.OrgId, org.HospitalId)
  478. // 业务量收入统计表
  479. SyncTB_STAT_YWL_Report(orgDb, org.OrgId, org.HospitalId)
  480. SyncTB_Diagnosis_Detail(orgDb, org.OrgId, org.HospitalId)
  481. // 第四步:关闭数据库连接
  482. service.CloseDB(orgDb)
  483. }
  484. // }
  485. return
  486. }
  487. func SyncToSzblbr() {
  488. org := &sz.DataUploadConfig{
  489. OrgId: 10278,
  490. ProvinceId: 19,
  491. CityId: 291,
  492. DepartmentName: "深圳市百霖贝尔血液透析中心",
  493. HospitalId: "MA5G5BPX7",
  494. InstType: 1,
  495. DbHost: "127.0.0.1",
  496. DbPort: "1433",
  497. DbPass: "1Q2W3e4r!@#$",
  498. DbUser: "adapter",
  499. DbName: "adapter_blbe",
  500. }
  501. // for _, org := range configs {
  502. // 第二步:跟进配置,创建数据库连接
  503. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  504. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  505. if err != nil {
  506. utils.ErrorLog("创建数据库连接失败:%v", err)
  507. return
  508. }
  509. // 第三步:开始同步数据
  510. // 同步医院信息 t_hd_hospital
  511. SyncHospital(orgDb, org.OrgId, org.HospitalId, org.InstType, org.DepartmentName)
  512. // 同步员工 t_hd_staff
  513. SyncStaff(orgDb, org.OrgId, org.HospitalId)
  514. // 布局表(T_HD_LAYOUT)
  515. SyncLayout(orgDb, org.OrgId, org.HospitalId)
  516. // 同步设备 t_hd_dm
  517. SyncDM(orgDb, org.OrgId, org.HospitalId)
  518. // 同步水处理器 t_hd_wm
  519. SyncWMS(orgDb, org.OrgId, org.HospitalId)
  520. // 同步维修 t_hd_maintain
  521. SyncMachineRepair(orgDb, org.OrgId, org.HospitalId)
  522. // 同步设备消毒方法表(T_HD_DISINFECT_METHOD
  523. SyncDisinfectMethod(orgDb, org.OrgId, org.HospitalId)
  524. // 同步其它设备信息表(T_HD_OTHER_MACHINE)
  525. SyncOtherMachine(orgDb, org.OrgId, org.HospitalId)
  526. // 同步透析机消毒检测记录表(T_HD_DM_DISINFECT)
  527. SyncDmDisinfect(orgDb, org.OrgId, org.HospitalId)
  528. // 透析机透析液细菌培养检测记录表(t_hd_dm_dialysate_bc)
  529. SyncLisCulture(orgDb, org.OrgId, org.HospitalId)
  530. // 透析机透析液内毒素检测记录表(T_HD_DM_DIALYSATE_EN)
  531. SyncDialysate(orgDb, org.OrgId, org.HospitalId)
  532. // 水处理机消毒记录表(T_HD_WM_DISINFECT)
  533. SyncWmDisinfect(orgDb, org.OrgId, org.HospitalId)
  534. //透析用水PH值检测表(T_HD_WATER_PH)
  535. SynLisWaterPh(orgDb, org.OrgId, org.HospitalId)
  536. //透析用水细菌培养检测表(T_HD_WATER_BC)
  537. SyncLisWaterBc(orgDb, org.OrgId, org.HospitalId)
  538. //透析用水内毒素检测表(T_HD_WATER_EN)
  539. SyncLisWaterEn(orgDb, org.OrgId, org.HospitalId)
  540. //透析用水有毒化学物检测表(T_HD_WATER_NC)
  541. SynLisWaterNc(orgDb, org.OrgId, org.HospitalId)
  542. //透析用水水硬度检测表(T_HD_WATER_WH)
  543. SynListHadWater(orgDb, org.OrgId, org.HospitalId)
  544. //透析用水游离氯检测表(T_HD_WATER_FC)
  545. SyncLisWaterFc(orgDb, org.OrgId, org.HospitalId)
  546. //透析用水电解质检测表(T_HD_WATER_EL)
  547. SyncLisWaterEl(orgDb, org.OrgId, org.HospitalId)
  548. //透析用水微量元素检测表(T_HD_WATER_TE)
  549. SyncLisWaterTe(orgDb, org.OrgId, org.HospitalId)
  550. //透析室空气消毒记录表(T_HD_AIR_DISINFECT)
  551. SyncLisAirDetection(orgDb, org.OrgId, org.HospitalId)
  552. //物表消毒记录表(T_HD_SURFACE_DISINFECT)
  553. SyncLisBodyDetection(orgDb, org.OrgId, org.HospitalId)
  554. // 同步血透患者基本信息表(T_HD_PATIENT)
  555. SyncPatient(orgDb, org.OrgId, org.HospitalId)
  556. // 同步患者退出信息表(T_HD_PATIENT_QUIT)
  557. SyncPatientOut(orgDb, org.OrgId, org.HospitalId)
  558. // 同步处方 t_hd_ps
  559. SyncPs(orgDb, org.OrgId, org.HospitalId)
  560. // 同步处方药品 t_hd_ps
  561. SyncPsMedicine(orgDb, org.OrgId, org.HospitalId)
  562. // 患者诊断信息表(T_HD_DIAGNOSIS)
  563. SyncDiagnosis(orgDb, org.OrgId, org.HospitalId)
  564. // 患者通路信息表(T_HD_ACCESS)
  565. SyncAccess(orgDb, org.OrgId, org.HospitalId)
  566. //导管感染记录表(T_HD_CI)
  567. SynListHdCi(orgDb, org.OrgId, org.HospitalId)
  568. //导管感染转归记录表(T_HD_CI_OUTCOME)
  569. SynLisHdCiOutCome(orgDb, org.OrgId, org.HospitalId)
  570. // city.UpdatePatient(orgDb, org.OrgId, org.HospitalId)
  571. // 患者传染病检查记录表(T_HD_INFECTION
  572. SyncInfection(orgDb, org.OrgId, org.HospitalId)
  573. // 同步排班 t_hd_shift
  574. SyncShift(orgDb, org.OrgId, org.HospitalId)
  575. // 同步透析医嘱表(T_HD_DOCTORS_ADVICE)
  576. SyncDoctorAdvice(orgDb, org.OrgId, org.HospitalId)
  577. // 同步患者透析记录 t_hd_dialysis
  578. SyncDialysis(orgDb, org.OrgId, org.HospitalId)
  579. // 同步透中信息 t_hd_middle
  580. SyncMiddle(orgDb, org.OrgId, org.HospitalId)
  581. // 透析并发症记录表(T_HD_COMPLICATION)
  582. SyncComplication(orgDb, org.OrgId, org.HospitalId)
  583. // 透析床位表(T_HD_SICKBED)
  584. SyncSickbed(orgDb, org.OrgId, org.HospitalId)
  585. // 同步透析床位分区 t_hd_division
  586. SyncDivision(orgDb, org.OrgId, org.HospitalId)
  587. // 血透患者检测结果表(T_HD_LIS_REPORT)
  588. SyncLisReport(orgDb, org.OrgId, org.HospitalId)
  589. // 血透患者检验结果指标表(T_HD_LIS_INDICATORS)
  590. SyncLisIndicators(orgDb, org.OrgId, org.HospitalId)
  591. SyncLisIndicatorsBc(orgDb, org.OrgId, org.HospitalId)
  592. SyncLisReportBc(orgDb, org.OrgId, org.HospitalId)
  593. // 第四步:关闭数据库连接
  594. service.CloseDB(orgDb)
  595. }
  596. // }
  597. return
  598. }
  599. func SyncToSzblpg() {
  600. org := &sz.DataUploadConfig{
  601. OrgId: 10610,
  602. ProvinceId: 19,
  603. CityId: 291,
  604. DepartmentName: "深圳百霖鹏港血液透析中心",
  605. HospitalId: "MACWP1CB3",
  606. InstType: 1,
  607. DbHost: "127.0.0.1",
  608. DbPort: "1433",
  609. DbPass: "1Q2W3e4r!@#$",
  610. DbUser: "adapter_new",
  611. DbName: "adapter_new",
  612. }
  613. // for _, org := range configs {
  614. // 第二步:跟进配置,创建数据库连接
  615. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  616. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  617. if err != nil {
  618. utils.ErrorLog("创建数据库连接失败:%v", err)
  619. return
  620. }
  621. // 第三步:开始同步数据
  622. // 同步医院信息 t_hd_hospital
  623. SyncHospital(orgDb, org.OrgId, org.HospitalId, org.InstType, org.DepartmentName)
  624. // 同步员工 t_hd_staff
  625. SyncStaff(orgDb, org.OrgId, org.HospitalId)
  626. // 布局表(T_HD_LAYOUT)
  627. SyncLayout(orgDb, org.OrgId, org.HospitalId)
  628. // 同步设备 t_hd_dm
  629. SyncDM(orgDb, org.OrgId, org.HospitalId)
  630. // 同步水处理器 t_hd_wm
  631. SyncWMS(orgDb, org.OrgId, org.HospitalId)
  632. // 同步维修 t_hd_maintain
  633. SyncMachineRepair(orgDb, org.OrgId, org.HospitalId)
  634. // 同步设备消毒方法表(T_HD_DISINFECT_METHOD
  635. SyncDisinfectMethod(orgDb, org.OrgId, org.HospitalId)
  636. // 同步其它设备信息表(T_HD_OTHER_MACHINE)
  637. SyncOtherMachine(orgDb, org.OrgId, org.HospitalId)
  638. // 同步透析机消毒检测记录表(T_HD_DM_DISINFECT)
  639. SyncDmDisinfect(orgDb, org.OrgId, org.HospitalId)
  640. // 透析机透析液细菌培养检测记录表(t_hd_dm_dialysate_bc)
  641. SyncLisCulture(orgDb, org.OrgId, org.HospitalId)
  642. // 透析机透析液内毒素检测记录表(T_HD_DM_DIALYSATE_EN)
  643. SyncDialysate(orgDb, org.OrgId, org.HospitalId)
  644. // 水处理机消毒记录表(T_HD_WM_DISINFECT)
  645. SyncWmDisinfect(orgDb, org.OrgId, org.HospitalId)
  646. //透析用水PH值检测表(T_HD_WATER_PH)
  647. SynLisWaterPh(orgDb, org.OrgId, org.HospitalId)
  648. //透析用水细菌培养检测表(T_HD_WATER_BC)
  649. SyncLisWaterBc(orgDb, org.OrgId, org.HospitalId)
  650. //透析用水内毒素检测表(T_HD_WATER_EN)
  651. SyncLisWaterEn(orgDb, org.OrgId, org.HospitalId)
  652. //透析用水有毒化学物检测表(T_HD_WATER_NC)
  653. SynLisWaterNc(orgDb, org.OrgId, org.HospitalId)
  654. //透析用水水硬度检测表(T_HD_WATER_WH)
  655. SynListHadWater(orgDb, org.OrgId, org.HospitalId)
  656. //透析用水游离氯检测表(T_HD_WATER_FC)
  657. SyncLisWaterFc(orgDb, org.OrgId, org.HospitalId)
  658. //透析用水电解质检测表(T_HD_WATER_EL)
  659. SyncLisWaterEl(orgDb, org.OrgId, org.HospitalId)
  660. //透析用水微量元素检测表(T_HD_WATER_TE)
  661. SyncLisWaterTe(orgDb, org.OrgId, org.HospitalId)
  662. //透析室空气消毒记录表(T_HD_AIR_DISINFECT)
  663. SyncLisAirDetection(orgDb, org.OrgId, org.HospitalId)
  664. //物表消毒记录表(T_HD_SURFACE_DISINFECT)
  665. SyncLisBodyDetection(orgDb, org.OrgId, org.HospitalId)
  666. // 同步血透患者基本信息表(T_HD_PATIENT)
  667. SyncPatient(orgDb, org.OrgId, org.HospitalId)
  668. // 同步患者退出信息表(T_HD_PATIENT_QUIT)
  669. SyncPatientOut(orgDb, org.OrgId, org.HospitalId)
  670. // 同步处方 t_hd_ps
  671. SyncPs(orgDb, org.OrgId, org.HospitalId)
  672. // 同步处方药品 t_hd_ps
  673. SyncPsMedicine(orgDb, org.OrgId, org.HospitalId)
  674. // 患者诊断信息表(T_HD_DIAGNOSIS)
  675. SyncDiagnosis(orgDb, org.OrgId, org.HospitalId)
  676. // 患者通路信息表(T_HD_ACCESS)
  677. SyncAccess(orgDb, org.OrgId, org.HospitalId)
  678. //导管感染记录表(T_HD_CI)
  679. SynListHdCi(orgDb, org.OrgId, org.HospitalId)
  680. //导管感染转归记录表(T_HD_CI_OUTCOME)
  681. SynLisHdCiOutCome(orgDb, org.OrgId, org.HospitalId)
  682. // city.UpdatePatient(orgDb, org.OrgId, org.HospitalId)
  683. // 患者传染病检查记录表(T_HD_INFECTION
  684. SyncInfection(orgDb, org.OrgId, org.HospitalId)
  685. // 同步排班 t_hd_shift
  686. SyncShift(orgDb, org.OrgId, org.HospitalId)
  687. // 同步透析医嘱表(T_HD_DOCTORS_ADVICE)
  688. SyncDoctorAdvice(orgDb, org.OrgId, org.HospitalId)
  689. // 同步患者透析记录 t_hd_dialysis
  690. SyncDialysis(orgDb, org.OrgId, org.HospitalId)
  691. // 同步透中信息 t_hd_middle
  692. SyncMiddle(orgDb, org.OrgId, org.HospitalId)
  693. // 透析并发症记录表(T_HD_COMPLICATION)
  694. SyncComplication(orgDb, org.OrgId, org.HospitalId)
  695. // 透析床位表(T_HD_SICKBED)
  696. SyncSickbed2(orgDb, org.OrgId, org.HospitalId)
  697. // 同步透析床位分区 t_hd_division
  698. SyncDivision(orgDb, org.OrgId, org.HospitalId)
  699. // 血透患者检测结果表(T_HD_LIS_REPORT)
  700. SyncLisReport(orgDb, org.OrgId, org.HospitalId)
  701. // 血透患者检验结果指标表(T_HD_LIS_INDICATORS)
  702. SyncLisIndicators(orgDb, org.OrgId, org.HospitalId)
  703. SyncLisIndicatorsBc(orgDb, org.OrgId, org.HospitalId)
  704. SyncLisReportBc(orgDb, org.OrgId, org.HospitalId)
  705. // 第四步:关闭数据库连接
  706. service.CloseDB(orgDb)
  707. }
  708. // }
  709. return
  710. }
  711. func SyncToSzblgpYxxxzx() {
  712. org := &sz.DataUploadConfig{
  713. OrgId: 10610,
  714. ProvinceId: 19,
  715. CityId: 291,
  716. DepartmentName: "深圳市百霖鹏港血液透析中心",
  717. HospitalId: "MACWP1CB3",
  718. InstType: 1,
  719. DbHost: "127.0.0.1",
  720. DbPort: "1433",
  721. DbPass: "1Q2W3e4r!@#$",
  722. DbUser: "adapter",
  723. DbName: "adapter_blpg",
  724. }
  725. // for _, org := range configs {
  726. // 第二步:跟进配置,创建数据库连接
  727. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  728. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  729. if err != nil {
  730. utils.ErrorLog("创建数据库连接失败:%v", err)
  731. return
  732. }
  733. // 第三步:开始同步数据
  734. // 机构人员字典表 t_hd_hospital
  735. SyncTBDICPractitioner_pg(orgDb, org.OrgId, org.HospitalId)
  736. // 药品目录字典表
  737. SyncTBDICMedicines_pg(orgDb, org.OrgId, org.HospitalId)
  738. // 药品对照字典
  739. SyncTBDICYpdzzd_pg(orgDb, org.OrgId, org.HospitalId)
  740. // 诊疗项目目录字典表
  741. SyncTBDICZlxmml_pg(orgDb, org.OrgId, org.HospitalId)
  742. // 诊疗项目目录字典表
  743. SyncTBDICZlxmdzzd_pg(orgDb, org.OrgId, org.HospitalId)
  744. // 机构床位 t_hd_wm
  745. SyncTMDICTBED_pg(orgDb, org.OrgId, org.HospitalId)
  746. // 门诊患者信息表
  747. SyncTBMZPatientInformation_pg(orgDb, org.OrgId, org.HospitalId)
  748. // 挂号表
  749. SyncTBHISMZReg_pg(orgDb, org.OrgId, org.HospitalId)
  750. // 门诊就诊记录表
  751. SyncTB_YL_MZ_Medical_Record_pg(orgDb, org.OrgId, org.HospitalId)
  752. // 门诊处方主表
  753. SyncTB_CIS_Prescription_pg(orgDb, org.OrgId, org.HospitalId)
  754. // 18. 门诊处方明细表
  755. SyncTB_CIS_Prescription_Detail_pg(orgDb, org.OrgId, org.HospitalId)
  756. // 19. 门诊收费表
  757. SyncTB_HIS_MZ_Charge_pg(orgDb, org.OrgId, org.HospitalId)
  758. // 20. 门诊收费明细表
  759. SyncTB_HIS_MZ_Fee_Detail_pg(orgDb, org.OrgId, org.HospitalId)
  760. // 业务量收入统计表
  761. SyncTB_STAT_YWL_Report_pg(orgDb, org.OrgId, org.HospitalId)
  762. SyncDM(orgDb, org.OrgId, org.HospitalId)
  763. SyncTB_Diagnosis_Detail_pg(orgDb, org.OrgId, org.HospitalId)
  764. // 第四步:关闭数据库连接
  765. service.CloseDB(orgDb)
  766. }
  767. // }
  768. return
  769. }
  770. func SyncToSzzxtmp() {
  771. org := &sz.DataUploadConfig{
  772. OrgId: 10138,
  773. ProvinceId: 19,
  774. CityId: 291,
  775. DepartmentName: "深圳市百霖血液透析中心",
  776. HospitalId: "MA5DB4KB6",
  777. InstType: 1,
  778. DbHost: "127.0.0.1",
  779. DbPort: "1433",
  780. DbPass: "1Q2W3e4r!@#$",
  781. DbUser: "adapter",
  782. DbName: "adapter_2019",
  783. }
  784. // for _, org := range configs {
  785. // 第二步:跟进配置,创建数据库连接
  786. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  787. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  788. if err != nil {
  789. utils.ErrorLog("创建数据库连接失败:%v", err)
  790. return
  791. }
  792. //// 第三步:开始同步数据
  793. //// 机构人员字典表 t_hd_hospital
  794. //SyncTBDICPractitioner(orgDb, org.OrgId, org.HospitalId)
  795. //// 药品目录字典表
  796. //SyncTBDICMedicines(orgDb, org.OrgId, org.HospitalId)
  797. //// 药品对照字典
  798. //SyncTBDICYpdzzd(orgDb, org.OrgId, org.HospitalId)
  799. //// 诊疗项目目录字典表
  800. //SyncTBDICZlxmml(orgDb, org.OrgId, org.HospitalId)
  801. //// 诊疗项目目录字典表
  802. //SyncTBDICZlxmdzzd(orgDb, org.OrgId, org.HospitalId)
  803. //// 机构床位 t_hd_wm
  804. //SyncTMDICTBED(orgDb, org.OrgId, org.HospitalId)
  805. //// 门诊患者信息表
  806. //SyncTBMZPatientInformation(orgDb, org.OrgId, org.HospitalId)
  807. //// 挂号表
  808. //SyncTBHISMZReg(orgDb, org.OrgId, org.HospitalId)
  809. //// 门诊就诊记录表
  810. //SyncTB_YL_MZ_Medical_Record(orgDb, org.OrgId, org.HospitalId)
  811. //// 门诊处方主表
  812. //SyncTB_CIS_Prescription(orgDb, org.OrgId, org.HospitalId)
  813. //// 18. 门诊处方明细表
  814. //SyncTB_CIS_Prescription_Detail(orgDb, org.OrgId, org.HospitalId)
  815. //// 19. 门诊收费表
  816. //SyncTB_HIS_MZ_Charge(orgDb, org.OrgId, org.HospitalId)
  817. //// 20. 门诊收费明细表
  818. //SyncTB_HIS_MZ_Fee_Detail(orgDb, org.OrgId, org.HospitalId)
  819. //// 业务量收入统计表
  820. //SyncTB_STAT_YWL_Report(orgDb, org.OrgId, org.HospitalId)
  821. //SyncTB_Diagnosis_Detail(orgDb, org.OrgId, org.HospitalId)
  822. SyncTB_HIS_MZ_BL_Detail(orgDb,org.OrgId,org.HospitalId)
  823. // 第四步:关闭数据库连接
  824. service.CloseDB(orgDb)
  825. }
  826. // }
  827. return
  828. }
  829. func SyncToSzblbrYxxxzxtmpp() {
  830. org := &sz.DataUploadConfig{
  831. OrgId: 10278,
  832. ProvinceId: 19,
  833. CityId: 291,
  834. DepartmentName: "深圳市百霖贝尔血液透析中心",
  835. HospitalId: "MA5G5BPX7",
  836. InstType: 1,
  837. DbHost: "127.0.0.1",
  838. DbPort: "1433",
  839. DbPass: "1Q2W3e4r!@#$",
  840. DbUser: "adapter",
  841. DbName: "adapter_blbe",
  842. }
  843. // for _, org := range configs {
  844. // 第二步:跟进配置,创建数据库连接
  845. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  846. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  847. if err != nil {
  848. utils.ErrorLog("创建数据库连接失败:%v", err)
  849. return
  850. }
  851. SyncTB_HIS_MZ_BL_Detail(orgDb,org.OrgId,org.HospitalId)
  852. // 第四步:关闭数据库连接
  853. service.CloseDB(orgDb)
  854. }
  855. // }
  856. return
  857. }
  858. func SyncToSzbltmp() {
  859. org := &sz.DataUploadConfig{
  860. OrgId: 10138,
  861. ProvinceId: 19,
  862. CityId: 291,
  863. DepartmentName: "深圳市百霖贝尔血液透析中心",
  864. HospitalId: "MA5G5BPX7",
  865. InstType: 1,
  866. DbHost: "127.0.0.1",
  867. DbPort: "1433",
  868. DbPass: "1Q2W3e4r!@#$",
  869. DbUser: "adapter",
  870. DbName: "adapter_blbe",
  871. }
  872. // for _, org := range configs {
  873. // 第二步:跟进配置,创建数据库连接
  874. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  875. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  876. if err != nil {
  877. utils.ErrorLog("创建数据库连接失败:%v", err)
  878. return
  879. }
  880. SyncLisIndicatorsBc(orgDb, org.OrgId, org.HospitalId)
  881. SyncLisReportBc(orgDb, org.OrgId, org.HospitalId)
  882. // 第四步:关闭数据库连接
  883. service.CloseDB(orgDb)
  884. }
  885. return
  886. }
  887. func SyncToSzblbrtmp() {
  888. org := &sz.DataUploadConfig{
  889. OrgId: 10278,
  890. ProvinceId: 19,
  891. CityId: 291,
  892. DepartmentName: "深圳市百霖贝尔血液透析中心",
  893. HospitalId: "MA5G5BPX7",
  894. InstType: 1,
  895. DbHost: "127.0.0.1",
  896. DbPort: "1433",
  897. DbPass: "1Q2W3e4r!@#$",
  898. DbUser: "adapter",
  899. DbName: "adapter_blbe",
  900. }
  901. // for _, org := range configs {
  902. // 第二步:跟进配置,创建数据库连接
  903. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  904. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  905. if err != nil {
  906. utils.ErrorLog("创建数据库连接失败:%v", err)
  907. return
  908. }
  909. SyncLisIndicatorsBc(orgDb, org.OrgId, org.HospitalId)
  910. SyncLisReportBc(orgDb, org.OrgId, org.HospitalId)
  911. // 第四步:关闭数据库连接
  912. service.CloseDB(orgDb)
  913. }
  914. return
  915. }
  916. func SyncToSzblbrYxxxzx() {
  917. org := &sz.DataUploadConfig{
  918. OrgId: 10278,
  919. ProvinceId: 19,
  920. CityId: 291,
  921. DepartmentName: "深圳市百霖贝尔血液透析中心",
  922. HospitalId: "MA5G5BPX7",
  923. InstType: 1,
  924. DbHost: "127.0.0.1",
  925. DbPort: "1433",
  926. DbPass: "1Q2W3e4r!@#$",
  927. DbUser: "adapter",
  928. DbName: "adapter_blbe",
  929. }
  930. // for _, org := range configs {
  931. // 第二步:跟进配置,创建数据库连接
  932. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  933. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  934. if err != nil {
  935. utils.ErrorLog("创建数据库连接失败:%v", err)
  936. return
  937. }
  938. // 第三步:开始同步数据
  939. // 机构人员字典表 t_hd_hospital
  940. SyncTBDICPractitioner(orgDb, org.OrgId, org.HospitalId)
  941. // 药品目录字典表
  942. SyncTBDICMedicines(orgDb, org.OrgId, org.HospitalId)
  943. // 药品对照字典
  944. SyncTBDICYpdzzd(orgDb, org.OrgId, org.HospitalId)
  945. // 诊疗项目目录字典表
  946. SyncTBDICZlxmml(orgDb, org.OrgId, org.HospitalId)
  947. // 诊疗项目目录字典表
  948. SyncTBDICZlxmdzzd(orgDb, org.OrgId, org.HospitalId)
  949. // 机构床位 t_hd_wm
  950. SyncTMDICTBED(orgDb, org.OrgId, org.HospitalId)
  951. // 门诊患者信息表
  952. SyncTBMZPatientInformation(orgDb, org.OrgId, org.HospitalId)
  953. // 挂号表
  954. SyncTBHISMZReg(orgDb, org.OrgId, org.HospitalId)
  955. // 门诊就诊记录表
  956. SyncTB_YL_MZ_Medical_Record(orgDb, org.OrgId, org.HospitalId)
  957. // 门诊处方主表
  958. SyncTB_CIS_Prescription(orgDb, org.OrgId, org.HospitalId)
  959. // 18. 门诊处方明细表
  960. SyncTB_CIS_Prescription_Detail(orgDb, org.OrgId, org.HospitalId)
  961. // 19. 门诊收费表
  962. SyncTB_HIS_MZ_Charge(orgDb, org.OrgId, org.HospitalId)
  963. // 20. 门诊收费明细表
  964. SyncTB_HIS_MZ_Fee_Detail(orgDb, org.OrgId, org.HospitalId)
  965. // 业务量收入统计表
  966. SyncTB_STAT_YWL_Report(orgDb, org.OrgId, org.HospitalId)
  967. SyncTB_Diagnosis_Detail(orgDb, org.OrgId, org.HospitalId)
  968. // 第四步:关闭数据库连接
  969. service.CloseDB(orgDb)
  970. }
  971. // }
  972. return
  973. }
  974. func SyncToSzjk() {
  975. org := &sz.DataUploadConfig{
  976. OrgId: 10245,
  977. ProvinceId: 19,
  978. CityId: 291,
  979. DepartmentName: "深圳静康医院血液透析中心",
  980. HospitalId: "MA5DKWHG3",
  981. InstType: 1,
  982. DbHost: "localhost",
  983. DbPort: "1433",
  984. DbPass: "Ya2019",
  985. DbUser: "sa",
  986. DbName: "xtzk",
  987. }
  988. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  989. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  990. if err != nil {
  991. utils.ErrorLog("创建数据库连接失败:%v", err)
  992. return
  993. }
  994. // 第三步:开始同步数据
  995. // 同步医院信息 t_hd_hospital
  996. SyncHospital(orgDb, org.OrgId, org.HospitalId, org.InstType, org.DepartmentName)
  997. // 同步员工 t_hd_staff
  998. SyncStaff(orgDb, org.OrgId, org.HospitalId)
  999. // 布局表(T_HD_LAYOUT)
  1000. SyncLayout(orgDb, org.OrgId, org.HospitalId)
  1001. // 同步设备 t_hd_dm
  1002. SyncDM(orgDb, org.OrgId, org.HospitalId)
  1003. // 同步水处理器 t_hd_wm
  1004. SyncWMS(orgDb, org.OrgId, org.HospitalId)
  1005. // 同步维修 t_hd_maintain
  1006. SyncMachineRepair(orgDb, org.OrgId, org.HospitalId)
  1007. // 同步设备消毒方法表(T_HD_DISINFECT_METHOD
  1008. SyncDisinfectMethod(orgDb, org.OrgId, org.HospitalId)
  1009. // 同步其它设备信息表(T_HD_OTHER_MACHINE)
  1010. SyncOtherMachine(orgDb, org.OrgId, org.HospitalId)
  1011. // 同步透析机消毒检测记录表(T_HD_DM_DISINFECT)
  1012. SyncDmDisinfect(orgDb, org.OrgId, org.HospitalId)
  1013. // 透析机透析液细菌培养检测记录表(t_hd_dm_dialysate_bc)
  1014. SyncLisCulture(orgDb, org.OrgId, org.HospitalId)
  1015. // 透析机透析液内毒素检测记录表(T_HD_DM_DIALYSATE_EN)
  1016. SyncDialysate(orgDb, org.OrgId, org.HospitalId)
  1017. // 水处理机消毒记录表(T_HD_WM_DISINFECT)
  1018. SyncWmDisinfect(orgDb, org.OrgId, org.HospitalId)
  1019. //透析用水PH值检测表(T_HD_WATER_PH)
  1020. SynLisWaterPh(orgDb, org.OrgId, org.HospitalId)
  1021. //透析用水细菌培养检测表(T_HD_WATER_BC)
  1022. SyncLisWaterBc(orgDb, org.OrgId, org.HospitalId)
  1023. //透析用水内毒素检测表(T_HD_WATER_EN)
  1024. SyncLisWaterEn(orgDb, org.OrgId, org.HospitalId)
  1025. //透析用水有毒化学物检测表(T_HD_WATER_NC)
  1026. SynLisWaterNc(orgDb, org.OrgId, org.HospitalId)
  1027. //透析用水水硬度检测表(T_HD_WATER_WH)
  1028. SynListHadWater(orgDb, org.OrgId, org.HospitalId)
  1029. //透析用水游离氯检测表(T_HD_WATER_FC)
  1030. SyncLisWaterFc(orgDb, org.OrgId, org.HospitalId)
  1031. //透析用水电解质检测表(T_HD_WATER_EL)
  1032. SyncLisWaterEl(orgDb, org.OrgId, org.HospitalId)
  1033. //透析用水微量元素检测表(T_HD_WATER_TE)
  1034. SyncLisWaterTe(orgDb, org.OrgId, org.HospitalId)
  1035. //透析室空气消毒记录表(T_HD_AIR_DISINFECT)
  1036. SyncLisAirDetection(orgDb, org.OrgId, org.HospitalId)
  1037. //物表消毒记录表(T_HD_SURFACE_DISINFECT)
  1038. SyncLisBodyDetection(orgDb, org.OrgId, org.HospitalId)
  1039. // 同步血透患者基本信息表(T_HD_PATIENT)
  1040. SyncPatient(orgDb, org.OrgId, org.HospitalId)
  1041. // 同步患者退出信息表(T_HD_PATIENT_QUIT)
  1042. SyncPatientOut(orgDb, org.OrgId, org.HospitalId)
  1043. // 同步处方 t_hd_ps
  1044. SyncPs(orgDb, org.OrgId, org.HospitalId)
  1045. // 同步处方药品 t_hd_ps
  1046. SyncPsMedicine(orgDb, org.OrgId, org.HospitalId)
  1047. // 患者诊断信息表(T_HD_DIAGNOSIS)
  1048. SyncDiagnosis(orgDb, org.OrgId, org.HospitalId)
  1049. // 患者通路信息表(T_HD_ACCESS)
  1050. SyncAccess(orgDb, org.OrgId, org.HospitalId)
  1051. //导管感染记录表(T_HD_CI)
  1052. SynListHdCi(orgDb, org.OrgId, org.HospitalId)
  1053. //导管感染转归记录表(T_HD_CI_OUTCOME)
  1054. SynLisHdCiOutCome(orgDb, org.OrgId, org.HospitalId)
  1055. // city.UpdatePatient(orgDb, org.OrgId, org.HospitalId)
  1056. // 患者传染病检查记录表(T_HD_INFECTION
  1057. SyncInfection(orgDb, org.OrgId, org.HospitalId)
  1058. // 同步排班 t_hd_shift
  1059. SyncShift(orgDb, org.OrgId, org.HospitalId)
  1060. // 同步透析医嘱表(T_HD_DOCTORS_ADVICE)
  1061. SyncDoctorAdvice(orgDb, org.OrgId, org.HospitalId)
  1062. // 同步患者透析记录 t_hd_dialysis
  1063. SyncDialysis(orgDb, org.OrgId, org.HospitalId)
  1064. // 同步透中信息 t_hd_middle
  1065. SyncMiddle(orgDb, org.OrgId, org.HospitalId)
  1066. // 透析并发症记录表(T_HD_COMPLICATION)
  1067. SyncComplication(orgDb, org.OrgId, org.HospitalId)
  1068. // 透析床位表(T_HD_SICKBED)
  1069. SyncSickbed(orgDb, org.OrgId, org.HospitalId)
  1070. // 同步透析床位分区 t_hd_division
  1071. SyncDivision(orgDb, org.OrgId, org.HospitalId)
  1072. // 血透患者检测结果表(T_HD_LIS_REPORT)
  1073. SyncLisReport(orgDb, org.OrgId, org.HospitalId)
  1074. // 血透患者检验结果指标表(T_HD_LIS_INDICATORS)
  1075. SyncLisIndicators(orgDb, org.OrgId, org.HospitalId)
  1076. // 第四步:关闭数据库连接
  1077. service.CloseDB(orgDb)
  1078. }
  1079. // }
  1080. return
  1081. }
  1082. func SyncToLg2h() {
  1083. // 第一步:到上报配置表中找到深圳需要上报的机构
  1084. // sz_province, _ := beego.AppConfig.Int64("sz_province")
  1085. // sz_city, _ := beego.AppConfig.Int64("sz_city")
  1086. // configs, _ := service.FindAllDataUploadConfigOrgInfo(sz_province, sz_city, 3)
  1087. org := &sz.DataUploadConfig{
  1088. OrgId: 9598,
  1089. ProvinceId: 19,
  1090. CityId: 291,
  1091. DepartmentName: "深圳市龙岗区第二人民医院",
  1092. HospitalId: "455835506",
  1093. InstType: 1,
  1094. DbHost: "183.62.158.36",
  1095. DbPort: "61433",
  1096. DbPass: "LG2H+9897",
  1097. DbUser: "sa",
  1098. DbName: "adapter_2019",
  1099. }
  1100. // for _, org := range configs {
  1101. // 第二步:跟进配置,创建数据库连接
  1102. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  1103. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  1104. if err != nil {
  1105. utils.ErrorLog("创建数据库连接失败:%v", err)
  1106. return
  1107. }
  1108. // 第三步:开始同步数据
  1109. // 同步医院信息 t_hd_hospital
  1110. SyncHospital(orgDb, org.OrgId, org.HospitalId, org.InstType, org.DepartmentName)
  1111. // 同步员工 t_hd_staff
  1112. SyncStaff(orgDb, org.OrgId, org.HospitalId)
  1113. // 布局表(T_HD_LAYOUT)
  1114. SyncLayout(orgDb, org.OrgId, org.HospitalId)
  1115. // 同步设备 t_hd_dm
  1116. SyncDM(orgDb, org.OrgId, org.HospitalId)
  1117. // 同步水处理器 t_hd_wm
  1118. SyncWMS(orgDb, org.OrgId, org.HospitalId)
  1119. // 同步维修 t_hd_maintain
  1120. SyncMachineRepair(orgDb, org.OrgId, org.HospitalId)
  1121. // 同步设备消毒方法表(T_HD_DISINFECT_METHOD
  1122. SyncDisinfectMethod(orgDb, org.OrgId, org.HospitalId)
  1123. // 同步其它设备信息表(T_HD_OTHER_MACHINE)
  1124. SyncOtherMachine(orgDb, org.OrgId, org.HospitalId)
  1125. // 同步透析机消毒检测记录表(T_HD_DM_DISINFECT)
  1126. SyncDmDisinfect(orgDb, org.OrgId, org.HospitalId)
  1127. // 透析机透析液细菌培养检测记录表(t_hd_dm_dialysate_bc)
  1128. SyncLisCulture(orgDb, org.OrgId, org.HospitalId)
  1129. // 透析机透析液内毒素检测记录表(T_HD_DM_DIALYSATE_EN)
  1130. SyncDialysate(orgDb, org.OrgId, org.HospitalId)
  1131. // 水处理机消毒记录表(T_HD_WM_DISINFECT)
  1132. SyncWmDisinfect(orgDb, org.OrgId, org.HospitalId)
  1133. //透析用水PH值检测表(T_HD_WATER_PH)
  1134. SynLisWaterPh(orgDb, org.OrgId, org.HospitalId)
  1135. //透析用水细菌培养检测表(T_HD_WATER_BC)
  1136. SyncLisWaterBc(orgDb, org.OrgId, org.HospitalId)
  1137. //透析用水内毒素检测表(T_HD_WATER_EN)
  1138. SyncLisWaterEn(orgDb, org.OrgId, org.HospitalId)
  1139. //透析用水有毒化学物检测表(T_HD_WATER_NC)
  1140. SynLisWaterNc(orgDb, org.OrgId, org.HospitalId)
  1141. //透析用水水硬度检测表(T_HD_WATER_WH)
  1142. SynListHadWater(orgDb, org.OrgId, org.HospitalId)
  1143. //透析用水游离氯检测表(T_HD_WATER_FC)
  1144. SyncLisWaterFc(orgDb, org.OrgId, org.HospitalId)
  1145. //透析用水电解质检测表(T_HD_WATER_EL)
  1146. SyncLisWaterEl(orgDb, org.OrgId, org.HospitalId)
  1147. //透析用水微量元素检测表(T_HD_WATER_TE)
  1148. SyncLisWaterTe(orgDb, org.OrgId, org.HospitalId)
  1149. //透析室空气消毒记录表(T_HD_AIR_DISINFECT)
  1150. SyncLisAirDetection(orgDb, org.OrgId, org.HospitalId)
  1151. //物表消毒记录表(T_HD_SURFACE_DISINFECT)
  1152. SyncLisBodyDetection(orgDb, org.OrgId, org.HospitalId)
  1153. // 同步血透患者基本信息表(T_HD_PATIENT)
  1154. SyncPatient(orgDb, org.OrgId, org.HospitalId)
  1155. // 同步患者退出信息表(T_HD_PATIENT_QUIT)
  1156. SyncPatientOut(orgDb, org.OrgId, org.HospitalId)
  1157. // 同步处方 t_hd_ps
  1158. SyncPs(orgDb, org.OrgId, org.HospitalId)
  1159. // 同步处方药品 t_hd_ps
  1160. SyncPsMedicine(orgDb, org.OrgId, org.HospitalId)
  1161. // 患者诊断信息表(T_HD_DIAGNOSIS)
  1162. SyncDiagnosis(orgDb, org.OrgId, org.HospitalId)
  1163. // 患者通路信息表(T_HD_ACCESS)
  1164. SyncAccess(orgDb, org.OrgId, org.HospitalId)
  1165. //导管感染记录表(T_HD_CI)
  1166. SynListHdCi(orgDb, org.OrgId, org.HospitalId)
  1167. //导管感染转归记录表(T_HD_CI_OUTCOME)
  1168. SynLisHdCiOutCome(orgDb, org.OrgId, org.HospitalId)
  1169. // UpdatePatient(orgDb, org.OrgId, org.HospitalId)
  1170. // 患者传染病检查记录表(T_HD_INFECTION
  1171. SyncInfection(orgDb, org.OrgId, org.HospitalId)
  1172. // 同步排班 t_hd_shift
  1173. SyncShift(orgDb, org.OrgId, org.HospitalId)
  1174. // 同步透析医嘱表(T_HD_DOCTORS_ADVICE)
  1175. SyncDoctorAdvice(orgDb, org.OrgId, org.HospitalId)
  1176. // 同步患者透析记录 t_hd_dialysis
  1177. SyncDialysis(orgDb, org.OrgId, org.HospitalId)
  1178. // 同步透中信息 t_hd_middle
  1179. SyncMiddle(orgDb, org.OrgId, org.HospitalId)
  1180. // 透析并发症记录表(T_HD_COMPLICATION)
  1181. SyncComplication(orgDb, org.OrgId, org.HospitalId)
  1182. // 透析床位表(T_HD_SICKBED)
  1183. SyncSickbed(orgDb, org.OrgId, org.HospitalId)
  1184. // 同步透析床位分区 t_hd_division
  1185. SyncDivision(orgDb, org.OrgId, org.HospitalId)
  1186. // 血透患者检测结果表(T_HD_LIS_REPORT)
  1187. SyncLisReport(orgDb, org.OrgId, org.HospitalId)
  1188. // 血透患者检验结果指标表(T_HD_LIS_INDICATORS)
  1189. SyncLisIndicators(orgDb, org.OrgId, org.HospitalId)
  1190. // 第四步:关闭数据库连接
  1191. service.CloseDB(orgDb)
  1192. }
  1193. // }
  1194. return
  1195. }
  1196. func SyncToHqyy() {
  1197. // 第一步:到上报配置表中找到深圳需要上报的机构
  1198. // sz_province, _ := beego.AppConfig.Int64("sz_province")
  1199. // sz_city, _ := beego.AppConfig.Int64("sz_city")
  1200. // configs, _ := service.FindAllDataUploadConfigOrgInfo(sz_province, sz_city, 3)
  1201. org := &sz.DataUploadConfig{
  1202. OrgId: 9442,
  1203. ProvinceId: 19,
  1204. CityId: 291,
  1205. DepartmentName: "暨南大学附属深圳华侨医院",
  1206. HospitalId: "73307826X",
  1207. InstType: 1,
  1208. DbHost: "183.11.232.26",
  1209. DbPort: "3306",
  1210. DbPass: "1Q2W3e4r!@#$",
  1211. DbUser: "sa",
  1212. DbName: "xtzk",
  1213. }
  1214. // for _, org := range configs {
  1215. // 第二步:跟进配置,创建数据库连接
  1216. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  1217. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  1218. if err != nil {
  1219. utils.ErrorLog("创建数据库连接失败:%v", err)
  1220. return
  1221. }
  1222. // 第三步:开始同步数据
  1223. // 同步医院信息 t_hd_hospital
  1224. SyncHospital(orgDb, org.OrgId, org.HospitalId, org.InstType, org.DepartmentName)
  1225. // 同步水处理器 t_hd_wm
  1226. SyncWMS(orgDb, org.OrgId, org.HospitalId)
  1227. // // 同步员工 t_hd_staff
  1228. SyncStaff(orgDb, org.OrgId, org.HospitalId)
  1229. // // 同步病人 t_hd_patient
  1230. SyncPatient(orgDb, org.OrgId, org.HospitalId)
  1231. // // 同步排班 t_hd_shift
  1232. SyncShift(orgDb, org.OrgId, org.HospitalId)
  1233. // 同步处方 t_hd_ps
  1234. SyncPs(orgDb, org.OrgId, org.HospitalId)
  1235. // 同步处方药品 t_hd_ps
  1236. SyncPsMedicine(orgDb, org.OrgId, org.HospitalId)
  1237. // // 同步转院信息 t_hd_patient_out
  1238. SyncPatientOut(orgDb, org.OrgId, org.HospitalId)
  1239. // 同步处方信息 t_hd_doctors_advice
  1240. SyncDoctorAdvice(orgDb, org.OrgId, org.HospitalId)
  1241. // 同步透中信息 t_hd_middle
  1242. SyncMiddle(orgDb, org.OrgId, org.HospitalId)
  1243. // // 同步设备 t_hd_other_machine
  1244. SyncOtherMachine(orgDb, org.OrgId, org.HospitalId)
  1245. // // 同步维修 t_hd_maintain
  1246. SyncMachineRepair(orgDb, org.OrgId, org.HospitalId)
  1247. // // 同步设备 t_hd_dm
  1248. SyncDM(orgDb, org.OrgId, org.HospitalId)
  1249. // // 同步患者透析记录 t_hd_dialysis
  1250. SyncDialysis(orgDb, org.OrgId, org.HospitalId)
  1251. // 同步透析床位分区 t_hd_division
  1252. SyncDivision(orgDb, org.OrgId, org.HospitalId)
  1253. // 患者通路信息表(T_HD_ACCESS)
  1254. SyncAccess(orgDb, org.OrgId, org.HospitalId)
  1255. // 透析床位表(T_HD_SICKBED)
  1256. SyncSickbed(orgDb, org.OrgId, org.HospitalId)
  1257. // 患者诊断信息表(T_HD_DIAGNOSIS)
  1258. SyncDiagnosis(orgDb, org.OrgId, org.HospitalId)
  1259. // 患者传染病检查记录表(T_HD_INFECTION
  1260. SyncInfection(orgDb, org.OrgId, org.HospitalId)
  1261. // 透析并发症记录表(T_HD_COMPLICATION)
  1262. SyncComplication(orgDb, org.OrgId, org.HospitalId)
  1263. // 血透患者检测结果表(T_HD_LIS_REPORT)
  1264. SyncLisReport(orgDb, org.OrgId, org.HospitalId)
  1265. // 血透患者检验结果指标表(T_HD_LIS_INDICATORS)
  1266. SyncLisIndicators(orgDb, org.OrgId, org.HospitalId)
  1267. // 第四步:关闭数据库连接
  1268. service.CloseDB(orgDb)
  1269. }
  1270. // }
  1271. return
  1272. }
  1273. func SyncToSmzy() {
  1274. // 第一步:到上报配置表中找到深圳需要上报的机构
  1275. // sz_province, _ := beego.AppConfig.Int64("sz_province")
  1276. // sz_city, _ := beego.AppConfig.Int64("sz_city")
  1277. // configs, _ := service.FindAllDataUploadConfigOrgInfo(sz_province, sz_city, 3)
  1278. org := &sz.DataUploadConfig{
  1279. OrgId: 9504,
  1280. ProvinceId: 19,
  1281. CityId: 291,
  1282. DepartmentName: "深圳生命之源血液透析中心",
  1283. HospitalId: "MA5EU4PC0",
  1284. InstType: 1,
  1285. DbHost: "127.0.0.1",
  1286. DbPort: "1433",
  1287. DbPass: "1Q2W3e4r!@#$",
  1288. DbUser: "sa",
  1289. DbName: "adapter_2019",
  1290. }
  1291. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  1292. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  1293. if err != nil {
  1294. utils.ErrorLog("创建数据库连接失败:%v", err)
  1295. return
  1296. }
  1297. // 第三步:开始同步数据
  1298. // 同步医院信息 t_hd_hospital
  1299. SyncHospital(orgDb, org.OrgId, org.HospitalId, org.InstType, org.DepartmentName)
  1300. // 同步员工 t_hd_staff
  1301. SyncStaff(orgDb, org.OrgId, org.HospitalId)
  1302. // 布局表(T_HD_LAYOUT)
  1303. SyncLayout(orgDb, org.OrgId, org.HospitalId)
  1304. // 同步设备 t_hd_dm
  1305. SyncDM(orgDb, org.OrgId, org.HospitalId)
  1306. // 同步水处理器 t_hd_wm
  1307. SyncWMS(orgDb, org.OrgId, org.HospitalId)
  1308. // 同步维修 t_hd_maintain
  1309. SyncMachineRepair(orgDb, org.OrgId, org.HospitalId)
  1310. // 同步设备消毒方法表(T_HD_DISINFECT_METHOD
  1311. SyncDisinfectMethod(orgDb, org.OrgId, org.HospitalId)
  1312. // 同步其它设备信息表(T_HD_OTHER_MACHINE)
  1313. SyncOtherMachine(orgDb, org.OrgId, org.HospitalId)
  1314. // 同步透析机消毒检测记录表(T_HD_DM_DISINFECT)
  1315. SyncDmDisinfect(orgDb, org.OrgId, org.HospitalId)
  1316. // 透析机透析液细菌培养检测记录表(t_hd_dm_dialysate_bc)
  1317. SyncLisCulture(orgDb, org.OrgId, org.HospitalId)
  1318. // 透析机透析液内毒素检测记录表(T_HD_DM_DIALYSATE_EN)
  1319. SyncDialysate(orgDb, org.OrgId, org.HospitalId)
  1320. // 水处理机消毒记录表(T_HD_WM_DISINFECT)
  1321. SyncWmDisinfect(orgDb, org.OrgId, org.HospitalId)
  1322. //透析用水PH值检测表(T_HD_WATER_PH)
  1323. SynLisWaterPh(orgDb, org.OrgId, org.HospitalId)
  1324. //透析用水细菌培养检测表(T_HD_WATER_BC)
  1325. SyncLisWaterBc(orgDb, org.OrgId, org.HospitalId)
  1326. //透析用水内毒素检测表(T_HD_WATER_EN)
  1327. SyncLisWaterEn(orgDb, org.OrgId, org.HospitalId)
  1328. //透析用水有毒化学物检测表(T_HD_WATER_NC)
  1329. SynLisWaterNc(orgDb, org.OrgId, org.HospitalId)
  1330. //透析用水水硬度检测表(T_HD_WATER_WH)
  1331. SynListHadWater(orgDb, org.OrgId, org.HospitalId)
  1332. //透析用水游离氯检测表(T_HD_WATER_FC)
  1333. SyncLisWaterFc(orgDb, org.OrgId, org.HospitalId)
  1334. //透析用水电解质检测表(T_HD_WATER_EL)
  1335. SyncLisWaterEl(orgDb, org.OrgId, org.HospitalId)
  1336. //透析用水微量元素检测表(T_HD_WATER_TE)
  1337. SyncLisWaterTe(orgDb, org.OrgId, org.HospitalId)
  1338. //透析室空气消毒记录表(T_HD_AIR_DISINFECT)
  1339. SyncLisAirDetection(orgDb, org.OrgId, org.HospitalId)
  1340. //物表消毒记录表(T_HD_SURFACE_DISINFECT)
  1341. SyncLisBodyDetection(orgDb, org.OrgId, org.HospitalId)
  1342. // 同步血透患者基本信息表(T_HD_PATIENT)
  1343. SyncPatient(orgDb, org.OrgId, org.HospitalId)
  1344. // 同步患者退出信息表(T_HD_PATIENT_QUIT)
  1345. SyncPatientOut(orgDb, org.OrgId, org.HospitalId)
  1346. // 同步处方 t_hd_ps
  1347. SyncPs(orgDb, org.OrgId, org.HospitalId)
  1348. // 同步处方药品 t_hd_ps
  1349. SyncPsMedicine(orgDb, org.OrgId, org.HospitalId)
  1350. // 患者诊断信息表(T_HD_DIAGNOSIS)
  1351. SyncDiagnosis(orgDb, org.OrgId, org.HospitalId)
  1352. // 患者通路信息表(T_HD_ACCESS)
  1353. SyncAccess(orgDb, org.OrgId, org.HospitalId)
  1354. //导管感染记录表(T_HD_CI)
  1355. SynListHdCi(orgDb, org.OrgId, org.HospitalId)
  1356. //导管感染转归记录表(T_HD_CI_OUTCOME)
  1357. SynLisHdCiOutCome(orgDb, org.OrgId, org.HospitalId)
  1358. // UpdatePatient(orgDb, org.OrgId, org.HospitalId)
  1359. // 患者传染病检查记录表(T_HD_INFECTION
  1360. SyncInfection(orgDb, org.OrgId, org.HospitalId)
  1361. // 同步排班 t_hd_shift
  1362. SyncShift(orgDb, org.OrgId, org.HospitalId)
  1363. // 同步透析医嘱表(T_HD_DOCTORS_ADVICE)
  1364. SyncDoctorAdvice(orgDb, org.OrgId, org.HospitalId)
  1365. // 同步患者透析记录 t_hd_dialysis
  1366. SyncDialysis(orgDb, org.OrgId, org.HospitalId)
  1367. // 同步透中信息 t_hd_middle
  1368. SyncMiddle(orgDb, org.OrgId, org.HospitalId)
  1369. // 透析并发症记录表(T_HD_COMPLICATION)
  1370. SyncComplication(orgDb, org.OrgId, org.HospitalId)
  1371. // 透析床位表(T_HD_SICKBED)
  1372. SyncSickbed(orgDb, org.OrgId, org.HospitalId)
  1373. // 同步透析床位分区 t_hd_division
  1374. SyncDivision(orgDb, org.OrgId, org.HospitalId)
  1375. // 血透患者检测结果表(T_HD_LIS_REPORT)
  1376. SyncLisReport(orgDb, org.OrgId, org.HospitalId)
  1377. // 血透患者检验结果指标表(T_HD_LIS_INDICATORS)
  1378. SyncLisIndicators(orgDb, org.OrgId, org.HospitalId)
  1379. // 第四步:关闭数据库连接
  1380. service.CloseDB(orgDb)
  1381. }
  1382. // }
  1383. return
  1384. }
  1385. func SyncToSmzyYxxxzx() {
  1386. org := &sz.DataUploadConfig{
  1387. OrgId: 9504,
  1388. ProvinceId: 19,
  1389. CityId: 291,
  1390. DepartmentName: "深圳生命之源血液透析中心",
  1391. HospitalId: "MA5EU4PC0",
  1392. InstType: 1,
  1393. DbHost: "127.0.0.1",
  1394. DbPort: "1433",
  1395. DbPass: "1Q2W3e4r!@#$",
  1396. DbUser: "sa",
  1397. DbName: "adapter_2019",
  1398. }
  1399. // for _, org := range configs {
  1400. // 第二步:跟进配置,创建数据库连接
  1401. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  1402. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  1403. if err != nil {
  1404. utils.ErrorLog("创建数据库连接失败:%v", err)
  1405. return
  1406. }
  1407. // 第三步:开始同步数据
  1408. // 机构人员字典表 t_hd_hospital
  1409. SyncTBDICPractitioner(orgDb, org.OrgId, org.HospitalId)
  1410. // 药品目录字典表
  1411. SyncTBDICMedicines(orgDb, org.OrgId, org.HospitalId)
  1412. // 药品对照字典
  1413. SyncTBDICYpdzzd(orgDb, org.OrgId, org.HospitalId)
  1414. // 诊疗项目目录字典表
  1415. SyncTBDICZlxmml(orgDb, org.OrgId, org.HospitalId)
  1416. // 诊疗项目目录字典表
  1417. SyncTBDICZlxmdzzd(orgDb, org.OrgId, org.HospitalId)
  1418. // 机构床位 t_hd_wm
  1419. SyncTMDICTBED(orgDb, org.OrgId, org.HospitalId)
  1420. // 门诊患者信息表
  1421. SyncTBMZPatientInformation(orgDb, org.OrgId, org.HospitalId)
  1422. // 挂号表
  1423. SyncTBHISMZReg(orgDb, org.OrgId, org.HospitalId)
  1424. // 门诊就诊记录表
  1425. SyncTB_YL_MZ_Medical_Record(orgDb, org.OrgId, org.HospitalId)
  1426. // 门诊处方主表
  1427. SyncTB_CIS_Prescription(orgDb, org.OrgId, org.HospitalId)
  1428. // 18. 门诊处方明细表
  1429. SyncTB_CIS_Prescription_Detail(orgDb, org.OrgId, org.HospitalId)
  1430. // 19. 门诊收费表
  1431. SyncTB_HIS_MZ_Charge(orgDb, org.OrgId, org.HospitalId)
  1432. // 20. 门诊收费明细表
  1433. SyncTB_HIS_MZ_Fee_Detail(orgDb, org.OrgId, org.HospitalId)
  1434. // 业务量收入统计表
  1435. SyncTB_STAT_YWL_Report(orgDb, org.OrgId, org.HospitalId)
  1436. SyncTB_Diagnosis_Detail(orgDb, org.OrgId, org.HospitalId)
  1437. // 第四步:关闭数据库连接
  1438. service.CloseDB(orgDb)
  1439. }
  1440. // }
  1441. return
  1442. }
  1443. func SyncToSmzyt() {
  1444. org := &sz.DataUploadConfig{
  1445. OrgId: 9504,
  1446. ProvinceId: 19,
  1447. CityId: 291,
  1448. DepartmentName: "深圳生命之源血液透析中心",
  1449. HospitalId: "MA5EU4PC0",
  1450. InstType: 1,
  1451. DbHost: "127.0.0.1",
  1452. DbPort: "1433",
  1453. DbPass: "1Q2W3e4r!@#$",
  1454. DbUser: "sa",
  1455. DbName: "adapter_2019",
  1456. }
  1457. // for _, org := range configs {
  1458. // 第二步:跟进配置,创建数据库连接
  1459. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  1460. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  1461. if err != nil {
  1462. utils.ErrorLog("创建数据库连接失败:%v", err)
  1463. return
  1464. }
  1465. // 第三步:开始同步数据
  1466. // 机构人员字典表 t_hd_hospital
  1467. SyncTBDICPractitioner(orgDb, org.OrgId, org.HospitalId)
  1468. // 药品目录字典表
  1469. SyncTBDICMedicines(orgDb, org.OrgId, org.HospitalId)
  1470. // 药品对照字典
  1471. SyncTBDICYpdzzd(orgDb, org.OrgId, org.HospitalId)
  1472. // 诊疗项目目录字典表
  1473. SyncTBDICZlxmml(orgDb, org.OrgId, org.HospitalId)
  1474. // 诊疗项目目录字典表
  1475. SyncTBDICZlxmdzzd(orgDb, org.OrgId, org.HospitalId)
  1476. // 机构床位 t_hd_wm
  1477. SyncTMDICTBED(orgDb, org.OrgId, org.HospitalId)
  1478. // 门诊患者信息表
  1479. SyncTBMZPatientInformation(orgDb, org.OrgId, org.HospitalId)
  1480. // 挂号表
  1481. SyncTBHISMZReg(orgDb, org.OrgId, org.HospitalId)
  1482. // 门诊就诊记录表
  1483. SyncTB_YL_MZ_Medical_Record(orgDb, org.OrgId, org.HospitalId)
  1484. // 门诊处方主表
  1485. SyncTB_CIS_Prescription(orgDb, org.OrgId, org.HospitalId)
  1486. // 18. 门诊处方明细表
  1487. SyncTB_CIS_Prescription_Detail(orgDb, org.OrgId, org.HospitalId)
  1488. // 19. 门诊收费表
  1489. SyncTB_HIS_MZ_Charge(orgDb, org.OrgId, org.HospitalId)
  1490. // 20. 门诊收费明细表
  1491. SyncTB_HIS_MZ_Fee_Detail(orgDb, org.OrgId, org.HospitalId)
  1492. // 业务量收入统计表
  1493. SyncTB_STAT_YWL_Report(orgDb, org.OrgId, org.HospitalId)
  1494. // 第四步:关闭数据库连接
  1495. service.CloseDB(orgDb)
  1496. }
  1497. // }
  1498. return
  1499. }
  1500. // 同步医院信息
  1501. func SyncHospital(rdb *gorm.DB, org_id int64, hospital_id string, inst_type int64, department_name string) {
  1502. // 第一步:根据机构id获取上次同步时间
  1503. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1)
  1504. var sync_time int64
  1505. if syncLastInfo.ID > 0 {
  1506. sync_time = syncLastInfo.SyncTime
  1507. } else {
  1508. sync_time = 0
  1509. }
  1510. // 第二步:跟进上次同步时间找出这个时间段内增加的数据
  1511. org, _ := service.FindOrgData(org_id, sync_time)
  1512. if org.ID > 0 {
  1513. hospital := &sz.TempHdHospital{
  1514. HospitalId: hospital_id,
  1515. InstType: strconv.FormatInt(inst_type, 10),
  1516. DepartmentName: department_name,
  1517. AuthorizedBeds: int64(len(org.DeviceNumber)),
  1518. CreateTime: time.Now(),
  1519. UpdateTime: time.Now(),
  1520. Sjscsj: time.Now(),
  1521. Xgbz: 0,
  1522. }
  1523. err := service.CreateOrgRecord(rdb, hospital)
  1524. if err == nil {
  1525. // 第三步:同步成功后,添加同步记录
  1526. upload := &sz.DataUpload{
  1527. SyncType: 1,
  1528. OrgId: org_id,
  1529. SyncTime: time.Now().Unix(),
  1530. SyncResultType: 1,
  1531. CreateTime: time.Now().Unix(),
  1532. UpdateTime: time.Now().Unix(),
  1533. }
  1534. err := service.CreateUploadRecord(upload)
  1535. if err != nil {
  1536. utils.ErrorLog("%v", err)
  1537. }
  1538. }
  1539. }
  1540. }
  1541. // 同步水处理器
  1542. func SyncWMS(rdb *gorm.DB, org_id int64, hospital_id string) {
  1543. // 第一步:根据机构id获取上次同步时间
  1544. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 22)
  1545. var sync_time int64
  1546. if syncLastInfo.ID > 0 {
  1547. sync_time = syncLastInfo.SyncTime
  1548. } else {
  1549. sync_time = 0
  1550. }
  1551. //同步水处理机
  1552. waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
  1553. var wms []*sz.TempHdWm
  1554. for _, item := range waterMachine {
  1555. wm := &sz.TempHdWm{
  1556. HospitalId: hospital_id,
  1557. EquipmentId: strconv.FormatInt(item.ID, 10),
  1558. EquipmentBrand: item.ManufactureFactory,
  1559. EnableTime: time.Unix(item.StartDate, 0),
  1560. EquipmentType: "21",
  1561. CreateTime: time.Unix(item.Ctime, 0),
  1562. UpdateTime: time.Unix(item.Mtime, 0),
  1563. Sjscsj: time.Now(),
  1564. Xgbz: 0,
  1565. }
  1566. wms = append(wms, wm)
  1567. }
  1568. if len(wms) > 0 {
  1569. err := service.BatchCreateWMsRecord(wms, rdb)
  1570. if err == nil {
  1571. // 第三步:同步成功后,添加同步记录
  1572. upload := &sz.DataUpload{
  1573. SyncType: 22,
  1574. OrgId: org_id,
  1575. SyncTime: time.Now().Unix(),
  1576. SyncResultType: 1,
  1577. CreateTime: time.Now().Unix(),
  1578. UpdateTime: time.Now().Unix(),
  1579. }
  1580. err := service.CreateUploadRecord(upload)
  1581. if err != nil {
  1582. utils.ErrorLog("%v", err)
  1583. }
  1584. } else {
  1585. //错误处理
  1586. }
  1587. }
  1588. }
  1589. // 同步员工
  1590. func SyncStaff(rdb *gorm.DB, org_id int64, hospital_id string) {
  1591. // 第一步:根据机构id获取上次同步时间
  1592. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 21)
  1593. var sync_time int64
  1594. if syncLastInfo.ID > 0 {
  1595. sync_time = syncLastInfo.SyncTime
  1596. } else {
  1597. sync_time = 0
  1598. }
  1599. //同步员工信息
  1600. roles, _ := service.FindOrgRolesData(org_id, sync_time, time.Now().Unix())
  1601. //waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
  1602. var staffs []*sz.TempHdStaff
  1603. for _, role := range roles {
  1604. var title int
  1605. switch role.UserType {
  1606. case 2:
  1607. title = 1
  1608. break
  1609. case 3:
  1610. title = 2
  1611. break
  1612. }
  1613. staff := &sz.TempHdStaff{
  1614. HospitalId: hospital_id,
  1615. StaffId: strconv.FormatInt(role.AdminUserId, 10),
  1616. StaffName: role.UserName,
  1617. Position: int64(title),
  1618. PermanentType: 1,
  1619. CreateTime: time.Unix(role.Ctime, 0),
  1620. UpdateTime: time.Unix(role.Mtime, 0),
  1621. Sjscsj: time.Now(),
  1622. Xgbz: 0,
  1623. }
  1624. staffs = append(staffs, staff)
  1625. }
  1626. if len(staffs) > 0 {
  1627. err := service.BatchCreateStaffRecord(staffs, rdb)
  1628. if err == nil {
  1629. // 第三步:同步成功后,添加同步记录
  1630. upload := &sz.DataUpload{
  1631. SyncType: 21,
  1632. OrgId: org_id,
  1633. SyncTime: time.Now().Unix(),
  1634. SyncResultType: 1,
  1635. CreateTime: time.Now().Unix(),
  1636. UpdateTime: time.Now().Unix(),
  1637. }
  1638. err := service.CreateUploadRecord(upload)
  1639. if err != nil {
  1640. utils.ErrorLog("%v", err)
  1641. }
  1642. } else {
  1643. //错误处理
  1644. }
  1645. }
  1646. }
  1647. // 同步分区
  1648. func SyncLayout(rdb *gorm.DB, org_id int64, hospital_id string) {
  1649. // 第一步:根据机构id获取上次同步时间
  1650. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 2001)
  1651. var sync_time int64
  1652. if syncLastInfo.ID > 0 {
  1653. sync_time = syncLastInfo.SyncTime
  1654. } else {
  1655. sync_time = 0
  1656. }
  1657. //同步分区信息
  1658. zones, _ := service.FindOrgDeviceZone(org_id, sync_time, time.Now().Unix())
  1659. //waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
  1660. var layouts []*sz.TempHdLayout
  1661. for _, zone := range zones {
  1662. layout := &sz.TempHdLayout{
  1663. HospitalId: hospital_id,
  1664. PartitionName: zone.Name,
  1665. CreateTime: time.Unix(zone.CreateTime, 0),
  1666. Sjscsj: time.Now(),
  1667. Xgbz: "0",
  1668. }
  1669. layouts = append(layouts, layout)
  1670. }
  1671. if len(layouts) > 0 {
  1672. err := service.BatchCreateLayoutRecord(layouts, rdb)
  1673. if err == nil {
  1674. // 第三步:同步成功后,添加同步记录
  1675. upload := &sz.DataUpload{
  1676. SyncType: 2001,
  1677. OrgId: org_id,
  1678. SyncTime: time.Now().Unix(),
  1679. SyncResultType: 1,
  1680. CreateTime: time.Now().Unix(),
  1681. UpdateTime: time.Now().Unix(),
  1682. }
  1683. err := service.CreateUploadRecord(upload)
  1684. if err != nil {
  1685. utils.ErrorLog("%v", err)
  1686. }
  1687. } else {
  1688. //错误处理
  1689. }
  1690. }
  1691. }
  1692. func UpdatePatient(rdb *gorm.DB, org_id int64, hospital_id string) {
  1693. patients, _ := service.FindSyncPatientAllData(rdb)
  1694. for _, patient := range patients {
  1695. IdNo := patient.IdNo
  1696. fmt.Println(patient)
  1697. patientInfo, _ := service.FindPatientInfoByIdno(IdNo)
  1698. fmt.Println(patientInfo)
  1699. if patientInfo.ID > 0 {
  1700. patient.Ylyl1 = patientInfo.HomeAddress
  1701. service.UpdateSyncPatient(patientInfo.ID, patient.Ylyl1, rdb)
  1702. }
  1703. }
  1704. }
  1705. // 同步血透患者基本信息表(T_HD_PATIENT)
  1706. func SyncPatientByID(rdb *gorm.DB, org_id int64, hospital_id string, patient_id int64) {
  1707. // 第一步:根据机构id获取上次同步时间
  1708. // syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 15)
  1709. // var sync_time int64
  1710. // if syncLastInfo.ID > 0 {
  1711. // sync_time = syncLastInfo.SyncTime
  1712. // } else {
  1713. // sync_time = 0
  1714. // }
  1715. //同步员工信息
  1716. patient, _ := service.FindOrgPatientInfoById(patient_id)
  1717. hdpatients, _ := service.FindSyncPatient(patient_id, rdb)
  1718. if len(hdpatients) > 0 {
  1719. return
  1720. }
  1721. //waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
  1722. var hdPatients []*sz.TempHdPatient
  1723. idcard_year, _ := strconv.Atoi(Substr(patient.IdCardNo, 6, 4)) // 年
  1724. idcard_mo, _ := strconv.Atoi(Substr(patient.IdCardNo, 10, 2)) // 月
  1725. idcard_day, _ := strconv.Atoi(Substr(patient.IdCardNo, 12, 2)) // 日
  1726. date := strconv.Itoa(idcard_year)
  1727. if idcard_mo < 10 {
  1728. date = date + "-0" + strconv.Itoa(idcard_mo)
  1729. } else {
  1730. date = date + "-" + strconv.Itoa(idcard_mo)
  1731. }
  1732. if idcard_day < 10 {
  1733. date = date + "-0" + strconv.Itoa(idcard_day)
  1734. } else {
  1735. date = date + "-" + strconv.Itoa(idcard_day)
  1736. }
  1737. local, _ := time.LoadLocation("Local")
  1738. birthday, _ := time.ParseInLocation("2006-01-02", date, local)
  1739. fmt.Println(birthday)
  1740. var isCKD int
  1741. value := strings.Index(patient.Diagnose, "慢性肾脏病")
  1742. value2 := strings.Index(patient.Diagnose, "CKD")
  1743. value3 := strings.Index(patient.Diagnose, "慢性肾衰竭")
  1744. if value != -1 || value2 != -1 || value3 != -1 {
  1745. isCKD = 1
  1746. } else {
  1747. isCKD = 0
  1748. }
  1749. p := &sz.TempHdPatient{
  1750. HospitalId: hospital_id,
  1751. PatientNk: patient.ID,
  1752. CardNo: "000000000000000000",
  1753. CardType: 1,
  1754. IdNo: patient.IdCardNo,
  1755. IdType: "01",
  1756. PatientName: patient.Name,
  1757. Gender: strconv.FormatInt(patient.Gender, 10),
  1758. BornDate: birthday,
  1759. DiagnosisSummary: patient.Diagnose,
  1760. IsCrf: strconv.Itoa(isCKD),
  1761. DialysisStartTime: time.Unix(patient.FirstDialysisDate, 0),
  1762. LocalStartTime: time.Unix(patient.HospitalFirstDialysisDate, 0),
  1763. OutpatientNo: patient.DialysisNo,
  1764. HospitalizedNo: "_",
  1765. CreateTime: time.Unix(patient.CreatedTime, 0),
  1766. UpdateTime: time.Unix(patient.UpdatedTime, 0),
  1767. Sjscsj: time.Now(),
  1768. Ylyl1: patient.HomeAddress,
  1769. Xgbz: 0,
  1770. }
  1771. if patient.FirstDialysisDate != 0 {
  1772. p.DialysisStartTime = time.Unix(patient.FirstDialysisDate, 0)
  1773. }
  1774. if patient.HospitalFirstDialysisDate != 0 {
  1775. p.LocalStartTime = time.Unix(patient.HospitalFirstDialysisDate, 0)
  1776. }
  1777. hdPatients = append(hdPatients, p)
  1778. service.BatchCreatePatinet(hdPatients, rdb)
  1779. }
  1780. // 同步血透患者基本信息表(T_HD_PATIENT)
  1781. func SyncPatient(rdb *gorm.DB, org_id int64, hospital_id string) {
  1782. // 第一步:根据机构id获取上次同步时间
  1783. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 15)
  1784. var sync_time int64
  1785. if syncLastInfo.ID > 0 {
  1786. sync_time = syncLastInfo.SyncTime
  1787. } else {
  1788. sync_time = 0
  1789. }
  1790. //同步员工信息
  1791. patients, _ := service.FindOrgPatientData(org_id, sync_time, time.Now().Unix())
  1792. //waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
  1793. var hdPatients []*sz.TempHdPatient
  1794. for _, patient := range patients {
  1795. idcard_year, _ := strconv.Atoi(Substr(patient.IdCardNo, 6, 4)) // 年
  1796. idcard_mo, _ := strconv.Atoi(Substr(patient.IdCardNo, 10, 2)) // 月
  1797. idcard_day, _ := strconv.Atoi(Substr(patient.IdCardNo, 12, 2)) // 日
  1798. date := strconv.Itoa(idcard_year)
  1799. if idcard_mo < 10 {
  1800. date = date + "-0" + strconv.Itoa(idcard_mo)
  1801. } else {
  1802. date = date + "-" + strconv.Itoa(idcard_mo)
  1803. }
  1804. if idcard_day < 10 {
  1805. date = date + "-0" + strconv.Itoa(idcard_day)
  1806. } else {
  1807. date = date + "-" + strconv.Itoa(idcard_day)
  1808. }
  1809. local, _ := time.LoadLocation("Local")
  1810. birthday, _ := time.ParseInLocation("2006-01-02", date, local)
  1811. fmt.Println(birthday)
  1812. var isCKD int
  1813. value := strings.Index(patient.Diagnose, "慢性肾脏病")
  1814. value2 := strings.Index(patient.Diagnose, "CKD")
  1815. value3 := strings.Index(patient.Diagnose, "慢性肾衰竭")
  1816. if value != -1 || value2 != -1 || value3 != -1 {
  1817. isCKD = 1
  1818. } else {
  1819. isCKD = 0
  1820. }
  1821. p := &sz.TempHdPatient{
  1822. HospitalId: hospital_id,
  1823. PatientNk: patient.ID,
  1824. CardNo: "000000000000000000",
  1825. CardType: 1,
  1826. IdNo: patient.IdCardNo,
  1827. IdType: "01",
  1828. PatientName: patient.Name,
  1829. Gender: strconv.FormatInt(patient.Gender, 10),
  1830. BornDate: birthday,
  1831. DiagnosisSummary: patient.Diagnose,
  1832. IsCrf: strconv.Itoa(isCKD),
  1833. DialysisStartTime: time.Unix(patient.FirstDialysisDate, 0),
  1834. LocalStartTime: time.Unix(patient.HospitalFirstDialysisDate, 0),
  1835. OutpatientNo: patient.DialysisNo,
  1836. HospitalizedNo: "_",
  1837. CreateTime: time.Unix(patient.CreatedTime, 0),
  1838. UpdateTime: time.Unix(patient.UpdatedTime, 0),
  1839. Sjscsj: time.Now(),
  1840. Ylyl1: patient.HomeAddress,
  1841. Xgbz: 0,
  1842. }
  1843. if patient.FirstDialysisDate != 0 {
  1844. p.DialysisStartTime = time.Unix(patient.FirstDialysisDate, 0)
  1845. }
  1846. if patient.HospitalFirstDialysisDate != 0 {
  1847. p.LocalStartTime = time.Unix(patient.HospitalFirstDialysisDate, 0)
  1848. }
  1849. hdPatients = append(hdPatients, p)
  1850. }
  1851. if len(hdPatients) > 0 {
  1852. err := service.BatchCreatePatinet(hdPatients, rdb)
  1853. if err == nil {
  1854. // 第三步:同步成功后,添加同步记录
  1855. upload := &sz.DataUpload{
  1856. SyncType: 15,
  1857. OrgId: org_id,
  1858. SyncTime: time.Now().Unix(),
  1859. SyncResultType: 1,
  1860. CreateTime: time.Now().Unix(),
  1861. UpdateTime: time.Now().Unix(),
  1862. }
  1863. err := service.CreateUploadRecord(upload)
  1864. if err != nil {
  1865. utils.ErrorLog("%v", err)
  1866. }
  1867. } else {
  1868. //错误处理
  1869. }
  1870. }
  1871. }
  1872. func Substr(str string, start, length int) string {
  1873. rs := []rune(str)
  1874. rl := len(rs)
  1875. end := 0
  1876. if start < 0 {
  1877. start = rl - 1 + start
  1878. }
  1879. end = start + length
  1880. if start > end {
  1881. start, end = end, start
  1882. }
  1883. if start < 0 {
  1884. start = 0
  1885. }
  1886. if start > rl {
  1887. start = rl
  1888. }
  1889. if end < 0 {
  1890. end = 0
  1891. }
  1892. if end > rl {
  1893. end = rl
  1894. }
  1895. return string(rs[start:end])
  1896. }
  1897. // 同步排班
  1898. func SyncShift(rdb *gorm.DB, org_id int64, hospital_id string) {
  1899. // 第一步:根据机构id获取上次同步时间
  1900. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 19)
  1901. var sync_time int64
  1902. if syncLastInfo.ID > 0 {
  1903. sync_time = syncLastInfo.SyncTime
  1904. } else {
  1905. sync_time = 1577808000
  1906. }
  1907. var hdShift []*sz.TempHdShift
  1908. schs, _ := service.FindOrgScheduleData(org_id, sync_time, time.Now().Unix())
  1909. for _, sch := range schs {
  1910. shift := &sz.TempHdShift{
  1911. PsId: strconv.FormatInt(sch.ID, 10),
  1912. HospitalId: hospital_id,
  1913. PatientNk: strconv.FormatInt(sch.PatientId, 10),
  1914. ScheduleDate: time.Unix(sch.ScheduleDate, 0),
  1915. ShiftType: strconv.FormatInt(sch.ScheduleType, 10),
  1916. SickbedNo: sch.DeviceNumber.ID,
  1917. ScheduleStatus: "1",
  1918. CreateTime: time.Unix(sch.CreatedTime, 0),
  1919. Sjscsj: time.Now(),
  1920. Xgbz: 0,
  1921. }
  1922. hdShift = append(hdShift, shift)
  1923. }
  1924. if len(hdShift) > 0 {
  1925. err := service.BatchCreateSchedual(hdShift, rdb)
  1926. if err == nil {
  1927. // 第三步:同步成功后,添加同步记录
  1928. upload := &sz.DataUpload{
  1929. SyncType: 19,
  1930. OrgId: org_id,
  1931. SyncTime: time.Now().Unix(),
  1932. SyncResultType: 1,
  1933. CreateTime: time.Now().Unix(),
  1934. UpdateTime: time.Now().Unix(),
  1935. }
  1936. err := service.CreateUploadRecord(upload)
  1937. if err != nil {
  1938. utils.ErrorLog("%v", err)
  1939. }
  1940. } else {
  1941. //错误处理
  1942. }
  1943. }
  1944. }
  1945. // 同步处方
  1946. func SyncPs(rdb *gorm.DB, org_id int64, hospital_id string) {
  1947. // 第一步:根据机构id获取上次同步时间
  1948. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 17)
  1949. var sync_time int64
  1950. if syncLastInfo.ID > 0 {
  1951. sync_time = syncLastInfo.SyncTime
  1952. } else {
  1953. sync_time = 1577808000
  1954. }
  1955. var hdPrescription []*sz.TempHdPs
  1956. prescriptions, _ := service.FindOrgDialysisPrescriptionData(org_id, sync_time, time.Now().Unix())
  1957. for _, item := range prescriptions {
  1958. ps := &sz.TempHdPs{
  1959. PrescribeId: strconv.FormatInt(item.ID, 10),
  1960. HospitalId: hospital_id,
  1961. PatientNk: strconv.FormatInt(item.PatientId, 10),
  1962. Sjscsj: time.Now(),
  1963. Xgbz: 0,
  1964. PrescribeTime: time.Unix(item.RecordDate, 0),
  1965. CreateTime: time.Unix(item.CreatedTime, 0),
  1966. }
  1967. switch item.ModeId {
  1968. case 1:
  1969. ps.DialysisFrequency = 5
  1970. ps.FrequencyUnit = 2
  1971. ps.RrtTypeName = "HD"
  1972. ps.RrtType = 1
  1973. break
  1974. case 2:
  1975. ps.DialysisFrequency = 5
  1976. ps.FrequencyUnit = 2
  1977. ps.RrtTypeName = "HDF"
  1978. ps.RrtType = 3
  1979. break
  1980. case 4:
  1981. ps.DialysisFrequency = 5
  1982. ps.FrequencyUnit = 2
  1983. ps.RrtTypeName = "HP"
  1984. ps.RrtType = 5
  1985. break
  1986. case 5:
  1987. ps.DialysisFrequency = 5
  1988. ps.FrequencyUnit = 2
  1989. ps.RrtTypeName = "HF"
  1990. ps.RrtType = 2
  1991. break
  1992. case 7:
  1993. ps.DialysisFrequency = 5
  1994. ps.FrequencyUnit = 2
  1995. ps.RrtTypeName = "IUF"
  1996. ps.RrtType = 6
  1997. break
  1998. default:
  1999. ps.DialysisFrequency = 5
  2000. ps.FrequencyUnit = 2
  2001. ps.RrtTypeName = "HD"
  2002. ps.RrtType = 1
  2003. break
  2004. }
  2005. hdPrescription = append(hdPrescription, ps)
  2006. }
  2007. if len(hdPrescription) > 0 {
  2008. var err error
  2009. for _, hdps := range hdPrescription {
  2010. err = service.BatchCreatePsOther(hdps, rdb)
  2011. }
  2012. // err := service.BatchCreatePs(hdPrescription, rdb)
  2013. if err == nil {
  2014. // 第三步:同步成功后,添加同步记录
  2015. upload := &sz.DataUpload{
  2016. SyncType: 17,
  2017. OrgId: org_id,
  2018. SyncTime: time.Now().Unix(),
  2019. SyncResultType: 1,
  2020. CreateTime: time.Now().Unix(),
  2021. UpdateTime: time.Now().Unix(),
  2022. }
  2023. err := service.CreateUploadRecord(upload)
  2024. if err != nil {
  2025. utils.ErrorLog("%v", err)
  2026. }
  2027. } else {
  2028. //错误处理
  2029. }
  2030. }
  2031. }
  2032. // 同步处方药物
  2033. func SyncPsMedicine(rdb *gorm.DB, org_id int64, hospital_id string) {
  2034. // 第一步:根据机构id获取上次同步时间
  2035. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 18)
  2036. var sync_time int64
  2037. if syncLastInfo.ID > 0 {
  2038. sync_time = syncLastInfo.SyncTime
  2039. } else {
  2040. sync_time = 1577808000
  2041. }
  2042. var tempPsmedicine []*sz.TempHdPsMedicine
  2043. prescriptions, _ := service.FindOrgDialysisPrescriptionData(org_id, sync_time, time.Now().Unix())
  2044. for _, item := range prescriptions {
  2045. psm := &sz.TempHdPsMedicine{
  2046. Sn: strconv.FormatInt(item.ID, 10),
  2047. HospitalId: hospital_id,
  2048. MedicineTypeId: "5",
  2049. MedicineId: "1",
  2050. CreateTime: time.Unix(item.CreatedTime, 0),
  2051. Sjscsj: time.Now(),
  2052. Xgbz: 0,
  2053. }
  2054. tempPsmedicine = append(tempPsmedicine, psm)
  2055. }
  2056. if len(tempPsmedicine) > 0 {
  2057. err := service.BatchCreatePsm(tempPsmedicine, rdb)
  2058. if err == nil {
  2059. // 第三步:同步成功后,添加同步记录
  2060. upload := &sz.DataUpload{
  2061. SyncType: 18,
  2062. OrgId: org_id,
  2063. SyncTime: time.Now().Unix(),
  2064. SyncResultType: 1,
  2065. CreateTime: time.Now().Unix(),
  2066. UpdateTime: time.Now().Unix(),
  2067. }
  2068. err := service.CreateUploadRecord(upload)
  2069. if err != nil {
  2070. utils.ErrorLog("%v", err)
  2071. }
  2072. } else {
  2073. //错误处理
  2074. }
  2075. }
  2076. }
  2077. // 同步患者退出信息表(T_HD_PATIENT_QUIT)
  2078. func SyncPatientOutByID(rdb *gorm.DB, org_id int64, hospital_id string, patient_id int64) {
  2079. // 第一步:根据机构id获取上次同步时间
  2080. // syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 16)
  2081. // var sync_time int64
  2082. // if syncLastInfo.ID > 0 {
  2083. // sync_time = syncLastInfo.SyncTime
  2084. // } else {
  2085. // sync_time = 0
  2086. // }
  2087. var hdPatientOuts []*sz.TempHdPatientOut
  2088. patient, _ := service.FindOrgPatientOutDataByID(patient_id)
  2089. orgPatient, _ := service.FindOrgPatientInfoById(patient_id)
  2090. if orgPatient.UserOrgId != org_id {
  2091. return
  2092. }
  2093. hdpatients, _ := service.FindSyncPatientOut(patient_id, rdb)
  2094. if len(hdpatients) > 0 {
  2095. return
  2096. }
  2097. p := &sz.TempHdPatientOut{
  2098. Sn: strconv.FormatInt(patient.ID, 10),
  2099. HospitalId: hospital_id,
  2100. PatientNk: strconv.FormatInt(patient.PatientId, 10),
  2101. SequelaeDate: time.Unix(patient.LapsetoTime, 0),
  2102. CreateTime: time.Unix(patient.CreatedTime, 0),
  2103. Sjscsj: time.Now(),
  2104. Xgbz: "0",
  2105. }
  2106. if patient.LapsetoType == 2 {
  2107. p.SequelaeType = "2"
  2108. p.DeathReason = "0"
  2109. p.ExtReason = "13"
  2110. } else {
  2111. p.SequelaeType = "1"
  2112. p.DeathReason = "99"
  2113. p.ExtReason = "0"
  2114. }
  2115. hdPatientOuts = append(hdPatientOuts, p)
  2116. service.BatchCreatePatientOut(hdPatientOuts, rdb)
  2117. }
  2118. // 同步患者退出信息表(T_HD_PATIENT_QUIT)
  2119. func SyncPatientOut(rdb *gorm.DB, org_id int64, hospital_id string) {
  2120. // 第一步:根据机构id获取上次同步时间
  2121. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 16)
  2122. var sync_time int64
  2123. if syncLastInfo.ID > 0 {
  2124. sync_time = syncLastInfo.SyncTime
  2125. } else {
  2126. sync_time = 0
  2127. }
  2128. var hdPatientOuts []*sz.TempHdPatientOut
  2129. patients, _ := service.FindOrgPatientOutDataTwo(sync_time, time.Now().Unix())
  2130. //
  2131. for _, patient := range patients {
  2132. orgPatient, _ := service.FindOrgPatientInfoById(patient.PatientId)
  2133. if orgPatient.UserOrgId != org_id {
  2134. continue
  2135. } else {
  2136. p := &sz.TempHdPatientOut{
  2137. Sn: strconv.FormatInt(patient.ID, 10),
  2138. HospitalId: hospital_id,
  2139. PatientNk: strconv.FormatInt(patient.PatientId, 10),
  2140. SequelaeDate: time.Unix(patient.Ctime, 0),
  2141. CreateTime: time.Unix(patient.Ctime, 0),
  2142. Sjscsj: time.Now(),
  2143. Xgbz: "0",
  2144. }
  2145. switch patient.PatientSource {
  2146. case 3:
  2147. p.SequelaeType = "1"
  2148. p.DeathReason = "99"
  2149. p.ExtReason = "13"
  2150. break
  2151. case 4:
  2152. p.SequelaeType = "2"
  2153. p.DeathReason = "0"
  2154. p.ExtReason = "13"
  2155. break
  2156. case 5:
  2157. p.SequelaeType = "3"
  2158. p.DeathReason = "0"
  2159. p.ExtReason = "13"
  2160. break
  2161. case 6:
  2162. p.SequelaeType = "4"
  2163. p.DeathReason = "0"
  2164. p.ExtReason = "13"
  2165. break
  2166. case 7:
  2167. p.SequelaeType = "5"
  2168. p.DeathReason = "0"
  2169. p.ExtReason = "13"
  2170. break
  2171. case 8:
  2172. p.SequelaeType = "6"
  2173. p.DeathReason = "0"
  2174. p.ExtReason = "13"
  2175. break
  2176. case 9:
  2177. p.SequelaeType = "7"
  2178. p.DeathReason = "0"
  2179. p.ExtReason = "13"
  2180. break
  2181. default:
  2182. p.SequelaeType = "2"
  2183. p.DeathReason = "0"
  2184. p.ExtReason = "13"
  2185. break
  2186. }
  2187. hdPatientOuts = append(hdPatientOuts, p)
  2188. }
  2189. }
  2190. if len(hdPatientOuts) > 0 {
  2191. err := service.BatchCreatePatientOut(hdPatientOuts, rdb)
  2192. if err == nil {
  2193. // 第三步:同步成功后,添加同步记录
  2194. upload := &sz.DataUpload{
  2195. SyncType: 16,
  2196. OrgId: org_id,
  2197. SyncTime: time.Now().Unix(),
  2198. SyncResultType: 1,
  2199. CreateTime: time.Now().Unix(),
  2200. UpdateTime: time.Now().Unix(),
  2201. }
  2202. err := service.CreateUploadRecord(upload)
  2203. if err != nil {
  2204. utils.ErrorLog("%v", err)
  2205. }
  2206. } else {
  2207. //错误处理
  2208. }
  2209. }
  2210. }
  2211. // 同步处方信息
  2212. func SyncDoctorAdvice(rdb *gorm.DB, org_id int64, hospital_id string) {
  2213. // 第一步:根据机构id获取上次同步时间
  2214. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 6)
  2215. var sync_time int64
  2216. if syncLastInfo.ID > 0 {
  2217. sync_time = syncLastInfo.SyncTime
  2218. } else {
  2219. sync_time = 1577808000
  2220. }
  2221. var hdDoctorAdvices []*sz.TempHdDoctorsAdvice
  2222. dialysisPrescriptions, _ := service.FindOrgDialysisPrescriptionData(org_id, sync_time, time.Now().Unix())
  2223. for _, dp := range dialysisPrescriptions {
  2224. if dp.DialysisOrder.ID > 0 {
  2225. advice := &sz.TempHdDoctorsAdvice{
  2226. MedicalOrderId: strconv.FormatInt(dp.ID, 10),
  2227. HospitalId: hospital_id,
  2228. DialysisId: strconv.FormatInt(dp.DialysisOrder.ID, 10),
  2229. OrderType: "1",
  2230. PatientNk: strconv.FormatInt(dp.PatientId, 10),
  2231. DialysisDuration: dp.DialysisDurationHour*60 + dp.DialysisDurationMinute,
  2232. BloodVol: int64(math.Floor(dp.BloodFlowVolume + 0/5)),
  2233. Anticoagulant: dp.Anticoagulant,
  2234. CreateTime: time.Unix(dp.CreatedTime, 0),
  2235. Sjscsj: time.Now(),
  2236. Xgbz: 0,
  2237. DryWeight: dp.AssessmentBeforeDislysis.DryWeight,
  2238. }
  2239. switch dp.ModeId {
  2240. case 1:
  2241. advice.RrtTypeName = "HD"
  2242. advice.RrtType = 1
  2243. break
  2244. case 2:
  2245. advice.RrtTypeName = "HDF"
  2246. advice.RrtType = 3
  2247. break
  2248. case 4:
  2249. advice.RrtTypeName = "HP"
  2250. advice.RrtType = 5
  2251. break
  2252. case 5:
  2253. advice.RrtTypeName = "HF"
  2254. advice.RrtType = 2
  2255. break
  2256. case 7:
  2257. advice.RrtTypeName = "IUF"
  2258. advice.RrtType = 6
  2259. break
  2260. default:
  2261. advice.RrtTypeName = "HD"
  2262. advice.RrtType = 1
  2263. }
  2264. if advice.RrtType == 0 {
  2265. continue
  2266. }
  2267. hdDoctorAdvices = append(hdDoctorAdvices, advice)
  2268. }
  2269. }
  2270. if len(hdDoctorAdvices) > 0 {
  2271. err := service.BatchCreateDoctorsAdvice(hdDoctorAdvices, rdb)
  2272. if err == nil {
  2273. // 第三步:同步成功后,添加同步记录
  2274. upload := &sz.DataUpload{
  2275. SyncType: 6,
  2276. OrgId: org_id,
  2277. SyncTime: time.Now().Unix(),
  2278. SyncResultType: 1,
  2279. CreateTime: time.Now().Unix(),
  2280. UpdateTime: time.Now().Unix(),
  2281. }
  2282. err := service.CreateUploadRecord(upload)
  2283. if err != nil {
  2284. utils.ErrorLog("%v", err)
  2285. }
  2286. } else {
  2287. //错误处理
  2288. }
  2289. }
  2290. }
  2291. func SyncMiddle(rdb *gorm.DB, org_id int64, hospital_id string) {
  2292. // 第一步:根据机构id获取上次同步时间
  2293. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 36)
  2294. var sync_time int64
  2295. if syncLastInfo.ID > 0 {
  2296. sync_time = syncLastInfo.SyncTime
  2297. } else {
  2298. sync_time = 1662134400
  2299. }
  2300. var hdMiddle []*sz.TempHdMiddle
  2301. monitors, _ := service.FindOrgMonitorRecordData(org_id, sync_time, time.Now().Unix())
  2302. for _, item := range monitors {
  2303. mid := &sz.TempHdMiddle{
  2304. Sn: item.ID,
  2305. HospitalId: hospital_id,
  2306. DialysisId: strconv.FormatInt(item.DialysisOrder.ID, 10),
  2307. MonitorTime: time.Unix(item.OperateTime, 0),
  2308. Sbp: int64(math.Floor(item.SystolicBloodPressure + 0/5)),
  2309. Dbp: int64(math.Floor(item.DiastolicBloodPressure + 0/5)),
  2310. PatientNk: strconv.FormatInt(item.PatientId, 10),
  2311. CreateTime: time.Unix(item.CreatedTime, 0),
  2312. Sjscsj: time.Now(),
  2313. Xgbz: 0,
  2314. }
  2315. if mid.Sbp > 999 {
  2316. continue
  2317. }
  2318. if mid.Dbp > 999 {
  2319. continue
  2320. }
  2321. hdMiddle = append(hdMiddle, mid)
  2322. }
  2323. if len(hdMiddle) > 0 {
  2324. err := service.BatchCreateMonitor(hdMiddle, rdb)
  2325. if err == nil {
  2326. // 第三步:同步成功后,添加同步记录
  2327. upload := &sz.DataUpload{
  2328. SyncType: 36,
  2329. OrgId: org_id,
  2330. SyncTime: time.Now().Unix(),
  2331. SyncResultType: 1,
  2332. CreateTime: time.Now().Unix(),
  2333. UpdateTime: time.Now().Unix(),
  2334. }
  2335. err := service.CreateUploadRecord(upload)
  2336. if err != nil {
  2337. utils.ErrorLog("%v", err)
  2338. }
  2339. } else {
  2340. //错误处理
  2341. }
  2342. }
  2343. }
  2344. // 同步设备
  2345. func SyncOtherMachine(rdb *gorm.DB, org_id int64, hospital_id string) {
  2346. // 第一步:根据机构id获取上次同步时间
  2347. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 13)
  2348. var sync_time int64
  2349. if syncLastInfo.ID > 0 {
  2350. sync_time = syncLastInfo.SyncTime
  2351. } else {
  2352. sync_time = 0
  2353. }
  2354. //同步设备
  2355. waterMachine, _ := service.FindOrgOtherMachineData(org_id, sync_time, time.Now().Unix())
  2356. var wms []*sz.TempHdOtherMachine
  2357. for _, item := range waterMachine {
  2358. wm := &sz.TempHdOtherMachine{
  2359. HospitalId: hospital_id,
  2360. EquipmentId: strconv.FormatInt(item.ID, 10),
  2361. EquipmentBrand: item.ManufactureFactory,
  2362. EnableTime: time.Unix(item.BuyDate, 0),
  2363. Status: "1",
  2364. EquipmentType: "99",
  2365. CreateTime: time.Unix(item.Ctime, 0),
  2366. UpdateTime: time.Unix(item.Mtime, 0),
  2367. Sjscsj: time.Now(),
  2368. Xgbz: "0",
  2369. }
  2370. switch item.MachineStatus {
  2371. case 1:
  2372. wm.Status = "1"
  2373. break
  2374. case 4:
  2375. wm.Status = "3"
  2376. break
  2377. default:
  2378. wm.Status = "1"
  2379. break
  2380. }
  2381. wms = append(wms, wm)
  2382. }
  2383. if len(wms) > 0 {
  2384. err := service.BatchCreateOtherMachineRecord(wms, rdb)
  2385. if err == nil {
  2386. // 第三步:同步成功后,添加同步记录
  2387. upload := &sz.DataUpload{
  2388. SyncType: 13,
  2389. OrgId: org_id,
  2390. SyncTime: time.Now().Unix(),
  2391. SyncResultType: 1,
  2392. CreateTime: time.Now().Unix(),
  2393. UpdateTime: time.Now().Unix(),
  2394. }
  2395. err := service.CreateUploadRecord(upload)
  2396. if err != nil {
  2397. utils.ErrorLog("%v", err)
  2398. }
  2399. } else {
  2400. //错误处理
  2401. }
  2402. }
  2403. }
  2404. // 同步透析机消毒检测记录表(T_HD_DM_DISINFECT)
  2405. func SyncDmDisinfect(rdb *gorm.DB, org_id int64, hospital_id string) {
  2406. // 第一步:根据机构id获取上次同步时间
  2407. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 2003)
  2408. var sync_time int64
  2409. if syncLastInfo.ID > 0 {
  2410. sync_time = syncLastInfo.SyncTime
  2411. } else {
  2412. sync_time = 0
  2413. }
  2414. //同步透析机消毒检测记录表
  2415. deviceInformations, _ := service.FindOrgDeviceInformationData(org_id, sync_time, time.Now().Unix())
  2416. var dfs []*sz.TempHdDmDisinfect
  2417. for _, item := range deviceInformations {
  2418. if item.VMDeviceAddmacher.DeviceType != 1 {
  2419. continue
  2420. } else {
  2421. df := &sz.TempHdDmDisinfect{
  2422. Sn: strconv.FormatInt(item.ID, 10),
  2423. HospitalId: hospital_id,
  2424. EquipmentId: strconv.FormatInt(item.EquimentId, 10),
  2425. SickbedNo: strconv.FormatInt(item.BedNumber, 10),
  2426. InspectionTime: time.Unix(item.Date, 0),
  2427. IsQualified: "1",
  2428. CaseOrder: "1",
  2429. CreateTime: time.Unix(item.Ctime, 0),
  2430. Sjscsj: time.Now(),
  2431. Xgbz: "0",
  2432. }
  2433. dfs = append(dfs, df)
  2434. }
  2435. }
  2436. if len(dfs) > 0 {
  2437. err := service.BatchCreateDmDisinfect(dfs, rdb)
  2438. if err == nil {
  2439. // 第三步:同步成功后,添加同步记录
  2440. upload := &sz.DataUpload{
  2441. SyncType: 2003,
  2442. OrgId: org_id,
  2443. SyncTime: time.Now().Unix(),
  2444. SyncResultType: 1,
  2445. CreateTime: time.Now().Unix(),
  2446. UpdateTime: time.Now().Unix(),
  2447. }
  2448. err := service.CreateUploadRecord(upload)
  2449. if err != nil {
  2450. utils.ErrorLog("%v", err)
  2451. }
  2452. } else {
  2453. //错误处理
  2454. }
  2455. }
  2456. }
  2457. // 水处理机消毒记录表(T_HD_WM_DISINFECT)
  2458. func SyncWmDisinfect(rdb *gorm.DB, org_id int64, hospital_id string) {
  2459. // 第一步:根据机构id获取上次同步时间
  2460. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 2004)
  2461. var sync_time int64
  2462. if syncLastInfo.ID > 0 {
  2463. sync_time = syncLastInfo.SyncTime
  2464. } else {
  2465. sync_time = 0
  2466. }
  2467. //同步透析机消毒检测记录表
  2468. deviceInformations, _ := service.FindOrgDeviceInformationData(org_id, sync_time, time.Now().Unix())
  2469. var dfs []*sz.TempWdDmDisinfect
  2470. for _, item := range deviceInformations {
  2471. if item.VMDeviceAddmacher.DeviceType != 2 {
  2472. continue
  2473. } else {
  2474. df := &sz.TempWdDmDisinfect{
  2475. Sn: strconv.FormatInt(item.ID, 10),
  2476. HospitalId: hospital_id,
  2477. EquipmentId: strconv.FormatInt(item.EquimentId, 10),
  2478. InspectionTime: time.Unix(item.Date, 0),
  2479. IsQualified: "1",
  2480. CaseOrder: "1",
  2481. CreateTime: time.Unix(item.Ctime, 0),
  2482. Sjscsj: time.Now(),
  2483. Xgbz: "0",
  2484. }
  2485. dfs = append(dfs, df)
  2486. }
  2487. }
  2488. if len(dfs) > 0 {
  2489. err := service.BatchCreateWmDisinfect(dfs, rdb)
  2490. if err == nil {
  2491. // 第三步:同步成功后,添加同步记录
  2492. upload := &sz.DataUpload{
  2493. SyncType: 2004,
  2494. OrgId: org_id,
  2495. SyncTime: time.Now().Unix(),
  2496. SyncResultType: 1,
  2497. CreateTime: time.Now().Unix(),
  2498. UpdateTime: time.Now().Unix(),
  2499. }
  2500. err := service.CreateUploadRecord(upload)
  2501. if err != nil {
  2502. utils.ErrorLog("%v", err)
  2503. }
  2504. } else {
  2505. //错误处理
  2506. }
  2507. }
  2508. }
  2509. // 同步维修
  2510. func SyncMachineRepair(rdb *gorm.DB, org_id int64, hospital_id string) {
  2511. // 第一步:根据机构id获取上次同步时间
  2512. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 11)
  2513. var sync_time int64
  2514. if syncLastInfo.ID > 0 {
  2515. sync_time = syncLastInfo.SyncTime
  2516. } else {
  2517. sync_time = 0
  2518. }
  2519. //同步设备
  2520. hdMaintain, _ := service.FindOrgMachineRepairData(org_id, sync_time, time.Now().Unix())
  2521. var maintain []*sz.TempHdMaintain
  2522. for _, item := range hdMaintain {
  2523. mt := &sz.TempHdMaintain{
  2524. Sn: strconv.FormatInt(item.ID, 10),
  2525. HospitalId: hospital_id,
  2526. EquipmentId: strconv.FormatInt(item.VMDeviceAddmacher.ID, 10),
  2527. RepairTime: time.Unix(item.GuaranteeDate, 0),
  2528. CreateTime: time.Unix(item.Ctime, 0),
  2529. Sjscsj: time.Now(),
  2530. Xgbz: 0,
  2531. }
  2532. switch item.VMDeviceAddmacher.DeviceType {
  2533. case 1:
  2534. mt.EquipmentType = "11"
  2535. break
  2536. case 2:
  2537. mt.EquipmentType = "21"
  2538. break
  2539. case 3:
  2540. mt.EquipmentType = "99"
  2541. break
  2542. }
  2543. maintain = append(maintain, mt)
  2544. }
  2545. if len(maintain) > 0 {
  2546. err := service.BatchCreateMainTain(maintain, rdb)
  2547. if err == nil {
  2548. // 第三步:同步成功后,添加同步记录
  2549. upload := &sz.DataUpload{
  2550. SyncType: 11,
  2551. OrgId: org_id,
  2552. SyncTime: time.Now().Unix(),
  2553. SyncResultType: 1,
  2554. CreateTime: time.Now().Unix(),
  2555. UpdateTime: time.Now().Unix(),
  2556. }
  2557. err := service.CreateUploadRecord(upload)
  2558. if err != nil {
  2559. utils.ErrorLog("%v", err)
  2560. }
  2561. } else {
  2562. //错误处理
  2563. }
  2564. }
  2565. }
  2566. // 同步设备消毒方法表(T_HD_DISINFECT_METHOD
  2567. func SyncDisinfectMethod(rdb *gorm.DB, org_id int64, hospital_id string) {
  2568. // 第一步:根据机构id获取上次同步时间
  2569. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 2002)
  2570. var sync_time int64
  2571. if syncLastInfo.ID > 0 {
  2572. sync_time = syncLastInfo.SyncTime
  2573. } else {
  2574. sync_time = 0
  2575. }
  2576. //同步设备消毒方法表
  2577. deviceplans, _ := service.FindOrgDevicePlan(org_id, sync_time, time.Now().Unix())
  2578. var disinfects []*sz.TempHdDisinfectMethod
  2579. for _, item := range deviceplans {
  2580. disinfect := &sz.TempHdDisinfectMethod{
  2581. Sn: strconv.FormatInt(item.ID, 10),
  2582. HospitalId: hospital_id,
  2583. EquipmentId: strconv.FormatInt(item.VMDeviceAddmacher.ID, 10),
  2584. DisinfectMethod: "1",
  2585. Concentration: "0_",
  2586. CreateTime: time.Unix(item.Ctime, 0),
  2587. UpdateTime: time.Unix(item.Mtime, 0),
  2588. Sjscsj: time.Now(),
  2589. Xgbz: 0,
  2590. }
  2591. switch item.VMDeviceAddmacher.DeviceType {
  2592. case 1:
  2593. disinfect.EquipmentType = "11"
  2594. break
  2595. case 2:
  2596. disinfect.EquipmentType = "21"
  2597. break
  2598. case 3:
  2599. disinfect.EquipmentType = "99"
  2600. break
  2601. }
  2602. switch item.MachineDisinfectant {
  2603. case 1:
  2604. disinfect.Disinfector = "0.22%季铵盐"
  2605. break
  2606. case 2:
  2607. disinfect.Disinfector = "500mg/l含氯消毒剂"
  2608. break
  2609. case 3:
  2610. disinfect.Disinfector = "1000mg/l含氯消毒剂"
  2611. break
  2612. case 4:
  2613. disinfect.Disinfector = "1500mg/l含氯消毒剂"
  2614. break
  2615. case 5:
  2616. disinfect.Disinfector = "消毒湿巾"
  2617. break
  2618. default:
  2619. disinfect.Disinfector = "0_"
  2620. break
  2621. }
  2622. disinfects = append(disinfects, disinfect)
  2623. }
  2624. if len(disinfects) > 0 {
  2625. err := service.BatchCreateDisinfectMethod(disinfects, rdb)
  2626. if err == nil {
  2627. // 第三步:同步成功后,添加同步记录
  2628. upload := &sz.DataUpload{
  2629. SyncType: 2002,
  2630. OrgId: org_id,
  2631. SyncTime: time.Now().Unix(),
  2632. SyncResultType: 1,
  2633. CreateTime: time.Now().Unix(),
  2634. UpdateTime: time.Now().Unix(),
  2635. }
  2636. err := service.CreateUploadRecord(upload)
  2637. if err != nil {
  2638. utils.ErrorLog("%v", err)
  2639. }
  2640. } else {
  2641. //错误处理
  2642. }
  2643. }
  2644. }
  2645. // 同步 透析机信息表
  2646. func SyncDM_pg(rdb *gorm.DB, org_id int64, hospital_id string) {
  2647. // 第一步:根据机构id获取上次同步时间
  2648. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 5)
  2649. var sync_time int64
  2650. if syncLastInfo.ID > 0 {
  2651. sync_time = syncLastInfo.SyncTime
  2652. } else {
  2653. sync_time = 0
  2654. }
  2655. //同步设备
  2656. dm, _ := service.FindOrgMachineData(org_id, sync_time, time.Now().Unix())
  2657. var hdms []*sz.TempHdDm
  2658. for _, item := range dm {
  2659. hdm := &sz.TempHdDm{
  2660. HospitalId: hospital_id,
  2661. EquipmentId: strconv.FormatInt(item.ID, 10),
  2662. SickbedNo: strconv.FormatInt(item.DeviceNumber.ID, 10),
  2663. SickbedType: "0",
  2664. EquipmentBrand: item.ManufactureFactory,
  2665. EnableTime: time.Unix(item.BuyDate, 0),
  2666. EquipmentType: "12",
  2667. Bbp: "1",
  2668. CreateTime: time.Unix(item.Ctime, 0),
  2669. UpdateTime: time.Unix(item.Mtime, 0),
  2670. Sjscsj: time.Now(),
  2671. Xgbz: strconv.FormatInt(0, 10),
  2672. }
  2673. switch item.MachineStatus {
  2674. case 1:
  2675. hdm.Status = "1"
  2676. break
  2677. case 4:
  2678. hdm.Status = "3"
  2679. break
  2680. }
  2681. hdms = append(hdms, hdm)
  2682. }
  2683. if len(hdms) > 0 {
  2684. err := service.BatchCreateHDMRecord(hdms, rdb)
  2685. if err == nil {
  2686. // 第三步:同步成功后,添加同步记录
  2687. upload := &sz.DataUpload{
  2688. SyncType: 5,
  2689. OrgId: org_id,
  2690. SyncTime: time.Now().Unix(),
  2691. SyncResultType: 1,
  2692. CreateTime: time.Now().Unix(),
  2693. UpdateTime: time.Now().Unix(),
  2694. }
  2695. err := service.CreateUploadRecord(upload)
  2696. if err != nil {
  2697. utils.ErrorLog("%v", err)
  2698. }
  2699. } else {
  2700. //错误处理
  2701. }
  2702. }
  2703. }
  2704. func SyncDM(rdb *gorm.DB, org_id int64, hospital_id string) {
  2705. // 第一步:根据机构id获取上次同步时间
  2706. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 5)
  2707. var sync_time int64
  2708. if syncLastInfo.ID > 0 {
  2709. sync_time = syncLastInfo.SyncTime
  2710. } else {
  2711. sync_time = 0
  2712. }
  2713. //同步设备
  2714. dm, _ := service.FindOrgMachineData(org_id, sync_time, time.Now().Unix())
  2715. var hdms []*sz.TempHdDm
  2716. for _, item := range dm {
  2717. hdm := &sz.TempHdDm{
  2718. HospitalId: hospital_id,
  2719. EquipmentId: strconv.FormatInt(item.ID, 10),
  2720. SickbedNo: strconv.FormatInt(item.DeviceNumber.ID, 10),
  2721. SickbedType: "0",
  2722. EquipmentBrand: item.ManufactureFactory,
  2723. EnableTime: time.Unix(item.BuyDate, 0),
  2724. EquipmentType: "12",
  2725. Bbp: "1",
  2726. CreateTime: time.Unix(item.Ctime, 0),
  2727. UpdateTime: time.Unix(item.Mtime, 0),
  2728. Sjscsj: time.Now(),
  2729. Xgbz: strconv.FormatInt(0, 10),
  2730. }
  2731. switch item.MachineStatus {
  2732. case 1:
  2733. hdm.Status = "1"
  2734. break
  2735. case 4:
  2736. hdm.Status = "3"
  2737. break
  2738. }
  2739. hdms = append(hdms, hdm)
  2740. }
  2741. if len(hdms) > 0 {
  2742. err := service.BatchCreateHDMRecord(hdms, rdb)
  2743. if err == nil {
  2744. // 第三步:同步成功后,添加同步记录
  2745. upload := &sz.DataUpload{
  2746. SyncType: 5,
  2747. OrgId: org_id,
  2748. SyncTime: time.Now().Unix(),
  2749. SyncResultType: 1,
  2750. CreateTime: time.Now().Unix(),
  2751. UpdateTime: time.Now().Unix(),
  2752. }
  2753. err := service.CreateUploadRecord(upload)
  2754. if err != nil {
  2755. utils.ErrorLog("%v", err)
  2756. }
  2757. } else {
  2758. //错误处理
  2759. }
  2760. }
  2761. }
  2762. // 同步患者透析记录
  2763. func SyncDialysis(rdb *gorm.DB, org_id int64, hospital_id string) {
  2764. // 第一步:根据机构id获取上次同步时间
  2765. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 2)
  2766. var sync_time int64
  2767. if syncLastInfo.ID > 0 {
  2768. sync_time = syncLastInfo.SyncTime
  2769. } else {
  2770. sync_time = 1577808000
  2771. }
  2772. var tempDialysis []*sz.TempHdDialysis
  2773. dialysisData, _ := service.FindOrgDialysisData(org_id, sync_time, time.Now().Unix())
  2774. for _, item := range dialysisData {
  2775. psm := &sz.TempHdDialysis{
  2776. DialysisId: strconv.FormatInt(item.ID, 10),
  2777. HospitalId: hospital_id,
  2778. PatientNk: strconv.FormatInt(item.PatientId, 10),
  2779. PsId: strconv.FormatInt(item.Schedule.ID, 10),
  2780. DialysisDate: time.Unix(item.DialysisDate, 0),
  2781. SickbedNo: strconv.FormatInt(item.DeviceNumber.ID, 10),
  2782. DivisionId: strconv.FormatInt(item.Schedule.PartitionId, 10),
  2783. EquipmentId: strconv.FormatInt(item.DeviceNumber.ID, 10),
  2784. MixDialysis: "0",
  2785. TotalTreatDuration: item.AssessmentAfterDislysis.ActualTreatmentHour*60 + item.AssessmentAfterDislysis.ActualTreatmentMinute,
  2786. IsHospitalization: "0",
  2787. IsEmergency: "0",
  2788. IsPerioperativePeriod: "0",
  2789. BeforeSbp: int64(item.AssessmentBeforeDislysis.SystolicBloodPressure),
  2790. BeforeDbp: int64(item.AssessmentBeforeDislysis.DiastolicBloodPressure),
  2791. AfterSbp: int64(item.AssessmentAfterDislysis.SystolicBloodPressure),
  2792. AfterDbp: int64(item.AssessmentAfterDislysis.DiastolicBloodPressure),
  2793. BeforeWeight: item.AssessmentBeforeDislysis.WeightBefore,
  2794. AfterWeight: item.AssessmentAfterDislysis.WeightAfter,
  2795. Ktv: item.AssessmentAfterDislysis.Ktv,
  2796. Urr: item.AssessmentAfterDislysis.Urr,
  2797. ChargeDoctorId: strconv.FormatInt(item.VMDialysisPrescription.PrescriptionDoctor, 10),
  2798. ChargeNurseId: strconv.FormatInt(item.StartNurse, 10),
  2799. UpNurseId: strconv.FormatInt(item.StartNurse, 10),
  2800. DownNurseId: strconv.FormatInt(item.FinishNurse, 10),
  2801. CheckNurseId: strconv.FormatInt(item.FinishNurse, 10),
  2802. PunctureNurseId: strconv.FormatInt(item.PunctureNurse, 10),
  2803. StartTime: time.Unix(item.StartTime, 0),
  2804. EndTime: time.Unix(item.EndTime, 0),
  2805. CreateTime: time.Unix(item.CreatedTime, 0),
  2806. Sjscsj: time.Now(),
  2807. Xgbz: 0,
  2808. }
  2809. if item.AssessmentAfterDislysis.ActualUltrafiltration < 10 {
  2810. psm.ActualufMl = int64(item.AssessmentAfterDislysis.ActualUltrafiltration * 1000)
  2811. } else {
  2812. psm.ActualufMl = int64(item.AssessmentAfterDislysis.ActualUltrafiltration)
  2813. }
  2814. if item.VMDialysisPrescription.TargetUltrafiltration < 10 {
  2815. psm.Ufv = int64(item.VMDialysisPrescription.TargetUltrafiltration * 1000)
  2816. } else {
  2817. psm.Ufv = int64(item.VMDialysisPrescription.TargetUltrafiltration)
  2818. }
  2819. if item.AssessmentAfterDislysis.ActualDisplacement < 10 {
  2820. psm.TotalReplace = int64(item.AssessmentAfterDislysis.ActualDisplacement * 1000)
  2821. } else {
  2822. psm.TotalReplace = int64(item.AssessmentAfterDislysis.ActualDisplacement)
  2823. }
  2824. tempDialysis = append(tempDialysis, psm)
  2825. }
  2826. if len(tempDialysis) > 0 {
  2827. err := service.BatchCreateDialysis(tempDialysis, rdb)
  2828. if err == nil {
  2829. // 第三步:同步成功后,添加同步记录
  2830. upload := &sz.DataUpload{
  2831. SyncType: 2,
  2832. OrgId: org_id,
  2833. SyncTime: time.Now().Unix(),
  2834. SyncResultType: 1,
  2835. CreateTime: time.Now().Unix(),
  2836. UpdateTime: time.Now().Unix(),
  2837. }
  2838. err := service.CreateUploadRecord(upload)
  2839. if err != nil {
  2840. utils.ErrorLog("%v", err)
  2841. }
  2842. } else {
  2843. //错误处理
  2844. }
  2845. }
  2846. }
  2847. // 同步透析床位分区
  2848. func SyncDivision(rdb *gorm.DB, org_id int64, hospital_id string) {
  2849. // 第一步:根据机构id获取上次同步时间
  2850. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 55)
  2851. var sync_time int64
  2852. if syncLastInfo.ID > 0 {
  2853. sync_time = syncLastInfo.SyncTime
  2854. } else {
  2855. sync_time = 0
  2856. }
  2857. //同步透析床位分区
  2858. dm, _ := service.FindOrgDeviceZoneRecordData(org_id, sync_time, time.Now().Unix())
  2859. var hdms []*sz.TempHdDivision
  2860. for _, item := range dm {
  2861. hdm := &sz.TempHdDivision{
  2862. DivisionId: strconv.FormatInt(item.ID, 10),
  2863. HospitalId: hospital_id,
  2864. DivisionName: item.Name,
  2865. DivisionType: strconv.FormatInt(item.Type, 10),
  2866. CreateTime: time.Unix(item.CreateTime, 0),
  2867. UpdateTime: time.Unix(item.ModifyTime, 0),
  2868. Sjscsj: time.Now(),
  2869. Xgbz: strconv.FormatInt(0, 10),
  2870. }
  2871. hdms = append(hdms, hdm)
  2872. }
  2873. if len(hdms) > 0 {
  2874. err := service.CreateHDDivision(hdms, rdb)
  2875. if err == nil {
  2876. // 第三步:同步成功后,添加同步记录
  2877. upload := &sz.DataUpload{
  2878. SyncType: 55,
  2879. OrgId: org_id,
  2880. SyncTime: time.Now().Unix(),
  2881. SyncResultType: 1,
  2882. CreateTime: time.Now().Unix(),
  2883. UpdateTime: time.Now().Unix(),
  2884. }
  2885. err := service.CreateUploadRecord(upload)
  2886. if err != nil {
  2887. utils.ErrorLog("%v", err)
  2888. }
  2889. } else {
  2890. //错误处理
  2891. }
  2892. }
  2893. }
  2894. // 患者通路信息表
  2895. func SyncAccess(rdb *gorm.DB, org_id int64, hospital_id string) {
  2896. // 第一步:根据机构id获取上次同步时间
  2897. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 56)
  2898. var sync_time int64
  2899. if syncLastInfo.ID > 0 {
  2900. sync_time = syncLastInfo.SyncTime
  2901. } else {
  2902. sync_time = 1577808000
  2903. }
  2904. //同步员工信息
  2905. patientaccess, _ := service.FindOrgAccess(org_id, sync_time, time.Now().Unix())
  2906. var accessList []*sz.TempHdAccess
  2907. for _, item := range patientaccess {
  2908. access := &sz.TempHdAccess{
  2909. AccessId: strconv.FormatInt(item.ID, 10),
  2910. HospitalId: hospital_id,
  2911. PatientNk: strconv.FormatInt(item.PatientId, 10),
  2912. AccessType: "1",
  2913. AccessTypeName: "自体动静脉内瘘",
  2914. AccessStatus: "1",
  2915. SetupDate: time.Unix(item.StartTime, 0),
  2916. FirstUseTime: time.Unix(item.FirstStartTime, 0),
  2917. CreateTime: time.Unix(item.Ctime, 0),
  2918. UpdateTime: time.Unix(item.Mtime, 0),
  2919. Sjscsj: time.Now(),
  2920. Xgbz: 0,
  2921. }
  2922. accessList = append(accessList, access)
  2923. }
  2924. if len(accessList) > 0 {
  2925. err := service.CreateAccess(accessList, rdb)
  2926. if err == nil {
  2927. // 第三步:同步成功后,添加同步记录
  2928. upload := &sz.DataUpload{
  2929. SyncType: 56,
  2930. OrgId: org_id,
  2931. SyncTime: time.Now().Unix(),
  2932. SyncResultType: 1,
  2933. CreateTime: time.Now().Unix(),
  2934. UpdateTime: time.Now().Unix(),
  2935. }
  2936. err := service.CreateUploadRecord(upload)
  2937. if err != nil {
  2938. utils.ErrorLog("%v", err)
  2939. }
  2940. } else {
  2941. //错误处理
  2942. }
  2943. }
  2944. }
  2945. // 透析床位表
  2946. func SyncSickbed(rdb *gorm.DB, org_id int64, hospital_id string) {
  2947. // 第一步:根据机构id获取上次同步时间
  2948. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 57)
  2949. var sync_time int64
  2950. if syncLastInfo.ID > 0 {
  2951. sync_time = syncLastInfo.SyncTime
  2952. } else {
  2953. sync_time = 0
  2954. }
  2955. //同步床位
  2956. devices, _ := service.FindOrgDeviceNumber(org_id, sync_time, time.Now().Unix())
  2957. var sickbedList []*sz.TempHdSickbed
  2958. for _, device := range devices {
  2959. sickbed := &sz.TempHdSickbed{
  2960. SickbedNo: device.ID,
  2961. HospitalId: hospital_id,
  2962. DivisionId: strconv.FormatInt(device.ZoneId, 10),
  2963. SickbedCode: device.Number,
  2964. SickbedType: "0",
  2965. CreateTime: time.Unix(device.Ctime, 0),
  2966. UpdateTime: time.Unix(device.Mtime, 0),
  2967. Sjscsj: time.Now(),
  2968. Xgbz: 0,
  2969. }
  2970. sickbedList = append(sickbedList, sickbed)
  2971. }
  2972. if len(sickbedList) > 0 {
  2973. err := service.CreateSickbed(sickbedList, rdb)
  2974. if err == nil {
  2975. // 第三步:同步成功后,添加同步记录
  2976. upload := &sz.DataUpload{
  2977. SyncType: 57,
  2978. OrgId: org_id,
  2979. SyncTime: time.Now().Unix(),
  2980. SyncResultType: 1,
  2981. CreateTime: time.Now().Unix(),
  2982. UpdateTime: time.Now().Unix(),
  2983. }
  2984. err := service.CreateUploadRecord(upload)
  2985. if err != nil {
  2986. utils.ErrorLog("%v", err)
  2987. }
  2988. } else {
  2989. //错误处理
  2990. }
  2991. }
  2992. }
  2993. func SyncSickbed2(rdb *gorm.DB, org_id int64, hospital_id string) {
  2994. // 第一步:根据机构id获取上次同步时间
  2995. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 57)
  2996. var sync_time int64
  2997. if syncLastInfo.ID > 0 {
  2998. sync_time = syncLastInfo.SyncTime
  2999. } else {
  3000. sync_time = 0
  3001. }
  3002. //同步床位
  3003. devices, _ := service.FindOrgDeviceNumber(org_id, sync_time, time.Now().Unix())
  3004. var sickbedList []*sz.TempHdSickbed
  3005. for _, device := range devices {
  3006. sickbed := &sz.TempHdSickbed{
  3007. SickbedNo: device.ID,
  3008. HospitalId: hospital_id,
  3009. DivisionId: strconv.FormatInt(device.ZoneId, 10),
  3010. SickbedCode: device.Number,
  3011. SickbedType: "0",
  3012. CreateTime: time.Unix(device.Ctime, 0),
  3013. UpdateTime: time.Unix(device.Mtime, 0),
  3014. Sjscsj: time.Now(),
  3015. Xgbz: 0,
  3016. Ylyl1 : "0",
  3017. }
  3018. if device.ID == 7305{
  3019. sickbed.Ylyl1 = "1"
  3020. }
  3021. sickbedList = append(sickbedList, sickbed)
  3022. }
  3023. if len(sickbedList) > 0 {
  3024. err := service.CreateSickbed2(sickbedList, rdb)
  3025. if err == nil {
  3026. // 第三步:同步成功后,添加同步记录
  3027. upload := &sz.DataUpload{
  3028. SyncType: 57,
  3029. OrgId: org_id,
  3030. SyncTime: time.Now().Unix(),
  3031. SyncResultType: 1,
  3032. CreateTime: time.Now().Unix(),
  3033. UpdateTime: time.Now().Unix(),
  3034. }
  3035. err := service.CreateUploadRecord(upload)
  3036. if err != nil {
  3037. utils.ErrorLog("%v", err)
  3038. }
  3039. } else {
  3040. //错误处理
  3041. }
  3042. }
  3043. }
  3044. // 患者诊断信息表(T_HD_DIAGNOSIS)
  3045. func SyncDiagnosis(rdb *gorm.DB, org_id int64, hospital_id string) {
  3046. // 第一步:根据机构id获取上次同步时间
  3047. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 58)
  3048. var sync_time int64
  3049. if syncLastInfo.ID > 0 {
  3050. sync_time = syncLastInfo.SyncTime
  3051. } else {
  3052. sync_time = 1577808000
  3053. }
  3054. //同步患者
  3055. prescriptions, _ := service.FindOrgDialysisPrescriptionData(org_id, sync_time, time.Now().Unix())
  3056. var diagnosisList []*sz.TempHdDiagnosis
  3057. for _, item := range prescriptions {
  3058. diagnosis := &sz.TempHdDiagnosis{
  3059. DiagnosisId: strconv.FormatInt(item.ID, 10),
  3060. HospitalId: hospital_id,
  3061. PatientNk: strconv.FormatInt(item.PatientId, 10),
  3062. DiagnosisTime: time.Unix(item.CreatedTime, 0),
  3063. DiagnosisType: "10",
  3064. DiagnosisTypeItem: "1001",
  3065. DiagnosisTypeDetail: "100113",
  3066. CreateTime: time.Unix(item.CreatedTime, 0),
  3067. UpdateTime: time.Unix(item.UpdatedTime, 0),
  3068. Sjscsj: time.Now(),
  3069. Xgbz: 0,
  3070. }
  3071. diagnosisList = append(diagnosisList, diagnosis)
  3072. }
  3073. if len(diagnosisList) > 0 {
  3074. err := service.CreateDiagnosis(diagnosisList, rdb)
  3075. if err == nil {
  3076. // 第三步:同步成功后,添加同步记录
  3077. upload := &sz.DataUpload{
  3078. SyncType: 58,
  3079. OrgId: org_id,
  3080. SyncTime: time.Now().Unix(),
  3081. SyncResultType: 1,
  3082. CreateTime: time.Now().Unix(),
  3083. UpdateTime: time.Now().Unix(),
  3084. }
  3085. err := service.CreateUploadRecord(upload)
  3086. if err != nil {
  3087. utils.ErrorLog("%v", err)
  3088. }
  3089. } else {
  3090. //错误处理
  3091. }
  3092. }
  3093. }
  3094. // 患者传染病检查记录表(T_HD_INFECTION
  3095. func SyncInfection(rdb *gorm.DB, org_id int64, hospital_id string) {
  3096. // 第一步:根据机构id获取上次同步时间
  3097. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 59)
  3098. var sync_time int64
  3099. if syncLastInfo.ID > 0 {
  3100. sync_time = syncLastInfo.SyncTime
  3101. } else {
  3102. sync_time = 0
  3103. }
  3104. //同步患者
  3105. patients, _ := service.FindOrgPatientDataOne(org_id)
  3106. var infectionList []*sz.TempHdInfection
  3107. for _, patient := range patients {
  3108. // 查询有没有做传染病检查并返回检验检查时间
  3109. if org_id == 9598 {
  3110. // 龙岗二院
  3111. inspections, _ := service.FindOrgInspectionGroupLgey(org_id, sync_time, time.Now().Unix(), patient.ID)
  3112. if len(inspections) > 0 {
  3113. for _, insp := range inspections {
  3114. inspection_arr, _ := service.FindOrgInspectionGroupLgeyTwo(org_id, insp.InspectDate, patient.ID)
  3115. if len(inspection_arr) > 0 {
  3116. infection := &sz.TempHdInfection{
  3117. Sn: strconv.FormatInt(patient.ID, 10),
  3118. HospitalId: hospital_id,
  3119. PatientNk: strconv.FormatInt(patient.ID, 10),
  3120. Hbv: 9,
  3121. Hcv: 9,
  3122. Rpr: 9,
  3123. Hiv: 9,
  3124. Hbsag: 9,
  3125. Hbsab: 9,
  3126. Hbeag: 9,
  3127. Hbeab: 9,
  3128. Hbcab: 9,
  3129. CheckDate: time.Unix(insp.InspectDate, 0),
  3130. DoctorId: "599",
  3131. CreateTime: time.Now(),
  3132. Sjscsj: time.Now(),
  3133. Xgbz: 0,
  3134. }
  3135. for _, infectionDiseases := range inspection_arr {
  3136. infection.Sn = strconv.FormatInt(infectionDiseases.ID, 10)
  3137. // 乙肝
  3138. if len(infectionDiseases.InspectValue) > 0 {
  3139. if infectionDiseases.ItemId == 62 || infectionDiseases.ItemId == 18001056 || infectionDiseases.ItemId == 18001049 || infectionDiseases.ItemId == 18006001 || infectionDiseases.ItemId == 18131005 || infectionDiseases.ItemId == 18142001 || infectionDiseases.ItemId == 18169001 || infectionDiseases.ItemId == 18245006 || infectionDiseases.ItemId == 178 {
  3140. infection.Hbv = 0
  3141. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3142. infection.Hbv = 1
  3143. }
  3144. }
  3145. // 丙肝
  3146. if infectionDiseases.ItemId == 60 || infectionDiseases.ItemId == 18006002 || infectionDiseases.ItemId == 18130001 || infectionDiseases.ItemId == 18143001 || infectionDiseases.ItemId == 18178001 || infectionDiseases.ItemId == 18245001 || infectionDiseases.ItemId == 179 {
  3147. infection.Hcv = 0
  3148. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3149. infection.Hcv = 1
  3150. }
  3151. }
  3152. // 梅毒
  3153. if infectionDiseases.ItemId == 112 || infectionDiseases.ItemId == 18001055 || infectionDiseases.ItemId == 18008002 || infectionDiseases.ItemId == 18044001 || infectionDiseases.ItemId == 18051001 || infectionDiseases.ItemId == 18051003 || infectionDiseases.ItemId == 18065001 || infectionDiseases.ItemId == 18065003 || infectionDiseases.ItemId == 18076001 || infectionDiseases.ItemId == 18076003 || infectionDiseases.ItemId == 18078001 || infectionDiseases.ItemId == 18078004 || infectionDiseases.ItemId == 18131007 || infectionDiseases.ItemId == 18141001 || infectionDiseases.ItemId == 18167001 || infectionDiseases.ItemId == 18175002 || infectionDiseases.ItemId == 18176001 || infectionDiseases.ItemId == 18176002 || infectionDiseases.ItemId == 18176004 || infectionDiseases.ItemId == 18230002 || infectionDiseases.ItemId == 18241002 || infectionDiseases.ItemId == 18246002 || infectionDiseases.ItemId == 18246003 || infectionDiseases.ItemId == 112 {
  3154. infection.Rpr = 0
  3155. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3156. infection.Rpr = 1
  3157. }
  3158. }
  3159. // 艾滋病
  3160. if infectionDiseases.ItemId == 111 || infectionDiseases.ItemId == 18008001 || infectionDiseases.ItemId == 18001054 || infectionDiseases.ItemId == 18131006 || infectionDiseases.ItemId == 18044002 || infectionDiseases.ItemId == 18051002 || infectionDiseases.ItemId == 18065002 || infectionDiseases.ItemId == 18076002 || infectionDiseases.ItemId == 18078003 || infectionDiseases.ItemId == 18114001 || infectionDiseases.ItemId == 18175001 || infectionDiseases.ItemId == 18176003 || infectionDiseases.ItemId == 18230001 || infectionDiseases.ItemId == 18241001 || infectionDiseases.ItemId == 18246001 || infectionDiseases.ItemId == 111 {
  3161. infection.Rpr = 0
  3162. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3163. infection.Rpr = 1
  3164. }
  3165. }
  3166. // HBsAg 乙型肝炎表面抗原;
  3167. if infectionDiseases.ItemId == 62 || infectionDiseases.ItemId == 18006001 || infectionDiseases.ItemId == 18131005 || infectionDiseases.ItemId == 18142001 || infectionDiseases.ItemId == 18169001 || infectionDiseases.ItemId == 18245006 || infectionDiseases.ItemId == 62 {
  3168. infection.Hbsag = 0
  3169. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3170. infection.Hbsag = 1
  3171. }
  3172. }
  3173. // HBsAb 乙型肝炎表面抗体;
  3174. if infectionDiseases.ItemId == 63 || infectionDiseases.ItemId == 18006006 || infectionDiseases.ItemId == 18131004 || infectionDiseases.ItemId == 18142005 || infectionDiseases.ItemId == 18169002 || infectionDiseases.ItemId == 18245005 || infectionDiseases.ItemId == 63 {
  3175. infection.Hbsab = 0
  3176. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3177. infection.Hbsab = 1
  3178. }
  3179. }
  3180. // HBeAg 乙肝病毒e抗原;
  3181. if infectionDiseases.ItemId == 64 || infectionDiseases.ItemId == 18006003 || infectionDiseases.ItemId == 18131003 || infectionDiseases.ItemId == 18142004 || infectionDiseases.ItemId == 18169003 || infectionDiseases.ItemId == 18245004 || infectionDiseases.ItemId == 64 {
  3182. infection.Hbeag = 0
  3183. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3184. infection.Hbeag = 1
  3185. }
  3186. }
  3187. // HBeAb 乙型肝炎E抗体;
  3188. if infectionDiseases.ItemId == 65 || infectionDiseases.ItemId == 18006004 || infectionDiseases.ItemId == 18131002 || infectionDiseases.ItemId == 18142003 || infectionDiseases.ItemId == 18169004 || infectionDiseases.ItemId == 18245003 || infectionDiseases.ItemId == 65 {
  3189. infection.Hbeab = 0
  3190. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3191. infection.Hbeab = 1
  3192. }
  3193. }
  3194. // HBcAb 乙肝核心抗体;
  3195. if infectionDiseases.ItemId == 66 || infectionDiseases.ItemId == 18006005 || infectionDiseases.ItemId == 18131001 || infectionDiseases.ItemId == 18142002 || infectionDiseases.ItemId == 18169005 || infectionDiseases.ItemId == 18245002 || infectionDiseases.ItemId == 66 {
  3196. infection.Hbcab = 0
  3197. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3198. infection.Hbcab = 1
  3199. }
  3200. }
  3201. }
  3202. }
  3203. infectionList = append(infectionList, infection)
  3204. }
  3205. }
  3206. }
  3207. }
  3208. if org_id == 10138 {
  3209. // 深圳百霖
  3210. inspections, _ := service.FindOrgInspectionGroupSzbl(org_id, sync_time, time.Now().Unix(), patient.ID)
  3211. if len(inspections) > 0 {
  3212. for _, insp := range inspections {
  3213. inspection_arr, _ := service.FindOrgInspectionGroupSzblTwo(org_id, insp.InspectDate, patient.ID)
  3214. if len(inspection_arr) > 0 {
  3215. infection := &sz.TempHdInfection{
  3216. Sn: strconv.FormatInt(patient.ID, 10),
  3217. HospitalId: hospital_id,
  3218. PatientNk: strconv.FormatInt(patient.ID, 10),
  3219. Hbv: 9,
  3220. Hcv: 9,
  3221. Rpr: 9,
  3222. Hiv: 9,
  3223. Hbsag: 9,
  3224. Hbsab: 9,
  3225. Hbeag: 9,
  3226. Hbeab: 9,
  3227. Hbcab: 9,
  3228. CheckDate: time.Unix(insp.InspectDate, 0),
  3229. DoctorId: "2232",
  3230. CreateTime: time.Now(),
  3231. Sjscsj: time.Now(),
  3232. Xgbz: 0,
  3233. }
  3234. for _, infectionDiseases := range inspection_arr {
  3235. infection.Sn = strconv.FormatInt(infectionDiseases.ID, 10)
  3236. infection.CheckDate = time.Unix(infectionDiseases.InspectDate, 0)
  3237. // 乙肝
  3238. if infectionDiseases.ItemId == 101380001 || infectionDiseases.ItemId == 101387010 {
  3239. infection.Hbv = 0
  3240. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3241. infection.Hbv = 1
  3242. }
  3243. }
  3244. // 丙肝
  3245. if infectionDiseases.ItemId == 101380006 || infectionDiseases.ItemId == 101387004 {
  3246. infection.Hcv = 0
  3247. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3248. infection.Hcv = 1
  3249. }
  3250. }
  3251. // 梅毒
  3252. if infectionDiseases.ItemId == 101380009 || infectionDiseases.ItemId == 101387001 {
  3253. infection.Rpr = 0
  3254. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3255. infection.Rpr = 1
  3256. }
  3257. }
  3258. // 艾滋病
  3259. if infectionDiseases.ItemId == 101380010 || infectionDiseases.ItemId == 101387005 {
  3260. infection.Rpr = 0
  3261. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3262. infection.Rpr = 1
  3263. }
  3264. }
  3265. // HBsAg 乙型肝炎表面抗原;
  3266. if infectionDiseases.ItemId == 101380001 || infectionDiseases.ItemId == 101387010 {
  3267. infection.Hbsag = 0
  3268. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3269. infection.Hbsag = 1
  3270. }
  3271. }
  3272. // HBsAb 乙型肝炎表面抗体;
  3273. if infectionDiseases.ItemId == 101380002 || infectionDiseases.ItemId == 101387009 {
  3274. infection.Hbsab = 0
  3275. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3276. infection.Hbsab = 1
  3277. }
  3278. }
  3279. // HBeAg 乙肝病毒e抗原;
  3280. if infectionDiseases.ItemId == 101380003 || infectionDiseases.ItemId == 101387008 {
  3281. infection.Hbeag = 0
  3282. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3283. infection.Hbeag = 1
  3284. }
  3285. }
  3286. // HBeAb 乙型肝炎E抗体;
  3287. if infectionDiseases.ItemId == 101380004 || infectionDiseases.ItemId == 101387007 {
  3288. infection.Hbeab = 0
  3289. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3290. infection.Hbeab = 1
  3291. }
  3292. }
  3293. // HBcAb 乙肝核心抗体;
  3294. if infectionDiseases.ItemId == 101380005 || infectionDiseases.ItemId == 101387006 {
  3295. infection.Hbcab = 0
  3296. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3297. infection.Hbcab = 1
  3298. }
  3299. }
  3300. }
  3301. infectionList = append(infectionList, infection)
  3302. }
  3303. }
  3304. }
  3305. }
  3306. if org_id == 10278 {
  3307. // 深圳百霖贝尔
  3308. inspections, _ := service.FindOrgInspectionGroupSzblbr(org_id, sync_time, time.Now().Unix(), patient.ID)
  3309. if len(inspections) > 0 {
  3310. for _, insp := range inspections {
  3311. inspection_arr, _ := service.FindOrgInspectionGroupSzblbrTwo(org_id, insp.InspectDate, patient.ID)
  3312. if len(inspection_arr) > 0 {
  3313. infection := &sz.TempHdInfection{
  3314. Sn: strconv.FormatInt(patient.ID, 10),
  3315. HospitalId: hospital_id,
  3316. PatientNk: strconv.FormatInt(patient.ID, 10),
  3317. Hbv: 9,
  3318. Hcv: 9,
  3319. Rpr: 9,
  3320. Hiv: 9,
  3321. Hbsag: 9,
  3322. Hbsab: 9,
  3323. Hbeag: 9,
  3324. Hbeab: 9,
  3325. Hbcab: 9,
  3326. CheckDate: time.Unix(insp.InspectDate, 0),
  3327. DoctorId: "751",
  3328. CreateTime: time.Now(),
  3329. Sjscsj: time.Now(),
  3330. Xgbz: 0,
  3331. }
  3332. for _, infectionDiseases := range inspection_arr {
  3333. infection.Sn = strconv.FormatInt(infectionDiseases.ID, 10)
  3334. infection.CheckDate = time.Unix(infectionDiseases.InspectDate, 0)
  3335. // 乙肝
  3336. if infectionDiseases.ItemId == 101380302 || infectionDiseases.ItemId == 101385607 {
  3337. infection.Hbv = 0
  3338. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3339. infection.Hbv = 1
  3340. }
  3341. }
  3342. // 丙肝
  3343. if infectionDiseases.ItemId == 101380307 || infectionDiseases.ItemId == 101385609 {
  3344. infection.Hcv = 0
  3345. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3346. infection.Hcv = 1
  3347. }
  3348. }
  3349. // 梅毒
  3350. if infectionDiseases.ItemId == 101380009 || infectionDiseases.ItemId == 101385601 {
  3351. infection.Rpr = 0
  3352. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3353. infection.Rpr = 1
  3354. }
  3355. }
  3356. // 艾滋病
  3357. if infectionDiseases.ItemId == 101380301 || infectionDiseases.ItemId == 101380301 {
  3358. infection.Rpr = 0
  3359. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3360. infection.Rpr = 1
  3361. }
  3362. }
  3363. // HBsAg 乙型肝炎表面抗原;
  3364. if infectionDiseases.ItemId == 101380302 || infectionDiseases.ItemId == 101385607 {
  3365. infection.Hbsag = 0
  3366. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3367. infection.Hbsag = 1
  3368. }
  3369. }
  3370. // HBsAb 乙型肝炎表面抗体;
  3371. if infectionDiseases.ItemId == 101380303 || infectionDiseases.ItemId == 101385606 {
  3372. infection.Hbsab = 0
  3373. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3374. infection.Hbsab = 1
  3375. }
  3376. }
  3377. // HBeAg 乙肝病毒e抗原;
  3378. if infectionDiseases.ItemId == 101380304 || infectionDiseases.ItemId == 101385605 {
  3379. infection.Hbeag = 0
  3380. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3381. infection.Hbeag = 1
  3382. }
  3383. }
  3384. // HBeAb 乙型肝炎E抗体;
  3385. if infectionDiseases.ItemId == 101380305 || infectionDiseases.ItemId == 101385604 {
  3386. infection.Hbeab = 0
  3387. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3388. infection.Hbeab = 1
  3389. }
  3390. }
  3391. // HBcAb 乙肝核心抗体;
  3392. if infectionDiseases.ItemId == 101380306 || infectionDiseases.ItemId == 101385603 {
  3393. infection.Hbcab = 0
  3394. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3395. infection.Hbcab = 1
  3396. }
  3397. }
  3398. }
  3399. infectionList = append(infectionList, infection)
  3400. }
  3401. }
  3402. }
  3403. }
  3404. if org_id == 9504 {
  3405. inspections, _ := service.FindOrgInspectionGroupLgey(org_id, sync_time, time.Now().Unix(), patient.ID)
  3406. if len(inspections) > 0 {
  3407. for _, insp := range inspections {
  3408. inspection_arr, _ := service.FindOrgInspectionGroupTwo(org_id, insp.InspectDate, patient.ID)
  3409. if len(inspection_arr) > 0 {
  3410. infection := &sz.TempHdInfection{
  3411. Sn: strconv.FormatInt(patient.ID, 10),
  3412. HospitalId: hospital_id,
  3413. PatientNk: strconv.FormatInt(patient.ID, 10),
  3414. Hbv: 9,
  3415. Hcv: 9,
  3416. Rpr: 9,
  3417. Hiv: 9,
  3418. Hbsag: 9,
  3419. Hbsab: 9,
  3420. Hbeag: 9,
  3421. Hbeab: 9,
  3422. Hbcab: 9,
  3423. CheckDate: time.Unix(patient.CreatedTime, 0),
  3424. DoctorId: strconv.FormatInt(patient.RegistrarsId, 10),
  3425. CreateTime: time.Now(),
  3426. Sjscsj: time.Now(),
  3427. Xgbz: 0,
  3428. }
  3429. for _, infectionDiseases := range inspection_arr {
  3430. infection.Sn = strconv.FormatInt(infectionDiseases.ID, 10)
  3431. if infectionDiseases.ItemId == 60 {
  3432. infection.Hcv = 0
  3433. if infectionDiseases.InspectValue == "阳性" {
  3434. infection.Hcv = 1
  3435. }
  3436. }
  3437. if infectionDiseases.ItemId == 62 {
  3438. infection.Hbsag = 0
  3439. if infectionDiseases.InspectValue == "阳性" {
  3440. infection.Hbsag = 1
  3441. }
  3442. }
  3443. if infectionDiseases.ItemId == 63 {
  3444. infection.Hbsab = 0
  3445. if infectionDiseases.InspectValue == "阳性" {
  3446. infection.Hbsab = 1
  3447. }
  3448. }
  3449. if infectionDiseases.ItemId == 64 {
  3450. infection.Hbeag = 0
  3451. if infectionDiseases.InspectValue == "阳性" {
  3452. infection.Hbeag = 1
  3453. }
  3454. }
  3455. if infectionDiseases.ItemId == 65 {
  3456. infection.Hbeab = 0
  3457. if infectionDiseases.InspectValue == "阳性" {
  3458. infection.Hbeab = 1
  3459. }
  3460. }
  3461. if infectionDiseases.ItemId == 66 {
  3462. infection.Hbcab = 0
  3463. if infectionDiseases.InspectValue == "阳性" {
  3464. infection.Hbcab = 1
  3465. }
  3466. }
  3467. if infectionDiseases.ItemId == 111 {
  3468. infection.Hiv = 0
  3469. if infectionDiseases.InspectValue == "阳性" {
  3470. infection.Hiv = 1
  3471. }
  3472. }
  3473. if infectionDiseases.ItemId == 112 {
  3474. infection.Rpr = 0
  3475. if infectionDiseases.InspectValue == "阳性" {
  3476. infection.Rpr = 1
  3477. }
  3478. }
  3479. if infectionDiseases.ItemId == 178 {
  3480. infection.Hbv = 0
  3481. if infectionDiseases.InspectValue == "阳性" {
  3482. infection.Hbv = 1
  3483. }
  3484. }
  3485. if infectionDiseases.ItemId == 179 {
  3486. infection.Hcv = 0
  3487. if infectionDiseases.InspectValue == "阳性" {
  3488. infection.Hcv = 1
  3489. }
  3490. }
  3491. }
  3492. infectionList = append(infectionList, infection)
  3493. }
  3494. }
  3495. }
  3496. }
  3497. if org_id == 10580 {
  3498. inspections, _ := service.FindOrgInspectionGroupOne(org_id, sync_time, time.Now().Unix(), patient.ID)
  3499. if len(inspections) > 0 {
  3500. for _, insp := range inspections {
  3501. inspection_arr, _ := service.FindOrgInspectionGroupTwo(org_id, insp.InspectDate, patient.ID)
  3502. if len(inspection_arr) > 0 {
  3503. infection := &sz.TempHdInfection{
  3504. Sn: strconv.FormatInt(patient.ID, 10),
  3505. HospitalId: hospital_id,
  3506. PatientNk: strconv.FormatInt(patient.ID, 10),
  3507. Hbv: 9,
  3508. Hcv: 9,
  3509. Rpr: 9,
  3510. Hiv: 9,
  3511. Hbsag: 9,
  3512. Hbsab: 9,
  3513. Hbeag: 9,
  3514. Hbeab: 9,
  3515. Hbcab: 9,
  3516. CheckDate: time.Unix(patient.CreatedTime, 0),
  3517. DoctorId: strconv.FormatInt(patient.RegistrarsId, 10),
  3518. CreateTime: time.Now(),
  3519. Sjscsj: time.Now(),
  3520. Xgbz: 0,
  3521. }
  3522. for _, infectionDiseases := range inspection_arr {
  3523. infection.Sn = strconv.FormatInt(infectionDiseases.ID, 10)
  3524. if infectionDiseases.ItemId == 60 {
  3525. infection.Hcv = 0
  3526. if infectionDiseases.InspectValue == "阳性" {
  3527. infection.Hcv = 1
  3528. }
  3529. }
  3530. if infectionDiseases.ItemId == 62 {
  3531. infection.Hbsag = 0
  3532. if infectionDiseases.InspectValue == "阳性" {
  3533. infection.Hbsag = 1
  3534. }
  3535. }
  3536. if infectionDiseases.ItemId == 63 {
  3537. infection.Hbsab = 0
  3538. if infectionDiseases.InspectValue == "阳性" {
  3539. infection.Hbsab = 1
  3540. }
  3541. }
  3542. if infectionDiseases.ItemId == 64 {
  3543. infection.Hbeag = 0
  3544. if infectionDiseases.InspectValue == "阳性" {
  3545. infection.Hbeag = 1
  3546. }
  3547. }
  3548. if infectionDiseases.ItemId == 65 {
  3549. infection.Hbeab = 0
  3550. if infectionDiseases.InspectValue == "阳性" {
  3551. infection.Hbeab = 1
  3552. }
  3553. }
  3554. if infectionDiseases.ItemId == 66 {
  3555. infection.Hbcab = 0
  3556. if infectionDiseases.InspectValue == "阳性" {
  3557. infection.Hbcab = 1
  3558. }
  3559. }
  3560. if infectionDiseases.ItemId == 111 {
  3561. infection.Hiv = 0
  3562. if infectionDiseases.InspectValue == "阳性" {
  3563. infection.Hiv = 1
  3564. }
  3565. }
  3566. if infectionDiseases.ItemId == 112 {
  3567. infection.Rpr = 0
  3568. if infectionDiseases.InspectValue == "阳性" {
  3569. infection.Rpr = 1
  3570. }
  3571. }
  3572. if infectionDiseases.ItemId == 178 {
  3573. infection.Hbv = 0
  3574. if infectionDiseases.InspectValue == "阳性" {
  3575. infection.Hbv = 1
  3576. }
  3577. }
  3578. if infectionDiseases.ItemId == 179 {
  3579. infection.Hcv = 0
  3580. if infectionDiseases.InspectValue == "阳性" {
  3581. infection.Hcv = 1
  3582. }
  3583. }
  3584. }
  3585. infectionList = append(infectionList, infection)
  3586. }
  3587. }
  3588. }
  3589. }
  3590. }
  3591. if len(infectionList) > 0 {
  3592. err := service.CreateInfection(infectionList, rdb)
  3593. if err == nil {
  3594. // 第三步:同步成功后,添加同步记录
  3595. upload := &sz.DataUpload{
  3596. SyncType: 59,
  3597. OrgId: org_id,
  3598. SyncTime: time.Now().Unix(),
  3599. SyncResultType: 1,
  3600. CreateTime: time.Now().Unix(),
  3601. UpdateTime: time.Now().Unix(),
  3602. }
  3603. err := service.CreateUploadRecord(upload)
  3604. if err != nil {
  3605. utils.ErrorLog("%v", err)
  3606. }
  3607. } else {
  3608. //错误处理
  3609. }
  3610. }
  3611. }
  3612. func SyncInfectionByID( org_id int64,ids []int64) {
  3613. org := &sz.DataUploadConfig{
  3614. OrgId: 10138,
  3615. ProvinceId: 19,
  3616. CityId: 291,
  3617. DepartmentName: "深圳市百霖血液透析中心",
  3618. HospitalId: "MA5DB4KB6",
  3619. InstType: 1,
  3620. DbHost: "127.0.0.1",
  3621. DbPort: "1433",
  3622. DbPass: "1Q2W3e4r!@#$",
  3623. DbUser: "adapter",
  3624. DbName: "adapter_2019",
  3625. }
  3626. hospital_id := org.HospitalId
  3627. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  3628. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  3629. if err != nil {
  3630. utils.ErrorLog("创建数据库连接失败:%v", err)
  3631. return
  3632. }
  3633. // 第一步:根据机构id获取上次同步时间
  3634. //syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 59)
  3635. var sync_time int64
  3636. //if syncLastInfo.ID > 0 {
  3637. // sync_time = syncLastInfo.SyncTime
  3638. //} else {
  3639. // sync_time = 0
  3640. //}
  3641. sync_time = 1704038400
  3642. //同步患者
  3643. patients, _ := service.FindOrgPatientDataTwo(org_id,ids)
  3644. var infectionList []*sz.TempHdInfection
  3645. for _, patient := range patients {
  3646. // 查询有没有做传染病检查并返回检验检查时间
  3647. if org_id == 9598 {
  3648. // 龙岗二院
  3649. inspections, _ := service.FindOrgInspectionGroupLgey(org_id, sync_time, time.Now().Unix(), patient.ID)
  3650. if len(inspections) > 0 {
  3651. for _, insp := range inspections {
  3652. inspection_arr, _ := service.FindOrgInspectionGroupLgeyTwo(org_id, insp.InspectDate, patient.ID)
  3653. if len(inspection_arr) > 0 {
  3654. infection := &sz.TempHdInfection{
  3655. Sn: strconv.FormatInt(patient.ID, 10),
  3656. HospitalId: hospital_id,
  3657. PatientNk: strconv.FormatInt(patient.ID, 10),
  3658. Hbv: 9,
  3659. Hcv: 9,
  3660. Rpr: 9,
  3661. Hiv: 9,
  3662. Hbsag: 9,
  3663. Hbsab: 9,
  3664. Hbeag: 9,
  3665. Hbeab: 9,
  3666. Hbcab: 9,
  3667. CheckDate: time.Unix(insp.InspectDate, 0),
  3668. DoctorId: "599",
  3669. CreateTime: time.Now(),
  3670. Sjscsj: time.Now(),
  3671. Xgbz: 0,
  3672. }
  3673. for _, infectionDiseases := range inspection_arr {
  3674. infection.Sn = strconv.FormatInt(infectionDiseases.ID, 10)
  3675. // 乙肝
  3676. if len(infectionDiseases.InspectValue) > 0 {
  3677. if infectionDiseases.ItemId == 62 || infectionDiseases.ItemId == 18001056 || infectionDiseases.ItemId == 18001049 || infectionDiseases.ItemId == 18006001 || infectionDiseases.ItemId == 18131005 || infectionDiseases.ItemId == 18142001 || infectionDiseases.ItemId == 18169001 || infectionDiseases.ItemId == 18245006 || infectionDiseases.ItemId == 178 {
  3678. infection.Hbv = 0
  3679. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3680. infection.Hbv = 1
  3681. }
  3682. }
  3683. // 丙肝
  3684. if infectionDiseases.ItemId == 60 || infectionDiseases.ItemId == 18006002 || infectionDiseases.ItemId == 18130001 || infectionDiseases.ItemId == 18143001 || infectionDiseases.ItemId == 18178001 || infectionDiseases.ItemId == 18245001 || infectionDiseases.ItemId == 179 {
  3685. infection.Hcv = 0
  3686. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3687. infection.Hcv = 1
  3688. }
  3689. }
  3690. // 梅毒
  3691. if infectionDiseases.ItemId == 112 || infectionDiseases.ItemId == 18001055 || infectionDiseases.ItemId == 18008002 || infectionDiseases.ItemId == 18044001 || infectionDiseases.ItemId == 18051001 || infectionDiseases.ItemId == 18051003 || infectionDiseases.ItemId == 18065001 || infectionDiseases.ItemId == 18065003 || infectionDiseases.ItemId == 18076001 || infectionDiseases.ItemId == 18076003 || infectionDiseases.ItemId == 18078001 || infectionDiseases.ItemId == 18078004 || infectionDiseases.ItemId == 18131007 || infectionDiseases.ItemId == 18141001 || infectionDiseases.ItemId == 18167001 || infectionDiseases.ItemId == 18175002 || infectionDiseases.ItemId == 18176001 || infectionDiseases.ItemId == 18176002 || infectionDiseases.ItemId == 18176004 || infectionDiseases.ItemId == 18230002 || infectionDiseases.ItemId == 18241002 || infectionDiseases.ItemId == 18246002 || infectionDiseases.ItemId == 18246003 || infectionDiseases.ItemId == 112 {
  3692. infection.Rpr = 0
  3693. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3694. infection.Rpr = 1
  3695. }
  3696. }
  3697. // 艾滋病
  3698. if infectionDiseases.ItemId == 111 || infectionDiseases.ItemId == 18008001 || infectionDiseases.ItemId == 18001054 || infectionDiseases.ItemId == 18131006 || infectionDiseases.ItemId == 18044002 || infectionDiseases.ItemId == 18051002 || infectionDiseases.ItemId == 18065002 || infectionDiseases.ItemId == 18076002 || infectionDiseases.ItemId == 18078003 || infectionDiseases.ItemId == 18114001 || infectionDiseases.ItemId == 18175001 || infectionDiseases.ItemId == 18176003 || infectionDiseases.ItemId == 18230001 || infectionDiseases.ItemId == 18241001 || infectionDiseases.ItemId == 18246001 || infectionDiseases.ItemId == 111 {
  3699. infection.Rpr = 0
  3700. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3701. infection.Rpr = 1
  3702. }
  3703. }
  3704. // HBsAg 乙型肝炎表面抗原;
  3705. if infectionDiseases.ItemId == 62 || infectionDiseases.ItemId == 18006001 || infectionDiseases.ItemId == 18131005 || infectionDiseases.ItemId == 18142001 || infectionDiseases.ItemId == 18169001 || infectionDiseases.ItemId == 18245006 || infectionDiseases.ItemId == 62 {
  3706. infection.Hbsag = 0
  3707. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3708. infection.Hbsag = 1
  3709. }
  3710. }
  3711. // HBsAb 乙型肝炎表面抗体;
  3712. if infectionDiseases.ItemId == 63 || infectionDiseases.ItemId == 18006006 || infectionDiseases.ItemId == 18131004 || infectionDiseases.ItemId == 18142005 || infectionDiseases.ItemId == 18169002 || infectionDiseases.ItemId == 18245005 || infectionDiseases.ItemId == 63 {
  3713. infection.Hbsab = 0
  3714. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3715. infection.Hbsab = 1
  3716. }
  3717. }
  3718. // HBeAg 乙肝病毒e抗原;
  3719. if infectionDiseases.ItemId == 64 || infectionDiseases.ItemId == 18006003 || infectionDiseases.ItemId == 18131003 || infectionDiseases.ItemId == 18142004 || infectionDiseases.ItemId == 18169003 || infectionDiseases.ItemId == 18245004 || infectionDiseases.ItemId == 64 {
  3720. infection.Hbeag = 0
  3721. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3722. infection.Hbeag = 1
  3723. }
  3724. }
  3725. // HBeAb 乙型肝炎E抗体;
  3726. if infectionDiseases.ItemId == 65 || infectionDiseases.ItemId == 18006004 || infectionDiseases.ItemId == 18131002 || infectionDiseases.ItemId == 18142003 || infectionDiseases.ItemId == 18169004 || infectionDiseases.ItemId == 18245003 || infectionDiseases.ItemId == 65 {
  3727. infection.Hbeab = 0
  3728. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3729. infection.Hbeab = 1
  3730. }
  3731. }
  3732. // HBcAb 乙肝核心抗体;
  3733. if infectionDiseases.ItemId == 66 || infectionDiseases.ItemId == 18006005 || infectionDiseases.ItemId == 18131001 || infectionDiseases.ItemId == 18142002 || infectionDiseases.ItemId == 18169005 || infectionDiseases.ItemId == 18245002 || infectionDiseases.ItemId == 66 {
  3734. infection.Hbcab = 0
  3735. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3736. infection.Hbcab = 1
  3737. }
  3738. }
  3739. }
  3740. }
  3741. infectionList = append(infectionList, infection)
  3742. }
  3743. }
  3744. }
  3745. }
  3746. if org_id == 10138 {
  3747. // 深圳百霖
  3748. inspections, _ := service.FindOrgInspectionGroupSzbl(org_id, sync_time, time.Now().Unix(), patient.ID)
  3749. if len(inspections) > 0 {
  3750. for _, insp := range inspections {
  3751. inspection_arr, _ := service.FindOrgInspectionGroupSzblTwo(org_id, insp.InspectDate, patient.ID)
  3752. if len(inspection_arr) > 0 {
  3753. infection := &sz.TempHdInfection{
  3754. Sn: strconv.FormatInt(patient.ID, 10),
  3755. HospitalId: org.HospitalId,
  3756. PatientNk: strconv.FormatInt(patient.ID, 10),
  3757. Hbv: 9,
  3758. Hcv: 9,
  3759. Rpr: 9,
  3760. Hiv: 9,
  3761. Hbsag: 9,
  3762. Hbsab: 9,
  3763. Hbeag: 9,
  3764. Hbeab: 9,
  3765. Hbcab: 9,
  3766. CheckDate: time.Unix(insp.InspectDate, 0),
  3767. DoctorId: "2232",
  3768. CreateTime: time.Now(),
  3769. Sjscsj: time.Now(),
  3770. Xgbz: 0,
  3771. }
  3772. for _, infectionDiseases := range inspection_arr {
  3773. infection.Sn = strconv.FormatInt(infectionDiseases.ID, 10)
  3774. infection.CheckDate = time.Unix(infectionDiseases.InspectDate, 0)
  3775. // 乙肝
  3776. if infectionDiseases.ItemId == 101380001 || infectionDiseases.ItemId == 101387010 {
  3777. infection.Hbv = 0
  3778. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3779. infection.Hbv = 1
  3780. }
  3781. }
  3782. // 丙肝
  3783. if infectionDiseases.ItemId == 101380006 || infectionDiseases.ItemId == 101387004 {
  3784. infection.Hcv = 0
  3785. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3786. infection.Hcv = 1
  3787. }
  3788. }
  3789. // 梅毒
  3790. if infectionDiseases.ItemId == 101380009 || infectionDiseases.ItemId == 101387001 {
  3791. infection.Rpr = 0
  3792. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3793. infection.Rpr = 1
  3794. }
  3795. }
  3796. // 艾滋病
  3797. if infectionDiseases.ItemId == 101380010 || infectionDiseases.ItemId == 101387005 {
  3798. infection.Rpr = 0
  3799. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3800. infection.Rpr = 1
  3801. }
  3802. }
  3803. // HBsAg 乙型肝炎表面抗原;
  3804. if infectionDiseases.ItemId == 101380001 || infectionDiseases.ItemId == 101387010 {
  3805. infection.Hbsag = 0
  3806. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3807. infection.Hbsag = 1
  3808. }
  3809. }
  3810. // HBsAb 乙型肝炎表面抗体;
  3811. if infectionDiseases.ItemId == 101380002 || infectionDiseases.ItemId == 101387009 {
  3812. infection.Hbsab = 0
  3813. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3814. infection.Hbsab = 1
  3815. }
  3816. }
  3817. // HBeAg 乙肝病毒e抗原;
  3818. if infectionDiseases.ItemId == 101380003 || infectionDiseases.ItemId == 101387008 {
  3819. infection.Hbeag = 0
  3820. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3821. infection.Hbeag = 1
  3822. }
  3823. }
  3824. // HBeAb 乙型肝炎E抗体;
  3825. if infectionDiseases.ItemId == 101380004 || infectionDiseases.ItemId == 101387007 {
  3826. infection.Hbeab = 0
  3827. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3828. infection.Hbeab = 1
  3829. }
  3830. }
  3831. // HBcAb 乙肝核心抗体;
  3832. if infectionDiseases.ItemId == 101380005 || infectionDiseases.ItemId == 101387006 {
  3833. infection.Hbcab = 0
  3834. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3835. infection.Hbcab = 1
  3836. }
  3837. }
  3838. }
  3839. infectionList = append(infectionList, infection)
  3840. }
  3841. }
  3842. }
  3843. }
  3844. if org_id == 10278 {
  3845. // 深圳百霖贝尔
  3846. inspections, _ := service.FindOrgInspectionGroupSzblbr(org_id, sync_time, time.Now().Unix(), patient.ID)
  3847. if len(inspections) > 0 {
  3848. for _, insp := range inspections {
  3849. inspection_arr, _ := service.FindOrgInspectionGroupSzblbrTwo(org_id, insp.InspectDate, patient.ID)
  3850. if len(inspection_arr) > 0 {
  3851. infection := &sz.TempHdInfection{
  3852. Sn: strconv.FormatInt(patient.ID, 10),
  3853. HospitalId: hospital_id,
  3854. PatientNk: strconv.FormatInt(patient.ID, 10),
  3855. Hbv: 9,
  3856. Hcv: 9,
  3857. Rpr: 9,
  3858. Hiv: 9,
  3859. Hbsag: 9,
  3860. Hbsab: 9,
  3861. Hbeag: 9,
  3862. Hbeab: 9,
  3863. Hbcab: 9,
  3864. CheckDate: time.Unix(insp.InspectDate, 0),
  3865. DoctorId: "751",
  3866. CreateTime: time.Now(),
  3867. Sjscsj: time.Now(),
  3868. Xgbz: 0,
  3869. }
  3870. for _, infectionDiseases := range inspection_arr {
  3871. infection.Sn = strconv.FormatInt(infectionDiseases.ID, 10)
  3872. infection.CheckDate = time.Unix(infectionDiseases.InspectDate, 0)
  3873. // 乙肝
  3874. if infectionDiseases.ItemId == 101380302 || infectionDiseases.ItemId == 101385607 {
  3875. infection.Hbv = 0
  3876. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3877. infection.Hbv = 1
  3878. }
  3879. }
  3880. // 丙肝
  3881. if infectionDiseases.ItemId == 101380307 || infectionDiseases.ItemId == 101385609 {
  3882. infection.Hcv = 0
  3883. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3884. infection.Hcv = 1
  3885. }
  3886. }
  3887. // 梅毒
  3888. if infectionDiseases.ItemId == 101380009 || infectionDiseases.ItemId == 101385601 {
  3889. infection.Rpr = 0
  3890. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3891. infection.Rpr = 1
  3892. }
  3893. }
  3894. // 艾滋病
  3895. if infectionDiseases.ItemId == 101380301 || infectionDiseases.ItemId == 101380301 {
  3896. infection.Rpr = 0
  3897. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3898. infection.Rpr = 1
  3899. }
  3900. }
  3901. // HBsAg 乙型肝炎表面抗原;
  3902. if infectionDiseases.ItemId == 101380302 || infectionDiseases.ItemId == 101385607 {
  3903. infection.Hbsag = 0
  3904. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3905. infection.Hbsag = 1
  3906. }
  3907. }
  3908. // HBsAb 乙型肝炎表面抗体;
  3909. if infectionDiseases.ItemId == 101380303 || infectionDiseases.ItemId == 101385606 {
  3910. infection.Hbsab = 0
  3911. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3912. infection.Hbsab = 1
  3913. }
  3914. }
  3915. // HBeAg 乙肝病毒e抗原;
  3916. if infectionDiseases.ItemId == 101380304 || infectionDiseases.ItemId == 101385605 {
  3917. infection.Hbeag = 0
  3918. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3919. infection.Hbeag = 1
  3920. }
  3921. }
  3922. // HBeAb 乙型肝炎E抗体;
  3923. if infectionDiseases.ItemId == 101380305 || infectionDiseases.ItemId == 101385604 {
  3924. infection.Hbeab = 0
  3925. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3926. infection.Hbeab = 1
  3927. }
  3928. }
  3929. // HBcAb 乙肝核心抗体;
  3930. if infectionDiseases.ItemId == 101380306 || infectionDiseases.ItemId == 101385603 {
  3931. infection.Hbcab = 0
  3932. if strings.Contains(infectionDiseases.InspectValue, "阳性") {
  3933. infection.Hbcab = 1
  3934. }
  3935. }
  3936. }
  3937. infectionList = append(infectionList, infection)
  3938. }
  3939. }
  3940. }
  3941. }
  3942. if org_id == 9504 {
  3943. inspections, _ := service.FindOrgInspectionGroupLgey(org_id, sync_time, time.Now().Unix(), patient.ID)
  3944. if len(inspections) > 0 {
  3945. for _, insp := range inspections {
  3946. inspection_arr, _ := service.FindOrgInspectionGroupTwo(org_id, insp.InspectDate, patient.ID)
  3947. if len(inspection_arr) > 0 {
  3948. infection := &sz.TempHdInfection{
  3949. Sn: strconv.FormatInt(patient.ID, 10),
  3950. HospitalId: hospital_id,
  3951. PatientNk: strconv.FormatInt(patient.ID, 10),
  3952. Hbv: 9,
  3953. Hcv: 9,
  3954. Rpr: 9,
  3955. Hiv: 9,
  3956. Hbsag: 9,
  3957. Hbsab: 9,
  3958. Hbeag: 9,
  3959. Hbeab: 9,
  3960. Hbcab: 9,
  3961. CheckDate: time.Unix(patient.CreatedTime, 0),
  3962. DoctorId: strconv.FormatInt(patient.RegistrarsId, 10),
  3963. CreateTime: time.Now(),
  3964. Sjscsj: time.Now(),
  3965. Xgbz: 0,
  3966. }
  3967. for _, infectionDiseases := range inspection_arr {
  3968. infection.Sn = strconv.FormatInt(infectionDiseases.ID, 10)
  3969. if infectionDiseases.ItemId == 60 {
  3970. infection.Hcv = 0
  3971. if infectionDiseases.InspectValue == "阳性" {
  3972. infection.Hcv = 1
  3973. }
  3974. }
  3975. if infectionDiseases.ItemId == 62 {
  3976. infection.Hbsag = 0
  3977. if infectionDiseases.InspectValue == "阳性" {
  3978. infection.Hbsag = 1
  3979. }
  3980. }
  3981. if infectionDiseases.ItemId == 63 {
  3982. infection.Hbsab = 0
  3983. if infectionDiseases.InspectValue == "阳性" {
  3984. infection.Hbsab = 1
  3985. }
  3986. }
  3987. if infectionDiseases.ItemId == 64 {
  3988. infection.Hbeag = 0
  3989. if infectionDiseases.InspectValue == "阳性" {
  3990. infection.Hbeag = 1
  3991. }
  3992. }
  3993. if infectionDiseases.ItemId == 65 {
  3994. infection.Hbeab = 0
  3995. if infectionDiseases.InspectValue == "阳性" {
  3996. infection.Hbeab = 1
  3997. }
  3998. }
  3999. if infectionDiseases.ItemId == 66 {
  4000. infection.Hbcab = 0
  4001. if infectionDiseases.InspectValue == "阳性" {
  4002. infection.Hbcab = 1
  4003. }
  4004. }
  4005. if infectionDiseases.ItemId == 111 {
  4006. infection.Hiv = 0
  4007. if infectionDiseases.InspectValue == "阳性" {
  4008. infection.Hiv = 1
  4009. }
  4010. }
  4011. if infectionDiseases.ItemId == 112 {
  4012. infection.Rpr = 0
  4013. if infectionDiseases.InspectValue == "阳性" {
  4014. infection.Rpr = 1
  4015. }
  4016. }
  4017. if infectionDiseases.ItemId == 178 {
  4018. infection.Hbv = 0
  4019. if infectionDiseases.InspectValue == "阳性" {
  4020. infection.Hbv = 1
  4021. }
  4022. }
  4023. if infectionDiseases.ItemId == 179 {
  4024. infection.Hcv = 0
  4025. if infectionDiseases.InspectValue == "阳性" {
  4026. infection.Hcv = 1
  4027. }
  4028. }
  4029. }
  4030. infectionList = append(infectionList, infection)
  4031. }
  4032. }
  4033. }
  4034. }
  4035. if org_id == 10580 {
  4036. inspections, _ := service.FindOrgInspectionGroupOne(org_id, sync_time, time.Now().Unix(), patient.ID)
  4037. if len(inspections) > 0 {
  4038. for _, insp := range inspections {
  4039. inspection_arr, _ := service.FindOrgInspectionGroupTwo(org_id, insp.InspectDate, patient.ID)
  4040. if len(inspection_arr) > 0 {
  4041. infection := &sz.TempHdInfection{
  4042. Sn: strconv.FormatInt(patient.ID, 10),
  4043. HospitalId: hospital_id,
  4044. PatientNk: strconv.FormatInt(patient.ID, 10),
  4045. Hbv: 9,
  4046. Hcv: 9,
  4047. Rpr: 9,
  4048. Hiv: 9,
  4049. Hbsag: 9,
  4050. Hbsab: 9,
  4051. Hbeag: 9,
  4052. Hbeab: 9,
  4053. Hbcab: 9,
  4054. CheckDate: time.Unix(patient.CreatedTime, 0),
  4055. DoctorId: strconv.FormatInt(patient.RegistrarsId, 10),
  4056. CreateTime: time.Now(),
  4057. Sjscsj: time.Now(),
  4058. Xgbz: 0,
  4059. }
  4060. for _, infectionDiseases := range inspection_arr {
  4061. infection.Sn = strconv.FormatInt(infectionDiseases.ID, 10)
  4062. if infectionDiseases.ItemId == 60 {
  4063. infection.Hcv = 0
  4064. if infectionDiseases.InspectValue == "阳性" {
  4065. infection.Hcv = 1
  4066. }
  4067. }
  4068. if infectionDiseases.ItemId == 62 {
  4069. infection.Hbsag = 0
  4070. if infectionDiseases.InspectValue == "阳性" {
  4071. infection.Hbsag = 1
  4072. }
  4073. }
  4074. if infectionDiseases.ItemId == 63 {
  4075. infection.Hbsab = 0
  4076. if infectionDiseases.InspectValue == "阳性" {
  4077. infection.Hbsab = 1
  4078. }
  4079. }
  4080. if infectionDiseases.ItemId == 64 {
  4081. infection.Hbeag = 0
  4082. if infectionDiseases.InspectValue == "阳性" {
  4083. infection.Hbeag = 1
  4084. }
  4085. }
  4086. if infectionDiseases.ItemId == 65 {
  4087. infection.Hbeab = 0
  4088. if infectionDiseases.InspectValue == "阳性" {
  4089. infection.Hbeab = 1
  4090. }
  4091. }
  4092. if infectionDiseases.ItemId == 66 {
  4093. infection.Hbcab = 0
  4094. if infectionDiseases.InspectValue == "阳性" {
  4095. infection.Hbcab = 1
  4096. }
  4097. }
  4098. if infectionDiseases.ItemId == 111 {
  4099. infection.Hiv = 0
  4100. if infectionDiseases.InspectValue == "阳性" {
  4101. infection.Hiv = 1
  4102. }
  4103. }
  4104. if infectionDiseases.ItemId == 112 {
  4105. infection.Rpr = 0
  4106. if infectionDiseases.InspectValue == "阳性" {
  4107. infection.Rpr = 1
  4108. }
  4109. }
  4110. if infectionDiseases.ItemId == 178 {
  4111. infection.Hbv = 0
  4112. if infectionDiseases.InspectValue == "阳性" {
  4113. infection.Hbv = 1
  4114. }
  4115. }
  4116. if infectionDiseases.ItemId == 179 {
  4117. infection.Hcv = 0
  4118. if infectionDiseases.InspectValue == "阳性" {
  4119. infection.Hcv = 1
  4120. }
  4121. }
  4122. }
  4123. infectionList = append(infectionList, infection)
  4124. }
  4125. }
  4126. }
  4127. }
  4128. }
  4129. if len(infectionList) > 0 {
  4130. err := service.CreateInfection(infectionList, orgDb)
  4131. if err == nil {
  4132. // 第三步:同步成功后,添加同步记录
  4133. upload := &sz.DataUpload{
  4134. SyncType: 59,
  4135. OrgId: org_id,
  4136. SyncTime: time.Now().Unix(),
  4137. SyncResultType: 1,
  4138. CreateTime: time.Now().Unix(),
  4139. UpdateTime: time.Now().Unix(),
  4140. }
  4141. err := service.CreateUploadRecord(upload)
  4142. if err != nil {
  4143. utils.ErrorLog("%v", err)
  4144. }
  4145. } else {
  4146. //错误处理
  4147. }
  4148. }
  4149. service.CloseDB(orgDb)
  4150. }
  4151. return
  4152. }
  4153. // 透析并发症记录表(T_HD_COMPLICATION)
  4154. func SyncComplication(rdb *gorm.DB, org_id int64, hospital_id string) {
  4155. // 第一步:根据机构id获取上次同步时间
  4156. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 60)
  4157. var sync_time int64
  4158. if syncLastInfo.ID > 0 {
  4159. sync_time = syncLastInfo.SyncTime
  4160. } else {
  4161. sync_time = 1662134400
  4162. }
  4163. //同步监测记录
  4164. var complicationList []*sz.TempHdComplication
  4165. monitors, _ := service.FindOrgMonitorRecordByLike(org_id, "%肌肉痉挛%", sync_time, time.Now().Unix())
  4166. for _, monitor := range monitors {
  4167. complication := &sz.TempHdComplication{
  4168. Sn: strconv.FormatInt(monitor.ID, 10),
  4169. HospitalId: hospital_id,
  4170. PatientNk: strconv.FormatInt(monitor.PatientId, 10),
  4171. DialysisId: monitor.DialysisOrderId,
  4172. MonitorId: monitor.ID,
  4173. NeopathyTime: 1,
  4174. NeopathyType: "3",
  4175. NeopathyDesc: monitor.Symptom,
  4176. CreateTime: time.Unix(monitor.CreatedTime, 0),
  4177. Sjscsj: time.Now(),
  4178. Xgbz: 0,
  4179. }
  4180. complicationList = append(complicationList, complication)
  4181. }
  4182. monitorones, _ := service.FindOrgMonitorRecordByLike(org_id, "%胸痛%", sync_time, time.Now().Unix())
  4183. for _, monitor := range monitorones {
  4184. complicationone := &sz.TempHdComplication{
  4185. Sn: strconv.FormatInt(monitor.ID, 10),
  4186. HospitalId: hospital_id,
  4187. PatientNk: strconv.FormatInt(monitor.PatientId, 10),
  4188. DialysisId: monitor.DialysisOrderId,
  4189. MonitorId: monitor.ID,
  4190. NeopathyTime: 1,
  4191. NeopathyType: "6",
  4192. NeopathyDesc: monitor.Symptom,
  4193. CreateTime: time.Unix(monitor.CreatedTime, 0),
  4194. Sjscsj: time.Now(),
  4195. Xgbz: 0,
  4196. }
  4197. complicationList = append(complicationList, complicationone)
  4198. }
  4199. monitortwos, _ := service.FindOrgMonitorRecordByLike(org_id, "%恶心%", sync_time, time.Now().Unix())
  4200. for _, monitor := range monitortwos {
  4201. complicationtwo := &sz.TempHdComplication{
  4202. Sn: strconv.FormatInt(monitor.ID, 10),
  4203. HospitalId: hospital_id,
  4204. PatientNk: strconv.FormatInt(monitor.PatientId, 10),
  4205. DialysisId: monitor.DialysisOrderId,
  4206. MonitorId: monitor.ID,
  4207. NeopathyTime: 1,
  4208. NeopathyType: "7",
  4209. NeopathyDesc: monitor.Symptom,
  4210. CreateTime: time.Unix(monitor.CreatedTime, 0),
  4211. Sjscsj: time.Now(),
  4212. Xgbz: 0,
  4213. }
  4214. complicationList = append(complicationList, complicationtwo)
  4215. }
  4216. monitorfours, _ := service.FindOrgMonitorRecordByLike(org_id, "%头痛%", sync_time, time.Now().Unix())
  4217. for _, monitor := range monitorfours {
  4218. complicationfour := &sz.TempHdComplication{
  4219. Sn: strconv.FormatInt(monitor.ID, 10),
  4220. HospitalId: hospital_id,
  4221. PatientNk: strconv.FormatInt(monitor.PatientId, 10),
  4222. DialysisId: monitor.DialysisOrderId,
  4223. MonitorId: monitor.ID,
  4224. NeopathyTime: 1,
  4225. NeopathyType: "11",
  4226. NeopathyDesc: monitor.Symptom,
  4227. CreateTime: time.Unix(monitor.CreatedTime, 0),
  4228. Sjscsj: time.Now(),
  4229. Xgbz: 0,
  4230. }
  4231. complicationList = append(complicationList, complicationfour)
  4232. }
  4233. monitorthrees, _ := service.FindOrgMonitorRecordByLike(org_id, "%发热%", sync_time, time.Now().Unix())
  4234. for _, monitor := range monitorthrees {
  4235. complicationthree := &sz.TempHdComplication{
  4236. Sn: strconv.FormatInt(monitor.ID, 10),
  4237. HospitalId: hospital_id,
  4238. PatientNk: strconv.FormatInt(monitor.PatientId, 10),
  4239. DialysisId: monitor.DialysisOrderId,
  4240. MonitorId: monitor.ID,
  4241. NeopathyTime: 1,
  4242. NeopathyType: "15",
  4243. NeopathyDesc: monitor.Symptom,
  4244. CreateTime: time.Unix(monitor.CreatedTime, 0),
  4245. Sjscsj: time.Now(),
  4246. Xgbz: 0,
  4247. }
  4248. complicationList = append(complicationList, complicationthree)
  4249. }
  4250. if len(complicationList) > 0 {
  4251. err := service.CreateComplication(complicationList, rdb)
  4252. if err == nil {
  4253. // 第三步:同步成功后,添加同步记录
  4254. upload := &sz.DataUpload{
  4255. SyncType: 60,
  4256. OrgId: org_id,
  4257. SyncTime: time.Now().Unix(),
  4258. SyncResultType: 1,
  4259. CreateTime: time.Now().Unix(),
  4260. UpdateTime: time.Now().Unix(),
  4261. }
  4262. err := service.CreateUploadRecord(upload)
  4263. if err != nil {
  4264. utils.ErrorLog("%v", err)
  4265. }
  4266. } else {
  4267. //错误处理
  4268. }
  4269. }
  4270. }
  4271. func SyncLisReportBc(rdb *gorm.DB, org_id int64, hospital_id string) {
  4272. var sync_time int64
  4273. sync_time = 1704038400
  4274. inspections, _ := service.FindOrgInspection(org_id, sync_time, time.Now().Unix())
  4275. var lisReportList []*sz.TempHdLisReport
  4276. tempFlag := 0
  4277. for _, inspection := range inspections {
  4278. tempFlag = 0
  4279. LabSno := strconv.FormatInt(inspection.InspectDate, 10) + strconv.FormatInt(inspection.ProjectId, 10) + strconv.FormatInt(inspection.PatientId, 10)
  4280. // 判断该检查是否已经同步过
  4281. hdLisReportInfo, _ := service.FindLisReportByLAB(rdb, LabSno)
  4282. if len(hdLisReportInfo) > 0 {
  4283. tempFlag = 0
  4284. } else {
  4285. tempFlag = 1
  4286. }
  4287. if tempFlag == 1 {
  4288. lisReport := &sz.TempHdLisReport{
  4289. LabSno: strconv.FormatInt(inspection.InspectDate, 10) + strconv.FormatInt(inspection.ProjectId, 10) + strconv.FormatInt(inspection.PatientId, 10),
  4290. HospitalId: hospital_id,
  4291. PatientNk: strconv.FormatInt(inspection.PatientId, 10),
  4292. ReportDate: time.Unix(inspection.InspectDate, 0),
  4293. CheckDate: "1",
  4294. JzNo: inspection.Patients.AdmissionNumber,
  4295. MzFlag: "1",
  4296. ZyNo: "-",
  4297. MzNo: inspection.Patients.AdmissionNumber,
  4298. DepartmentCode: "1001",
  4299. DepartmentName: "血透中心",
  4300. CardNo: inspection.Patients.IdCardNo,
  4301. CardType: "9",
  4302. PatientName: inspection.Patients.Name,
  4303. DepCode: "A03.05",
  4304. DepName: "血透中心",
  4305. InspectedType: "1",
  4306. ReportCategry: inspection.ProjectName,
  4307. ApplicationName: inspection.ProjectName,
  4308. ApplicationType: strconv.FormatInt(inspection.ProjectId, 10),
  4309. CheckName: inspection.ProjectName,
  4310. CheckItemName: inspection.ProjectName,
  4311. CheckItemCode: strconv.FormatInt(inspection.ProjectId, 10),
  4312. RecordCcount: 0,
  4313. CheckResult: "完成",
  4314. DiagnoseName: "-",
  4315. CreateTime: time.Unix(inspection.CreatedTime, 0),
  4316. Sjscsj: time.Now(),
  4317. Xgbz: 0,
  4318. }
  4319. lisReportList = append(lisReportList, lisReport)
  4320. } else {
  4321. continue
  4322. }
  4323. }
  4324. if len(lisReportList) > 0 {
  4325. err := service.CreateLisReport(lisReportList, rdb)
  4326. if err == nil {
  4327. // 第三步:同步成功后,添加同步记录
  4328. upload := &sz.DataUpload{
  4329. SyncType: 61,
  4330. OrgId: org_id,
  4331. SyncTime: time.Now().Unix(),
  4332. SyncResultType: 1,
  4333. CreateTime: time.Now().Unix(),
  4334. UpdateTime: time.Now().Unix(),
  4335. }
  4336. err := service.CreateUploadRecord(upload)
  4337. if err != nil {
  4338. utils.ErrorLog("%v", err)
  4339. }
  4340. } else {
  4341. //错误处理
  4342. }
  4343. }
  4344. }
  4345. // 血透患者检测结果表(T_HD_LIS_REPORT)
  4346. func SyncLisReport(rdb *gorm.DB, org_id int64, hospital_id string) {
  4347. // 第一步:根据机构id获取上次同步时间
  4348. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 61)
  4349. var sync_time int64
  4350. if syncLastInfo.ID > 0 {
  4351. sync_time = syncLastInfo.SyncTime
  4352. } else {
  4353. sync_time = 1672502400
  4354. }
  4355. //同步监测记录
  4356. inspections, _ := service.FindOrgInspection(org_id, sync_time, time.Now().Unix())
  4357. var lisReportList []*sz.TempHdLisReport
  4358. tempFlag := 1
  4359. for _, inspection := range inspections {
  4360. tempFlag = 1
  4361. // for _, tempReport := range lisReportList {
  4362. // // fmt.Println("2")
  4363. // if tempReport.ReportDate == time.Unix(inspection.InspectDate, 0) && tempReport.ApplicationType == strconv.FormatInt(inspection.ProjectId, 10) && tempReport.PatientNk == strconv.FormatInt(inspection.PatientId, 10) {
  4364. // tempFlag = 0
  4365. // break
  4366. // } else {
  4367. // continue
  4368. // }
  4369. // }
  4370. if tempFlag == 1 {
  4371. lisReport := &sz.TempHdLisReport{
  4372. LabSno: strconv.FormatInt(inspection.InspectDate, 10) + strconv.FormatInt(inspection.ProjectId, 10) + strconv.FormatInt(inspection.PatientId, 10),
  4373. HospitalId: hospital_id,
  4374. PatientNk: strconv.FormatInt(inspection.PatientId, 10),
  4375. ReportDate: time.Unix(inspection.InspectDate, 0),
  4376. CheckDate: "1",
  4377. JzNo: inspection.Patients.AdmissionNumber,
  4378. MzFlag: "1",
  4379. ZyNo: "-",
  4380. MzNo: inspection.Patients.AdmissionNumber,
  4381. DepartmentCode: "1001",
  4382. DepartmentName: "血透中心",
  4383. CardNo: inspection.Patients.IdCardNo,
  4384. CardType: "9",
  4385. PatientName: inspection.Patients.Name,
  4386. DepCode: "A03.05",
  4387. DepName: "血透中心",
  4388. InspectedType: "1",
  4389. ReportCategry: inspection.ProjectName,
  4390. ApplicationName: inspection.ProjectName,
  4391. ApplicationType: strconv.FormatInt(inspection.ProjectId, 10),
  4392. CheckName: inspection.ProjectName,
  4393. CheckItemName: inspection.ProjectName,
  4394. CheckItemCode: strconv.FormatInt(inspection.ProjectId, 10),
  4395. RecordCcount: 0,
  4396. CheckResult: "完成",
  4397. DiagnoseName: "-",
  4398. CreateTime: time.Unix(inspection.CreatedTime, 0),
  4399. Sjscsj: time.Now(),
  4400. Xgbz: 0,
  4401. }
  4402. lisReportList = append(lisReportList, lisReport)
  4403. } else {
  4404. continue
  4405. }
  4406. }
  4407. if len(lisReportList) > 0 {
  4408. err := service.CreateLisReport(lisReportList, rdb)
  4409. if err == nil {
  4410. // 第三步:同步成功后,添加同步记录
  4411. upload := &sz.DataUpload{
  4412. SyncType: 61,
  4413. OrgId: org_id,
  4414. SyncTime: time.Now().Unix(),
  4415. SyncResultType: 1,
  4416. CreateTime: time.Now().Unix(),
  4417. UpdateTime: time.Now().Unix(),
  4418. }
  4419. err := service.CreateUploadRecord(upload)
  4420. if err != nil {
  4421. utils.ErrorLog("%v", err)
  4422. }
  4423. } else {
  4424. //错误处理
  4425. }
  4426. }
  4427. }
  4428. func SyncLisIndicatorsBcUpdate(rdb *gorm.DB, org_id int64, hospital_id string) {
  4429. var sync_time int64
  4430. sync_time = 1704038400
  4431. //同步监测记录
  4432. inspections, _ := service.FindOrgInspectionThree(org_id, sync_time, time.Now().Unix(), "101380701")
  4433. for _, inspection := range inspections {
  4434. LabSno := strconv.FormatInt(inspection.InspectDate, 10) + strconv.FormatInt(inspection.ProjectId, 10) + strconv.FormatInt(inspection.PatientId, 10)
  4435. // 判断该检查是否已经同步过
  4436. service.FindLisINDICATORSByNoUpdate(rdb, LabSno, strconv.FormatInt(inspection.ID, 10), inspection.InspectValue, inspection.XtInspectionReference.Unit, time.Now())
  4437. //if len(hdLisReportInfo.InspectedResultNo) > 0 {
  4438. // utils.InfoLog("1111111%v:", hdLisReportInfo)
  4439. // if len(hdLisReportInfo.InspectedResultNo) > 0 {
  4440. // hdLisReportInfo.InspectedResultDesc = inspection.InspectValue
  4441. // hdLisReportInfo.InspectedResultValue = inspection.InspectValue
  4442. // hdLisReportInfo.InspectedResultUnit = inspection.XtInspectionReference.Unit
  4443. // hdLisReportInfo.UnitType = inspection.XtInspectionReference.Unit
  4444. // hdLisReportInfo.CreateTime = time.Now()
  4445. //
  4446. // rdb.Save(&hdLisReportInfo)
  4447. // }
  4448. //}
  4449. }
  4450. }
  4451. func SyncLisIndicatorsBc(rdb *gorm.DB, org_id int64, hospital_id string) {
  4452. var sync_time int64
  4453. sync_time = 1704038400
  4454. //同步监测记录
  4455. inspections, _ := service.FindOrgInspectionTwo(org_id, sync_time, time.Now().Unix())
  4456. var lisIndicatorsList []*sz.TempHdLisIndicators
  4457. tempFlag := 0
  4458. for _, inspection := range inspections {
  4459. tempFlag = 0
  4460. LabSno := strconv.FormatInt(inspection.InspectDate, 10) + strconv.FormatInt(inspection.ProjectId, 10) + strconv.FormatInt(inspection.PatientId, 10)
  4461. // 判断该检查是否已经同步过
  4462. hdLisReportInfo, _ := service.FindLisINDICATORSByNo(rdb, LabSno, strconv.FormatInt(inspection.ID, 10))
  4463. if len(hdLisReportInfo) > 0 {
  4464. tempFlag = 0
  4465. } else {
  4466. tempFlag = 1
  4467. }
  4468. if tempFlag == 1 {
  4469. lisIndicators := &sz.TempHdLisIndicators{
  4470. InspectedResultNo: strconv.FormatInt(inspection.ID, 10),
  4471. HospitalId: hospital_id,
  4472. LabSno: strconv.FormatInt(inspection.InspectDate, 10) + strconv.FormatInt(inspection.ProjectId, 10) + strconv.FormatInt(inspection.PatientId, 10),
  4473. ReportDate: time.Unix(inspection.InspectDate, 0),
  4474. CheckDate: time.Unix(inspection.InspectDate, 0),
  4475. InspectedIndicate: inspection.ProjectName,
  4476. InspectedItemEnName: strconv.FormatInt(inspection.ItemId, 10),
  4477. InspectedItemCnName: inspection.ItemName,
  4478. InspectedResultDesc: inspection.InspectValue,
  4479. InspectedResultValue: inspection.InspectValue,
  4480. InspectedResultUnit: inspection.XtInspectionReference.Unit,
  4481. RefRange: "-",
  4482. UnitType: inspection.XtInspectionReference.Unit,
  4483. InspectedResult: 5,
  4484. CreateTime: time.Unix(inspection.CreatedTime, 0),
  4485. Sjscsj: time.Now(),
  4486. Xgbz: 0,
  4487. }
  4488. if len(inspection.XtInspectionReference.Unit) == 0 {
  4489. lisIndicators.InspectedResultUnit = "-"
  4490. lisIndicators.UnitType = "-"
  4491. }
  4492. temp1, _ := strconv.ParseFloat(inspection.InspectValue, 32)
  4493. if inspection.ItemId == 101380701 && inspection.OrgId == 10138 {
  4494. lisIndicators.InspectedResultValue = strconv.FormatFloat(temp1*9.43, 'f', 1, 32)
  4495. lisIndicators.InspectedResultDesc = strconv.FormatFloat(temp1*9.43, 'f', 1, 32)
  4496. lisIndicators.InspectedResultUnit = "pg/mL"
  4497. }
  4498. if inspection.ItemId == 101380601 && inspection.OrgId == 10278 {
  4499. lisIndicators.InspectedResultValue = strconv.FormatFloat(temp1*9.43, 'f', 1, 32)
  4500. lisIndicators.InspectedResultDesc = strconv.FormatFloat(temp1*9.43, 'f', 1, 32)
  4501. lisIndicators.InspectedResultUnit = "pg/mL"
  4502. }
  4503. if inspection.XtInspectionReference.RangeType == 1 {
  4504. lisIndicators.RefRange = inspection.XtInspectionReference.RangeMin + "-" + inspection.XtInspectionReference.RangeMax
  4505. } else {
  4506. if len(inspection.XtInspectionReference.RangeOptions) == 0 {
  4507. lisIndicators.RefRange = "-"
  4508. } else {
  4509. lisIndicators.RefRange = inspection.XtInspectionReference.RangeOptions
  4510. }
  4511. }
  4512. lisIndicatorsList = append(lisIndicatorsList, lisIndicators)
  4513. }
  4514. }
  4515. if len(lisIndicatorsList) > 0 {
  4516. err := service.CreateLisIndicators(lisIndicatorsList, rdb)
  4517. if err == nil {
  4518. // 第三步:同步成功后,添加同步记录
  4519. upload := &sz.DataUpload{
  4520. SyncType: 62,
  4521. OrgId: org_id,
  4522. SyncTime: time.Now().Unix(),
  4523. SyncResultType: 1,
  4524. CreateTime: time.Now().Unix(),
  4525. UpdateTime: time.Now().Unix(),
  4526. }
  4527. err := service.CreateUploadRecord(upload)
  4528. if err != nil {
  4529. utils.ErrorLog("%v", err)
  4530. }
  4531. } else {
  4532. //错误处理
  4533. }
  4534. }
  4535. }
  4536. // 血透患者检验结果指标表(T_HD_LIS_INDICATORS)
  4537. func SyncLisIndicators(rdb *gorm.DB, org_id int64, hospital_id string) {
  4538. // 第一步:根据机构id获取上次同步时间
  4539. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 62)
  4540. var sync_time int64
  4541. if syncLastInfo.ID > 0 {
  4542. sync_time = syncLastInfo.SyncTime
  4543. } else {
  4544. sync_time = 1672502400
  4545. }
  4546. //同步监测记录
  4547. inspections, _ := service.FindOrgInspectionTwo(org_id, sync_time, time.Now().Unix())
  4548. var lisIndicatorsList []*sz.TempHdLisIndicators
  4549. for _, inspection := range inspections {
  4550. lisIndicators := &sz.TempHdLisIndicators{
  4551. InspectedResultNo: strconv.FormatInt(inspection.ID, 10),
  4552. HospitalId: hospital_id,
  4553. LabSno: strconv.FormatInt(inspection.InspectDate, 10) + strconv.FormatInt(inspection.ProjectId, 10) + strconv.FormatInt(inspection.PatientId, 10),
  4554. ReportDate: time.Unix(inspection.InspectDate, 0),
  4555. CheckDate: time.Unix(inspection.InspectDate, 0),
  4556. InspectedIndicate: inspection.ProjectName,
  4557. InspectedItemEnName: strconv.FormatInt(inspection.ItemId, 10),
  4558. InspectedItemCnName: inspection.ItemName,
  4559. InspectedResultDesc: inspection.InspectValue,
  4560. InspectedResultValue: inspection.InspectValue,
  4561. InspectedResultUnit: inspection.XtInspectionReference.Unit,
  4562. RefRange: "-",
  4563. UnitType: inspection.XtInspectionReference.Unit,
  4564. InspectedResult: 5,
  4565. CreateTime: time.Unix(inspection.CreatedTime, 0),
  4566. Sjscsj: time.Now(),
  4567. Xgbz: 0,
  4568. }
  4569. if len(inspection.XtInspectionReference.Unit) == 0 {
  4570. lisIndicators.InspectedResultUnit = "-"
  4571. lisIndicators.UnitType = "-"
  4572. }
  4573. temp1, _ := strconv.ParseFloat(inspection.InspectValue, 32)
  4574. if inspection.ItemId == 101380701 && inspection.OrgId == 10138 {
  4575. lisIndicators.InspectedResultValue = strconv.FormatFloat(temp1*9.43, 'f', 1, 32)
  4576. lisIndicators.InspectedResultDesc = strconv.FormatFloat(temp1*9.43, 'f', 1, 32)
  4577. lisIndicators.InspectedResultUnit = "pg/mL"
  4578. }
  4579. if inspection.ItemId == 101380601 && inspection.OrgId == 10278 {
  4580. lisIndicators.InspectedResultValue = strconv.FormatFloat(temp1*9.43, 'f', 1, 32)
  4581. lisIndicators.InspectedResultDesc = strconv.FormatFloat(temp1*9.43, 'f', 1, 32)
  4582. lisIndicators.InspectedResultUnit = "pg/mL"
  4583. }
  4584. if inspection.XtInspectionReference.RangeType == 1 {
  4585. lisIndicators.RefRange = inspection.XtInspectionReference.RangeMin + "-" + inspection.XtInspectionReference.RangeMax
  4586. } else {
  4587. if len(inspection.XtInspectionReference.RangeOptions) == 0 {
  4588. lisIndicators.RefRange = "-"
  4589. } else {
  4590. lisIndicators.RefRange = inspection.XtInspectionReference.RangeOptions
  4591. }
  4592. }
  4593. lisIndicatorsList = append(lisIndicatorsList, lisIndicators)
  4594. }
  4595. if len(lisIndicatorsList) > 0 {
  4596. err := service.CreateLisIndicators(lisIndicatorsList, rdb)
  4597. if err == nil {
  4598. // 第三步:同步成功后,添加同步记录
  4599. upload := &sz.DataUpload{
  4600. SyncType: 62,
  4601. OrgId: org_id,
  4602. SyncTime: time.Now().Unix(),
  4603. SyncResultType: 1,
  4604. CreateTime: time.Now().Unix(),
  4605. UpdateTime: time.Now().Unix(),
  4606. }
  4607. err := service.CreateUploadRecord(upload)
  4608. if err != nil {
  4609. utils.ErrorLog("%v", err)
  4610. }
  4611. } else {
  4612. //错误处理
  4613. }
  4614. }
  4615. }
  4616. // 同步透析机透析液细菌培养检测记录表(T_HD_DM_DIALYSATE_BC)
  4617. func SyncLisCulture(rdb *gorm.DB, org_id int64, hospital_id string) {
  4618. // 第一步:根据机构id获取上次同步时间
  4619. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 63)
  4620. var sync_time int64
  4621. if syncLastInfo.ID > 0 {
  4622. sync_time = syncLastInfo.SyncTime
  4623. } else {
  4624. sync_time = 0
  4625. }
  4626. //同步细菌培养数据
  4627. dialysate, _ := service.FindOrgCulture(org_id, sync_time, time.Now().Unix())
  4628. var lisHdLisCulture []*sz.TempHdLisCulture
  4629. for _, item := range dialysate {
  4630. lisDialysate := &sz.TempHdLisCulture{
  4631. Sn: strconv.FormatInt(item.ID, 10),
  4632. HospitalId: hospital_id,
  4633. EquitmentId: strconv.FormatInt(item.EquitmentId, 10),
  4634. InspectionTime: time.Unix(item.SpelingDate, 0),
  4635. IsQualified: strconv.FormatInt(item.Modifications, 10),
  4636. InspectedValue: item.DetectionResult + "CFU/mL",
  4637. IsSubstitutionQualified: strconv.FormatInt(item.Modifications, 10),
  4638. CaseOrder: item.Sort,
  4639. CreateTime: time.Unix(item.Ctime, 0),
  4640. Sjscsj: time.Now(),
  4641. Xgbz: "0",
  4642. }
  4643. lisHdLisCulture = append(lisHdLisCulture, lisDialysate)
  4644. }
  4645. if len(lisHdLisCulture) > 0 {
  4646. err := service.CreateLisCulture(lisHdLisCulture, rdb)
  4647. if err == nil {
  4648. // 第三步:同步成功后,添加同步记录
  4649. upload := &sz.DataUpload{
  4650. SyncType: 63,
  4651. OrgId: org_id,
  4652. SyncTime: time.Now().Unix(),
  4653. SyncResultType: 1,
  4654. CreateTime: time.Now().Unix(),
  4655. UpdateTime: time.Now().Unix(),
  4656. }
  4657. err := service.CreateUploadRecord(upload)
  4658. if err != nil {
  4659. utils.ErrorLog("%v", err)
  4660. }
  4661. } else {
  4662. //错误处理
  4663. }
  4664. }
  4665. }
  4666. // 透析机透析液内毒素检测记录表(T_HD_DM_DIALYSATE_EN)
  4667. func SyncDialysate(rdb *gorm.DB, org_id int64, hospital_id string) {
  4668. // 第一步:根据机构id获取上次同步时间
  4669. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 64)
  4670. var sync_time int64
  4671. if syncLastInfo.ID > 0 {
  4672. sync_time = syncLastInfo.SyncTime
  4673. } else {
  4674. sync_time = 0
  4675. }
  4676. //同步透析机透析液内毒素检测记录表
  4677. dialysate, _ := service.FindOrgDialysate(org_id, sync_time, time.Now().Unix())
  4678. var lisHdLisDialysate []*sz.TempHdLisDialysate
  4679. for _, item := range dialysate {
  4680. lisDialysate := &sz.TempHdLisDialysate{
  4681. Sn: strconv.FormatInt(item.ID, 10),
  4682. HospitalId: hospital_id,
  4683. EquitmentId: strconv.FormatInt(item.EquitmentId, 10),
  4684. InspectionTime: time.Unix(item.SamplingDate, 0),
  4685. IsQualified: strconv.FormatInt(item.Modifications, 10),
  4686. InspectedValue: item.DetectionResultb + "EU/mL",
  4687. CaseOrder: item.Sort,
  4688. CreateTime: time.Unix(item.Ctime, 0),
  4689. Sjscsj: time.Now(),
  4690. Xgbz: 0,
  4691. }
  4692. lisHdLisDialysate = append(lisHdLisDialysate, lisDialysate)
  4693. }
  4694. if len(lisHdLisDialysate) > 0 {
  4695. err := service.CreateLisDialysate(lisHdLisDialysate, rdb)
  4696. if err == nil {
  4697. // 第三步:同步成功后,添加同步记录
  4698. upload := &sz.DataUpload{
  4699. SyncType: 64,
  4700. OrgId: org_id,
  4701. SyncTime: time.Now().Unix(),
  4702. SyncResultType: 1,
  4703. CreateTime: time.Now().Unix(),
  4704. UpdateTime: time.Now().Unix(),
  4705. }
  4706. err := service.CreateUploadRecord(upload)
  4707. if err != nil {
  4708. utils.ErrorLog("%v", err)
  4709. }
  4710. } else {
  4711. //错误处理
  4712. }
  4713. }
  4714. }
  4715. func SyncLisBodyDetection(rdb *gorm.DB, org_id int64, hospital_id string) {
  4716. // 第一步:根据机构id获取上次同步时间
  4717. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 65)
  4718. var sync_time int64
  4719. if syncLastInfo.ID > 0 {
  4720. sync_time = syncLastInfo.SyncTime
  4721. } else {
  4722. sync_time = 0
  4723. }
  4724. //同步物表消毒记录表
  4725. detection, _ := service.FindOrgBodyDetection(org_id, sync_time, time.Now().Unix())
  4726. var lisHdLisBodyDisinfect []*sz.TempHdLisBodyDisinfect
  4727. for _, item := range detection {
  4728. disinfect := &sz.TempHdLisBodyDisinfect{
  4729. Sn: strconv.FormatInt(item.ID, 10),
  4730. HospitalId: hospital_id,
  4731. IsQualified: strconv.FormatInt(item.CheckOut, 10),
  4732. InspectedValue: item.DetectionResult,
  4733. InspectionTime: time.Unix(item.CreatedTime, 0),
  4734. CaseOrder: item.Sort,
  4735. CreateTime: time.Unix(item.Ctime, 0),
  4736. Sjscsj: time.Now(),
  4737. Xgbz: "0",
  4738. }
  4739. lisHdLisBodyDisinfect = append(lisHdLisBodyDisinfect, disinfect)
  4740. }
  4741. if len(lisHdLisBodyDisinfect) > 0 {
  4742. err := service.CreateBodyDisinfect(lisHdLisBodyDisinfect, rdb)
  4743. if err == nil {
  4744. // 第三步:同步成功后,添加同步记录
  4745. upload := &sz.DataUpload{
  4746. SyncType: 65,
  4747. OrgId: org_id,
  4748. SyncTime: time.Now().Unix(),
  4749. SyncResultType: 1,
  4750. CreateTime: time.Now().Unix(),
  4751. UpdateTime: time.Now().Unix(),
  4752. }
  4753. err := service.CreateUploadRecord(upload)
  4754. if err != nil {
  4755. utils.ErrorLog("%v", err)
  4756. }
  4757. } else {
  4758. //错误处理
  4759. }
  4760. }
  4761. }
  4762. func SyncLisWaterFc(rdb *gorm.DB, org_id int64, hospital_id string) {
  4763. // 第一步:根据机构id获取上次同步时间
  4764. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 66)
  4765. var sync_time int64
  4766. if syncLastInfo.ID > 0 {
  4767. sync_time = syncLastInfo.SyncTime
  4768. } else {
  4769. sync_time = 0
  4770. }
  4771. //透析用水游离氯检测表
  4772. waterfc, _ := service.FindOrgWaterFc(org_id, sync_time, time.Now().Unix())
  4773. var lisHdLisWaterFc []*sz.TempHdLisWaterFc
  4774. for _, item := range waterfc {
  4775. disinfect := &sz.TempHdLisWaterFc{
  4776. Sn: strconv.FormatInt(item.ID, 10),
  4777. HospitalId: hospital_id,
  4778. EquitmentId: strconv.FormatInt(item.EquitmentId, 10),
  4779. InspectionOrgId: "1",
  4780. InspectionTime: time.Unix(item.SamplingDate, 0),
  4781. IsQualified: strconv.FormatInt(item.PassExamination, 10),
  4782. InspectedValue: item.DetectionResultb,
  4783. CaseOrder: item.Sort,
  4784. CreateTime: time.Unix(item.Ctime, 0),
  4785. Sjscsj: time.Now(),
  4786. Xgbz: 0,
  4787. }
  4788. switch item.Specimenb {
  4789. case 1:
  4790. disinfect.WaterType = "3"
  4791. break
  4792. case 2:
  4793. disinfect.WaterType = "2"
  4794. break
  4795. case 3:
  4796. disinfect.WaterType = "2"
  4797. break
  4798. case 4:
  4799. disinfect.WaterType = "1"
  4800. break
  4801. case 5:
  4802. disinfect.WaterType = "1"
  4803. break
  4804. }
  4805. lisHdLisWaterFc = append(lisHdLisWaterFc, disinfect)
  4806. }
  4807. if len(lisHdLisWaterFc) > 0 {
  4808. err := service.CreateWaterFc(lisHdLisWaterFc, rdb)
  4809. if err == nil {
  4810. // 第三步:同步成功后,添加同步记录
  4811. upload := &sz.DataUpload{
  4812. SyncType: 66,
  4813. OrgId: org_id,
  4814. SyncTime: time.Now().Unix(),
  4815. SyncResultType: 1,
  4816. CreateTime: time.Now().Unix(),
  4817. UpdateTime: time.Now().Unix(),
  4818. }
  4819. err := service.CreateUploadRecord(upload)
  4820. if err != nil {
  4821. utils.ErrorLog("%v", err)
  4822. }
  4823. } else {
  4824. //错误处理
  4825. }
  4826. }
  4827. }
  4828. // 透析用水电解质检测表(T_HD_WATER_EL)
  4829. func SyncLisWaterEl(rdb *gorm.DB, org_id int64, hospital_id string) {
  4830. // 第一步:根据机构id获取上次同步时间
  4831. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 2008)
  4832. var sync_time int64
  4833. if syncLastInfo.ID > 0 {
  4834. sync_time = syncLastInfo.SyncTime
  4835. } else {
  4836. sync_time = 0
  4837. }
  4838. //透析用水游离氯检测表
  4839. waterfc, _ := service.FindOrgWaterEl(org_id, sync_time, time.Now().Unix())
  4840. var lisHdLisWaterFc []*sz.TempHdLisWaterEl
  4841. for _, item := range waterfc {
  4842. disinfect := &sz.TempHdLisWaterEl{
  4843. Sn: strconv.FormatInt(item.ID, 10),
  4844. HospitalId: hospital_id,
  4845. EquitmentId: strconv.FormatInt(item.EquitmentId, 10),
  4846. WaterType: "3",
  4847. InspectionOrgId: "1",
  4848. InspectionTime: time.Unix(item.SamplingDate, 0),
  4849. IsQualified: strconv.FormatInt(item.PassExamination, 10),
  4850. InspectedValue: item.Remakes,
  4851. CaseOrder: item.Sort,
  4852. CreateTime: time.Unix(item.Ctime, 0),
  4853. Sjscsj: time.Now(),
  4854. Xgbz: 0,
  4855. }
  4856. lisHdLisWaterFc = append(lisHdLisWaterFc, disinfect)
  4857. }
  4858. if len(lisHdLisWaterFc) > 0 {
  4859. err := service.CreateWaterEl(lisHdLisWaterFc, rdb)
  4860. if err == nil {
  4861. // 第三步:同步成功后,添加同步记录
  4862. upload := &sz.DataUpload{
  4863. SyncType: 2008,
  4864. OrgId: org_id,
  4865. SyncTime: time.Now().Unix(),
  4866. SyncResultType: 1,
  4867. CreateTime: time.Now().Unix(),
  4868. UpdateTime: time.Now().Unix(),
  4869. }
  4870. err := service.CreateUploadRecord(upload)
  4871. if err != nil {
  4872. utils.ErrorLog("%v", err)
  4873. }
  4874. } else {
  4875. //错误处理
  4876. }
  4877. }
  4878. }
  4879. // 透析用水电解质检测表(T_HD_WATER_EL)
  4880. func SyncLisWaterTe(rdb *gorm.DB, org_id int64, hospital_id string) {
  4881. // 第一步:根据机构id获取上次同步时间
  4882. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 2009)
  4883. var sync_time int64
  4884. if syncLastInfo.ID > 0 {
  4885. sync_time = syncLastInfo.SyncTime
  4886. } else {
  4887. sync_time = 0
  4888. }
  4889. //透析用水游离氯检测表
  4890. waterfc, _ := service.FindOrgWaterEl(org_id, sync_time, time.Now().Unix())
  4891. var lisHdLisWaterFc []*sz.TempHdLisWaterTe
  4892. for _, item := range waterfc {
  4893. disinfect := &sz.TempHdLisWaterTe{
  4894. Sn: strconv.FormatInt(item.ID, 10),
  4895. HospitalId: hospital_id,
  4896. EquitmentId: strconv.FormatInt(item.EquitmentId, 10),
  4897. WaterType: "3",
  4898. InspectionOrgId: "1",
  4899. InspectionTime: time.Unix(item.SamplingDate, 0),
  4900. IsQualified: strconv.FormatInt(item.PassExamination, 10),
  4901. CaseOrder: item.Sort,
  4902. CreateTime: time.Unix(item.Ctime, 0),
  4903. Sjscsj: time.Now(),
  4904. Xgbz: 0,
  4905. }
  4906. lisHdLisWaterFc = append(lisHdLisWaterFc, disinfect)
  4907. }
  4908. if len(lisHdLisWaterFc) > 0 {
  4909. err := service.CreateWaterTe(lisHdLisWaterFc, rdb)
  4910. if err == nil {
  4911. // 第三步:同步成功后,添加同步记录
  4912. upload := &sz.DataUpload{
  4913. SyncType: 2009,
  4914. OrgId: org_id,
  4915. SyncTime: time.Now().Unix(),
  4916. SyncResultType: 1,
  4917. CreateTime: time.Now().Unix(),
  4918. UpdateTime: time.Now().Unix(),
  4919. }
  4920. err := service.CreateUploadRecord(upload)
  4921. if err != nil {
  4922. utils.ErrorLog("%v", err)
  4923. }
  4924. } else {
  4925. //错误处理
  4926. }
  4927. }
  4928. }
  4929. func SynLisWaterNc(rdb *gorm.DB, org_id int64, hospital_id string) {
  4930. // 第一步:根据机构id获取上次同步时间
  4931. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 67)
  4932. var sync_time int64
  4933. if syncLastInfo.ID > 0 {
  4934. sync_time = syncLastInfo.SyncTime
  4935. } else {
  4936. sync_time = 0
  4937. }
  4938. //透析用水游离氯检测表
  4939. waternc, _ := service.FindOrgWaterNc(org_id, sync_time, time.Now().Unix())
  4940. var lisHdLisWaterNc []*sz.TempHdLisWaterNc
  4941. for _, item := range waternc {
  4942. disinfect := &sz.TempHdLisWaterNc{
  4943. Sn: strconv.FormatInt(item.ID, 10),
  4944. HospitalId: hospital_id,
  4945. EquitmentId: strconv.FormatInt(item.EquitmentId, 10),
  4946. InspectionOrgId: "1",
  4947. InspectionTime: time.Unix(item.SamplingDate, 0),
  4948. IsQualified: strconv.FormatInt(item.PassExamination, 10),
  4949. InspectedValue: item.DetectionResultb,
  4950. CaseOrder: item.Sort,
  4951. CreateTime: time.Unix(item.Ctime, 0),
  4952. Sjscsj: time.Now(),
  4953. Xgbz: "0",
  4954. }
  4955. switch item.Specimenb {
  4956. case 1:
  4957. disinfect.WaterType = "3"
  4958. break
  4959. case 2:
  4960. disinfect.WaterType = "2"
  4961. break
  4962. case 3:
  4963. disinfect.WaterType = "2"
  4964. break
  4965. case 4:
  4966. disinfect.WaterType = "1"
  4967. break
  4968. case 5:
  4969. disinfect.WaterType = "1"
  4970. break
  4971. }
  4972. lisHdLisWaterNc = append(lisHdLisWaterNc, disinfect)
  4973. }
  4974. if len(lisHdLisWaterNc) > 0 {
  4975. err := service.CreateWaterNc(lisHdLisWaterNc, rdb)
  4976. if err == nil {
  4977. // 第三步:同步成功后,添加同步记录
  4978. upload := &sz.DataUpload{
  4979. SyncType: 67,
  4980. OrgId: org_id,
  4981. SyncTime: time.Now().Unix(),
  4982. SyncResultType: 1,
  4983. CreateTime: time.Now().Unix(),
  4984. UpdateTime: time.Now().Unix(),
  4985. }
  4986. err := service.CreateUploadRecord(upload)
  4987. if err != nil {
  4988. utils.ErrorLog("%v", err)
  4989. }
  4990. } else {
  4991. //错误处理
  4992. }
  4993. }
  4994. }
  4995. func SynLisWaterPh(rdb *gorm.DB, org_id int64, hospital_id string) {
  4996. // 第一步:根据机构id获取上次同步时间
  4997. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 68)
  4998. var sync_time int64
  4999. if syncLastInfo.ID > 0 {
  5000. sync_time = syncLastInfo.SyncTime
  5001. } else {
  5002. sync_time = 0
  5003. }
  5004. //透析用水PH值检测表
  5005. waternc, _ := service.FindOrgWaterPh(org_id, sync_time, time.Now().Unix())
  5006. var lisHdLisWaterPh []*sz.TempHdLisWaterPh
  5007. for _, item := range waternc {
  5008. disinfect := &sz.TempHdLisWaterPh{
  5009. Sn: strconv.FormatInt(item.ID, 10),
  5010. HospitalId: hospital_id,
  5011. EquitmentId: strconv.FormatInt(item.EquitmentId, 10),
  5012. InspectionOrgId: "1",
  5013. InspectionTime: time.Unix(item.SamplingDate, 0),
  5014. IsQualified: strconv.FormatInt(item.PassExamination, 10),
  5015. InspectedValue: item.DetectionResultb,
  5016. CaseOrder: item.Sort,
  5017. CreateTime: time.Unix(item.Ctime, 0),
  5018. Sjscsj: time.Now(),
  5019. Xgbz: "0",
  5020. }
  5021. switch item.Specimenb {
  5022. case 1:
  5023. disinfect.WaterType = "3"
  5024. break
  5025. case 2:
  5026. disinfect.WaterType = "2"
  5027. break
  5028. case 3:
  5029. disinfect.WaterType = "2"
  5030. break
  5031. case 4:
  5032. disinfect.WaterType = "1"
  5033. break
  5034. case 5:
  5035. disinfect.WaterType = "1"
  5036. break
  5037. }
  5038. lisHdLisWaterPh = append(lisHdLisWaterPh, disinfect)
  5039. }
  5040. if len(lisHdLisWaterPh) > 0 {
  5041. err := service.CreateWaterPh(lisHdLisWaterPh, rdb)
  5042. if err == nil {
  5043. // 第三步:同步成功后,添加同步记录
  5044. upload := &sz.DataUpload{
  5045. SyncType: 68,
  5046. OrgId: org_id,
  5047. SyncTime: time.Now().Unix(),
  5048. SyncResultType: 1,
  5049. CreateTime: time.Now().Unix(),
  5050. UpdateTime: time.Now().Unix(),
  5051. }
  5052. err := service.CreateUploadRecord(upload)
  5053. if err != nil {
  5054. utils.ErrorLog("%v", err)
  5055. }
  5056. } else {
  5057. //错误处理
  5058. }
  5059. }
  5060. }
  5061. func SynListHadWater(rdb *gorm.DB, org_id int64, hospital_id string) {
  5062. // 第一步:根据机构id获取上次同步时间
  5063. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 69)
  5064. var sync_time int64
  5065. if syncLastInfo.ID > 0 {
  5066. sync_time = syncLastInfo.SyncTime
  5067. } else {
  5068. sync_time = 0
  5069. }
  5070. //透析用水PH值检测表
  5071. waterwh, _ := service.FindOrgWaterWh(org_id, sync_time, time.Now().Unix())
  5072. var lisHdLisWaterWh []*sz.TempHdLisWaterWh
  5073. for _, item := range waterwh {
  5074. disinfect := &sz.TempHdLisWaterWh{
  5075. Sn: strconv.FormatInt(item.ID, 10),
  5076. HospitalId: hospital_id,
  5077. EquitmentId: strconv.FormatInt(item.EquitmentId, 10),
  5078. InspectionOrgId: "1",
  5079. InspectionTime: time.Unix(item.SamplingDate, 0),
  5080. IsQualified: strconv.FormatInt(item.PassExamination, 10),
  5081. InspectedValue: item.DetectionResultb,
  5082. CaseOrder: item.Sort,
  5083. CreateTime: time.Unix(item.Ctime, 0),
  5084. Sjscsj: time.Now(),
  5085. Xgbz: "0",
  5086. }
  5087. switch item.Specimenb {
  5088. case 1:
  5089. disinfect.WaterType = "3"
  5090. break
  5091. case 2:
  5092. disinfect.WaterType = "2"
  5093. break
  5094. case 3:
  5095. disinfect.WaterType = "2"
  5096. break
  5097. case 4:
  5098. disinfect.WaterType = "1"
  5099. break
  5100. case 5:
  5101. disinfect.WaterType = "1"
  5102. break
  5103. }
  5104. lisHdLisWaterWh = append(lisHdLisWaterWh, disinfect)
  5105. }
  5106. if len(lisHdLisWaterWh) > 0 {
  5107. err := service.CreateWaterWh(lisHdLisWaterWh, rdb)
  5108. if err == nil {
  5109. // 第三步:同步成功后,添加同步记录
  5110. upload := &sz.DataUpload{
  5111. SyncType: 69,
  5112. OrgId: org_id,
  5113. SyncTime: time.Now().Unix(),
  5114. SyncResultType: 1,
  5115. CreateTime: time.Now().Unix(),
  5116. UpdateTime: time.Now().Unix(),
  5117. }
  5118. err := service.CreateUploadRecord(upload)
  5119. if err != nil {
  5120. utils.ErrorLog("%v", err)
  5121. }
  5122. } else {
  5123. //错误处理
  5124. }
  5125. }
  5126. }
  5127. func SynListHdCi(rdb *gorm.DB, org_id int64, hospital_id string) {
  5128. // 第一步:根据机构id获取上次同步时间
  5129. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 70)
  5130. var sync_time int64
  5131. if syncLastInfo.ID > 0 {
  5132. sync_time = syncLastInfo.SyncTime
  5133. } else {
  5134. sync_time = 0
  5135. }
  5136. //导管感染记录表
  5137. hdci, _ := service.FindOrgHdCi(org_id, sync_time, time.Now().Unix())
  5138. var temphdci []*sz.TempHdCi
  5139. for _, item := range hdci {
  5140. ci := &sz.TempHdCi{
  5141. InfectSn: strconv.FormatInt(item.ID, 10),
  5142. HospitalId: hospital_id,
  5143. PatientNk: strconv.FormatInt(item.PatientId, 10),
  5144. AccessId: strconv.FormatInt(item.ID, 10),
  5145. CiType: strconv.FormatInt(item.SequelaeType, 10),
  5146. BloodCulture: strconv.FormatInt(item.BloodCultupe, 10),
  5147. InfectionDate: time.Unix(item.StartTime, 0),
  5148. CreateTime: time.Unix(item.Ctime, 0),
  5149. Xgbz: 0,
  5150. Sjscsj: time.Now(),
  5151. }
  5152. temphdci = append(temphdci, ci)
  5153. }
  5154. if len(temphdci) > 0 {
  5155. err := service.CreateHdCi(temphdci, rdb)
  5156. if err == nil {
  5157. // 第三步:同步成功后,添加同步记录
  5158. upload := &sz.DataUpload{
  5159. SyncType: 70,
  5160. OrgId: org_id,
  5161. SyncTime: time.Now().Unix(),
  5162. SyncResultType: 1,
  5163. CreateTime: time.Now().Unix(),
  5164. UpdateTime: time.Now().Unix(),
  5165. }
  5166. err := service.CreateUploadRecord(upload)
  5167. if err != nil {
  5168. utils.ErrorLog("%v", err)
  5169. }
  5170. } else {
  5171. //错误处理
  5172. }
  5173. }
  5174. }
  5175. func SynLisHdCiOutCome(rdb *gorm.DB, org_id int64, hospital_id string) {
  5176. // 第一步:根据机构id获取上次同步时间
  5177. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 71)
  5178. var sync_time int64
  5179. if syncLastInfo.ID > 0 {
  5180. sync_time = syncLastInfo.SyncTime
  5181. } else {
  5182. sync_time = 0
  5183. }
  5184. //导管感染记录表
  5185. hdcioutcome, _ := service.FindOrgHdCiOutCome(org_id, sync_time, time.Now().Unix())
  5186. var temphdcioutcome []*sz.TempHdCiOutCome
  5187. for _, item := range hdcioutcome {
  5188. outcome := &sz.TempHdCiOutCome{
  5189. Sn: strconv.FormatInt(item.ID, 10),
  5190. HospitalId: hospital_id,
  5191. InfectSn: strconv.FormatInt(item.ID, 10),
  5192. PatientNk: strconv.FormatInt(item.PatientId, 10),
  5193. SequelaeType: strconv.FormatInt(item.CiType, 10),
  5194. Sjscsj: time.Now(),
  5195. Xgbz: 0,
  5196. CreateTime: time.Unix(item.Ctime, 0),
  5197. UpdateTime: time.Unix(item.Mtime, 0),
  5198. Ylyl1: "",
  5199. Ylyl2: "",
  5200. }
  5201. if outcome.SequelaeType == "0" {
  5202. outcome.SequelaeType = "9"
  5203. }
  5204. temphdcioutcome = append(temphdcioutcome, outcome)
  5205. }
  5206. if len(temphdcioutcome) > 0 {
  5207. err := service.CreateHdCiOutCome(temphdcioutcome, rdb)
  5208. if err == nil {
  5209. // 第三步:同步成功后,添加同步记录
  5210. upload := &sz.DataUpload{
  5211. SyncType: 71,
  5212. OrgId: org_id,
  5213. SyncTime: time.Now().Unix(),
  5214. SyncResultType: 1,
  5215. CreateTime: time.Now().Unix(),
  5216. UpdateTime: time.Now().Unix(),
  5217. }
  5218. err := service.CreateUploadRecord(upload)
  5219. if err != nil {
  5220. utils.ErrorLog("%v", err)
  5221. }
  5222. } else {
  5223. //错误处理
  5224. }
  5225. }
  5226. }
  5227. func SyncLisAirDetection(rdb *gorm.DB, org_id int64, hospital_id string) {
  5228. // 第一步:根据机构id获取上次同步时间
  5229. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 72)
  5230. var sync_time int64
  5231. if syncLastInfo.ID > 0 {
  5232. sync_time = syncLastInfo.SyncTime
  5233. } else {
  5234. sync_time = 0
  5235. }
  5236. //同步透析室空气消毒记录表
  5237. detection, _ := service.FindOrgArialDetection(org_id, sync_time, time.Now().Unix())
  5238. var lisHdLisAirDisinfect []*sz.TempHdLisAirDisinfect
  5239. for _, item := range detection {
  5240. disinfect := &sz.TempHdLisAirDisinfect{
  5241. Sn: strconv.FormatInt(item.ID, 10),
  5242. HospitalId: hospital_id,
  5243. IsQualified: strconv.FormatInt(item.CheckOut, 10),
  5244. InspectedValue: item.DetectionResult,
  5245. InspectionTime: time.Unix(item.CreatedTime, 0),
  5246. CaseOrder: item.Sort,
  5247. CreateTime: time.Unix(item.Ctime, 0),
  5248. Sjscsj: time.Now(),
  5249. Xgbz: "0",
  5250. }
  5251. lisHdLisAirDisinfect = append(lisHdLisAirDisinfect, disinfect)
  5252. }
  5253. if len(lisHdLisAirDisinfect) > 0 {
  5254. err := service.CreateAirDisinfect(lisHdLisAirDisinfect, rdb)
  5255. if err == nil {
  5256. // 第三步:同步成功后,添加同步记录
  5257. upload := &sz.DataUpload{
  5258. SyncType: 72,
  5259. OrgId: org_id,
  5260. SyncTime: time.Now().Unix(),
  5261. SyncResultType: 1,
  5262. CreateTime: time.Now().Unix(),
  5263. UpdateTime: time.Now().Unix(),
  5264. }
  5265. err := service.CreateUploadRecord(upload)
  5266. if err != nil {
  5267. utils.ErrorLog("%v", err)
  5268. }
  5269. } else {
  5270. //错误处理
  5271. }
  5272. }
  5273. }
  5274. func SyncLisWaterBc(rdb *gorm.DB, org_id int64, hospital_id string) {
  5275. // 第一步:根据机构id获取上次同步时间
  5276. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 73)
  5277. var sync_time int64
  5278. if syncLastInfo.ID > 0 {
  5279. sync_time = syncLastInfo.SyncTime
  5280. } else {
  5281. sync_time = 0
  5282. }
  5283. //同步细菌培养数据
  5284. dialysate, _ := service.FindOrgCulture(org_id, sync_time, time.Now().Unix())
  5285. var lisHdLisWaterBc []*sz.TempHdLisWaterBc
  5286. for _, item := range dialysate {
  5287. waterbc := &sz.TempHdLisWaterBc{
  5288. Sn: strconv.FormatInt(item.ID, 10),
  5289. HospitalId: hospital_id,
  5290. EquitmentId: strconv.FormatInt(item.EquitmentId, 10),
  5291. InspectionOrgId: "1",
  5292. InspectionTime: time.Unix(item.SpelingDate, 0),
  5293. IsQualified: strconv.FormatInt(item.Modifications, 10),
  5294. InspectedValue: item.DetectionResult,
  5295. CaseOrder: item.Sort,
  5296. Sjscsj: time.Now(),
  5297. Xgbz: "0",
  5298. CreateTime: time.Unix(item.Ctime, 0),
  5299. }
  5300. switch item.Specimen {
  5301. case 1:
  5302. waterbc.WaterType = "3"
  5303. break
  5304. case 2:
  5305. waterbc.WaterType = "2"
  5306. break
  5307. case 3:
  5308. waterbc.WaterType = "2"
  5309. break
  5310. case 4:
  5311. waterbc.WaterType = "1"
  5312. break
  5313. case 5:
  5314. waterbc.WaterType = "1"
  5315. break
  5316. }
  5317. lisHdLisWaterBc = append(lisHdLisWaterBc, waterbc)
  5318. }
  5319. if len(lisHdLisWaterBc) > 0 {
  5320. err := service.CreateLisWaterBc(lisHdLisWaterBc, rdb)
  5321. if err == nil {
  5322. // 第三步:同步成功后,添加同步记录
  5323. upload := &sz.DataUpload{
  5324. SyncType: 73,
  5325. OrgId: org_id,
  5326. SyncTime: time.Now().Unix(),
  5327. SyncResultType: 1,
  5328. CreateTime: time.Now().Unix(),
  5329. UpdateTime: time.Now().Unix(),
  5330. }
  5331. err := service.CreateUploadRecord(upload)
  5332. if err != nil {
  5333. utils.ErrorLog("%v", err)
  5334. }
  5335. } else {
  5336. //错误处理
  5337. }
  5338. }
  5339. }
  5340. func SyncLisWaterEn(rdb *gorm.DB, org_id int64, hospital_id string) {
  5341. // 第一步:根据机构id获取上次同步时间
  5342. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 74)
  5343. var sync_time int64
  5344. if syncLastInfo.ID > 0 {
  5345. sync_time = syncLastInfo.SyncTime
  5346. } else {
  5347. sync_time = 0
  5348. }
  5349. //同步细菌培养数据
  5350. dialysate, _ := service.FindOrgDialysate(org_id, sync_time, time.Now().Unix())
  5351. fmt.Println("dia", dialysate)
  5352. var lisHdLisWaterEn []*sz.TempHdLisWaterEn
  5353. for _, item := range dialysate {
  5354. wateren := &sz.TempHdLisWaterEn{
  5355. Sn: strconv.FormatInt(item.ID, 10),
  5356. HospitalId: hospital_id,
  5357. EquitmentId: strconv.FormatInt(item.EquitmentId, 10),
  5358. InspectionOrgId: "1",
  5359. InspectionTime: time.Unix(item.SamplingDate, 0),
  5360. IsQualified: strconv.FormatInt(item.Modifications, 10),
  5361. InspectedValue: item.DetectionResultb,
  5362. CaseOrder: item.Sort,
  5363. Sjscsj: time.Now(),
  5364. Xgbz: 0,
  5365. CreateTime: time.Unix(item.Ctime, 0),
  5366. }
  5367. switch item.Specimenb {
  5368. case 1:
  5369. wateren.WaterType = "3"
  5370. break
  5371. case 2:
  5372. wateren.WaterType = "2"
  5373. break
  5374. case 3:
  5375. wateren.WaterType = "2"
  5376. break
  5377. case 4:
  5378. wateren.WaterType = "1"
  5379. break
  5380. case 5:
  5381. wateren.WaterType = "1"
  5382. break
  5383. }
  5384. lisHdLisWaterEn = append(lisHdLisWaterEn, wateren)
  5385. }
  5386. if len(lisHdLisWaterEn) > 0 {
  5387. err := service.CreateLisWaterEn(lisHdLisWaterEn, rdb)
  5388. if err == nil {
  5389. // 第三步:同步成功后,添加同步记录
  5390. upload := &sz.DataUpload{
  5391. SyncType: 74,
  5392. OrgId: org_id,
  5393. SyncTime: time.Now().Unix(),
  5394. SyncResultType: 1,
  5395. CreateTime: time.Now().Unix(),
  5396. UpdateTime: time.Now().Unix(),
  5397. }
  5398. err := service.CreateUploadRecord(upload)
  5399. if err != nil {
  5400. utils.ErrorLog("%v", err)
  5401. }
  5402. } else {
  5403. //错误处理
  5404. }
  5405. }
  5406. }
  5407. // 机构人员字典表
  5408. func SyncTBDICPractitioner(rdb *gorm.DB, org_id int64, hospital_id string) {
  5409. // 第一步:根据机构id获取上次同步时间
  5410. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1001)
  5411. var sync_time int64
  5412. if syncLastInfo.ID > 0 {
  5413. sync_time = syncLastInfo.SyncTime
  5414. } else {
  5415. sync_time = 0
  5416. }
  5417. //同步员工信息
  5418. roles, _ := service.FindOrgRolesData(org_id, sync_time, time.Now().Unix())
  5419. //waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
  5420. // var staffs []*sz.TBDICPractitioner
  5421. for _, role := range roles {
  5422. var zwdm, zhiw, zcdm, zhic, lb string
  5423. switch role.UserType {
  5424. case 2:
  5425. zwdm = "234"
  5426. zhiw = "医师"
  5427. zcdm = "420"
  5428. zhic = "中级"
  5429. lb = "11"
  5430. break
  5431. case 3:
  5432. zwdm = "255"
  5433. zhiw = "护士"
  5434. zcdm = "420"
  5435. zhic = "中级"
  5436. lb = "21"
  5437. break
  5438. }
  5439. staff := &sz.TBDICPractitioner{
  5440. GH: strconv.FormatInt(role.AdminUserId, 10),
  5441. YLJGDM: hospital_id,
  5442. ZCM: role.UserName,
  5443. XM: role.UserName,
  5444. XBBM: "2",
  5445. SSKS: "1001",
  5446. SZYWKSMC: "血透中心",
  5447. ZWDM: zwdm,
  5448. ZHIW: zhiw,
  5449. ZCDM: zcdm,
  5450. ZHIC: zhic,
  5451. NNRYLDQK: "9",
  5452. BZQK: "2",
  5453. LB: lb,
  5454. YWSCSJ: time.Now(),
  5455. SJSCSJ: time.Now(),
  5456. XGBZ: 0,
  5457. }
  5458. service.BatchCreateTBDICPractitioner(staff, rdb)
  5459. }
  5460. // 第三步:同步成功后,添加同步记录
  5461. upload := &sz.DataUpload{
  5462. SyncType: 1001,
  5463. OrgId: org_id,
  5464. SyncTime: time.Now().Unix(),
  5465. SyncResultType: 1,
  5466. CreateTime: time.Now().Unix(),
  5467. UpdateTime: time.Now().Unix(),
  5468. }
  5469. service.CreateUploadRecord(upload)
  5470. }
  5471. // 机构人员字典表
  5472. func SyncTBDICPractitioner_pg(rdb *gorm.DB, org_id int64, hospital_id string) {
  5473. // 第一步:根据机构id获取上次同步时间
  5474. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1001)
  5475. var sync_time int64
  5476. if syncLastInfo.ID > 0 {
  5477. sync_time = syncLastInfo.SyncTime
  5478. } else {
  5479. sync_time = 0
  5480. }
  5481. //同步员工信息
  5482. roles, _ := service.FindOrgRolesData(org_id, sync_time, time.Now().Unix())
  5483. //waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
  5484. // var staffs []*sz.TBDICPractitioner
  5485. for _, role := range roles {
  5486. var zwdm, zhiw, zcdm, zhic, lb string
  5487. switch role.UserType {
  5488. case 2:
  5489. zwdm = "234"
  5490. zhiw = "医师"
  5491. zcdm = "420"
  5492. zhic = "中级"
  5493. lb = "11"
  5494. break
  5495. case 3:
  5496. zwdm = "255"
  5497. zhiw = "护士"
  5498. zcdm = "420"
  5499. zhic = "中级"
  5500. lb = "21"
  5501. break
  5502. }
  5503. staff := &sz.TBDICPractitioner{
  5504. GH: strconv.FormatInt(role.AdminUserId, 10),
  5505. YLJGDM: hospital_id,
  5506. ZCM: role.UserName,
  5507. XM: role.UserName,
  5508. XBBM: "2",
  5509. SSKS: "1001",
  5510. SZYWKSMC: "血透中心",
  5511. ZWDM: zwdm,
  5512. ZHIW: zhiw,
  5513. ZCDM: zcdm,
  5514. ZHIC: zhic,
  5515. NNRYLDQK: "9",
  5516. BZQK: "2",
  5517. LB: lb,
  5518. YWSCSJ: time.Now(),
  5519. SJSCSJ: time.Now(),
  5520. XGBZ: 0,
  5521. }
  5522. service.BatchCreateTBDICPractitioner(staff, rdb)
  5523. }
  5524. // 第三步:同步成功后,添加同步记录
  5525. upload := &sz.DataUpload{
  5526. SyncType: 1001,
  5527. OrgId: org_id,
  5528. SyncTime: time.Now().Unix(),
  5529. SyncResultType: 1,
  5530. CreateTime: time.Now().Unix(),
  5531. UpdateTime: time.Now().Unix(),
  5532. }
  5533. service.CreateUploadRecord(upload)
  5534. }
  5535. // 药品目录字典表
  5536. func SyncTBDICMedicines(rdb *gorm.DB, org_id int64, hospital_id string) {
  5537. // 第一步:根据机构id获取上次同步时间
  5538. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1081)
  5539. var sync_time int64
  5540. if syncLastInfo.ID > 0 {
  5541. sync_time = syncLastInfo.SyncTime
  5542. } else {
  5543. sync_time = 0
  5544. }
  5545. //同步员工信息
  5546. drugs, _ := service.FindDrugList(org_id, sync_time, time.Now().Unix())
  5547. //waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
  5548. // var staffs []*sz.TBDICPractitioner
  5549. for _, drug := range drugs {
  5550. medicines := &sz.TBDICMedicines{
  5551. YLJGDM: hospital_id,
  5552. YYZBDM: strconv.FormatInt(drug.ID, 10),
  5553. YPMC: drug.DrugName,
  5554. TYMC: drug.DrugName,
  5555. YPGG: drug.DrugSpec,
  5556. YNJXDA: "1",
  5557. YNJXMC: drug.DrugName,
  5558. SYBZ: strconv.FormatInt(drug.Status, 10),
  5559. TSBZ: "0",
  5560. KSSBZ: "0",
  5561. YPPZWH: drug.Number,
  5562. YPLX: "1",
  5563. YNZJBZ: "0",
  5564. GJYBZ: "0",
  5565. SJYBZ: "0",
  5566. SHJYBZ: "0",
  5567. QJYBZ: "0",
  5568. YWSCSJ: time.Now(),
  5569. SJSCSJ: time.Now(),
  5570. XGBZ: 0,
  5571. }
  5572. service.BatchCreateTBDICMedicines(medicines, rdb)
  5573. }
  5574. // 第三步:同步成功后,添加同步记录
  5575. upload := &sz.DataUpload{
  5576. SyncType: 1081,
  5577. OrgId: org_id,
  5578. SyncTime: time.Now().Unix(),
  5579. SyncResultType: 1,
  5580. CreateTime: time.Now().Unix(),
  5581. UpdateTime: time.Now().Unix(),
  5582. }
  5583. service.CreateUploadRecord(upload)
  5584. }
  5585. func SyncTBDICMedicines_pg(rdb *gorm.DB, org_id int64, hospital_id string) {
  5586. // 第一步:根据机构id获取上次同步时间
  5587. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1081)
  5588. var sync_time int64
  5589. if syncLastInfo.ID > 0 {
  5590. sync_time = syncLastInfo.SyncTime
  5591. } else {
  5592. sync_time = 0
  5593. }
  5594. //同步员工信息
  5595. drugs, _ := service.FindDrugList(org_id, sync_time, time.Now().Unix())
  5596. //waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
  5597. // var staffs []*sz.TBDICPractitioner
  5598. for _, drug := range drugs {
  5599. medicines := &sz.TBDICMedicines{
  5600. YLJGDM: hospital_id,
  5601. YYZBDM: strconv.FormatInt(drug.ID, 10),
  5602. YPMC: drug.DrugName,
  5603. TYMC: drug.DrugName,
  5604. YPGG: drug.DrugSpec,
  5605. YNJXDA: "1",
  5606. YNJXMC: drug.DrugName,
  5607. SYBZ: strconv.FormatInt(drug.Status, 10),
  5608. TSBZ: "0",
  5609. KSSBZ: "0",
  5610. YPPZWH: drug.Number,
  5611. YPLX: "1",
  5612. YNZJBZ: "0",
  5613. GJYBZ: "0",
  5614. SJYBZ: "0",
  5615. SHJYBZ: "0",
  5616. QJYBZ: "0",
  5617. YWSCSJ: time.Now(),
  5618. SJSCSJ: time.Now(),
  5619. XGBZ: 0,
  5620. }
  5621. service.BatchCreateTBDICMedicines(medicines, rdb)
  5622. }
  5623. // 第三步:同步成功后,添加同步记录
  5624. upload := &sz.DataUpload{
  5625. SyncType: 1081,
  5626. OrgId: org_id,
  5627. SyncTime: time.Now().Unix(),
  5628. SyncResultType: 1,
  5629. CreateTime: time.Now().Unix(),
  5630. UpdateTime: time.Now().Unix(),
  5631. }
  5632. service.CreateUploadRecord(upload)
  5633. }
  5634. // 药品目录字典表
  5635. func SyncTBDICYpdzzd(rdb *gorm.DB, org_id int64, hospital_id string) {
  5636. // 第一步:根据机构id获取上次同步时间
  5637. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1083)
  5638. var sync_time int64
  5639. if syncLastInfo.ID > 0 {
  5640. sync_time = syncLastInfo.SyncTime
  5641. } else {
  5642. sync_time = 0
  5643. }
  5644. //同步员工信息
  5645. drugs, _ := service.FindDrugList(org_id, sync_time, time.Now().Unix())
  5646. //waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
  5647. // var staffs []*sz.TBDICPractitioner
  5648. for _, drug := range drugs {
  5649. ypdzzd := &sz.TBDICYpdzzd{
  5650. YLJGDM: hospital_id,
  5651. YNYPDM: strconv.FormatInt(drug.ID, 10),
  5652. YPMC: drug.DrugName,
  5653. YPLX: "1",
  5654. YPSPWYBSDM: drug.MedicalInsuranceNumber,
  5655. YPSPWYBSMC: drug.DrugName,
  5656. SJSHCSJ: time.Now(),
  5657. SJSCSJ: time.Now(),
  5658. XGBZ: 0,
  5659. }
  5660. service.BatchCreateTBDICYpdzzd(ypdzzd, rdb)
  5661. }
  5662. // 第三步:同步成功后,添加同步记录
  5663. upload := &sz.DataUpload{
  5664. SyncType: 1083,
  5665. OrgId: org_id,
  5666. SyncTime: time.Now().Unix(),
  5667. SyncResultType: 1,
  5668. CreateTime: time.Now().Unix(),
  5669. UpdateTime: time.Now().Unix(),
  5670. }
  5671. service.CreateUploadRecord(upload)
  5672. }
  5673. func SyncTBDICYpdzzd_pg(rdb *gorm.DB, org_id int64, hospital_id string) {
  5674. // 第一步:根据机构id获取上次同步时间
  5675. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1083)
  5676. var sync_time int64
  5677. if syncLastInfo.ID > 0 {
  5678. sync_time = syncLastInfo.SyncTime
  5679. } else {
  5680. sync_time = 0
  5681. }
  5682. //同步员工信息
  5683. drugs, _ := service.FindDrugList(org_id, sync_time, time.Now().Unix())
  5684. //waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
  5685. // var staffs []*sz.TBDICPractitioner
  5686. for _, drug := range drugs {
  5687. ypdzzd := &sz.TBDICYpdzzd{
  5688. YLJGDM: hospital_id,
  5689. YNYPDM: strconv.FormatInt(drug.ID, 10),
  5690. YPMC: drug.DrugName,
  5691. YPLX: "1",
  5692. YPSPWYBSDM: drug.MedicalInsuranceNumber,
  5693. YPSPWYBSMC: drug.DrugName,
  5694. SJSHCSJ: time.Now(),
  5695. SJSCSJ: time.Now(),
  5696. XGBZ: 0,
  5697. }
  5698. service.BatchCreateTBDICYpdzzd(ypdzzd, rdb)
  5699. }
  5700. // 第三步:同步成功后,添加同步记录
  5701. upload := &sz.DataUpload{
  5702. SyncType: 1083,
  5703. OrgId: org_id,
  5704. SyncTime: time.Now().Unix(),
  5705. SyncResultType: 1,
  5706. CreateTime: time.Now().Unix(),
  5707. UpdateTime: time.Now().Unix(),
  5708. }
  5709. service.CreateUploadRecord(upload)
  5710. }
  5711. // 诊疗项目目录字典表
  5712. func SyncTBDICZlxmml(rdb *gorm.DB, org_id int64, hospital_id string) {
  5713. // 第一步:根据机构id获取上次同步时间
  5714. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1082)
  5715. var sync_time int64
  5716. if syncLastInfo.ID > 0 {
  5717. sync_time = syncLastInfo.SyncTime
  5718. } else {
  5719. sync_time = 0
  5720. }
  5721. //同步员工信息
  5722. projects, _ := service.FindProjectList(org_id, sync_time, time.Now().Unix())
  5723. //waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
  5724. // var staffs []*sz.TBDICPractitioner
  5725. for _, project := range projects {
  5726. zlxmml := &sz.TBDICZlxmml{
  5727. YLJGDM: hospital_id,
  5728. YYZBDM: strconv.FormatInt(project.ID, 10),
  5729. XMMC: project.ProjectName,
  5730. SFDW: "元",
  5731. SFDJ: strconv.FormatFloat(project.Price, 'f', 1, 32),
  5732. SYBZ: strconv.FormatInt(project.Status, 10),
  5733. YWSCSJ: time.Now(),
  5734. SJSCSJ: time.Now(),
  5735. XGBZ: 0,
  5736. }
  5737. service.BatchCreateTBDICZlxmml(zlxmml, rdb)
  5738. }
  5739. // 第三步:同步成功后,添加同步记录
  5740. upload := &sz.DataUpload{
  5741. SyncType: 1082,
  5742. OrgId: org_id,
  5743. SyncTime: time.Now().Unix(),
  5744. SyncResultType: 1,
  5745. CreateTime: time.Now().Unix(),
  5746. UpdateTime: time.Now().Unix(),
  5747. }
  5748. service.CreateUploadRecord(upload)
  5749. }
  5750. func SyncTBDICZlxmml_pg(rdb *gorm.DB, org_id int64, hospital_id string) {
  5751. // 第一步:根据机构id获取上次同步时间
  5752. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1082)
  5753. var sync_time int64
  5754. if syncLastInfo.ID > 0 {
  5755. sync_time = syncLastInfo.SyncTime
  5756. } else {
  5757. sync_time = 0
  5758. }
  5759. //同步员工信息
  5760. projects, _ := service.FindProjectList(org_id, sync_time, time.Now().Unix())
  5761. //waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
  5762. // var staffs []*sz.TBDICPractitioner
  5763. for _, project := range projects {
  5764. zlxmml := &sz.TBDICZlxmml{
  5765. YLJGDM: hospital_id,
  5766. YYZBDM: strconv.FormatInt(project.ID, 10),
  5767. XMMC: project.ProjectName,
  5768. SFDW: "元",
  5769. SFDJ: strconv.FormatFloat(project.Price, 'f', 1, 32),
  5770. SYBZ: strconv.FormatInt(project.Status, 10),
  5771. YWSCSJ: time.Now(),
  5772. SJSCSJ: time.Now(),
  5773. XGBZ: 0,
  5774. }
  5775. service.BatchCreateTBDICZlxmml(zlxmml, rdb)
  5776. }
  5777. // 第三步:同步成功后,添加同步记录
  5778. upload := &sz.DataUpload{
  5779. SyncType: 1082,
  5780. OrgId: org_id,
  5781. SyncTime: time.Now().Unix(),
  5782. SyncResultType: 1,
  5783. CreateTime: time.Now().Unix(),
  5784. UpdateTime: time.Now().Unix(),
  5785. }
  5786. service.CreateUploadRecord(upload)
  5787. }
  5788. // 诊疗项目目录字典表
  5789. func SyncTBDICZlxmdzzd(rdb *gorm.DB, org_id int64, hospital_id string) {
  5790. // 第一步:根据机构id获取上次同步时间
  5791. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1086)
  5792. var sync_time int64
  5793. if syncLastInfo.ID > 0 {
  5794. sync_time = syncLastInfo.SyncTime
  5795. } else {
  5796. sync_time = 0
  5797. }
  5798. //同步员工信息
  5799. projects, _ := service.FindProjectList(org_id, sync_time, time.Now().Unix())
  5800. //waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
  5801. // var staffs []*sz.TBDICPractitioner
  5802. for _, project := range projects {
  5803. zlxmdzzd := &sz.TBDICZlxmdzzd{
  5804. YLJGDM: hospital_id,
  5805. YNZLXMDM: strconv.FormatInt(project.ID, 10),
  5806. YNZLXMMC: project.ProjectName,
  5807. WJSFDM: project.MedicalCode,
  5808. WJSFMC: project.ProjectName,
  5809. SJSHCSJ: time.Now(),
  5810. SJSCSJ: time.Now(),
  5811. XGBZ: 0,
  5812. }
  5813. service.BatchCreateTBDICZlxmdzzd(zlxmdzzd, rdb)
  5814. }
  5815. // 第三步:同步成功后,添加同步记录
  5816. upload := &sz.DataUpload{
  5817. SyncType: 1086,
  5818. OrgId: org_id,
  5819. SyncTime: time.Now().Unix(),
  5820. SyncResultType: 1,
  5821. CreateTime: time.Now().Unix(),
  5822. UpdateTime: time.Now().Unix(),
  5823. }
  5824. service.CreateUploadRecord(upload)
  5825. }
  5826. func SyncTBDICZlxmdzzd_pg(rdb *gorm.DB, org_id int64, hospital_id string) {
  5827. // 第一步:根据机构id获取上次同步时间
  5828. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1086)
  5829. var sync_time int64
  5830. if syncLastInfo.ID > 0 {
  5831. sync_time = syncLastInfo.SyncTime
  5832. } else {
  5833. sync_time = 0
  5834. }
  5835. //同步员工信息
  5836. projects, _ := service.FindProjectList(org_id, sync_time, time.Now().Unix())
  5837. //waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
  5838. // var staffs []*sz.TBDICPractitioner
  5839. for _, project := range projects {
  5840. zlxmdzzd := &sz.TBDICZlxmdzzd{
  5841. YLJGDM: hospital_id,
  5842. YNZLXMDM: strconv.FormatInt(project.ID, 10),
  5843. YNZLXMMC: project.ProjectName,
  5844. WJSFDM: project.MedicalCode,
  5845. WJSFMC: project.ProjectName,
  5846. SJSHCSJ: time.Now(),
  5847. SJSCSJ: time.Now(),
  5848. XGBZ: 0,
  5849. }
  5850. service.BatchCreateTBDICZlxmdzzd(zlxmdzzd, rdb)
  5851. }
  5852. // 第三步:同步成功后,添加同步记录
  5853. upload := &sz.DataUpload{
  5854. SyncType: 1086,
  5855. OrgId: org_id,
  5856. SyncTime: time.Now().Unix(),
  5857. SyncResultType: 1,
  5858. CreateTime: time.Now().Unix(),
  5859. UpdateTime: time.Now().Unix(),
  5860. }
  5861. service.CreateUploadRecord(upload)
  5862. }
  5863. func SyncTMDICTBED(rdb *gorm.DB, org_id int64, hospital_id string) {
  5864. // 第一步:根据机构id获取上次同步时间
  5865. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1002)
  5866. var sync_time int64
  5867. if syncLastInfo.ID > 0 {
  5868. sync_time = syncLastInfo.SyncTime
  5869. } else {
  5870. sync_time = 0
  5871. }
  5872. //同步透析床位分区
  5873. dm, _ := service.FindOrgDeviceNumber(org_id, sync_time, time.Now().Unix())
  5874. // var hdms []*sz.TM_DICT_BED
  5875. for _, item := range dm {
  5876. hdm := &sz.TM_DICT_BED{
  5877. YLJGDM: hospital_id,
  5878. CWBM: strconv.FormatInt(item.ID, 10),
  5879. CH: item.Number,
  5880. SSKSDM: "1001",
  5881. SSKSMC: "血透中心",
  5882. CWLX: "1",
  5883. CWZT: "0",
  5884. DYZLXMDJ: "0",
  5885. ZYH: "",
  5886. YWSCSJ: time.Now(),
  5887. SJSCSJ: time.Now(),
  5888. XGBZ: 0,
  5889. }
  5890. service.BatchCreateTMDICTBED(hdm, rdb)
  5891. }
  5892. upload := &sz.DataUpload{
  5893. SyncType: 1002,
  5894. OrgId: org_id,
  5895. SyncTime: time.Now().Unix(),
  5896. SyncResultType: 1,
  5897. CreateTime: time.Now().Unix(),
  5898. UpdateTime: time.Now().Unix(),
  5899. }
  5900. service.CreateUploadRecord(upload)
  5901. }
  5902. func SyncTMDICTBED_pg(rdb *gorm.DB, org_id int64, hospital_id string) {
  5903. // 第一步:根据机构id获取上次同步时间
  5904. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1002)
  5905. var sync_time int64
  5906. if syncLastInfo.ID > 0 {
  5907. sync_time = syncLastInfo.SyncTime
  5908. } else {
  5909. sync_time = 0
  5910. }
  5911. //同步透析床位分区
  5912. dm, _ := service.FindOrgDeviceNumber(org_id, sync_time, time.Now().Unix())
  5913. // var hdms []*sz.TM_DICT_BED
  5914. for _, item := range dm {
  5915. hdm := &sz.TM_DICT_BED{
  5916. YLJGDM: hospital_id,
  5917. CWBM: strconv.FormatInt(item.ID, 10),
  5918. CH: item.Number,
  5919. SSKSDM: "1001",
  5920. SSKSMC: "血透中心",
  5921. CWLX: "1",
  5922. CWZT: "0",
  5923. DYZLXMDJ: "0",
  5924. ZYH: "",
  5925. YWSCSJ: time.Now(),
  5926. SJSCSJ: time.Now(),
  5927. XGBZ: 0,
  5928. }
  5929. service.BatchCreateTMDICTBED(hdm, rdb)
  5930. }
  5931. upload := &sz.DataUpload{
  5932. SyncType: 1002,
  5933. OrgId: org_id,
  5934. SyncTime: time.Now().Unix(),
  5935. SyncResultType: 1,
  5936. CreateTime: time.Now().Unix(),
  5937. UpdateTime: time.Now().Unix(),
  5938. }
  5939. service.CreateUploadRecord(upload)
  5940. }
  5941. // 14. 门诊患者信息表
  5942. func SyncTBMZPatientInformation(rdb *gorm.DB, org_id int64, hospital_id string) {
  5943. // 第一步:根据机构id获取上次同步时间
  5944. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1003)
  5945. var sync_time int64
  5946. if syncLastInfo.ID > 0 {
  5947. sync_time = syncLastInfo.SyncTime
  5948. } else {
  5949. sync_time = 0
  5950. }
  5951. //同步员工信息
  5952. patients, _ := service.FindOrgPatientData(org_id, sync_time, time.Now().Unix())
  5953. for _, patient := range patients {
  5954. var xbmc string
  5955. if patient.Gender == 1 {
  5956. xbmc = "男"
  5957. } else {
  5958. xbmc = "女"
  5959. }
  5960. tm := time.Unix(patient.Birthday, 0)
  5961. ghrq := tm.Format("20060102")
  5962. p := &sz.TB_MZ_Patient_Information{
  5963. KH: patient.DialysisNo,
  5964. KLX: "3",
  5965. YLJGDM: hospital_id,
  5966. FKDQ: "440300",
  5967. ZJHM: patient.IdCardNo,
  5968. ZJLXDM: "01",
  5969. ZJLXMC: "身份证",
  5970. XM: patient.Name,
  5971. CSRQ: ghrq,
  5972. MZDM: "1",
  5973. MZMC: "汉族",
  5974. GJDM: "156",
  5975. GJMC: "中国",
  5976. SJHM: patient.Phone,
  5977. XBDM: strconv.FormatInt(patient.Gender, 10),
  5978. XBMC: xbmc,
  5979. HZLXDM: "1",
  5980. HZLXMC: "本市",
  5981. YWSCSJ: time.Unix(patient.CreatedTime, 0),
  5982. SJSCSJ: time.Now(),
  5983. XGBZ: 0,
  5984. }
  5985. service.BatchCreateTB_MZ_Patient_Information(p, rdb)
  5986. }
  5987. upload := &sz.DataUpload{
  5988. SyncType: 1003,
  5989. OrgId: org_id,
  5990. SyncTime: time.Now().Unix(),
  5991. SyncResultType: 1,
  5992. CreateTime: time.Now().Unix(),
  5993. UpdateTime: time.Now().Unix(),
  5994. }
  5995. service.CreateUploadRecord(upload)
  5996. }
  5997. func SyncTBMZPatientInformation_pg(rdb *gorm.DB, org_id int64, hospital_id string) {
  5998. // 第一步:根据机构id获取上次同步时间
  5999. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1003)
  6000. var sync_time int64
  6001. if syncLastInfo.ID > 0 {
  6002. sync_time = syncLastInfo.SyncTime
  6003. } else {
  6004. sync_time = 0
  6005. }
  6006. //同步员工信息
  6007. patients, _ := service.FindOrgPatientData(org_id, sync_time, time.Now().Unix())
  6008. for _, patient := range patients {
  6009. var xbmc string
  6010. if patient.Gender == 1 {
  6011. xbmc = "男"
  6012. } else {
  6013. xbmc = "女"
  6014. }
  6015. tm := time.Unix(patient.Birthday, 0)
  6016. ghrq := tm.Format("20060102")
  6017. p := &sz.TB_MZ_Patient_Information{
  6018. KH: patient.DialysisNo,
  6019. KLX: "3",
  6020. YLJGDM: hospital_id,
  6021. FKDQ: "440300",
  6022. ZJHM: patient.IdCardNo,
  6023. ZJLXDM: "01",
  6024. ZJLXMC: "身份证",
  6025. XM: patient.Name,
  6026. CSRQ: ghrq,
  6027. MZDM: "1",
  6028. MZMC: "汉族",
  6029. GJDM: "156",
  6030. GJMC: "中国",
  6031. SJHM: patient.Phone,
  6032. XBDM: strconv.FormatInt(patient.Gender, 10),
  6033. XBMC: xbmc,
  6034. HZLXDM: "1",
  6035. HZLXMC: "本市",
  6036. YWSCSJ: time.Unix(patient.CreatedTime, 0),
  6037. SJSCSJ: time.Now(),
  6038. XGBZ: 0,
  6039. }
  6040. service.BatchCreateTB_MZ_Patient_Information(p, rdb)
  6041. }
  6042. upload := &sz.DataUpload{
  6043. SyncType: 1003,
  6044. OrgId: org_id,
  6045. SyncTime: time.Now().Unix(),
  6046. SyncResultType: 1,
  6047. CreateTime: time.Now().Unix(),
  6048. UpdateTime: time.Now().Unix(),
  6049. }
  6050. service.CreateUploadRecord(upload)
  6051. }
  6052. // 15. 挂号表
  6053. func SyncTBHISMZReg(rdb *gorm.DB, org_id int64, hospital_id string) {
  6054. // 第一步:根据机构id获取上次同步时间
  6055. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1004)
  6056. var sync_time int64
  6057. if syncLastInfo.ID > 0 {
  6058. sync_time = syncLastInfo.SyncTime
  6059. } else {
  6060. sync_time = 1714492800
  6061. }
  6062. //同步员工信息
  6063. patients, _ := service.FindOrgHisPatient(org_id, sync_time, time.Now().Unix())
  6064. for _, patient := range patients {
  6065. tm := time.Unix(patient.Ctime, 0)
  6066. ghrq := tm.Format("20060102")
  6067. gthsj := tm.Format("2006-01-02 15:04:05")
  6068. patientInfo, _ := service.FindOrgPatientInfoById(patient.PatientId)
  6069. p := &sz.TB_HIS_MZ_Reg{
  6070. GHRQ: ghrq,
  6071. JZLSH: strconv.FormatInt(patient.ID, 10),
  6072. GTHBZ: "1",
  6073. YLJGDM: hospital_id,
  6074. STFBH: strconv.FormatInt(patient.ID, 10),
  6075. GTHSJ: gthsj,
  6076. GHHX: strconv.FormatInt(patient.ID, 10),
  6077. GHLB: "04",
  6078. GHMC: "专科门诊",
  6079. YLFYLYDM: "01",
  6080. YLBXLBDM: "01",
  6081. YBZHBZ: "0000000000000000",
  6082. SSJYBZ: "1",
  6083. KSBM: "1001",
  6084. KSMC: "血透中心",
  6085. YSBM: "2232",
  6086. YSXM: "赵劲",
  6087. TXBZ: "0",
  6088. WDBZ: "1",
  6089. KH: patientInfo.DialysisNo,
  6090. KLX: "3",
  6091. SFYY: "0",
  6092. GHRCBS: "0",
  6093. GHFY: patient.RegisterCost,
  6094. JMGHF: patient.RegisterCost,
  6095. ZJF: patient.TreatmentCost,
  6096. JMZJF: patient.TreatmentCost,
  6097. QTF: "0",
  6098. CZYBM: "1001",
  6099. CZYXM: "Phony",
  6100. GHFXM: "003110000060000-311000006",
  6101. ZJFXM: "003110000060000-311000006",
  6102. SJSCSJ: time.Now(),
  6103. XGBZ: 0,
  6104. }
  6105. service.BatchCreateTB_HIS_MZ_Reg(p, rdb)
  6106. }
  6107. upload := &sz.DataUpload{
  6108. SyncType: 1004,
  6109. OrgId: org_id,
  6110. SyncTime: time.Now().Unix(),
  6111. SyncResultType: 1,
  6112. CreateTime: time.Now().Unix(),
  6113. UpdateTime: time.Now().Unix(),
  6114. }
  6115. service.CreateUploadRecord(upload)
  6116. }
  6117. func SyncTBHISMZReg_pg(rdb *gorm.DB, org_id int64, hospital_id string) {
  6118. // 第一步:根据机构id获取上次同步时间
  6119. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1004)
  6120. var sync_time int64
  6121. if syncLastInfo.ID > 0 {
  6122. sync_time = syncLastInfo.SyncTime
  6123. } else {
  6124. sync_time = 1714492800
  6125. }
  6126. //同步员工信息
  6127. patients, _ := service.FindOrgHisPatient(org_id, sync_time, time.Now().Unix())
  6128. for _, patient := range patients {
  6129. tm := time.Unix(patient.Ctime, 0)
  6130. ghrq := tm.Format("20060102")
  6131. gthsj := tm.Format("2006-01-02 15:04:05")
  6132. patientInfo, _ := service.FindOrgPatientInfoById(patient.PatientId)
  6133. p := &sz.TB_HIS_MZ_Reg{
  6134. GHRQ: ghrq,
  6135. JZLSH: strconv.FormatInt(patient.ID, 10),
  6136. GTHBZ: "1",
  6137. YLJGDM: hospital_id,
  6138. STFBH: strconv.FormatInt(patient.ID, 10),
  6139. GTHSJ: gthsj,
  6140. GHHX: strconv.FormatInt(patient.ID, 10),
  6141. GHLB: "04",
  6142. GHMC: "专科门诊",
  6143. YLFYLYDM: "01",
  6144. YLBXLBDM: "01",
  6145. YBZHBZ: "0000000000000000",
  6146. SSJYBZ: "1",
  6147. KSBM: "1001",
  6148. KSMC: "血透中心",
  6149. YSBM: "2232",
  6150. YSXM: "赵劲",
  6151. TXBZ: "0",
  6152. WDBZ: "1",
  6153. KH: patientInfo.DialysisNo,
  6154. KLX: "3",
  6155. SFYY: "0",
  6156. GHRCBS: "0",
  6157. GHFXM: "003110000060000-311000006",
  6158. ZJFXM: "003110000060000-311000006",
  6159. GHFY: patient.RegisterCost,
  6160. JMGHF: patient.RegisterCost,
  6161. ZJF: patient.TreatmentCost,
  6162. JMZJF: patient.TreatmentCost,
  6163. QTF: "0",
  6164. CZYBM: "1001",
  6165. CZYXM: "Phony",
  6166. SJSCSJ: time.Now(),
  6167. XGBZ: 0,
  6168. }
  6169. service.BatchCreateTB_HIS_MZ_Reg(p, rdb)
  6170. }
  6171. upload := &sz.DataUpload{
  6172. SyncType: 1004,
  6173. OrgId: org_id,
  6174. SyncTime: time.Now().Unix(),
  6175. SyncResultType: 1,
  6176. CreateTime: time.Now().Unix(),
  6177. UpdateTime: time.Now().Unix(),
  6178. }
  6179. service.CreateUploadRecord(upload)
  6180. }
  6181. func SyncTB_STAT_YWL_Report(rdb *gorm.DB, org_id int64, hospital_id string) {
  6182. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1068)
  6183. var sync_time int64
  6184. if syncLastInfo.ID > 0 {
  6185. sync_time = syncLastInfo.SyncTime
  6186. } else {
  6187. sync_time = 1714492800
  6188. }
  6189. syncDate := time.Unix(sync_time, 0).Format("20060102")
  6190. tempDate := time.Now().Format("20060102")
  6191. sync_time_date := time.Unix(sync_time, 0).Format("2006-01-02")
  6192. loc, _ := time.LoadLocation("Local")
  6193. timeLayout := "2006-01-02"
  6194. sync_times, _ := time.ParseInLocation(timeLayout+" 15:04:05", sync_time_date+" 00:00:00", loc)
  6195. sync_time_dd := sync_times.Unix()
  6196. for {
  6197. if syncDate < tempDate {
  6198. // 获取门诊人数
  6199. patientCnt, _ := service.FindOrgHisPatientCnt(org_id, sync_time_dd)
  6200. // 门急诊药品费用
  6201. amtOne, _ := service.FindOrgHisPatientCntTwo(org_id, sync_time_dd)
  6202. fmt.Println(amtOne)
  6203. // 门急诊医疗费用
  6204. amtTwo, _ := service.FindOrgHisPatientCntTwo(org_id, sync_time_dd)
  6205. p := &sz.TB_STAT_YWL_Report{
  6206. YLJGDM: hospital_id,
  6207. KSBM: "1001",
  6208. YWSJ: syncDate,
  6209. MZRC: patientCnt,
  6210. JZRC: 0,
  6211. TJRC: 0,
  6212. RYRC: 0,
  6213. CYRC: 0,
  6214. CGRC: 0,
  6215. RGBLS: 0,
  6216. ZYRS: 0,
  6217. SYCWS: 37,
  6218. BZCWS: 37,
  6219. SJSYCWS: 37,
  6220. KCS: 0,
  6221. KFTSCS: 0,
  6222. JTBCS: 0,
  6223. SSLS: 0,
  6224. MJZYLFY: amtOne.Sumamt,
  6225. ZYYLFY: 0,
  6226. MJZYPFY: amtTwo.Sumamt,
  6227. ZYYPFY: 0,
  6228. MJZYBYLFY: amtOne.Amt,
  6229. ZYYBYLFY: 0,
  6230. MJZYBYPFY: amtTwo.Amt,
  6231. ZYYBYPFY: 0,
  6232. ZYSJFSYS: 0,
  6233. CYYLSR: 0,
  6234. CYYPSR: 0,
  6235. CYYBYLSR: 0,
  6236. CYYBYPSR: 0,
  6237. SJSCSJ: time.Now(),
  6238. XGBZ: 0,
  6239. }
  6240. service.BatchCreateTB_STAT_YWL_Report(p, rdb)
  6241. sync_time = sync_time + 86400
  6242. syncDate = time.Unix(sync_time, 0).Format("20060102")
  6243. } else {
  6244. upload := &sz.DataUpload{
  6245. SyncType: 1068,
  6246. OrgId: org_id,
  6247. SyncTime: time.Now().Unix(),
  6248. SyncResultType: 1,
  6249. CreateTime: time.Now().Unix(),
  6250. UpdateTime: time.Now().Unix(),
  6251. }
  6252. service.CreateUploadRecord(upload)
  6253. break
  6254. }
  6255. }
  6256. }
  6257. func SyncTB_STAT_YWL_Report_pg(rdb *gorm.DB, org_id int64, hospital_id string) {
  6258. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1068)
  6259. var sync_time int64
  6260. if syncLastInfo.ID > 0 {
  6261. sync_time = syncLastInfo.SyncTime
  6262. } else {
  6263. sync_time = 1714492800
  6264. }
  6265. syncDate := time.Unix(sync_time, 0).Format("20060102")
  6266. tempDate := time.Now().Format("20060102")
  6267. sync_time_date := time.Unix(sync_time, 0).Format("2006-01-02")
  6268. loc, _ := time.LoadLocation("Local")
  6269. timeLayout := "2006-01-02"
  6270. sync_times, _ := time.ParseInLocation(timeLayout+" 15:04:05", sync_time_date+" 00:00:00", loc)
  6271. sync_time_dd := sync_times.Unix()
  6272. for {
  6273. if syncDate < tempDate {
  6274. // 获取门诊人数
  6275. patientCnt, _ := service.FindOrgHisPatientCnt(org_id, sync_time_dd)
  6276. // 门急诊药品费用
  6277. amtOne, _ := service.FindOrgHisPatientCntTwo(org_id, sync_time_dd)
  6278. fmt.Println(amtOne)
  6279. // 门急诊医疗费用
  6280. amtTwo, _ := service.FindOrgHisPatientCntTwo(org_id, sync_time_dd)
  6281. p := &sz.TB_STAT_YWL_Report{
  6282. YLJGDM: hospital_id,
  6283. KSBM: "1001",
  6284. YWSJ: syncDate,
  6285. MZRC: patientCnt,
  6286. JZRC: 0,
  6287. TJRC: 0,
  6288. RYRC: 0,
  6289. CYRC: 0,
  6290. CGRC: 0,
  6291. RGBLS: 0,
  6292. ZYRS: 0,
  6293. SYCWS: 37,
  6294. BZCWS: 37,
  6295. SJSYCWS: 37,
  6296. KCS: 0,
  6297. KFTSCS: 0,
  6298. JTBCS: 0,
  6299. SSLS: 0,
  6300. MJZYLFY: amtOne.Sumamt,
  6301. ZYYLFY: 0,
  6302. MJZYPFY: amtTwo.Sumamt,
  6303. ZYYPFY: 0,
  6304. MJZYBYLFY: amtOne.Amt,
  6305. ZYYBYLFY: 0,
  6306. MJZYBYPFY: amtTwo.Amt,
  6307. ZYYBYPFY: 0,
  6308. ZYSJFSYS: 0,
  6309. CYYLSR: 0,
  6310. CYYPSR: 0,
  6311. CYYBYLSR: 0,
  6312. CYYBYPSR: 0,
  6313. SJSCSJ: time.Now(),
  6314. XGBZ: 0,
  6315. }
  6316. service.BatchCreateTB_STAT_YWL_Report(p, rdb)
  6317. sync_time = sync_time + 86400
  6318. syncDate = time.Unix(sync_time, 0).Format("20060102")
  6319. } else {
  6320. upload := &sz.DataUpload{
  6321. SyncType: 1068,
  6322. OrgId: org_id,
  6323. SyncTime: time.Now().Unix(),
  6324. SyncResultType: 1,
  6325. CreateTime: time.Now().Unix(),
  6326. UpdateTime: time.Now().Unix(),
  6327. }
  6328. service.CreateUploadRecord(upload)
  6329. break
  6330. }
  6331. }
  6332. }
  6333. // 14. 诊断明细表
  6334. func SyncTB_YL_MZ_Medical_Record(rdb *gorm.DB, org_id int64, hospital_id string) {
  6335. // 第一步:根据机构id获取上次同步时间
  6336. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1005)
  6337. var sync_time int64
  6338. if syncLastInfo.ID > 0 {
  6339. sync_time = syncLastInfo.SyncTime
  6340. } else {
  6341. sync_time = 1714492800
  6342. }
  6343. //同步员工信息
  6344. patients, _ := service.FindOrgHisPatient(org_id, sync_time, time.Now().Unix())
  6345. for _, patient := range patients {
  6346. patientInfo, _ := service.FindOrgPatientInfoById(patient.PatientId)
  6347. tm := time.Unix(patient.RecordDate, 0)
  6348. ghrq := tm.Format("2006-01-02")
  6349. p := &sz.TB_YL_MZ_Medical_Record{
  6350. YLJGDM: hospital_id,
  6351. JZLSH: strconv.FormatInt(patient.ID, 10),
  6352. KH: patientInfo.DialysisNo,
  6353. KLX: "3",
  6354. MJZH: strconv.FormatInt(patient.ID, 10),
  6355. HZXM: patient.Name,
  6356. JZLX: "04",
  6357. CZBZ: "2",
  6358. SFTH: "0",
  6359. YLBXLBDM: "01",
  6360. YLFKFSDM: "01",
  6361. TXBZ: "0",
  6362. YBZHBZ: "0000000000000000",
  6363. WDBZ: "1",
  6364. SFSYZYZLJS: "0",
  6365. ZYZLJSLB: "其他",
  6366. SFSYZYZHLJS: "0",
  6367. JZKSBM: "1001",
  6368. JZKSMC: "血透中心",
  6369. JZKSRQ: ghrq,
  6370. ZZYSGH: "1001",
  6371. ZZYSXM: "Phony",
  6372. BMLX: "01",
  6373. JZZDBM: "N18.500",
  6374. JZZDSM: "慢性肾脏病5期",
  6375. JZZTDM: "3",
  6376. JZZTMC: "结束就诊",
  6377. ZS: "慢性肾功能不全",
  6378. ZZMS: "慢性肾脏病5期,需血液透析",
  6379. JZJSSJ: ghrq,
  6380. YWSCSJ: time.Now(),
  6381. SJSCSJ: time.Now(),
  6382. XGBZ: 0,
  6383. }
  6384. service.BatchCreateTB_YL_MZ_Medical_Record(p, rdb)
  6385. }
  6386. upload := &sz.DataUpload{
  6387. SyncType: 1005,
  6388. OrgId: org_id,
  6389. SyncTime: time.Now().Unix(),
  6390. SyncResultType: 1,
  6391. CreateTime: time.Now().Unix(),
  6392. UpdateTime: time.Now().Unix(),
  6393. }
  6394. service.CreateUploadRecord(upload)
  6395. }
  6396. // 14. 16. 门诊就诊记录表
  6397. func SyncTB_Diagnosis_Detail(rdb *gorm.DB, org_id int64, hospital_id string) {
  6398. // 第一步:根据机构id获取上次同步时间
  6399. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1105)
  6400. var sync_time int64
  6401. if syncLastInfo.ID > 0 {
  6402. sync_time = syncLastInfo.SyncTime
  6403. } else {
  6404. sync_time = 1714492800
  6405. }
  6406. //同步员工信息
  6407. patients, _ := service.FindOrgHisPatient(org_id, sync_time, time.Now().Unix())
  6408. for _, patient := range patients {
  6409. patientInfo, _ := service.FindOrgPatientInfoById(patient.PatientId)
  6410. tm := time.Unix(patient.RecordDate, 0)
  6411. ghrq := tm.Format("2006-01-02")
  6412. p := &sz.TB_Diagnosis_Detail{
  6413. ZYZDLSH: strconv.FormatInt(patient.ID, 10),
  6414. YLJGDM: hospital_id,
  6415. JZLSH: strconv.FormatInt(patient.ID, 10),
  6416. MZZYBZ: "1",
  6417. KH: patientInfo.DialysisNo,
  6418. KLX: "3",
  6419. ZDLXQF: "3",
  6420. ZDLB: "02",
  6421. ZDSJ: ghrq,
  6422. ZDBM: "N18.500",
  6423. BMLX: "02",
  6424. CYZDBZ: "1",
  6425. YZDBZ: "2",
  6426. CRBBZ: "0",
  6427. RYBQ: "4",
  6428. JLRQSJ: time.Now(),
  6429. SJSCSJ: time.Now(),
  6430. XGBZ: 0,
  6431. }
  6432. service.BatchCreateTB_Diagnosis_Detail(p, rdb)
  6433. }
  6434. upload := &sz.DataUpload{
  6435. SyncType: 1105,
  6436. OrgId: org_id,
  6437. SyncTime: time.Now().Unix(),
  6438. SyncResultType: 1,
  6439. CreateTime: time.Now().Unix(),
  6440. UpdateTime: time.Now().Unix(),
  6441. }
  6442. service.CreateUploadRecord(upload)
  6443. }
  6444. func SyncTB_Diagnosis_Detail_pg(rdb *gorm.DB, org_id int64, hospital_id string) {
  6445. // 第一步:根据机构id获取上次同步时间
  6446. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1105)
  6447. var sync_time int64
  6448. if syncLastInfo.ID > 0 {
  6449. sync_time = syncLastInfo.SyncTime
  6450. } else {
  6451. sync_time = 1714492800
  6452. }
  6453. //同步员工信息
  6454. patients, _ := service.FindOrgHisPatient(org_id, sync_time, time.Now().Unix())
  6455. for _, patient := range patients {
  6456. patientInfo, _ := service.FindOrgPatientInfoById(patient.PatientId)
  6457. tm := time.Unix(patient.RecordDate, 0)
  6458. ghrq := tm.Format("2006-01-02")
  6459. p := &sz.TB_Diagnosis_Detail{
  6460. ZYZDLSH: strconv.FormatInt(patient.ID, 10),
  6461. YLJGDM: hospital_id,
  6462. JZLSH: strconv.FormatInt(patient.ID, 10),
  6463. MZZYBZ: "1",
  6464. KH: patientInfo.DialysisNo,
  6465. KLX: "3",
  6466. ZDLXQF: "3",
  6467. ZDLB: "02",
  6468. ZDSJ: ghrq,
  6469. ZDBM: "N18.500",
  6470. BMLX: "02",
  6471. CYZDBZ: "1",
  6472. YZDBZ: "2",
  6473. CRBBZ: "0",
  6474. RYBQ: "4",
  6475. JLRQSJ: time.Now(),
  6476. SJSCSJ: time.Now(),
  6477. XGBZ: 0,
  6478. }
  6479. service.BatchCreateTB_Diagnosis_Detail(p, rdb)
  6480. }
  6481. upload := &sz.DataUpload{
  6482. SyncType: 1105,
  6483. OrgId: org_id,
  6484. SyncTime: time.Now().Unix(),
  6485. SyncResultType: 1,
  6486. CreateTime: time.Now().Unix(),
  6487. UpdateTime: time.Now().Unix(),
  6488. }
  6489. service.CreateUploadRecord(upload)
  6490. }
  6491. func SyncTB_YL_MZ_Medical_Record_pg(rdb *gorm.DB, org_id int64, hospital_id string) {
  6492. // 第一步:根据机构id获取上次同步时间
  6493. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1005)
  6494. var sync_time int64
  6495. if syncLastInfo.ID > 0 {
  6496. sync_time = syncLastInfo.SyncTime
  6497. } else {
  6498. sync_time = 1714492800
  6499. }
  6500. //同步员工信息
  6501. patients, _ := service.FindOrgHisPatient(org_id, sync_time, time.Now().Unix())
  6502. for _, patient := range patients {
  6503. patientInfo, _ := service.FindOrgPatientInfoById(patient.PatientId)
  6504. tm := time.Unix(patient.RecordDate, 0)
  6505. ghrq := tm.Format("2006-01-02")
  6506. p := &sz.TB_YL_MZ_Medical_Record{
  6507. YLJGDM: hospital_id,
  6508. JZLSH: strconv.FormatInt(patient.ID, 10),
  6509. KH: patientInfo.DialysisNo,
  6510. KLX: "3",
  6511. MJZH: strconv.FormatInt(patient.ID, 10),
  6512. HZXM: patient.Name,
  6513. NLS: (time.Now().Unix() - patient.Birthday) / 31536000,
  6514. JZLX: "04",
  6515. CZBZ: "2",
  6516. SFTH: "0",
  6517. YLBXLBDM: "01",
  6518. YLFKFSDM: "01",
  6519. TXBZ: "0",
  6520. YBZHBZ: "0000000000000000",
  6521. WDBZ: "1",
  6522. SFSYZYZLJS: "0",
  6523. ZYZLJSLB: "其他",
  6524. SFSYZYZHLJS: "0",
  6525. JZKSBM: "1001",
  6526. JZKSMC: "血透中心",
  6527. JZKSRQ: ghrq,
  6528. ZZYSGH: "1001",
  6529. ZZYSXM: "Phony",
  6530. BMLX: "01",
  6531. JZZDBM: "N18.500",
  6532. JZZDSM: "慢性肾脏病5期",
  6533. JZZTDM: "3",
  6534. JZZTMC: "结束就诊",
  6535. ZS: "慢性肾功能不全",
  6536. ZZMS: "慢性肾脏病5期,需血液透析",
  6537. JZJSSJ: ghrq,
  6538. YWSCSJ: time.Now(),
  6539. SJSCSJ: time.Now(),
  6540. XGBZ: 0,
  6541. }
  6542. service.BatchCreateTB_YL_MZ_Medical_Record(p, rdb)
  6543. }
  6544. upload := &sz.DataUpload{
  6545. SyncType: 1005,
  6546. OrgId: org_id,
  6547. SyncTime: time.Now().Unix(),
  6548. SyncResultType: 1,
  6549. CreateTime: time.Now().Unix(),
  6550. UpdateTime: time.Now().Unix(),
  6551. }
  6552. service.CreateUploadRecord(upload)
  6553. }
  6554. // 17. 门诊处方主表
  6555. func SyncTB_CIS_Prescription(rdb *gorm.DB, org_id int64, hospital_id string) {
  6556. // 第一步:根据机构id获取上次同步时间
  6557. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1006)
  6558. var sync_time int64
  6559. if syncLastInfo.ID > 0 {
  6560. sync_time = syncLastInfo.SyncTime
  6561. } else {
  6562. sync_time = 1714492800
  6563. }
  6564. //同步员工信息
  6565. patients, _ := service.FindOrgHisPrescriptionInfo(org_id, sync_time, time.Now().Unix())
  6566. for _, patient := range patients {
  6567. patient_info, _ := service.FindOrgHisPatientInfo(org_id, patient.RecordDate, patient.PatientId)
  6568. patientInfo, _ := service.FindOrgPatientInfoById(patient.PatientId)
  6569. adviceinfo, _ := service.FindOrgHisDoctorAdviceInfoByPid(org_id, patient.ID)
  6570. if patient_info.ID > 0 {
  6571. var cfypje float64
  6572. for _, advice := range adviceinfo {
  6573. cfypje = cfypje + advice.PrescribingNumber*advice.Price
  6574. }
  6575. tm := time.Unix(patient.Ctime, 0)
  6576. ghrq := tm.Format("2006-01-02")
  6577. p := &sz.TB_CIS_Prescription{
  6578. CYH: strconv.FormatInt(patient.ID, 10),
  6579. YLJGDM: hospital_id,
  6580. JZLSH: strconv.FormatInt(patient_info.ID, 10),
  6581. KH: patientInfo.DialysisNo,
  6582. KLX: "3",
  6583. CFLX: "1",
  6584. YPLX: "3",
  6585. ZYYPCFLB: "9",
  6586. CFJS: "0",
  6587. JZKSDM: "1001",
  6588. JZKSMC: "血透中心",
  6589. KFYS: "1001",
  6590. KFYSXM: "Phony",
  6591. KFRQ: ghrq,
  6592. CFLRSJ: ghrq,
  6593. SGCFBZ: "0",
  6594. CFYPJE: cfypje,
  6595. XYZDDM: "N18.500",
  6596. XYZDMC: "慢性肾脏病5期",
  6597. SJSCSJ: time.Now(),
  6598. XGBZ: 0,
  6599. }
  6600. service.BatchCreateTB_CIS_Prescription(p, rdb)
  6601. }
  6602. }
  6603. upload := &sz.DataUpload{
  6604. SyncType: 1006,
  6605. OrgId: org_id,
  6606. SyncTime: time.Now().Unix(),
  6607. SyncResultType: 1,
  6608. CreateTime: time.Now().Unix(),
  6609. UpdateTime: time.Now().Unix(),
  6610. }
  6611. service.CreateUploadRecord(upload)
  6612. }
  6613. func SyncTB_CIS_Prescription_pg(rdb *gorm.DB, org_id int64, hospital_id string) {
  6614. // 第一步:根据机构id获取上次同步时间
  6615. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1006)
  6616. var sync_time int64
  6617. if syncLastInfo.ID > 0 {
  6618. sync_time = syncLastInfo.SyncTime
  6619. } else {
  6620. sync_time = 1714492800
  6621. }
  6622. //同步员工信息
  6623. patients, _ := service.FindOrgHisPrescriptionInfo(org_id, sync_time, time.Now().Unix())
  6624. for _, patient := range patients {
  6625. patient_info, _ := service.FindOrgHisPatientInfo(org_id, patient.RecordDate, patient.PatientId)
  6626. patientInfo, _ := service.FindOrgPatientInfoById(patient.PatientId)
  6627. adviceinfo, _ := service.FindOrgHisDoctorAdviceInfoByPid(org_id, patient.ID)
  6628. if patient_info.ID > 0 {
  6629. var cfypje float64
  6630. for _, advice := range adviceinfo {
  6631. cfypje = cfypje + advice.PrescribingNumber*advice.Price
  6632. }
  6633. tm := time.Unix(patient.Ctime, 0)
  6634. ghrq := tm.Format("2006-01-02")
  6635. p := &sz.TB_CIS_Prescription{
  6636. CYH: strconv.FormatInt(patient.ID, 10),
  6637. YLJGDM: hospital_id,
  6638. JZLSH: strconv.FormatInt(patient_info.ID, 10),
  6639. KH: patientInfo.DialysisNo,
  6640. KLX: "3",
  6641. CFLX: "1",
  6642. YPLX: "3",
  6643. ZYYPCFLB: "9",
  6644. CFJS: "0",
  6645. JZKSDM: "1001",
  6646. JZKSMC: "血透中心",
  6647. KFYS: "1001",
  6648. KFYSXM: "Phony",
  6649. KFRQ: ghrq,
  6650. CFLRSJ: ghrq,
  6651. SGCFBZ: "0",
  6652. CFYPJE: cfypje,
  6653. TFBZ: "2",
  6654. XYZDDM: "N18.500",
  6655. XYZDMC: "慢性肾脏病5期",
  6656. SJSCSJ: time.Now(),
  6657. XGBZ: 0,
  6658. }
  6659. service.BatchCreateTB_CIS_Prescription(p, rdb)
  6660. }
  6661. }
  6662. upload := &sz.DataUpload{
  6663. SyncType: 1006,
  6664. OrgId: org_id,
  6665. SyncTime: time.Now().Unix(),
  6666. SyncResultType: 1,
  6667. CreateTime: time.Now().Unix(),
  6668. UpdateTime: time.Now().Unix(),
  6669. }
  6670. service.CreateUploadRecord(upload)
  6671. }
  6672. // 门诊处方明细表
  6673. func SyncTB_CIS_Prescription_Detail(rdb *gorm.DB, org_id int64, hospital_id string) {
  6674. // 第一步:根据机构id获取上次同步时间
  6675. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1007)
  6676. var sync_time int64
  6677. if syncLastInfo.ID > 0 {
  6678. sync_time = syncLastInfo.SyncTime
  6679. } else {
  6680. sync_time = 1714492800
  6681. }
  6682. //同步员工信息
  6683. patients, _ := service.FindOrgHisDoctorAdviceInfo(org_id, sync_time, time.Now().Unix())
  6684. for _, patient := range patients {
  6685. prescription, _ := service.FindOrgHisPrescriptionById(patient.PrescriptionId)
  6686. prescription_info, _ := service.FindOrgHisPrescriptionInfoByNumber(org_id, prescription.PrescriptionNumber)
  6687. patient_info, _ := service.FindOrgHisPatientInfo(org_id, prescription_info.RecordDate, prescription_info.PatientId)
  6688. basedrug, _ := service.FindBaseDrugLibById(patient.DrugId)
  6689. if patient_info.ID > 0 {
  6690. var yf, ypyf string
  6691. if len(patient.DeliveryWay) == 0 || patient.DeliveryWay == "口服" {
  6692. yf = "1"
  6693. ypyf = "口服"
  6694. } else {
  6695. yf = "4"
  6696. ypyf = "注射用药"
  6697. }
  6698. p := &sz.TB_CIS_Prescription_Detail{
  6699. CYH: strconv.FormatInt(prescription.ID, 10),
  6700. CFMXH: prescription.PrescriptionNumber,
  6701. YLJGDM: hospital_id,
  6702. JZLSH: strconv.FormatInt(patient_info.ID, 10),
  6703. XMBM: strconv.FormatInt(patient.DrugId, 10),
  6704. XMBMYB: patient.MedListCodg,
  6705. XMMC: patient.AdviceName,
  6706. XMSL: patient.PrescribingNumber,
  6707. XMDW: patient.PrescribingNumberUnit,
  6708. XMDJ: patient.Price,
  6709. XMJE: patient.Price * patient.PrescribingNumber,
  6710. XMLB: "01",
  6711. YWFLDM: "1",
  6712. SFJJ: "0",
  6713. SFPS: "0",
  6714. YPGG: basedrug.DrugSpec,
  6715. SCPH: basedrug.SocialSecurityDirectoryCode,
  6716. YXQZ: "2023-09-01",
  6717. SYPCDM: "QD",
  6718. SYPC: "每天一次",
  6719. JL: patient.SingleDose,
  6720. DW: patient.SingleDoseUnit,
  6721. MCSL: patient.SingleDose,
  6722. MCDW: patient.SingleDoseUnit,
  6723. YF: yf,
  6724. YPYF: ypyf,
  6725. YYTS: patient.Day,
  6726. YWSYZJL: patient.PrescribingNumber,
  6727. YWSYZJLDW: patient.PrescribingNumberUnit,
  6728. SJSCSJ: time.Now(),
  6729. XGBZ: 0,
  6730. }
  6731. service.BatchCreateTB_CIS_Prescription_Detail(p, rdb)
  6732. }
  6733. }
  6734. upload := &sz.DataUpload{
  6735. SyncType: 1007,
  6736. OrgId: org_id,
  6737. SyncTime: time.Now().Unix(),
  6738. SyncResultType: 1,
  6739. CreateTime: time.Now().Unix(),
  6740. UpdateTime: time.Now().Unix(),
  6741. }
  6742. service.CreateUploadRecord(upload)
  6743. }
  6744. func SyncTB_CIS_Prescription_Detail_pg(rdb *gorm.DB, org_id int64, hospital_id string) {
  6745. // 第一步:根据机构id获取上次同步时间
  6746. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1007)
  6747. var sync_time int64
  6748. if syncLastInfo.ID > 0 {
  6749. sync_time = syncLastInfo.SyncTime
  6750. } else {
  6751. sync_time = 1714492800
  6752. }
  6753. //同步员工信息
  6754. patients, _ := service.FindOrgHisDoctorAdviceInfo(org_id, sync_time, time.Now().Unix())
  6755. for _, patient := range patients {
  6756. prescription, _ := service.FindOrgHisPrescriptionById(patient.PrescriptionId)
  6757. prescription_info, _ := service.FindOrgHisPrescriptionInfoByNumber(org_id, prescription.PrescriptionNumber)
  6758. patient_info, _ := service.FindOrgHisPatientInfo(org_id, prescription_info.RecordDate, prescription_info.PatientId)
  6759. basedrug, _ := service.FindBaseDrugLibById(patient.DrugId)
  6760. if patient_info.ID > 0 {
  6761. var yf, ypyf string
  6762. if len(patient.DeliveryWay) == 0 || patient.DeliveryWay == "口服" {
  6763. yf = "1"
  6764. ypyf = "口服"
  6765. } else {
  6766. yf = "4"
  6767. ypyf = "注射用药"
  6768. }
  6769. if len(patient.MedListCodg) == 0 {
  6770. patient.MedListCodg = "ZZZZZZZZZZZZZZZ"
  6771. }
  6772. p := &sz.TB_CIS_Prescription_Detail{
  6773. CYH: strconv.FormatInt(prescription.ID, 10),
  6774. CFMXH: prescription.PrescriptionNumber,
  6775. YLJGDM: hospital_id,
  6776. JZLSH: strconv.FormatInt(patient_info.ID, 10),
  6777. XMBM: strconv.FormatInt(patient.DrugId, 10),
  6778. XMBMYB: patient.MedListCodg,
  6779. XMMC: patient.AdviceName,
  6780. XMSL: patient.PrescribingNumber,
  6781. XMDW: patient.PrescribingNumberUnit,
  6782. XMDJ: patient.Price,
  6783. XMJE: patient.Price * patient.PrescribingNumber,
  6784. XMLB: "01",
  6785. YWFLDM: "1",
  6786. SFJJ: "0",
  6787. SFPS: "0",
  6788. YPGG: basedrug.DrugSpec,
  6789. SCPH: basedrug.SocialSecurityDirectoryCode,
  6790. YXQZ: "2026-09-01",
  6791. SYPCDM: "QD",
  6792. SYPC: "每天一次",
  6793. JL: patient.SingleDose,
  6794. DW: patient.SingleDoseUnit,
  6795. MCSL: patient.SingleDose,
  6796. MCDW: patient.SingleDoseUnit,
  6797. YF: yf,
  6798. YPYF: ypyf,
  6799. YYTS: patient.Day,
  6800. YWSYZJL: patient.PrescribingNumber,
  6801. YWSYZJLDW: patient.PrescribingNumberUnit,
  6802. SJSCSJ: time.Now(),
  6803. XGBZ: 0,
  6804. }
  6805. service.BatchCreateTB_CIS_Prescription_Detail(p, rdb)
  6806. }
  6807. }
  6808. upload := &sz.DataUpload{
  6809. SyncType: 1007,
  6810. OrgId: org_id,
  6811. SyncTime: time.Now().Unix(),
  6812. SyncResultType: 1,
  6813. CreateTime: time.Now().Unix(),
  6814. UpdateTime: time.Now().Unix(),
  6815. }
  6816. service.CreateUploadRecord(upload)
  6817. }
  6818. // 门诊处方明细表
  6819. func SyncTB_HIS_MZ_Charge(rdb *gorm.DB, org_id int64, hospital_id string) {
  6820. // 第一步:根据机构id获取上次同步时间
  6821. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1008)
  6822. var sync_time int64
  6823. if syncLastInfo.ID > 0 {
  6824. sync_time = syncLastInfo.SyncTime
  6825. } else {
  6826. sync_time = 1714492800
  6827. }
  6828. //同步员工信息
  6829. patients, _ := service.FindOrgHisOrder(org_id, sync_time, time.Now().Unix())
  6830. for _, patient := range patients {
  6831. orderInfos, _ := service.GetHisOrderInfoByNumber(patient.Number)
  6832. patientInfo, _ := service.FindOrgPatientInfoById(patient.PatientId)
  6833. var bedCostTotal float64 = 0 //床位总费
  6834. var operationCostTotal float64 = 0 //手术费
  6835. var otherCostTotal float64 = 0 //其他费用
  6836. var materialCostTotal float64 = 0 //材料费
  6837. var westernMedicineCostTotal float64 = 0 //西药费
  6838. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  6839. var checkCostTotal float64 = 0 //检查费
  6840. var laboratoryCostTotal float64 = 0 //化验费
  6841. var treatCostTotal float64 = 0 //治疗费用
  6842. decimal.DivisionPrecision = 2
  6843. for _, item := range orderInfos {
  6844. if item.MedChrgitmType == "01" { //床位费
  6845. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6846. }
  6847. if item.MedChrgitmType == "03" { //检查费
  6848. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6849. }
  6850. if item.MedChrgitmType == "04" { //化验费
  6851. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6852. }
  6853. if item.MedChrgitmType == "05" { //治疗费
  6854. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6855. }
  6856. if item.MedChrgitmType == "06" { //手术费
  6857. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6858. }
  6859. if item.MedChrgitmType == "08" { //材料费
  6860. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6861. }
  6862. if item.MedChrgitmType == "09" { //西药费
  6863. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6864. }
  6865. if item.MedChrgitmType == "11" { //中成费
  6866. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6867. }
  6868. if item.MedChrgitmType == "14" { //其他费
  6869. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6870. }
  6871. }
  6872. tm := time.Unix(patient.SettleAccountsDate, 0)
  6873. ghrq := tm.Format("20060102")
  6874. p := &sz.TB_HIS_MZ_Charge{
  6875. STFRQ: ghrq,
  6876. STFBH: patient.Number,
  6877. STFBZ: "1",
  6878. YLJGDM: hospital_id,
  6879. GHBM: strconv.FormatInt(patient.HisPatientId, 10),
  6880. KH: patientInfo.DialysisNo,
  6881. KLX: "3",
  6882. FPH: "/",
  6883. YLFKFSDM: "01",
  6884. YLBXLBDM: "01",
  6885. YBZHBZ: "0000000000000000",
  6886. SSJYBZ: "1",
  6887. ZLLX: "04",
  6888. WDBZ: "1",
  6889. STFSJ: ghrq,
  6890. STFZE: patient.MedfeeSumamt,
  6891. SSJE: patient.MedfeeSumamt,
  6892. YHJE: 0,
  6893. ZFJE: patient.PsnPartAmt,
  6894. YBJZ: 0,
  6895. YBJJ: patient.FundPaySumamt,
  6896. YBZE: patient.InscpScpAmt,
  6897. YBZF: patient.AcctPay,
  6898. YBFWWZF: patient.OverlmtSelfPay,
  6899. TXFYE: "0",
  6900. TXYF: "0",
  6901. GHF: "0",
  6902. ZLF: "0",
  6903. ZHF: treatCostTotal,
  6904. JCF: checkCostTotal,
  6905. SSF: operationCostTotal,
  6906. WSCLF: operationCostTotal,
  6907. CWF: bedCostTotal,
  6908. HLF: "0",
  6909. YSFWF: "0",
  6910. YBZLF: "0",
  6911. HYF: laboratoryCostTotal,
  6912. TSF: "0",
  6913. SPF: "0",
  6914. XYF: westernMedicineCostTotal,
  6915. ZCYF: chineseTraditionalMedicineCostTotal,
  6916. ZYZJF: "0",
  6917. ZCAF: "0",
  6918. QTF: otherCostTotal,
  6919. CFZS: "1",
  6920. SJSCSJ: time.Now(),
  6921. XGBZ: 0,
  6922. }
  6923. service.BatchCreateTB_HIS_MZ_Charge(p, rdb)
  6924. }
  6925. upload := &sz.DataUpload{
  6926. SyncType: 1008,
  6927. OrgId: org_id,
  6928. SyncTime: time.Now().Unix(),
  6929. SyncResultType: 1,
  6930. CreateTime: time.Now().Unix(),
  6931. UpdateTime: time.Now().Unix(),
  6932. }
  6933. service.CreateUploadRecord(upload)
  6934. }
  6935. func SyncTB_HIS_MZ_Charge_pg(rdb *gorm.DB, org_id int64, hospital_id string) {
  6936. // 第一步:根据机构id获取上次同步时间
  6937. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1008)
  6938. var sync_time int64
  6939. if syncLastInfo.ID > 0 {
  6940. sync_time = syncLastInfo.SyncTime
  6941. } else {
  6942. sync_time = 1714492800
  6943. }
  6944. //同步员工信息
  6945. patients, _ := service.FindOrgHisOrder(org_id, sync_time, time.Now().Unix())
  6946. for _, patient := range patients {
  6947. orderInfos, _ := service.GetHisOrderInfoByNumber(patient.Number)
  6948. patientInfo, _ := service.FindOrgPatientInfoById(patient.PatientId)
  6949. var bedCostTotal float64 = 0 //床位总费
  6950. var operationCostTotal float64 = 0 //手术费
  6951. var otherCostTotal float64 = 0 //其他费用
  6952. var materialCostTotal float64 = 0 //材料费
  6953. var westernMedicineCostTotal float64 = 0 //西药费
  6954. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  6955. var checkCostTotal float64 = 0 //检查费
  6956. var laboratoryCostTotal float64 = 0 //化验费
  6957. var treatCostTotal float64 = 0 //治疗费用
  6958. decimal.DivisionPrecision = 2
  6959. for _, item := range orderInfos {
  6960. if item.MedChrgitmType == "01" { //床位费
  6961. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6962. }
  6963. if item.MedChrgitmType == "03" { //检查费
  6964. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6965. }
  6966. if item.MedChrgitmType == "04" { //化验费
  6967. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6968. }
  6969. if item.MedChrgitmType == "05" { //治疗费
  6970. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6971. }
  6972. if item.MedChrgitmType == "06" { //手术费
  6973. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6974. }
  6975. if item.MedChrgitmType == "08" { //材料费
  6976. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6977. }
  6978. if item.MedChrgitmType == "09" { //西药费
  6979. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6980. }
  6981. if item.MedChrgitmType == "11" { //中成费
  6982. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6983. }
  6984. if item.MedChrgitmType == "14" { //其他费
  6985. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6986. }
  6987. }
  6988. tm := time.Unix(patient.SettleAccountsDate, 0)
  6989. ghrq := tm.Format("20060102")
  6990. p := &sz.TB_HIS_MZ_Charge{
  6991. STFRQ: ghrq,
  6992. STFBH: patient.Number,
  6993. STFBZ: "1",
  6994. YLJGDM: hospital_id,
  6995. GHBM: strconv.FormatInt(patient.HisPatientId, 10),
  6996. KH: patientInfo.DialysisNo,
  6997. KLX: "3",
  6998. FPH: "/",
  6999. YLFKFSDM: "01",
  7000. YLBXLBDM: "01",
  7001. YBZHBZ: "0000000000000000",
  7002. SSJYBZ: "1",
  7003. ZLLX: "04",
  7004. WDBZ: "1",
  7005. STFSJ: ghrq,
  7006. STFZE: patient.MedfeeSumamt,
  7007. SSJE: patient.MedfeeSumamt,
  7008. YHJE: 0,
  7009. ZFJE: patient.PsnPartAmt,
  7010. YBJZ: 0,
  7011. YBJJ: patient.FundPaySumamt,
  7012. YBZE: patient.InscpScpAmt,
  7013. YBZF: patient.AcctPay,
  7014. YBFWWZF: patient.OverlmtSelfPay,
  7015. TXFYE: "0",
  7016. TXYF: "0",
  7017. GHF: "0",
  7018. ZLF: "0",
  7019. ZHF: treatCostTotal,
  7020. JCF: checkCostTotal,
  7021. SSF: operationCostTotal,
  7022. WSCLF: operationCostTotal,
  7023. CWF: bedCostTotal,
  7024. HLF: "0",
  7025. YSFWF: "0",
  7026. YBZLF: "0",
  7027. HYF: laboratoryCostTotal,
  7028. TSF: "0",
  7029. SPF: "0",
  7030. XYF: westernMedicineCostTotal,
  7031. ZCYF: chineseTraditionalMedicineCostTotal,
  7032. ZYZJF: "0",
  7033. ZCAF: "0",
  7034. QTF: otherCostTotal,
  7035. CFZS: "1",
  7036. SJSCSJ: time.Now(),
  7037. XGBZ: 0,
  7038. }
  7039. service.BatchCreateTB_HIS_MZ_Charge(p, rdb)
  7040. }
  7041. upload := &sz.DataUpload{
  7042. SyncType: 1008,
  7043. OrgId: org_id,
  7044. SyncTime: time.Now().Unix(),
  7045. SyncResultType: 1,
  7046. CreateTime: time.Now().Unix(),
  7047. UpdateTime: time.Now().Unix(),
  7048. }
  7049. service.CreateUploadRecord(upload)
  7050. }
  7051. func SyncTB_HIS_MZ_BL_Detail(rdb *gorm.DB, org_id int64, hospital_id string) {
  7052. // 第一步:根据机构id获取上次同步时间
  7053. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 20009)
  7054. var sync_time int64
  7055. if syncLastInfo.ID > 0 {
  7056. sync_time = syncLastInfo.SyncTime
  7057. } else {
  7058. sync_time = 1718899200
  7059. }
  7060. //同步员工信息
  7061. patients, _ := service.FindNewOrgHisOrder(org_id, sync_time, time.Now().Unix())
  7062. for _, p := range patients {
  7063. pp, _ := service.FindOrgPatientInfoById(p.PatientId)
  7064. role, _ := service.FindUserRoleData(org_id, p.HisPatient.Doctor)
  7065. // 转换时间戳为time.Time类型
  7066. t := time.Unix(p.HisPatient.Ctime, 0)
  7067. t2 := time.Unix(p.HisPatient.RecordDate, 0)
  7068. // 格式化时间为日期
  7069. date := t.Format("2006-01-02 15:04:05")
  7070. date2 := t2.Format("2006-01-02 15:04:05")
  7071. p := &sz.TB_HIS_MZ_BL_Detail{
  7072. YLJGDM: hospital_id,
  7073. BLLSH: p.Number,
  7074. JZLSH: strconv.FormatInt(p.HisPatientId, 10),
  7075. KH: pp.DialysisNo,
  7076. KLX: "3",
  7077. HZXM: pp.Name,
  7078. JZLX: "04",
  7079. JZRQSJ: date2,
  7080. MJZH: p.HisPatient.Number,
  7081. CZBZ: "2",
  7082. YSGH: role.DoctorNumber,
  7083. YSXM: role.UserName,
  7084. JLRQSJ: date,
  7085. SJSCSJ: time.Now(),
  7086. XGBZ: 0,
  7087. }
  7088. service.BatchCreateTB_HIS_MZ_BL_Detail(p, rdb)
  7089. }
  7090. upload := &sz.DataUpload{
  7091. SyncType: 20009,
  7092. OrgId: org_id,
  7093. SyncTime: time.Now().Unix(),
  7094. SyncResultType: 1,
  7095. CreateTime: time.Now().Unix(),
  7096. UpdateTime: time.Now().Unix(),
  7097. }
  7098. service.CreateUploadRecord(upload)
  7099. }
  7100. // 20. 门诊收费明细表
  7101. func SyncTB_HIS_MZ_Fee_Detail(rdb *gorm.DB, org_id int64, hospital_id string) {
  7102. // 第一步:根据机构id获取上次同步时间
  7103. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1009)
  7104. var sync_time int64
  7105. if syncLastInfo.ID > 0 {
  7106. sync_time = syncLastInfo.SyncTime
  7107. } else {
  7108. sync_time = 1714492800
  7109. }
  7110. //同步员工信息
  7111. patients, _ := service.FindOrgHisOrderInfo(org_id, sync_time, time.Now().Unix())
  7112. for _, patient := range patients {
  7113. // order,_ := service.GetHisOrderByNumber(patient.OrderNumber)
  7114. var MedListCodg, AdviceName, SingleDoseUnit, MXXMBM string
  7115. if patient.AdviceId > 0 {
  7116. advice, _ := service.GetHisDoctorAdviceInfo(patient.AdviceId)
  7117. MedListCodg = advice.MedListCodg
  7118. AdviceName = advice.AdviceName
  7119. SingleDoseUnit = advice.SingleDoseUnit
  7120. MXXMBM = strconv.FormatInt(advice.DrugId, 10)
  7121. } else {
  7122. advice, _ := service.GetHisPrescriptionProjectInfo(patient.ProjectId)
  7123. MedListCodg = advice.MedListCodg
  7124. if advice.ID > 0 {
  7125. if advice.Type == 2 {
  7126. project, _ := service.GetHisProjectInfo(advice.ProjectId)
  7127. AdviceName = project.ProjectName
  7128. SingleDoseUnit = project.Unit
  7129. MXXMBM = strconv.FormatInt(project.ID, 10)
  7130. } else {
  7131. project, _ := service.GetGoodInfo(advice.ProjectId)
  7132. AdviceName = project.GoodName
  7133. SingleDoseUnit = project.PackingUnit
  7134. MXXMBM = strconv.FormatInt(project.ID, 10)
  7135. }
  7136. }
  7137. }
  7138. patientInfo, _ := service.FindOrgPatientInfoById(patient.PatientId)
  7139. tm := time.Unix(patient.Ctime, 0)
  7140. ghrq := tm.Format("20060102")
  7141. var mxfylb string
  7142. mxfylb = "99"
  7143. if patient.MedChrgitmType == "01" { //床位费
  7144. mxfylb = "18"
  7145. }
  7146. if patient.MedChrgitmType == "03" { //检查费
  7147. mxfylb = "06"
  7148. }
  7149. if patient.MedChrgitmType == "04" { //化验费
  7150. mxfylb = "07"
  7151. }
  7152. if patient.MedChrgitmType == "05" { //治疗费
  7153. mxfylb = "03"
  7154. }
  7155. if patient.MedChrgitmType == "06" { //手术费
  7156. mxfylb = "04"
  7157. }
  7158. if patient.MedChrgitmType == "08" { //材料费
  7159. mxfylb = "05"
  7160. }
  7161. if patient.MedChrgitmType == "09" { //西药费
  7162. mxfylb = "12"
  7163. }
  7164. if patient.MedChrgitmType == "11" { //中成费
  7165. mxfylb = "13"
  7166. }
  7167. if patient.MedChrgitmType == "14" { //其他费
  7168. mxfylb = "99"
  7169. }
  7170. p := &sz.TB_HIS_MZ_Fee_Detail{
  7171. SFMXID: strconv.FormatInt(patient.ID, 10),
  7172. TFBZ: "1",
  7173. YLJGDM: hospital_id,
  7174. JZLSH: strconv.FormatInt(patient.HisPatientId, 10),
  7175. STFBH: patient.OrderNumber,
  7176. KH: patientInfo.DialysisNo,
  7177. KLX: "3",
  7178. ZLLX: "04",
  7179. YLFKFSDM: "01",
  7180. FPH: "/",
  7181. STFSJ: ghrq,
  7182. MXFYLB: mxfylb,
  7183. MXXMBM: MXXMBM,
  7184. MXXMBMYB: MedListCodg,
  7185. MXXMMC: AdviceName,
  7186. MXXMDW: SingleDoseUnit,
  7187. MXXMDJ: patient.Pric,
  7188. MXXMSL: patient.Cnt,
  7189. MXXMJE: patient.DetItemFeeSumamt,
  7190. KDKSBM: "1001",
  7191. KDKSMC: "血透中心",
  7192. KDRGH: "1001",
  7193. KDRXM: "Phony",
  7194. ZXKSBM: "1001",
  7195. ZXKSMC: "血透中心",
  7196. SJSCSJ: time.Now(),
  7197. XGBZ: 0,
  7198. }
  7199. service.BatchCreateTB_HIS_MZ_Fee_Detail(p, rdb)
  7200. }
  7201. upload := &sz.DataUpload{
  7202. SyncType: 1009,
  7203. OrgId: org_id,
  7204. SyncTime: time.Now().Unix(),
  7205. SyncResultType: 1,
  7206. CreateTime: time.Now().Unix(),
  7207. UpdateTime: time.Now().Unix(),
  7208. }
  7209. service.CreateUploadRecord(upload)
  7210. }
  7211. func SyncTB_HIS_MZ_Fee_Detail_pg(rdb *gorm.DB, org_id int64, hospital_id string) {
  7212. // 第一步:根据机构id获取上次同步时间
  7213. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1009)
  7214. var sync_time int64
  7215. if syncLastInfo.ID > 0 {
  7216. sync_time = syncLastInfo.SyncTime
  7217. } else {
  7218. sync_time = 1714492800
  7219. }
  7220. //同步员工信息
  7221. patients, _ := service.FindOrgHisOrderInfo(org_id, sync_time, time.Now().Unix())
  7222. for _, patient := range patients {
  7223. // order,_ := service.GetHisOrderByNumber(patient.OrderNumber)
  7224. var MedListCodg, AdviceName, SingleDoseUnit, MXXMBM string
  7225. if patient.AdviceId > 0 {
  7226. advice, _ := service.GetHisDoctorAdviceInfo(patient.AdviceId)
  7227. MedListCodg = advice.MedListCodg
  7228. AdviceName = advice.AdviceName
  7229. SingleDoseUnit = advice.SingleDoseUnit
  7230. MXXMBM = strconv.FormatInt(advice.DrugId, 10)
  7231. } else {
  7232. advice, _ := service.GetHisPrescriptionProjectInfo(patient.ProjectId)
  7233. MedListCodg = advice.MedListCodg
  7234. if advice.ID > 0 {
  7235. if advice.Type == 2 {
  7236. project, _ := service.GetHisProjectInfo(advice.ProjectId)
  7237. AdviceName = project.ProjectName
  7238. SingleDoseUnit = project.Unit
  7239. MXXMBM = strconv.FormatInt(project.ID, 10)
  7240. } else {
  7241. project, _ := service.GetGoodInfo(advice.ProjectId)
  7242. AdviceName = project.GoodName
  7243. SingleDoseUnit = project.PackingUnit
  7244. MXXMBM = strconv.FormatInt(project.ID, 10)
  7245. }
  7246. }
  7247. }
  7248. patientInfo, _ := service.FindOrgPatientInfoById(patient.PatientId)
  7249. tm := time.Unix(patient.Ctime, 0)
  7250. ghrq := tm.Format("20060102")
  7251. var mxfylb string
  7252. mxfylb = "99"
  7253. if patient.MedChrgitmType == "01" { //床位费
  7254. mxfylb = "18"
  7255. }
  7256. if patient.MedChrgitmType == "03" { //检查费
  7257. mxfylb = "06"
  7258. }
  7259. if patient.MedChrgitmType == "04" { //化验费
  7260. mxfylb = "07"
  7261. }
  7262. if patient.MedChrgitmType == "05" { //治疗费
  7263. mxfylb = "03"
  7264. }
  7265. if patient.MedChrgitmType == "06" { //手术费
  7266. mxfylb = "04"
  7267. }
  7268. if patient.MedChrgitmType == "08" { //材料费
  7269. mxfylb = "05"
  7270. }
  7271. if patient.MedChrgitmType == "09" { //西药费
  7272. mxfylb = "12"
  7273. }
  7274. if patient.MedChrgitmType == "11" { //中成费
  7275. mxfylb = "13"
  7276. }
  7277. if patient.MedChrgitmType == "14" { //其他费
  7278. mxfylb = "99"
  7279. }
  7280. p := &sz.TB_HIS_MZ_Fee_Detail{
  7281. SFMXID: strconv.FormatInt(patient.ID, 10),
  7282. TFBZ: "1",
  7283. YLJGDM: hospital_id,
  7284. JZLSH: strconv.FormatInt(patient.HisPatientId, 10),
  7285. STFBH: patient.OrderNumber,
  7286. KH: patientInfo.DialysisNo,
  7287. KLX: "3",
  7288. ZLLX: "04",
  7289. YLFKFSDM: "01",
  7290. FPH: "/",
  7291. STFSJ: ghrq,
  7292. MXFYLB: mxfylb,
  7293. MXXMBM: MXXMBM,
  7294. MXXMBMYB: MedListCodg,
  7295. MXXMMC: AdviceName,
  7296. MXXMDW: SingleDoseUnit,
  7297. MXXMDJ: patient.Pric,
  7298. MXXMSL: patient.Cnt,
  7299. MXXMJE: patient.DetItemFeeSumamt,
  7300. KDKSBM: "1001",
  7301. KDKSMC: "血透中心",
  7302. KDRGH: "1001",
  7303. KDRXM: "Phony",
  7304. ZXKSBM: "1001",
  7305. ZXKSMC: "血透中心",
  7306. SJSCSJ: time.Now(),
  7307. XGBZ: 0,
  7308. }
  7309. service.BatchCreateTB_HIS_MZ_Fee_Detail(p, rdb)
  7310. }
  7311. upload := &sz.DataUpload{
  7312. SyncType: 1009,
  7313. OrgId: org_id,
  7314. SyncTime: time.Now().Unix(),
  7315. SyncResultType: 1,
  7316. CreateTime: time.Now().Unix(),
  7317. UpdateTime: time.Now().Unix(),
  7318. }
  7319. service.CreateUploadRecord(upload)
  7320. }