auto_create_week_schedules_service.go 210KB

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