auto_create_week_schedules_service.go 99KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451
  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"
  11. "github.com/shopspring/decimal"
  12. "math"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. var createUploadDataCronJob *cron.Cron
  18. func init() {
  19. utils.InfoLog("开启定时任务")
  20. createUploadDataCronJob = cron.New()
  21. spec := "0 10 0 * * ?" // 每天凌晨0点检测数据上报情况
  22. // spec1 := "0 10 0 * * ?" // 每天凌晨0点检测数据上报情况
  23. // spec2 := "0 20 0 * * ?" // 每天凌晨0点检测数据上报情况
  24. createUploadDataCronJob.AddFunc(spec, func() {
  25. SyncToSzjk() //深圳市数据上报
  26. })
  27. // createUploadDataCronJob.AddFunc(spec1, func() {
  28. // SyncToHqyy() //深圳市数据上报
  29. // })
  30. // createUploadDataCronJob.AddFunc(spec2, func() {
  31. // SyncToSmzy() //深圳市数据上报
  32. // })
  33. }
  34. //
  35. func BeginAutoJob() {
  36. createUploadDataCronJob.Start()
  37. }
  38. func SyncToSzbl() {
  39. org := &sz.DataUploadConfig{
  40. OrgId: 10138,
  41. ProvinceId: 19,
  42. CityId: 291,
  43. DepartmentName: "深圳市百霖血液透析中心",
  44. HospitalId: "MA5DB4KB6 ",
  45. InstType: 1,
  46. DbHost: "127.0.0.1",
  47. DbPort: "1433",
  48. DbPass: "adapter",
  49. DbUser: "adapter",
  50. DbName: "adapter_2019",
  51. }
  52. // for _, org := range configs {
  53. // 第二步:跟进配置,创建数据库连接
  54. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  55. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  56. if err != nil {
  57. utils.ErrorLog("创建数据库连接失败:%v", err)
  58. return
  59. }
  60. // 第三步:开始同步数据
  61. // 机构人员字典表 t_hd_hospital
  62. SyncTBDICPractitioner(orgDb, org.OrgId, org.HospitalId)
  63. // 机构床位 t_hd_wm
  64. SyncTMDICTBED(orgDb, org.OrgId, org.HospitalId)
  65. // 门诊患者信息表
  66. SyncTBMZPatientInformation(orgDb, org.OrgId, org.HospitalId)
  67. // 挂号表
  68. SyncTBHISMZReg(orgDb, org.OrgId, org.HospitalId)
  69. // 门诊就诊记录表
  70. SyncTB_YL_MZ_Medical_Record(orgDb, org.OrgId, org.HospitalId)
  71. // 门诊处方主表
  72. SyncTB_CIS_Prescription(orgDb, org.OrgId, org.HospitalId)
  73. // 18. 门诊处方明细表
  74. SyncTB_CIS_Prescription_Detail(orgDb, org.OrgId, org.HospitalId)
  75. // 19. 门诊收费表
  76. SyncTB_HIS_MZ_Charge(orgDb, org.OrgId, org.HospitalId)
  77. // 20. 门诊收费明细表
  78. SyncTB_HIS_MZ_Fee_Detail(orgDb, org.OrgId, org.HospitalId)
  79. // 第四步:关闭数据库连接
  80. service.CloseDB(orgDb)
  81. }
  82. // }
  83. return
  84. }
  85. func SyncToSzjk() {
  86. org := &sz.DataUploadConfig{
  87. OrgId: 10245,
  88. ProvinceId: 19,
  89. CityId: 291,
  90. DepartmentName: "深圳静康医院血液透析中心",
  91. HospitalId: "MA5DKWHG3",
  92. InstType: 1,
  93. DbHost: "localhost",
  94. DbPort: "1433",
  95. DbPass: "Ya2019",
  96. DbUser: "sa",
  97. DbName: "xtzk",
  98. }
  99. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  100. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  101. if err != nil {
  102. utils.ErrorLog("创建数据库连接失败:%v", err)
  103. return
  104. }
  105. // 第三步:开始同步数据
  106. // 同步医院信息 t_hd_hospital
  107. SyncHospital(orgDb, org.OrgId, org.HospitalId, org.InstType, org.DepartmentName)
  108. // 同步水处理器 t_hd_wm
  109. SyncWMS(orgDb, org.OrgId, org.HospitalId)
  110. // // 同步员工 t_hd_staff
  111. SyncStaff(orgDb, org.OrgId, org.HospitalId)
  112. // // 同步病人 t_hd_patient
  113. SyncPatient(orgDb, org.OrgId, org.HospitalId)
  114. // // 同步排班 t_hd_shift
  115. SyncShift(orgDb, org.OrgId, org.HospitalId)
  116. // 同步处方 t_hd_ps
  117. SyncPs(orgDb, org.OrgId, org.HospitalId)
  118. //// 同步处方药品 t_hd_ps
  119. SyncPsMedicine(orgDb, org.OrgId, org.HospitalId)
  120. // // 同步转院信息 t_hd_patient_out
  121. SyncPatientOut(orgDb, org.OrgId, org.HospitalId)
  122. // 同步处方信息 t_hd_doctors_advice
  123. SyncDoctorAdvice(orgDb, org.OrgId, org.HospitalId)
  124. // 同步透中信息 t_hd_middle
  125. SyncMiddle(orgDb, org.OrgId, org.HospitalId)
  126. // // 同步设备 t_hd_other_machine
  127. SyncOtherMachine(orgDb, org.OrgId, org.HospitalId)
  128. // // 同步维修 t_hd_maintain
  129. SyncMachineRepair(orgDb, org.OrgId, org.HospitalId)
  130. // // 同步设备 t_hd_dm
  131. SyncDM(orgDb, org.OrgId, org.HospitalId)
  132. // // 同步患者透析记录 t_hd_dialysis
  133. SyncDialysis(orgDb, org.OrgId, org.HospitalId)
  134. // 同步透析床位分区 t_hd_division
  135. SyncDivision(orgDb, org.OrgId, org.HospitalId)
  136. // 患者通路信息表(T_HD_ACCESS)
  137. SyncAccess(orgDb, org.OrgId, org.HospitalId)
  138. // 透析床位表(T_HD_SICKBED)
  139. SyncSickbed(orgDb, org.OrgId, org.HospitalId)
  140. // 患者诊断信息表(T_HD_DIAGNOSIS)
  141. SyncDiagnosis(orgDb, org.OrgId, org.HospitalId)
  142. // 患者传染病检查记录表(T_HD_INFECTION
  143. SyncInfection(orgDb, org.OrgId, org.HospitalId)
  144. // 透析并发症记录表(T_HD_COMPLICATION)
  145. SyncComplication(orgDb, org.OrgId, org.HospitalId)
  146. // 血透患者检测结果表(T_HD_LIS_REPORT)
  147. SyncLisReport(orgDb, org.OrgId, org.HospitalId)
  148. // 血透患者检验结果指标表(T_HD_LIS_INDICATORS)
  149. SyncLisIndicators(orgDb, org.OrgId, org.HospitalId)
  150. // 透析机透析液细菌培养检测记录表(t_hd_dm_dialysate_bc)
  151. SyncLisCulture(orgDb,org.OrgId,org.HospitalId)
  152. //透析机透析液内毒素检测记录表(T_HD_DM_DIALYSATE_BC)
  153. SyncDialysate(orgDb,org.OrgId,org.HospitalId)
  154. //物表消毒记录表(T_HD_SURFACE_DISINFECT)
  155. SyncLisBodyDetection(orgDb,org.OrgId,org.HospitalId)
  156. //透析用水游离氯检测表(T_HD_WATER_FC)
  157. SyncLisWaterFc(orgDb,org.OrgId,org.HospitalId)
  158. //透析用水有毒化学物检测表(T_HD_WATER_NC)
  159. SynLisWaterNc(orgDb,org.OrgId,org.HospitalId)
  160. //透析用水PH值检测表(T_HD_WATER_PH)
  161. SynLisWaterPh(orgDb,org.OrgId,org.HospitalId)
  162. //透析用水水硬度检测表(T_HD_WATER_WH)
  163. SynListHadWater(orgDb,org.OrgId,org.HospitalId)
  164. //导管感染记录表(T_HD_CI)
  165. SynListHdCi(orgDb,org.OrgId,org.HospitalId)
  166. //导管感染转归记录表(T_HD_CI_OUTCOME)
  167. SynLisHdCiOutCome(orgDb,org.OrgId,org.HospitalId)
  168. //透析室空气消毒记录表(T_HD_AIR_DISINFECT)
  169. SyncLisAirDetection(orgDb,org.OrgId,org.HospitalId)
  170. //透析用水细菌培养检测表(T_HD_WATER_BC)
  171. SyncLisWaterBc(orgDb,org.OrgId,org.HospitalId)
  172. //透析用水内毒素检测表(T_HD_WATER_EN)
  173. SyncLisWaterEn(orgDb,org.OrgId,org.HospitalId)
  174. service.CloseDB(orgDb)
  175. }
  176. // }
  177. return
  178. }
  179. func SyncToLg2h() {
  180. // 第一步:到上报配置表中找到深圳需要上报的机构
  181. // sz_province, _ := beego.AppConfig.Int64("sz_province")
  182. // sz_city, _ := beego.AppConfig.Int64("sz_city")
  183. // configs, _ := service.FindAllDataUploadConfigOrgInfo(sz_province, sz_city, 3)
  184. org := &sz.DataUploadConfig{
  185. OrgId: 9598,
  186. ProvinceId: 19,
  187. CityId: 291,
  188. DepartmentName: "深圳市龙岗区第二人民医院",
  189. HospitalId: "455835506",
  190. InstType: 1,
  191. DbHost: "183.62.158.36",
  192. DbPort: "61433",
  193. DbPass: "LG2H+9897",
  194. DbUser: "sa",
  195. DbName: "xtzk",
  196. }
  197. // for _, org := range configs {
  198. // 第二步:跟进配置,创建数据库连接
  199. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  200. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  201. if err != nil {
  202. utils.ErrorLog("创建数据库连接失败:%v", err)
  203. return
  204. }
  205. // 第三步:开始同步数据
  206. // 同步医院信息 t_hd_hospital
  207. //SyncHospital(orgDb, org.OrgId, org.HospitalId, org.InstType, org.DepartmentName)
  208. // 同步水处理器 t_hd_wm
  209. //SyncWMS(orgDb, org.OrgId, org.HospitalId)
  210. // // 同步员工 t_hd_staff
  211. //SyncStaff(orgDb, org.OrgId, org.HospitalId)
  212. // // 同步病人 t_hd_patient
  213. //SyncPatient(orgDb, org.OrgId, org.HospitalId)
  214. // // 同步排班 t_hd_shift
  215. //SyncShift(orgDb, org.OrgId, org.HospitalId)
  216. // 同步处方 t_hd_ps
  217. //SyncPs(orgDb, org.OrgId, org.HospitalId)
  218. //// 同步处方药品 t_hd_ps
  219. //SyncPsMedicine(orgDb, org.OrgId, org.HospitalId)
  220. // // 同步转院信息 t_hd_patient_out
  221. //SyncPatientOut(orgDb, org.OrgId, org.HospitalId)
  222. // 同步处方信息 t_hd_doctors_advice
  223. //SyncDoctorAdvice(orgDb, org.OrgId, org.HospitalId)
  224. // 同步透中信息 t_hd_middle
  225. //SyncMiddle(orgDb, org.OrgId, org.HospitalId)
  226. // // 同步设备 t_hd_other_machine
  227. //SyncOtherMachine(orgDb, org.OrgId, org.HospitalId)
  228. // // 同步维修 t_hd_maintain
  229. //SyncMachineRepair(orgDb, org.OrgId, org.HospitalId)
  230. // // 同步设备 t_hd_dm
  231. //SyncDM(orgDb, org.OrgId, org.HospitalId)
  232. // // 同步患者透析记录 t_hd_dialysis
  233. //SyncDialysis(orgDb, org.OrgId, org.HospitalId)
  234. // 同步透析床位分区 t_hd_division
  235. //SyncDivision(orgDb, org.OrgId, org.HospitalId)
  236. // 患者通路信息表(T_HD_ACCESS)
  237. //SyncAccess(orgDb, org.OrgId, org.HospitalId)
  238. // 透析床位表(T_HD_SICKBED)
  239. //SyncSickbed(orgDb, org.OrgId, org.HospitalId)
  240. // 患者诊断信息表(T_HD_DIAGNOSIS)
  241. //SyncDiagnosis(orgDb, org.OrgId, org.HospitalId)
  242. // 患者传染病检查记录表(T_HD_INFECTION
  243. //SyncInfection(orgDb, org.OrgId, org.HospitalId)
  244. // 透析并发症记录表(T_HD_COMPLICATION)
  245. //SyncComplication(orgDb, org.OrgId, org.HospitalId)
  246. // 血透患者检测结果表(T_HD_LIS_REPORT)
  247. //SyncLisReport(orgDb, org.OrgId, org.HospitalId)
  248. // 血透患者检验结果指标表(T_HD_LIS_INDICATORS)
  249. // SyncLisIndicators(orgDb, org.OrgId, org.HospitalId)
  250. // 透析机透析液细菌培养检测记录表(t_hd_dm_dialysate_bc)
  251. //SyncLisCulture(orgDb,org.OrgId,org.HospitalId)
  252. //透析机透析液内毒素检测记录表(T_HD_DM_DIALYSATE_BC)
  253. //SyncDialysate(orgDb,org.OrgId,org.HospitalId)
  254. //物表消毒记录表(T_HD_SURFACE_DISINFECT)
  255. //SyncLisBodyDetection(orgDb,org.OrgId,org.HospitalId)
  256. // 第四步:关闭数据库连接
  257. //透析用水游离氯检测表(T_HD_WATER_FC)
  258. //SyncLisWaterFc(orgDb,org.OrgId,org.HospitalId)
  259. //透析用水有毒化学物检测表(T_HD_WATER_NC)
  260. //SynLisWaterNc(orgDb,org.OrgId,org.HospitalId)
  261. //透析用水PH值检测表(T_HD_WATER_PH)
  262. //SynLisWaterPh(orgDb,org.OrgId,org.HospitalId)
  263. //透析用水水硬度检测表(T_HD_WATER_WH)
  264. //SynListHadWater(orgDb,org.OrgId,org.HospitalId)
  265. //导管感染记录表(T_HD_CI)
  266. //SynListHdCi(orgDb,org.OrgId,org.HospitalId)
  267. //导管感染转归记录表(T_HD_CI_OUTCOME)
  268. // SynLisHdCiOutCome(orgDb,org.OrgId,org.HospitalId)
  269. //透析室空气消毒记录表(T_HD_AIR_DISINFECT)
  270. //SyncLisAirDetection(orgDb,org.OrgId,org.HospitalId)
  271. //透析用水细菌培养检测表(T_HD_WATER_BC)
  272. //SyncLisWaterBc(orgDb,org.OrgId,org.HospitalId)
  273. //透析用水内毒素检测表(T_HD_WATER_EN)
  274. //SyncLisWaterEn(orgDb,org.OrgId,org.HospitalId)
  275. service.CloseDB(orgDb)
  276. }
  277. // }
  278. return
  279. }
  280. func SyncToHqyy() {
  281. // 第一步:到上报配置表中找到深圳需要上报的机构
  282. // sz_province, _ := beego.AppConfig.Int64("sz_province")
  283. // sz_city, _ := beego.AppConfig.Int64("sz_city")
  284. // configs, _ := service.FindAllDataUploadConfigOrgInfo(sz_province, sz_city, 3)
  285. org := &sz.DataUploadConfig{
  286. OrgId: 9442,
  287. ProvinceId: 19,
  288. CityId: 291,
  289. DepartmentName: "暨南大学附属深圳华侨医院",
  290. HospitalId: "73307826X",
  291. InstType: 1,
  292. DbHost: "183.11.232.26",
  293. DbPort: "3306",
  294. DbPass: "1Q2W3e4r!@#$",
  295. DbUser: "sa",
  296. DbName: "xtzk",
  297. }
  298. // for _, org := range configs {
  299. // 第二步:跟进配置,创建数据库连接
  300. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  301. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  302. if err != nil {
  303. utils.ErrorLog("创建数据库连接失败:%v", err)
  304. return
  305. }
  306. // 第三步:开始同步数据
  307. // 同步医院信息 t_hd_hospital
  308. SyncHospital(orgDb, org.OrgId, org.HospitalId, org.InstType, org.DepartmentName)
  309. // 同步水处理器 t_hd_wm
  310. SyncWMS(orgDb, org.OrgId, org.HospitalId)
  311. // // 同步员工 t_hd_staff
  312. SyncStaff(orgDb, org.OrgId, org.HospitalId)
  313. // // 同步病人 t_hd_patient
  314. SyncPatient(orgDb, org.OrgId, org.HospitalId)
  315. // // 同步排班 t_hd_shift
  316. SyncShift(orgDb, org.OrgId, org.HospitalId)
  317. // 同步处方 t_hd_ps
  318. SyncPs(orgDb, org.OrgId, org.HospitalId)
  319. // 同步处方药品 t_hd_ps
  320. SyncPsMedicine(orgDb, org.OrgId, org.HospitalId)
  321. // // 同步转院信息 t_hd_patient_out
  322. SyncPatientOut(orgDb, org.OrgId, org.HospitalId)
  323. // 同步处方信息 t_hd_doctors_advice
  324. SyncDoctorAdvice(orgDb, org.OrgId, org.HospitalId)
  325. // 同步透中信息 t_hd_middle
  326. SyncMiddle(orgDb, org.OrgId, org.HospitalId)
  327. // // 同步设备 t_hd_other_machine
  328. SyncOtherMachine(orgDb, org.OrgId, org.HospitalId)
  329. // // 同步维修 t_hd_maintain
  330. SyncMachineRepair(orgDb, org.OrgId, org.HospitalId)
  331. // // 同步设备 t_hd_dm
  332. SyncDM(orgDb, org.OrgId, org.HospitalId)
  333. // // 同步患者透析记录 t_hd_dialysis
  334. SyncDialysis(orgDb, org.OrgId, org.HospitalId)
  335. // 同步透析床位分区 t_hd_division
  336. SyncDivision(orgDb, org.OrgId, org.HospitalId)
  337. // 患者通路信息表(T_HD_ACCESS)
  338. SyncAccess(orgDb, org.OrgId, org.HospitalId)
  339. // 透析床位表(T_HD_SICKBED)
  340. SyncSickbed(orgDb, org.OrgId, org.HospitalId)
  341. // 患者诊断信息表(T_HD_DIAGNOSIS)
  342. SyncDiagnosis(orgDb, org.OrgId, org.HospitalId)
  343. // 患者传染病检查记录表(T_HD_INFECTION
  344. SyncInfection(orgDb, org.OrgId, org.HospitalId)
  345. // 透析并发症记录表(T_HD_COMPLICATION)
  346. SyncComplication(orgDb, org.OrgId, org.HospitalId)
  347. // 血透患者检测结果表(T_HD_LIS_REPORT)
  348. SyncLisReport(orgDb, org.OrgId, org.HospitalId)
  349. // 血透患者检验结果指标表(T_HD_LIS_INDICATORS)
  350. SyncLisIndicators(orgDb, org.OrgId, org.HospitalId)
  351. // 第四步:关闭数据库连接
  352. service.CloseDB(orgDb)
  353. }
  354. // }
  355. return
  356. }
  357. func SyncToSmzy() {
  358. // 第一步:到上报配置表中找到深圳需要上报的机构
  359. // sz_province, _ := beego.AppConfig.Int64("sz_province")
  360. // sz_city, _ := beego.AppConfig.Int64("sz_city")
  361. // configs, _ := service.FindAllDataUploadConfigOrgInfo(sz_province, sz_city, 3)
  362. org := &sz.DataUploadConfig{
  363. OrgId: 9504,
  364. ProvinceId: 19,
  365. CityId: 291,
  366. DepartmentName: "深圳生命之源血液透析中心",
  367. HospitalId: "MA5EU4PC0",
  368. InstType: 1,
  369. DbHost: "localhost",
  370. DbPort: "1433",
  371. DbPass: "1Q2W3e4r!@#$",
  372. DbUser: "sa",
  373. DbName: "xtzk",
  374. }
  375. // for _, org := range configs {
  376. // 第二步:跟进配置,创建数据库连接
  377. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  378. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  379. if err != nil {
  380. utils.ErrorLog("创建数据库连接失败:%v", err)
  381. return
  382. }
  383. // 第三步:开始同步数据
  384. // 同步医院信息 t_hd_hospital
  385. SyncHospital(orgDb, org.OrgId, org.HospitalId, org.InstType, org.DepartmentName)
  386. // 同步水处理器 t_hd_wm
  387. SyncWMS(orgDb, org.OrgId, org.HospitalId)
  388. // // 同步员工 t_hd_staff
  389. SyncStaff(orgDb, org.OrgId, org.HospitalId)
  390. // // 同步病人 t_hd_patient
  391. SyncPatient(orgDb, org.OrgId, org.HospitalId)
  392. // // 同步排班 t_hd_shift
  393. SyncShift(orgDb, org.OrgId, org.HospitalId)
  394. // 同步处方 t_hd_ps
  395. SyncPs(orgDb, org.OrgId, org.HospitalId)
  396. // 同步处方药品 t_hd_ps
  397. SyncPsMedicine(orgDb, org.OrgId, org.HospitalId)
  398. // // 同步转院信息 t_hd_patient_out
  399. SyncPatientOut(orgDb, org.OrgId, org.HospitalId)
  400. // 同步处方信息 t_hd_doctors_advice
  401. SyncDoctorAdvice(orgDb, org.OrgId, org.HospitalId)
  402. // 同步透中信息 t_hd_middle
  403. SyncMiddle(orgDb, org.OrgId, org.HospitalId)
  404. // // 同步设备 t_hd_other_machine
  405. SyncOtherMachine(orgDb, org.OrgId, org.HospitalId)
  406. // // 同步维修 t_hd_maintain
  407. SyncMachineRepair(orgDb, org.OrgId, org.HospitalId)
  408. // // 同步设备 t_hd_dm
  409. SyncDM(orgDb, org.OrgId, org.HospitalId)
  410. // // 同步患者透析记录 t_hd_dialysis
  411. SyncDialysis(orgDb, org.OrgId, org.HospitalId)
  412. // 同步透析床位分区 t_hd_division
  413. SyncDivision(orgDb, org.OrgId, org.HospitalId)
  414. // 患者通路信息表(T_HD_ACCESS)
  415. SyncAccess(orgDb, org.OrgId, org.HospitalId)
  416. // 透析床位表(T_HD_SICKBED)
  417. SyncSickbed(orgDb, org.OrgId, org.HospitalId)
  418. // 患者诊断信息表(T_HD_DIAGNOSIS)
  419. SyncDiagnosis(orgDb, org.OrgId, org.HospitalId)
  420. // 患者传染病检查记录表(T_HD_INFECTION
  421. SyncInfection(orgDb, org.OrgId, org.HospitalId)
  422. // 透析并发症记录表(T_HD_COMPLICATION)
  423. SyncComplication(orgDb, org.OrgId, org.HospitalId)
  424. // 血透患者检测结果表(T_HD_LIS_REPORT)
  425. SyncLisReport(orgDb, org.OrgId, org.HospitalId)
  426. // 血透患者检验结果指标表(T_HD_LIS_INDICATORS)
  427. SyncLisIndicators(orgDb, org.OrgId, org.HospitalId)
  428. // 第四步:关闭数据库连接
  429. service.CloseDB(orgDb)
  430. }
  431. // }
  432. return
  433. }
  434. // 同步医院信息
  435. func SyncHospital(rdb *gorm.DB, org_id int64, hospital_id string, inst_type int64, department_name string) {
  436. // 第一步:根据机构id获取上次同步时间
  437. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1)
  438. var sync_time int64
  439. if syncLastInfo.ID > 0 {
  440. sync_time = syncLastInfo.SyncTime
  441. } else {
  442. sync_time = 0
  443. }
  444. // 第二步:跟进上次同步时间找出这个时间段内增加的数据
  445. org, _ := service.FindOrgData(org_id, sync_time)
  446. if org.ID > 0 {
  447. hospital := &sz.TempHdHospital{
  448. HospitalId: hospital_id,
  449. InstType: strconv.FormatInt(inst_type, 10),
  450. DepartmentName: department_name,
  451. AuthorizedBeds: int64(len(org.DeviceNumber)),
  452. CreateTime: time.Now(),
  453. UpdateTime: time.Now(),
  454. Sjscsj: time.Now(),
  455. Xgbz: 0,
  456. }
  457. err := service.CreateOrgRecord(rdb, hospital)
  458. if err == nil {
  459. // 第三步:同步成功后,添加同步记录
  460. upload := &sz.DataUpload{
  461. SyncType: 1,
  462. OrgId: org_id,
  463. SyncTime: time.Now().Unix(),
  464. SyncResultType: 1,
  465. CreateTime: time.Now().Unix(),
  466. UpdateTime: time.Now().Unix(),
  467. }
  468. err := service.CreateUploadRecord(upload)
  469. if err != nil {
  470. utils.ErrorLog("%v", err)
  471. }
  472. }
  473. }
  474. }
  475. // 同步水处理器
  476. func SyncWMS(rdb *gorm.DB, org_id int64, hospital_id string) {
  477. // 第一步:根据机构id获取上次同步时间
  478. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 22)
  479. var sync_time int64
  480. if syncLastInfo.ID > 0 {
  481. sync_time = syncLastInfo.SyncTime
  482. } else {
  483. sync_time = 0
  484. }
  485. //同步水处理机
  486. waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
  487. var wms []*sz.TempHdWm
  488. for _, item := range waterMachine {
  489. wm := &sz.TempHdWm{
  490. HospitalId: hospital_id,
  491. EquipmentId: strconv.FormatInt(item.ID, 10),
  492. EquipmentBrand: item.ManufactureFactory,
  493. EquipmentModel: strconv.FormatInt(item.UnitType, 10),
  494. EnableTime: time.Unix(item.StartDate, 0),
  495. DiscardedTime: time.Unix(item.RubbishDate, 0),
  496. EquipmentType: item.DeviceType,
  497. CreateTime: time.Now(),
  498. UpdateTime: time.Now(),
  499. Sjscsj: time.Now(),
  500. Xgbz: 0,
  501. }
  502. wms = append(wms, wm)
  503. }
  504. err := service.BatchCreateWMsRecord(wms, rdb)
  505. if err == nil {
  506. // 第三步:同步成功后,添加同步记录
  507. upload := &sz.DataUpload{
  508. SyncType: 22,
  509. OrgId: org_id,
  510. SyncTime: time.Now().Unix(),
  511. SyncResultType: 1,
  512. CreateTime: time.Now().Unix(),
  513. UpdateTime: time.Now().Unix(),
  514. }
  515. err := service.CreateUploadRecord(upload)
  516. if err != nil {
  517. utils.ErrorLog("%v", err)
  518. }
  519. } else {
  520. //错误处理
  521. }
  522. }
  523. // 同步员工
  524. func SyncStaff(rdb *gorm.DB, org_id int64, hospital_id string) {
  525. // 第一步:根据机构id获取上次同步时间
  526. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 21)
  527. var sync_time int64
  528. if syncLastInfo.ID > 0 {
  529. sync_time = syncLastInfo.SyncTime
  530. } else {
  531. sync_time = 0
  532. }
  533. //同步员工信息
  534. roles, _ := service.FindOrgRolesData(org_id, sync_time, time.Now().Unix())
  535. //waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
  536. var staffs []*sz.TempHdStaff
  537. for _, role := range roles {
  538. var title int
  539. switch role.UserType {
  540. case 2:
  541. title = 1
  542. break
  543. case 3:
  544. title = 2
  545. break
  546. }
  547. staff := &sz.TempHdStaff{
  548. ID: role.AdminUserId,
  549. HospitalId: hospital_id,
  550. StaffId: strconv.FormatInt(role.ID, 10),
  551. StaffName: role.UserName,
  552. Position: int64(title),
  553. PermanentType: 1,
  554. CreateTime: time.Now(),
  555. UpdateTime: time.Now(),
  556. Sjscsj: time.Now(),
  557. Xgbz: 0,
  558. }
  559. staffs = append(staffs, staff)
  560. }
  561. err := service.BatchCreateStaffRecord(staffs, rdb)
  562. if err == nil {
  563. // 第三步:同步成功后,添加同步记录
  564. upload := &sz.DataUpload{
  565. SyncType: 21,
  566. OrgId: org_id,
  567. SyncTime: time.Now().Unix(),
  568. SyncResultType: 1,
  569. CreateTime: time.Now().Unix(),
  570. UpdateTime: time.Now().Unix(),
  571. }
  572. err := service.CreateUploadRecord(upload)
  573. if err != nil {
  574. utils.ErrorLog("%v", err)
  575. }
  576. } else {
  577. //错误处理
  578. }
  579. }
  580. // 同步病人
  581. func SyncPatient(rdb *gorm.DB, org_id int64, hospital_id string) {
  582. // 第一步:根据机构id获取上次同步时间
  583. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 15)
  584. var sync_time int64
  585. if syncLastInfo.ID > 0 {
  586. sync_time = syncLastInfo.SyncTime
  587. } else {
  588. sync_time = 0
  589. }
  590. //同步员工信息
  591. patients, _ := service.FindOrgPatientData(org_id, sync_time, time.Now().Unix())
  592. //waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
  593. var hdPatients []*sz.TempHdPatient
  594. for _, patient := range patients {
  595. idcard_year, _ := strconv.Atoi(Substr(patient.IdCardNo, 6, 4)) // 年
  596. idcard_mo, _ := strconv.Atoi(Substr(patient.IdCardNo, 10, 2)) // 月
  597. idcard_day, _ := strconv.Atoi(Substr(patient.IdCardNo, 12, 2)) // 日
  598. date := strconv.Itoa(idcard_year)
  599. if idcard_mo < 10 {
  600. date = date + "-0" + strconv.Itoa(idcard_mo)
  601. } else {
  602. date = date + "-" + strconv.Itoa(idcard_mo)
  603. }
  604. if idcard_day < 10 {
  605. date = date + "-0" + strconv.Itoa(idcard_day)
  606. } else {
  607. date = date + "-" + strconv.Itoa(idcard_day)
  608. }
  609. local, _ := time.LoadLocation("Local")
  610. birthday, _ := time.ParseInLocation("2006-01-02", date, local)
  611. fmt.Println(birthday)
  612. var isCKD int
  613. value := strings.Index(patient.Diagnose, "慢性肾脏病")
  614. value2 := strings.Index(patient.Diagnose, "CKD")
  615. value3 := strings.Index(patient.Diagnose, "慢性肾衰竭")
  616. if value != -1 || value2 != -1 || value3 != -1 {
  617. isCKD = 1
  618. } else {
  619. isCKD = 0
  620. }
  621. p := &sz.TempHdPatient{
  622. HospitalId: hospital_id,
  623. PatientNk: patient.ID,
  624. CardNo: "000000000000000000",
  625. CardType: 1,
  626. IdNo: patient.IdCardNo,
  627. IdType: "01",
  628. PatientName: patient.Name,
  629. Gender: strconv.FormatInt(patient.Gender, 10),
  630. BornDate: birthday,
  631. DiagnosisSummary: patient.Diagnose,
  632. IsCrf: strconv.Itoa(isCKD),
  633. DialysisStartTime: time.Unix(patient.FirstDialysisDate, 0),
  634. LocalStartTime: time.Unix(patient.HospitalFirstDialysisDate, 0),
  635. OutpatientNo: patient.DialysisNo,
  636. HospitalizedNo: patient.AdmissionNumber,
  637. CreateTime: time.Now(),
  638. UpdateTime: time.Now(),
  639. Sjscsj: time.Now(),
  640. Xgbz: 0,
  641. }
  642. if patient.FirstDialysisDate != 0 {
  643. p.DialysisStartTime = time.Unix(patient.FirstDialysisDate, 0)
  644. }
  645. if patient.HospitalFirstDialysisDate != 0 {
  646. p.LocalStartTime = time.Unix(patient.HospitalFirstDialysisDate, 0)
  647. }
  648. hdPatients = append(hdPatients, p)
  649. }
  650. err := service.BatchCreatePatinet(hdPatients, rdb)
  651. if err == nil {
  652. // 第三步:同步成功后,添加同步记录
  653. upload := &sz.DataUpload{
  654. SyncType: 15,
  655. OrgId: org_id,
  656. SyncTime: time.Now().Unix(),
  657. SyncResultType: 1,
  658. CreateTime: time.Now().Unix(),
  659. UpdateTime: time.Now().Unix(),
  660. }
  661. err := service.CreateUploadRecord(upload)
  662. if err != nil {
  663. utils.ErrorLog("%v", err)
  664. }
  665. } else {
  666. //错误处理
  667. }
  668. }
  669. func Substr(str string, start, length int) string {
  670. rs := []rune(str)
  671. rl := len(rs)
  672. end := 0
  673. if start < 0 {
  674. start = rl - 1 + start
  675. }
  676. end = start + length
  677. if start > end {
  678. start, end = end, start
  679. }
  680. if start < 0 {
  681. start = 0
  682. }
  683. if start > rl {
  684. start = rl
  685. }
  686. if end < 0 {
  687. end = 0
  688. }
  689. if end > rl {
  690. end = rl
  691. }
  692. return string(rs[start:end])
  693. }
  694. // 同步排班
  695. func SyncShift(rdb *gorm.DB, org_id int64, hospital_id string) {
  696. // 第一步:根据机构id获取上次同步时间
  697. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 19)
  698. var sync_time int64
  699. if syncLastInfo.ID > 0 {
  700. sync_time = syncLastInfo.SyncTime
  701. } else {
  702. sync_time = 0
  703. }
  704. var hdShift []*sz.TempHdShift
  705. schs, _ := service.FindOrgScheduleData(org_id, sync_time, time.Now().Unix())
  706. for _, sch := range schs {
  707. shift := &sz.TempHdShift{
  708. PsId: strconv.FormatInt(sch.ID, 10),
  709. HospitalId: hospital_id,
  710. PatientNk: strconv.FormatInt(sch.PatientId, 10),
  711. ScheduleDate: time.Unix(sch.ScheduleDate, 0),
  712. ShiftType: strconv.FormatInt(sch.ScheduleType, 10),
  713. SickbedNo: sch.DeviceNumber.ID,
  714. ScheduleStatus: "1",
  715. CreateTime: time.Now(),
  716. Sjscsj: time.Now(),
  717. Xgbz: 0,
  718. }
  719. hdShift = append(hdShift, shift)
  720. }
  721. err := service.BatchCreateSchedual(hdShift, rdb)
  722. if err == nil {
  723. // 第三步:同步成功后,添加同步记录
  724. upload := &sz.DataUpload{
  725. SyncType: 19,
  726. OrgId: org_id,
  727. SyncTime: time.Now().Unix(),
  728. SyncResultType: 1,
  729. CreateTime: time.Now().Unix(),
  730. UpdateTime: time.Now().Unix(),
  731. }
  732. err := service.CreateUploadRecord(upload)
  733. if err != nil {
  734. utils.ErrorLog("%v", err)
  735. }
  736. } else {
  737. //错误处理
  738. }
  739. }
  740. // 同步处方
  741. func SyncPs(rdb *gorm.DB, org_id int64, hospital_id string) {
  742. // 第一步:根据机构id获取上次同步时间
  743. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 17)
  744. var sync_time int64
  745. if syncLastInfo.ID > 0 {
  746. sync_time = syncLastInfo.SyncTime
  747. } else {
  748. sync_time = 0
  749. }
  750. var hdPrescription []*sz.TempHdPs
  751. prescriptions, _ := service.FindOrgDialysisPrescriptionData(org_id, sync_time, time.Now().Unix())
  752. for _, item := range prescriptions {
  753. ps := &sz.TempHdPs{
  754. PrescribeId: strconv.FormatInt(item.ID, 10),
  755. HospitalId: hospital_id,
  756. PatientNk: strconv.FormatInt(item.PatientId, 10),
  757. Sjscsj: time.Now(),
  758. Xgbz: 0,
  759. PrescribeTime: time.Unix(item.RecordDate, 0),
  760. CreateTime: time.Unix(item.CreatedTime, 0),
  761. }
  762. switch item.ModeId {
  763. case 1:
  764. ps.DialysisFrequency = 5
  765. ps.FrequencyUnit = 2
  766. ps.RrtTypeName = "HD"
  767. ps.RrtType = 1
  768. break
  769. case 2:
  770. ps.DialysisFrequency = 5
  771. ps.FrequencyUnit = 2
  772. ps.RrtTypeName = "HDF"
  773. ps.RrtType = 3
  774. break
  775. case 4:
  776. ps.DialysisFrequency = 5
  777. ps.FrequencyUnit = 2
  778. ps.RrtTypeName = "HP"
  779. ps.RrtType = 5
  780. break
  781. case 5:
  782. ps.DialysisFrequency = 5
  783. ps.FrequencyUnit = 2
  784. ps.RrtTypeName = "HF"
  785. ps.RrtType = 2
  786. break
  787. case 7:
  788. ps.DialysisFrequency = 5
  789. ps.FrequencyUnit = 2
  790. ps.RrtTypeName = "IUF"
  791. ps.RrtType = 6
  792. break
  793. default:
  794. ps.DialysisFrequency = 5
  795. ps.FrequencyUnit = 2
  796. ps.RrtTypeName = "HD"
  797. ps.RrtType = 1
  798. break
  799. }
  800. hdPrescription = append(hdPrescription, ps)
  801. }
  802. var err error
  803. for _, hdps := range hdPrescription {
  804. err = service.BatchCreatePsOther(hdps, rdb)
  805. }
  806. // err := service.BatchCreatePs(hdPrescription, rdb)
  807. if err == nil {
  808. // 第三步:同步成功后,添加同步记录
  809. upload := &sz.DataUpload{
  810. SyncType: 17,
  811. OrgId: org_id,
  812. SyncTime: time.Now().Unix(),
  813. SyncResultType: 1,
  814. CreateTime: time.Now().Unix(),
  815. UpdateTime: time.Now().Unix(),
  816. }
  817. err := service.CreateUploadRecord(upload)
  818. if err != nil {
  819. utils.ErrorLog("%v", err)
  820. }
  821. } else {
  822. //错误处理
  823. }
  824. }
  825. // 同步处方药物
  826. func SyncPsMedicine(rdb *gorm.DB, org_id int64, hospital_id string) {
  827. // 第一步:根据机构id获取上次同步时间
  828. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 18)
  829. var sync_time int64
  830. if syncLastInfo.ID > 0 {
  831. sync_time = syncLastInfo.SyncTime
  832. } else {
  833. sync_time = 0
  834. }
  835. var tempPsmedicine []*sz.TempHdPsMedicine
  836. prescriptions, _ := service.FindOrgDoctorAdviceTemplateData(org_id, sync_time, time.Now().Unix())
  837. for _, item := range prescriptions {
  838. psm := &sz.TempHdPsMedicine{
  839. Sn: item.ID,
  840. HospitalId: hospital_id,
  841. MedicineTypeId: "2",
  842. MedicineId: strconv.FormatInt(item.ID, 10),
  843. CreateTime: time.Now(),
  844. Sjscsj: time.Now(),
  845. Xgbz: 0,
  846. }
  847. tempPsmedicine = append(tempPsmedicine, psm)
  848. }
  849. err := service.BatchCreatePsm(tempPsmedicine, rdb)
  850. if err == nil {
  851. // 第三步:同步成功后,添加同步记录
  852. upload := &sz.DataUpload{
  853. SyncType: 18,
  854. OrgId: org_id,
  855. SyncTime: time.Now().Unix(),
  856. SyncResultType: 1,
  857. CreateTime: time.Now().Unix(),
  858. UpdateTime: time.Now().Unix(),
  859. }
  860. err := service.CreateUploadRecord(upload)
  861. if err != nil {
  862. utils.ErrorLog("%v", err)
  863. }
  864. } else {
  865. //错误处理
  866. }
  867. }
  868. // 同步转院信息
  869. func SyncPatientOut(rdb *gorm.DB, org_id int64, hospital_id string) {
  870. // 第一步:根据机构id获取上次同步时间
  871. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 16)
  872. var sync_time int64
  873. if syncLastInfo.ID > 0 {
  874. sync_time = syncLastInfo.SyncTime
  875. } else {
  876. sync_time = 0
  877. }
  878. var hdPatientOuts []*sz.TempHdPatientOut
  879. patients, _ := service.FindOrgPatientOutData(org_id, sync_time, time.Now().Unix())
  880. //
  881. for _, patient := range patients {
  882. p := &sz.TempHdPatientOut{
  883. Sn: strconv.FormatInt(patient.PatientLapseto.ID, 10),
  884. HospitalId: hospital_id,
  885. PatientNk: strconv.FormatInt(patient.ID, 10),
  886. SequelaeDate: time.Unix(patient.PatientLapseto.LapsetoTime, 0),
  887. SequelaeType: "99",
  888. CreateTime: time.Unix(patient.PatientLapseto.CreatedTime, 0),
  889. DeathReason: "99",
  890. ExtReason: "99",
  891. Sjscsj: time.Now(),
  892. Xgbz: 0,
  893. }
  894. hdPatientOuts = append(hdPatientOuts, p)
  895. }
  896. err := service.BatchCreatePatientOut(hdPatientOuts, rdb)
  897. if err == nil {
  898. // 第三步:同步成功后,添加同步记录
  899. upload := &sz.DataUpload{
  900. SyncType: 16,
  901. OrgId: org_id,
  902. SyncTime: time.Now().Unix(),
  903. SyncResultType: 1,
  904. CreateTime: time.Now().Unix(),
  905. UpdateTime: time.Now().Unix(),
  906. }
  907. err := service.CreateUploadRecord(upload)
  908. if err != nil {
  909. utils.ErrorLog("%v", err)
  910. }
  911. } else {
  912. //错误处理
  913. }
  914. }
  915. // 同步处方信息
  916. func SyncDoctorAdvice(rdb *gorm.DB, org_id int64, hospital_id string) {
  917. // 第一步:根据机构id获取上次同步时间
  918. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 6)
  919. var sync_time int64
  920. if syncLastInfo.ID > 0 {
  921. sync_time = syncLastInfo.SyncTime
  922. } else {
  923. sync_time = 0
  924. }
  925. var hdDoctorAdvices []*sz.TempHdDoctorsAdvice
  926. dialysisPrescriptions, _ := service.FindOrgDialysisPrescriptionData(org_id, sync_time, time.Now().Unix())
  927. for _, dp := range dialysisPrescriptions {
  928. if dp.DialysisOrder.ID > 0 {
  929. advice := &sz.TempHdDoctorsAdvice{
  930. MedicalOrderId: strconv.FormatInt(dp.ID, 10),
  931. HospitalId: hospital_id,
  932. DialysisId: strconv.FormatInt(dp.DialysisOrder.ID, 10),
  933. OrderType: "1",
  934. PatientNk: strconv.FormatInt(dp.PatientId, 10),
  935. DialysisDuration: dp.DialysisDurationHour*60 + dp.DialysisDurationMinute,
  936. BloodVol: int64(math.Floor(dp.BloodFlowVolume + 0/5)),
  937. Anticoagulant: dp.Anticoagulant,
  938. CreateTime: time.Now(),
  939. Sjscsj: time.Now(),
  940. Xgbz: 0,
  941. DryWeight: dp.AssessmentBeforeDislysis.DryWeight,
  942. }
  943. switch dp.ModeId {
  944. case 1:
  945. advice.RrtTypeName = "HD"
  946. advice.RrtType = 1
  947. break
  948. case 2:
  949. advice.RrtTypeName = "HDF"
  950. advice.RrtType = 3
  951. break
  952. case 4:
  953. advice.RrtTypeName = "HP"
  954. advice.RrtType = 5
  955. break
  956. case 5:
  957. advice.RrtTypeName = "HF"
  958. advice.RrtType = 2
  959. break
  960. case 7:
  961. advice.RrtTypeName = "IUF"
  962. advice.RrtType = 6
  963. break
  964. default:
  965. advice.RrtTypeName = "HD"
  966. advice.RrtType = 1
  967. }
  968. if advice.RrtType == 0 {
  969. continue
  970. }
  971. hdDoctorAdvices = append(hdDoctorAdvices, advice)
  972. }
  973. }
  974. err := service.BatchCreateDoctorsAdvice(hdDoctorAdvices, rdb)
  975. if err == nil {
  976. // 第三步:同步成功后,添加同步记录
  977. upload := &sz.DataUpload{
  978. SyncType: 6,
  979. OrgId: org_id,
  980. SyncTime: time.Now().Unix(),
  981. SyncResultType: 1,
  982. CreateTime: time.Now().Unix(),
  983. UpdateTime: time.Now().Unix(),
  984. }
  985. err := service.CreateUploadRecord(upload)
  986. if err != nil {
  987. utils.ErrorLog("%v", err)
  988. }
  989. } else {
  990. //错误处理
  991. }
  992. }
  993. //
  994. func SyncMiddle(rdb *gorm.DB, org_id int64, hospital_id string) {
  995. // 第一步:根据机构id获取上次同步时间
  996. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 36)
  997. var sync_time int64
  998. if syncLastInfo.ID > 0 {
  999. sync_time = syncLastInfo.SyncTime
  1000. } else {
  1001. sync_time = 0
  1002. }
  1003. var hdMiddle []*sz.TempHdMiddle
  1004. monitors, _ := service.FindOrgMonitorRecordData(org_id, sync_time, time.Now().Unix())
  1005. for _, item := range monitors {
  1006. mid := &sz.TempHdMiddle{
  1007. Sn: item.ID,
  1008. HospitalId: hospital_id,
  1009. DialysisId: strconv.FormatInt(item.DialysisOrder.ID, 10),
  1010. MonitorTime: time.Unix(item.OperateTime, 0),
  1011. Sbp: int64(math.Floor(item.SystolicBloodPressure + 0/5)),
  1012. Dbp: int64(math.Floor(item.DiastolicBloodPressure + 0/5)),
  1013. PatientNk: strconv.FormatInt(item.PatientId, 10),
  1014. CreateTime: time.Now(),
  1015. Sjscsj: time.Now(),
  1016. Xgbz: 0,
  1017. }
  1018. if mid.Sbp > 999 {
  1019. continue
  1020. }
  1021. if mid.Dbp > 999 {
  1022. continue
  1023. }
  1024. hdMiddle = append(hdMiddle, mid)
  1025. }
  1026. err := service.BatchCreateMonitor(hdMiddle, rdb)
  1027. if err == nil {
  1028. // 第三步:同步成功后,添加同步记录
  1029. upload := &sz.DataUpload{
  1030. SyncType: 36,
  1031. OrgId: org_id,
  1032. SyncTime: time.Now().Unix(),
  1033. SyncResultType: 1,
  1034. CreateTime: time.Now().Unix(),
  1035. UpdateTime: time.Now().Unix(),
  1036. }
  1037. err := service.CreateUploadRecord(upload)
  1038. if err != nil {
  1039. utils.ErrorLog("%v", err)
  1040. }
  1041. } else {
  1042. //错误处理
  1043. }
  1044. }
  1045. // 同步设备
  1046. func SyncOtherMachine(rdb *gorm.DB, org_id int64, hospital_id string) {
  1047. // 第一步:根据机构id获取上次同步时间
  1048. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 13)
  1049. var sync_time int64
  1050. if syncLastInfo.ID > 0 {
  1051. sync_time = syncLastInfo.SyncTime
  1052. } else {
  1053. sync_time = 0
  1054. }
  1055. //同步设备
  1056. waterMachine, _ := service.FindOrgOtherMachineData(org_id, sync_time, time.Now().Unix())
  1057. var wms []*sz.TempHdOtherMachine
  1058. for _, item := range waterMachine {
  1059. wm := &sz.TempHdOtherMachine{
  1060. HospitalId: hospital_id,
  1061. EquipmentId: strconv.FormatInt(item.ID, 10),
  1062. EquipmentBrand: item.ManufactureFactory,
  1063. EquipmentModel: strconv.FormatInt(item.UnitType, 10),
  1064. EnableTime: time.Unix(item.BuyDate, 0),
  1065. Status: 1,
  1066. EquipmentType: 11,
  1067. CreateTime: time.Now(),
  1068. UpdateTime: time.Now(),
  1069. Sjscsj: time.Now(),
  1070. Xgbz: strconv.FormatInt(0, 10),
  1071. }
  1072. switch item.MachineStatus {
  1073. case 1:
  1074. wm.Status = 1
  1075. break
  1076. case 4:
  1077. wm.Status = 3
  1078. break
  1079. }
  1080. wms = append(wms, wm)
  1081. }
  1082. err := service.BatchCreateOtherMachineRecord(wms, rdb)
  1083. if err == nil {
  1084. // 第三步:同步成功后,添加同步记录
  1085. upload := &sz.DataUpload{
  1086. SyncType: 13,
  1087. OrgId: org_id,
  1088. SyncTime: time.Now().Unix(),
  1089. SyncResultType: 1,
  1090. CreateTime: time.Now().Unix(),
  1091. UpdateTime: time.Now().Unix(),
  1092. }
  1093. err := service.CreateUploadRecord(upload)
  1094. if err != nil {
  1095. utils.ErrorLog("%v", err)
  1096. }
  1097. } else {
  1098. //错误处理
  1099. }
  1100. }
  1101. // 同步维修
  1102. func SyncMachineRepair(rdb *gorm.DB, org_id int64, hospital_id string) {
  1103. // 第一步:根据机构id获取上次同步时间
  1104. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 11)
  1105. var sync_time int64
  1106. if syncLastInfo.ID > 0 {
  1107. sync_time = syncLastInfo.SyncTime
  1108. } else {
  1109. sync_time = 0
  1110. }
  1111. //同步设备
  1112. hdMaintain, _ := service.FindOrgMachineRepairData(org_id, sync_time, time.Now().Unix())
  1113. var maintain []*sz.TempHdMaintain
  1114. for _, item := range hdMaintain {
  1115. mt := &sz.TempHdMaintain{
  1116. HospitalId: hospital_id,
  1117. EquipmentId: strconv.FormatInt(item.VMDeviceAddmacher.ID, 10),
  1118. RepairTime: time.Unix(item.GuaranteeDate, 0),
  1119. CreateTime: time.Now(),
  1120. Sjscsj: time.Now(),
  1121. Xgbz: 0,
  1122. }
  1123. switch item.VMDeviceAddmacher.DeviceType {
  1124. case 1:
  1125. mt.EquipmentType = "11"
  1126. break
  1127. case 2:
  1128. mt.EquipmentType = "21"
  1129. break
  1130. case 3:
  1131. mt.EquipmentType = "99"
  1132. break
  1133. }
  1134. maintain = append(maintain, mt)
  1135. }
  1136. err := service.BatchCreateMainTain(maintain, rdb)
  1137. if err == nil {
  1138. // 第三步:同步成功后,添加同步记录
  1139. upload := &sz.DataUpload{
  1140. SyncType: 11,
  1141. OrgId: org_id,
  1142. SyncTime: time.Now().Unix(),
  1143. SyncResultType: 1,
  1144. CreateTime: time.Now().Unix(),
  1145. UpdateTime: time.Now().Unix(),
  1146. }
  1147. err := service.CreateUploadRecord(upload)
  1148. if err != nil {
  1149. utils.ErrorLog("%v", err)
  1150. }
  1151. } else {
  1152. //错误处理
  1153. }
  1154. }
  1155. // 同步设备
  1156. func SyncDM(rdb *gorm.DB, org_id int64, hospital_id string) {
  1157. // 第一步:根据机构id获取上次同步时间
  1158. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 5)
  1159. var sync_time int64
  1160. if syncLastInfo.ID > 0 {
  1161. sync_time = syncLastInfo.SyncTime
  1162. } else {
  1163. sync_time = 0
  1164. }
  1165. //同步设备
  1166. dm, _ := service.FindOrgMachineData(org_id, sync_time, time.Now().Unix())
  1167. var hdms []*sz.TempHdDm
  1168. for _, item := range dm {
  1169. hdm := &sz.TempHdDm{
  1170. HospitalId: hospital_id,
  1171. EquipmentId: strconv.FormatInt(item.ID, 10),
  1172. SickbedNo: strconv.FormatInt(item.DeviceNumber.ID, 10),
  1173. SickbedType: "0",
  1174. EquipmentBrand: item.ManufactureFactory,
  1175. EquipmentModel: strconv.FormatInt(item.UnitType, 10),
  1176. EnableTime: time.Unix(item.BuyDate, 0),
  1177. // EquipmentType: "11",
  1178. Bbp: "0",
  1179. CreateTime: time.Now(),
  1180. UpdateTime: time.Now(),
  1181. Sjscsj: time.Now(),
  1182. Xgbz: strconv.FormatInt(0, 10),
  1183. }
  1184. switch item.MachineStatus {
  1185. case 1:
  1186. hdm.Status = "1"
  1187. break
  1188. case 4:
  1189. hdm.Status = "3"
  1190. break
  1191. }
  1192. switch item.DeviceType {
  1193. case 1:
  1194. hdm.EquipmentType = "11"
  1195. break
  1196. case 3:
  1197. hdm.EquipmentType = "99"
  1198. break
  1199. }
  1200. hdms = append(hdms, hdm)
  1201. }
  1202. err := service.BatchCreateHDMRecord(hdms, rdb)
  1203. if err == nil {
  1204. // 第三步:同步成功后,添加同步记录
  1205. upload := &sz.DataUpload{
  1206. SyncType: 5,
  1207. OrgId: org_id,
  1208. SyncTime: time.Now().Unix(),
  1209. SyncResultType: 1,
  1210. CreateTime: time.Now().Unix(),
  1211. UpdateTime: time.Now().Unix(),
  1212. }
  1213. err := service.CreateUploadRecord(upload)
  1214. if err != nil {
  1215. utils.ErrorLog("%v", err)
  1216. }
  1217. } else {
  1218. //错误处理
  1219. }
  1220. }
  1221. // 同步患者透析记录
  1222. func SyncDialysis(rdb *gorm.DB, org_id int64, hospital_id string) {
  1223. // 第一步:根据机构id获取上次同步时间
  1224. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 2)
  1225. var sync_time int64
  1226. if syncLastInfo.ID > 0 {
  1227. sync_time = syncLastInfo.SyncTime
  1228. } else {
  1229. sync_time = 0
  1230. }
  1231. var tempDialysis []*sz.TempHdDialysis
  1232. dialysisData, _ := service.FindOrgDialysisData(org_id, sync_time, time.Now().Unix())
  1233. for _, item := range dialysisData {
  1234. psm := &sz.TempHdDialysis{
  1235. DialysisId: strconv.FormatInt(item.ID, 10),
  1236. HospitalId: hospital_id,
  1237. PatientNk: strconv.FormatInt(item.PatientId, 10),
  1238. PsId: strconv.FormatInt(item.Schedule.ID, 10),
  1239. DialysisDate: time.Unix(item.DialysisDate, 0),
  1240. SickbedNo: item.DeviceNumber.Number,
  1241. DivisionId: strconv.FormatInt(item.Schedule.PartitionId, 10),
  1242. EquipmentId: strconv.FormatInt(item.DeviceNumber.ID, 10),
  1243. MixDialysis: "0",
  1244. TotalTreatDuration: item.AssessmentAfterDislysis.ActualTreatmentHour*60 + item.AssessmentAfterDislysis.ActualTreatmentMinute,
  1245. IsHospitalization: "0",
  1246. IsEmergency: "0",
  1247. IsPerioperativePeriod: "0",
  1248. BeforeSbp: int64(item.AssessmentBeforeDislysis.SystolicBloodPressure),
  1249. BeforeDbp: int64(item.AssessmentBeforeDislysis.DiastolicBloodPressure),
  1250. AfterSbp: int64(item.AssessmentAfterDislysis.SystolicBloodPressure),
  1251. AfterDbp: int64(item.AssessmentAfterDislysis.DiastolicBloodPressure),
  1252. BeforeWeight: item.AssessmentBeforeDislysis.WeightBefore,
  1253. AfterWeight: item.AssessmentAfterDislysis.WeightAfter,
  1254. UpNurseId: strconv.FormatInt(item.StartNurse, 10),
  1255. DownNurseId: strconv.FormatInt(item.FinishNurse, 10),
  1256. CheckNurseId: strconv.FormatInt(item.FinishNurse, 10),
  1257. PunctureNurseId: strconv.FormatInt(item.PunctureNurse, 10),
  1258. StartTime: time.Unix(item.StartTime, 0),
  1259. EndTime: time.Unix(item.EndTime, 0),
  1260. CreateTime: time.Unix(item.CreatedTime, 0),
  1261. Sjscsj: time.Now(),
  1262. Xgbz: 0,
  1263. }
  1264. if item.AssessmentAfterDislysis.ActualUltrafiltration < 10 {
  1265. psm.ActualufMl = int64(item.AssessmentAfterDislysis.ActualUltrafiltration * 1000)
  1266. } else {
  1267. psm.ActualufMl = int64(item.AssessmentAfterDislysis.ActualUltrafiltration)
  1268. }
  1269. if item.VMDialysisPrescription.TargetUltrafiltration < 10 {
  1270. psm.Ufv = int64(item.VMDialysisPrescription.TargetUltrafiltration * 1000)
  1271. } else {
  1272. psm.Ufv = int64(item.VMDialysisPrescription.TargetUltrafiltration)
  1273. }
  1274. if item.AssessmentAfterDislysis.ActualDisplacement < 10 {
  1275. psm.TotalReplace = int64(item.AssessmentAfterDislysis.ActualDisplacement * 1000)
  1276. } else {
  1277. psm.TotalReplace = int64(item.AssessmentAfterDislysis.ActualDisplacement)
  1278. }
  1279. tempDialysis = append(tempDialysis, psm)
  1280. }
  1281. err := service.BatchCreateDialysis(tempDialysis, rdb)
  1282. if err == nil {
  1283. // 第三步:同步成功后,添加同步记录
  1284. upload := &sz.DataUpload{
  1285. SyncType: 2,
  1286. OrgId: org_id,
  1287. SyncTime: time.Now().Unix(),
  1288. SyncResultType: 1,
  1289. CreateTime: time.Now().Unix(),
  1290. UpdateTime: time.Now().Unix(),
  1291. }
  1292. err := service.CreateUploadRecord(upload)
  1293. if err != nil {
  1294. utils.ErrorLog("%v", err)
  1295. }
  1296. } else {
  1297. //错误处理
  1298. }
  1299. }
  1300. // 同步透析床位分区
  1301. func SyncDivision(rdb *gorm.DB, org_id int64, hospital_id string) {
  1302. // 第一步:根据机构id获取上次同步时间
  1303. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 55)
  1304. var sync_time int64
  1305. if syncLastInfo.ID > 0 {
  1306. sync_time = syncLastInfo.SyncTime
  1307. } else {
  1308. sync_time = 0
  1309. }
  1310. //同步透析床位分区
  1311. dm, _ := service.FindOrgDeviceZoneRecordData(org_id, sync_time, time.Now().Unix())
  1312. var hdms []*sz.TempHdDivision
  1313. for _, item := range dm {
  1314. hdm := &sz.TempHdDivision{
  1315. DivisionId: strconv.FormatInt(item.ID, 10),
  1316. HospitalId: hospital_id,
  1317. DivisionName: item.Name,
  1318. DivisionType: strconv.FormatInt(item.Type, 10),
  1319. CreateTime: time.Now(),
  1320. UpdateTime: time.Now(),
  1321. Sjscsj: time.Now(),
  1322. Xgbz: strconv.FormatInt(0, 10),
  1323. }
  1324. hdms = append(hdms, hdm)
  1325. }
  1326. err := service.CreateHDDivision(hdms, rdb)
  1327. if err == nil {
  1328. // 第三步:同步成功后,添加同步记录
  1329. upload := &sz.DataUpload{
  1330. SyncType: 55,
  1331. OrgId: org_id,
  1332. SyncTime: time.Now().Unix(),
  1333. SyncResultType: 1,
  1334. CreateTime: time.Now().Unix(),
  1335. UpdateTime: time.Now().Unix(),
  1336. }
  1337. err := service.CreateUploadRecord(upload)
  1338. if err != nil {
  1339. utils.ErrorLog("%v", err)
  1340. }
  1341. } else {
  1342. //错误处理
  1343. }
  1344. }
  1345. // 患者通路信息表
  1346. func SyncAccess(rdb *gorm.DB, org_id int64, hospital_id string) {
  1347. // 第一步:根据机构id获取上次同步时间
  1348. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 56)
  1349. var sync_time int64
  1350. if syncLastInfo.ID > 0 {
  1351. sync_time = syncLastInfo.SyncTime
  1352. } else {
  1353. sync_time = 0
  1354. }
  1355. //同步员工信息
  1356. patients, _ := service.FindOrgPatientData(org_id, sync_time, time.Now().Unix())
  1357. var accessList []*sz.TempHdAccess
  1358. for _, patient := range patients {
  1359. before, _ := service.FindAssessmentBeforeDislysis(org_id, patient.ID)
  1360. if before.ID > 0 {
  1361. access := &sz.TempHdAccess{
  1362. AccessId: before.ID,
  1363. HospitalId: hospital_id,
  1364. PatientNk: strconv.FormatInt(before.PatientId, 10),
  1365. AccessType: 1,
  1366. AccessTypeName: "自体动静脉内瘘",
  1367. AccessStatus: 1,
  1368. SetupDate: time.Unix(patient.FirstDialysisDate, 0),
  1369. FirstUseTime: time.Unix(patient.FirstDialysisDate, 0),
  1370. CreateTime: time.Now(),
  1371. UpdateTime: time.Now(),
  1372. Sjscsj: time.Now(),
  1373. Xgbz: 0,
  1374. }
  1375. accessList = append(accessList, access)
  1376. }
  1377. }
  1378. if len(accessList) > 0 {
  1379. err := service.CreateAccess(accessList, rdb)
  1380. if err == nil {
  1381. // 第三步:同步成功后,添加同步记录
  1382. upload := &sz.DataUpload{
  1383. SyncType: 56,
  1384. OrgId: org_id,
  1385. SyncTime: time.Now().Unix(),
  1386. SyncResultType: 1,
  1387. CreateTime: time.Now().Unix(),
  1388. UpdateTime: time.Now().Unix(),
  1389. }
  1390. err := service.CreateUploadRecord(upload)
  1391. if err != nil {
  1392. utils.ErrorLog("%v", err)
  1393. }
  1394. } else {
  1395. //错误处理
  1396. }
  1397. }
  1398. }
  1399. // 透析床位表
  1400. func SyncSickbed(rdb *gorm.DB, org_id int64, hospital_id string) {
  1401. // 第一步:根据机构id获取上次同步时间
  1402. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 57)
  1403. var sync_time int64
  1404. if syncLastInfo.ID > 0 {
  1405. sync_time = syncLastInfo.SyncTime
  1406. } else {
  1407. sync_time = 0
  1408. }
  1409. //同步床位
  1410. devices, _ := service.FindOrgDeviceNumber(org_id, sync_time, time.Now().Unix())
  1411. var sickbedList []*sz.TempHdSickbed
  1412. for _, device := range devices {
  1413. sickbed := &sz.TempHdSickbed{
  1414. SickbedNo: device.ID,
  1415. HospitalId: hospital_id,
  1416. DivisionId: strconv.FormatInt(device.ZoneId, 10),
  1417. SickbedCode: device.Number,
  1418. SickbedType: "0",
  1419. CreateTime: time.Now(),
  1420. UpdateTime: time.Now(),
  1421. Sjscsj: time.Now(),
  1422. Xgbz: 0,
  1423. }
  1424. sickbedList = append(sickbedList, sickbed)
  1425. }
  1426. if len(sickbedList) > 0 {
  1427. err := service.CreateSickbed(sickbedList, rdb)
  1428. if err == nil {
  1429. // 第三步:同步成功后,添加同步记录
  1430. upload := &sz.DataUpload{
  1431. SyncType: 57,
  1432. OrgId: org_id,
  1433. SyncTime: time.Now().Unix(),
  1434. SyncResultType: 1,
  1435. CreateTime: time.Now().Unix(),
  1436. UpdateTime: time.Now().Unix(),
  1437. }
  1438. err := service.CreateUploadRecord(upload)
  1439. if err != nil {
  1440. utils.ErrorLog("%v", err)
  1441. }
  1442. } else {
  1443. //错误处理
  1444. }
  1445. }
  1446. }
  1447. // 患者诊断信息表(T_HD_DIAGNOSIS)
  1448. func SyncDiagnosis(rdb *gorm.DB, org_id int64, hospital_id string) {
  1449. // 第一步:根据机构id获取上次同步时间
  1450. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 58)
  1451. var sync_time int64
  1452. if syncLastInfo.ID > 0 {
  1453. sync_time = syncLastInfo.SyncTime
  1454. } else {
  1455. sync_time = 0
  1456. }
  1457. //同步患者
  1458. patients, _ := service.FindOrgPatientData(org_id, sync_time, time.Now().Unix())
  1459. var diagnosisList []*sz.TempHdDiagnosis
  1460. for _, patient := range patients {
  1461. diagnosis := &sz.TempHdDiagnosis{
  1462. DiagnosisId: patient.ID,
  1463. HospitalId: hospital_id,
  1464. PatientNk: strconv.FormatInt(patient.ID, 10),
  1465. DiagnosisTime: time.Unix(patient.CreatedTime, 0),
  1466. DiagnosisType: "10",
  1467. DiagnosisTypeItem: "1001",
  1468. DiagnosisTypeDetail: "100113",
  1469. CreateTime: time.Now(),
  1470. UpdateTime: time.Now(),
  1471. Sjscsj: time.Now(),
  1472. Xgbz: 0,
  1473. }
  1474. diagnosisList = append(diagnosisList, diagnosis)
  1475. }
  1476. if len(diagnosisList) > 0 {
  1477. err := service.CreateDiagnosis(diagnosisList, rdb)
  1478. if err == nil {
  1479. // 第三步:同步成功后,添加同步记录
  1480. upload := &sz.DataUpload{
  1481. SyncType: 58,
  1482. OrgId: org_id,
  1483. SyncTime: time.Now().Unix(),
  1484. SyncResultType: 1,
  1485. CreateTime: time.Now().Unix(),
  1486. UpdateTime: time.Now().Unix(),
  1487. }
  1488. err := service.CreateUploadRecord(upload)
  1489. if err != nil {
  1490. utils.ErrorLog("%v", err)
  1491. }
  1492. } else {
  1493. //错误处理
  1494. }
  1495. }
  1496. }
  1497. // 患者传染病检查记录表(T_HD_INFECTION
  1498. func SyncInfection(rdb *gorm.DB, org_id int64, hospital_id string) {
  1499. // 第一步:根据机构id获取上次同步时间
  1500. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 59)
  1501. var sync_time int64
  1502. if syncLastInfo.ID > 0 {
  1503. sync_time = syncLastInfo.SyncTime
  1504. } else {
  1505. sync_time = 0
  1506. }
  1507. //同步患者
  1508. patients, _ := service.FindOrgPatientDataOne(org_id)
  1509. var infectionList []*sz.TempHdInfection
  1510. for _, patient := range patients {
  1511. // 查询有没有做传染病检查并返回检验检查时间
  1512. inspections, _ := service.FindOrgInspectionGroupOne(org_id, sync_time, time.Now().Unix(), patient.ID)
  1513. if len(inspections) > 0 {
  1514. for _, insp := range inspections {
  1515. inspection_arr, _ := service.FindOrgInspectionGroupTwo(org_id, insp.InspectDate, patient.ID)
  1516. if len(inspection_arr) > 0 {
  1517. infection := &sz.TempHdInfection{
  1518. Sn: strconv.FormatInt(patient.ID, 10),
  1519. HospitalId: hospital_id,
  1520. PatientNk: strconv.FormatInt(patient.ID, 10),
  1521. Hbv: 0,
  1522. Hcv: 0,
  1523. Rpr: 0,
  1524. Hiv: 0,
  1525. Hbsag: 9,
  1526. Hbsab: 9,
  1527. Hbeag: 9,
  1528. Hbeab: 9,
  1529. Hbcab: 9,
  1530. CheckDate: time.Unix(patient.CreatedTime, 0),
  1531. DoctorId: strconv.FormatInt(patient.RegistrarsId, 10),
  1532. CreateTime: time.Now(),
  1533. Sjscsj: time.Now(),
  1534. Xgbz: 0,
  1535. }
  1536. for _, infectionDiseases := range inspection_arr {
  1537. if infectionDiseases.ItemId == 60 {
  1538. infection.Hcv = 0
  1539. if infectionDiseases.InspectValue == "阳性" {
  1540. infection.Hcv = 1
  1541. }
  1542. }
  1543. if infectionDiseases.ItemId == 62 {
  1544. infection.Hbsag = 0
  1545. if infectionDiseases.InspectValue == "阳性" {
  1546. infection.Hbsag = 1
  1547. }
  1548. }
  1549. if infectionDiseases.ItemId == 63 {
  1550. infection.Hbsab = 0
  1551. if infectionDiseases.InspectValue == "阳性" {
  1552. infection.Hbsab = 1
  1553. }
  1554. }
  1555. if infectionDiseases.ItemId == 64 {
  1556. infection.Hbeag = 0
  1557. if infectionDiseases.InspectValue == "阳性" {
  1558. infection.Hbeag = 1
  1559. }
  1560. }
  1561. if infectionDiseases.ItemId == 65 {
  1562. infection.Hbeab = 0
  1563. if infectionDiseases.InspectValue == "阳性" {
  1564. infection.Hbeab = 1
  1565. }
  1566. }
  1567. if infectionDiseases.ItemId == 66 {
  1568. infection.Hbcab = 0
  1569. if infectionDiseases.InspectValue == "阳性" {
  1570. infection.Hbcab = 1
  1571. }
  1572. }
  1573. if infectionDiseases.ItemId == 111 {
  1574. infection.Hiv = 0
  1575. if infectionDiseases.InspectValue == "阳性" {
  1576. infection.Hiv = 1
  1577. }
  1578. }
  1579. if infectionDiseases.ItemId == 112 {
  1580. infection.Rpr = 0
  1581. if infectionDiseases.InspectValue == "阳性" {
  1582. infection.Rpr = 1
  1583. }
  1584. }
  1585. if infectionDiseases.ItemId == 178 {
  1586. infection.Hbv = 0
  1587. if infectionDiseases.InspectValue == "阳性" {
  1588. infection.Hbv = 1
  1589. }
  1590. }
  1591. if infectionDiseases.ItemId == 179 {
  1592. infection.Hcv = 0
  1593. if infectionDiseases.InspectValue == "阳性" {
  1594. infection.Hcv = 1
  1595. }
  1596. }
  1597. }
  1598. infectionList = append(infectionList, infection)
  1599. }
  1600. }
  1601. }
  1602. }
  1603. if len(infectionList) > 0 {
  1604. err := service.CreateInfection(infectionList, rdb)
  1605. if err == nil {
  1606. // 第三步:同步成功后,添加同步记录
  1607. upload := &sz.DataUpload{
  1608. SyncType: 59,
  1609. OrgId: org_id,
  1610. SyncTime: time.Now().Unix(),
  1611. SyncResultType: 1,
  1612. CreateTime: time.Now().Unix(),
  1613. UpdateTime: time.Now().Unix(),
  1614. }
  1615. err := service.CreateUploadRecord(upload)
  1616. if err != nil {
  1617. utils.ErrorLog("%v", err)
  1618. }
  1619. } else {
  1620. //错误处理
  1621. }
  1622. }
  1623. }
  1624. // 透析并发症记录表(T_HD_COMPLICATION)
  1625. func SyncComplication(rdb *gorm.DB, org_id int64, hospital_id string) {
  1626. // 第一步:根据机构id获取上次同步时间
  1627. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 60)
  1628. var sync_time int64
  1629. if syncLastInfo.ID > 0 {
  1630. sync_time = syncLastInfo.SyncTime
  1631. } else {
  1632. sync_time = 0
  1633. }
  1634. //同步监测记录
  1635. var complicationList []*sz.TempHdComplication
  1636. monitors, _ := service.FindOrgMonitorRecordByLike(org_id, "%肌肉痉挛%", sync_time, time.Now().Unix())
  1637. for _, monitor := range monitors {
  1638. complication := &sz.TempHdComplication{
  1639. Sn: strconv.FormatInt(monitor.ID, 10),
  1640. HospitalId: hospital_id,
  1641. PatientNk: strconv.FormatInt(monitor.PatientId, 10),
  1642. DialysisId: monitor.DialysisOrderId,
  1643. MonitorId: monitor.ID,
  1644. NeopathyTime: 1,
  1645. NeopathyType: "3",
  1646. NeopathyDesc: monitor.Symptom,
  1647. CreateTime: time.Unix(monitor.CreatedTime, 0),
  1648. Sjscsj: time.Now(),
  1649. Xgbz: 0,
  1650. }
  1651. complicationList = append(complicationList, complication)
  1652. }
  1653. monitorones, _ := service.FindOrgMonitorRecordByLike(org_id, "%胸痛%", sync_time, time.Now().Unix())
  1654. for _, monitor := range monitorones {
  1655. complicationone := &sz.TempHdComplication{
  1656. Sn: strconv.FormatInt(monitor.ID, 10),
  1657. HospitalId: hospital_id,
  1658. PatientNk: strconv.FormatInt(monitor.PatientId, 10),
  1659. DialysisId: monitor.DialysisOrderId,
  1660. MonitorId: monitor.ID,
  1661. NeopathyTime: 1,
  1662. NeopathyType: "6",
  1663. NeopathyDesc: monitor.Symptom,
  1664. CreateTime: time.Unix(monitor.CreatedTime, 0),
  1665. Sjscsj: time.Now(),
  1666. Xgbz: 0,
  1667. }
  1668. complicationList = append(complicationList, complicationone)
  1669. }
  1670. monitortwos, _ := service.FindOrgMonitorRecordByLike(org_id, "%恶心%", sync_time, time.Now().Unix())
  1671. for _, monitor := range monitortwos {
  1672. complicationtwo := &sz.TempHdComplication{
  1673. Sn: strconv.FormatInt(monitor.ID, 10),
  1674. HospitalId: hospital_id,
  1675. PatientNk: strconv.FormatInt(monitor.PatientId, 10),
  1676. DialysisId: monitor.DialysisOrderId,
  1677. MonitorId: monitor.ID,
  1678. NeopathyTime: 1,
  1679. NeopathyType: "7",
  1680. NeopathyDesc: monitor.Symptom,
  1681. CreateTime: time.Unix(monitor.CreatedTime, 0),
  1682. Sjscsj: time.Now(),
  1683. Xgbz: 0,
  1684. }
  1685. complicationList = append(complicationList, complicationtwo)
  1686. }
  1687. monitorfours, _ := service.FindOrgMonitorRecordByLike(org_id, "%头痛%", sync_time, time.Now().Unix())
  1688. for _, monitor := range monitorfours {
  1689. complicationfour := &sz.TempHdComplication{
  1690. Sn: strconv.FormatInt(monitor.ID, 10),
  1691. HospitalId: hospital_id,
  1692. PatientNk: strconv.FormatInt(monitor.PatientId, 10),
  1693. DialysisId: monitor.DialysisOrderId,
  1694. MonitorId: monitor.ID,
  1695. NeopathyTime: 1,
  1696. NeopathyType: "11",
  1697. NeopathyDesc: monitor.Symptom,
  1698. CreateTime: time.Unix(monitor.CreatedTime, 0),
  1699. Sjscsj: time.Now(),
  1700. Xgbz: 0,
  1701. }
  1702. complicationList = append(complicationList, complicationfour)
  1703. }
  1704. monitorthrees, _ := service.FindOrgMonitorRecordByLike(org_id, "%发热%", sync_time, time.Now().Unix())
  1705. for _, monitor := range monitorthrees {
  1706. complicationthree := &sz.TempHdComplication{
  1707. Sn: strconv.FormatInt(monitor.ID, 10),
  1708. HospitalId: hospital_id,
  1709. PatientNk: strconv.FormatInt(monitor.PatientId, 10),
  1710. DialysisId: monitor.DialysisOrderId,
  1711. MonitorId: monitor.ID,
  1712. NeopathyTime: 1,
  1713. NeopathyType: "15",
  1714. NeopathyDesc: monitor.Symptom,
  1715. CreateTime: time.Unix(monitor.CreatedTime, 0),
  1716. Sjscsj: time.Now(),
  1717. Xgbz: 0,
  1718. }
  1719. complicationList = append(complicationList, complicationthree)
  1720. }
  1721. if len(complicationList) > 0 {
  1722. err := service.CreateComplication(complicationList, rdb)
  1723. if err == nil {
  1724. // 第三步:同步成功后,添加同步记录
  1725. upload := &sz.DataUpload{
  1726. SyncType: 60,
  1727. OrgId: org_id,
  1728. SyncTime: time.Now().Unix(),
  1729. SyncResultType: 1,
  1730. CreateTime: time.Now().Unix(),
  1731. UpdateTime: time.Now().Unix(),
  1732. }
  1733. err := service.CreateUploadRecord(upload)
  1734. if err != nil {
  1735. utils.ErrorLog("%v", err)
  1736. }
  1737. } else {
  1738. //错误处理
  1739. }
  1740. }
  1741. }
  1742. // 血透患者检测结果表(T_HD_LIS_REPORT)
  1743. func SyncLisReport(rdb *gorm.DB, org_id int64, hospital_id string) {
  1744. // 第一步:根据机构id获取上次同步时间
  1745. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 61)
  1746. var sync_time int64
  1747. if syncLastInfo.ID > 0 {
  1748. sync_time = syncLastInfo.SyncTime
  1749. } else {
  1750. sync_time = 0
  1751. }
  1752. //同步监测记录
  1753. inspections, _ := service.FindOrgInspection(org_id, sync_time, time.Now().Unix())
  1754. var lisReportList []*sz.TempHdLisReport
  1755. tempFlag := 1
  1756. for _, inspection := range inspections {
  1757. tempFlag = 1
  1758. fmt.Println("1")
  1759. for _, tempReport := range lisReportList {
  1760. // fmt.Println("2")
  1761. if tempReport.ReportDate == time.Unix(inspection.InspectDate, 0) && tempReport.ApplicationType == strconv.FormatInt(inspection.ProjectId, 10) && tempReport.PatientNk == strconv.FormatInt(inspection.PatientId, 10) {
  1762. tempFlag = 0
  1763. break
  1764. } else {
  1765. continue
  1766. }
  1767. }
  1768. fmt.Println("3")
  1769. if tempFlag == 1 {
  1770. lisReport := &sz.TempHdLisReport{
  1771. LabSno: strconv.FormatInt(inspection.InspectDate, 10) + strconv.FormatInt(inspection.ProjectId, 10) + strconv.FormatInt(inspection.PatientId, 10),
  1772. HospitalId: hospital_id,
  1773. PatientNk: strconv.FormatInt(inspection.PatientId, 10),
  1774. ReportDate: time.Unix(inspection.InspectDate, 0),
  1775. CheckDate: "1",
  1776. JzNo: inspection.Patients.AdmissionNumber,
  1777. MzFlag: "1",
  1778. ZyNo: "-",
  1779. MzNo: inspection.Patients.AdmissionNumber,
  1780. DepartmentCode: "10035",
  1781. DepartmentName: "血透中心",
  1782. CardNo: inspection.Patients.IdCardNo,
  1783. CardType: "9",
  1784. PatientName: inspection.Patients.Name,
  1785. DepCode: "A03.05",
  1786. DepName: "血透中心",
  1787. InspectedType: "1",
  1788. ReportCategry: inspection.ProjectName,
  1789. ApplicationName: inspection.ProjectName,
  1790. ApplicationType: strconv.FormatInt(inspection.ProjectId, 10),
  1791. CheckName: inspection.ProjectName,
  1792. CheckItemName: inspection.ProjectName,
  1793. CheckItemCode: strconv.FormatInt(inspection.ProjectId, 10),
  1794. RecordCcount: 0,
  1795. CheckResult: "完成",
  1796. DiagnoseName: "-",
  1797. CreateTime: time.Unix(inspection.CreatedTime, 0),
  1798. Sjscsj: time.Now(),
  1799. Xgbz: 0,
  1800. }
  1801. lisReportList = append(lisReportList, lisReport)
  1802. } else {
  1803. continue
  1804. }
  1805. }
  1806. if len(lisReportList) > 0 {
  1807. err := service.CreateLisReport(lisReportList, rdb)
  1808. if err == nil {
  1809. // 第三步:同步成功后,添加同步记录
  1810. upload := &sz.DataUpload{
  1811. SyncType: 61,
  1812. OrgId: org_id,
  1813. SyncTime: time.Now().Unix(),
  1814. SyncResultType: 1,
  1815. CreateTime: time.Now().Unix(),
  1816. UpdateTime: time.Now().Unix(),
  1817. }
  1818. err := service.CreateUploadRecord(upload)
  1819. if err != nil {
  1820. utils.ErrorLog("%v", err)
  1821. }
  1822. } else {
  1823. //错误处理
  1824. }
  1825. }
  1826. }
  1827. // 血透患者检验结果指标表(T_HD_LIS_INDICATORS)
  1828. func SyncLisIndicators(rdb *gorm.DB, org_id int64, hospital_id string) {
  1829. // 第一步:根据机构id获取上次同步时间
  1830. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 62)
  1831. var sync_time int64
  1832. if syncLastInfo.ID > 0 {
  1833. sync_time = syncLastInfo.SyncTime
  1834. } else {
  1835. sync_time = 0
  1836. }
  1837. //同步监测记录
  1838. inspections, _ := service.FindOrgInspectionTwo(org_id, sync_time, time.Now().Unix())
  1839. var lisIndicatorsList []*sz.TempHdLisIndicators
  1840. for _, inspection := range inspections {
  1841. lisIndicators := &sz.TempHdLisIndicators{
  1842. InspectedResultNo: strconv.FormatInt(inspection.ID, 10),
  1843. HospitalId: hospital_id,
  1844. LabSno: strconv.FormatInt(inspection.InspectDate, 10) + strconv.FormatInt(inspection.ProjectId, 10) + strconv.FormatInt(inspection.PatientId, 10),
  1845. ReportDate: time.Unix(inspection.InspectDate, 0),
  1846. CheckDate: time.Unix(inspection.InspectDate, 0),
  1847. InspectedIndicate: inspection.ProjectName,
  1848. InspectedItemEnName: strconv.FormatInt(inspection.ItemId, 10),
  1849. InspectedItemCnName: inspection.ItemName,
  1850. InspectedResultDesc: inspection.InspectValue,
  1851. InspectedResultValue: inspection.InspectValue,
  1852. InspectedResultUnit: inspection.XtInspectionReference.Unit,
  1853. RefRange: "-",
  1854. UnitType: inspection.XtInspectionReference.Unit,
  1855. InspectedResult: 5,
  1856. CreateTime: time.Unix(inspection.CreatedTime, 0),
  1857. Sjscsj: time.Now(),
  1858. Xgbz: 0,
  1859. }
  1860. if len(inspection.XtInspectionReference.Unit) == 0 {
  1861. lisIndicators.InspectedResultUnit = "-"
  1862. lisIndicators.UnitType = "-"
  1863. }
  1864. if inspection.XtInspectionReference.RangeType == 1 {
  1865. lisIndicators.RefRange = inspection.XtInspectionReference.RangeMin + "-" + inspection.XtInspectionReference.RangeMax
  1866. } else {
  1867. if len(inspection.XtInspectionReference.RangeOptions) == 0 {
  1868. lisIndicators.RefRange = "-"
  1869. } else {
  1870. lisIndicators.RefRange = inspection.XtInspectionReference.RangeOptions
  1871. }
  1872. }
  1873. lisIndicatorsList = append(lisIndicatorsList, lisIndicators)
  1874. }
  1875. if len(lisIndicatorsList) > 0 {
  1876. err := service.CreateLisIndicators(lisIndicatorsList, rdb)
  1877. if err == nil {
  1878. // 第三步:同步成功后,添加同步记录
  1879. upload := &sz.DataUpload{
  1880. SyncType: 62,
  1881. OrgId: org_id,
  1882. SyncTime: time.Now().Unix(),
  1883. SyncResultType: 1,
  1884. CreateTime: time.Now().Unix(),
  1885. UpdateTime: time.Now().Unix(),
  1886. }
  1887. err := service.CreateUploadRecord(upload)
  1888. if err != nil {
  1889. utils.ErrorLog("%v", err)
  1890. }
  1891. } else {
  1892. //错误处理
  1893. }
  1894. }
  1895. }
  1896. //细菌培养检测记录表
  1897. func SyncLisCulture(rdb *gorm.DB, org_id int64, hospital_id string) {
  1898. // 第一步:根据机构id获取上次同步时间
  1899. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 63)
  1900. var sync_time int64
  1901. if syncLastInfo.ID > 0 {
  1902. sync_time = syncLastInfo.SyncTime
  1903. } else {
  1904. sync_time = 0
  1905. }
  1906. //同步细菌培养数据
  1907. dialysate, _ := service.FindOrgCulture(org_id, sync_time, time.Now().Unix())
  1908. var lisHdLisCulture []*sz.TempHdLisCulture
  1909. for _, item := range dialysate {
  1910. parseInt, _ := strconv.ParseInt(item.Sort, 10, 64)
  1911. lisDialysate := &sz.TempHdLisCulture{
  1912. Sn: strconv.FormatInt(item.ID, 10),
  1913. HospitalId: hospital_id,
  1914. EquitmentId: item.EquitmentId,
  1915. InspectionTime: time.Unix(item.SpelingDate, 0),
  1916. IsQualified: item.Modifications,
  1917. IsSubstitutionQualified: item.Modifications,
  1918. CaseOrder: parseInt,
  1919. CreateTime: time.Unix(item.Ctime, 0),
  1920. Sjscsj: time.Now(),
  1921. Xgbz: 0,
  1922. }
  1923. lisHdLisCulture = append(lisHdLisCulture, lisDialysate)
  1924. }
  1925. if len(lisHdLisCulture) > 0 {
  1926. err := service.CreateLisCulture(lisHdLisCulture, rdb)
  1927. if err == nil {
  1928. // 第三步:同步成功后,添加同步记录
  1929. upload := &sz.DataUpload{
  1930. SyncType: 63,
  1931. OrgId: org_id,
  1932. SyncTime: time.Now().Unix(),
  1933. SyncResultType: 1,
  1934. CreateTime: time.Now().Unix(),
  1935. UpdateTime: time.Now().Unix(),
  1936. }
  1937. err := service.CreateUploadRecord(upload)
  1938. if err != nil {
  1939. utils.ErrorLog("%v", err)
  1940. }
  1941. } else {
  1942. //错误处理
  1943. }
  1944. }
  1945. }
  1946. func SyncDialysate(rdb *gorm.DB, org_id int64, hospital_id string) {
  1947. // 第一步:根据机构id获取上次同步时间
  1948. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 64)
  1949. var sync_time int64
  1950. if syncLastInfo.ID > 0 {
  1951. sync_time = syncLastInfo.SyncTime
  1952. } else {
  1953. sync_time = 0
  1954. }
  1955. //同步细菌培养数据
  1956. dialysate, _ := service.FindOrgDialysate(org_id, sync_time, time.Now().Unix())
  1957. fmt.Println("dia", dialysate)
  1958. var lisHdLisDialysate []*sz.TempHdLisDialysate
  1959. for _, item := range dialysate {
  1960. parseInt, _ := strconv.ParseInt(item.Sort, 10, 64)
  1961. lisDialysate := &sz.TempHdLisDialysate{
  1962. Sn: strconv.FormatInt(item.ID, 10),
  1963. HospitalId: hospital_id,
  1964. EquitmentId: item.EquitmentId,
  1965. InspectionTime: time.Unix(item.SamplingDate, 0),
  1966. IsQualified: item.Modifications,
  1967. InspectedValue: 0,
  1968. CaseOrder: parseInt,
  1969. CreateTime: time.Unix(item.Ctime, 0),
  1970. Sjscsj: time.Now(),
  1971. Xgbz: 0,
  1972. }
  1973. lisHdLisDialysate = append(lisHdLisDialysate, lisDialysate)
  1974. }
  1975. if len(lisHdLisDialysate) > 0 {
  1976. err := service.CreateLisDialysate(lisHdLisDialysate, rdb)
  1977. if err == nil {
  1978. // 第三步:同步成功后,添加同步记录
  1979. upload := &sz.DataUpload{
  1980. SyncType: 64,
  1981. OrgId: org_id,
  1982. SyncTime: time.Now().Unix(),
  1983. SyncResultType: 1,
  1984. CreateTime: time.Now().Unix(),
  1985. UpdateTime: time.Now().Unix(),
  1986. }
  1987. err := service.CreateUploadRecord(upload)
  1988. if err != nil {
  1989. utils.ErrorLog("%v", err)
  1990. }
  1991. } else {
  1992. //错误处理
  1993. }
  1994. }
  1995. }
  1996. func SyncLisBodyDetection(rdb *gorm.DB, org_id int64, hospital_id string) {
  1997. // 第一步:根据机构id获取上次同步时间
  1998. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 65)
  1999. var sync_time int64
  2000. if syncLastInfo.ID > 0 {
  2001. sync_time = syncLastInfo.SyncTime
  2002. } else {
  2003. sync_time = 0
  2004. }
  2005. //同步物表消毒记录表
  2006. detection, _ := service.FindOrgBodyDetection(org_id, sync_time, time.Now().Unix())
  2007. var lisHdLisBodyDisinfect []*sz.TempHdLisBodyDisinfect
  2008. for _, item := range detection {
  2009. parseInt, _ := strconv.ParseInt(item.Sort, 10, 64)
  2010. disinfect := &sz.TempHdLisBodyDisinfect{
  2011. Sn: strconv.FormatInt(item.ID, 10),
  2012. HospitalId: hospital_id,
  2013. InspectionTime: time.Unix(item.CreatedTime, 0),
  2014. IsQualified: item.CheckOut,
  2015. InspectedValue: item.DetectionResult,
  2016. CaseOrder: parseInt,
  2017. CreateTime: time.Unix(item.Ctime, 0),
  2018. UpdateTime: time.Unix(item.Ctime, 0),
  2019. Sjscsj: time.Now(),
  2020. Xgbz: 0,
  2021. }
  2022. lisHdLisBodyDisinfect = append(lisHdLisBodyDisinfect, disinfect)
  2023. }
  2024. if len(lisHdLisBodyDisinfect) > 0 {
  2025. err := service.CreateBodyDisinfect(lisHdLisBodyDisinfect, rdb)
  2026. if err == nil {
  2027. // 第三步:同步成功后,添加同步记录
  2028. upload := &sz.DataUpload{
  2029. SyncType: 65,
  2030. OrgId: org_id,
  2031. SyncTime: time.Now().Unix(),
  2032. SyncResultType: 1,
  2033. CreateTime: time.Now().Unix(),
  2034. UpdateTime: time.Now().Unix(),
  2035. }
  2036. err := service.CreateUploadRecord(upload)
  2037. if err != nil {
  2038. utils.ErrorLog("%v", err)
  2039. }
  2040. } else {
  2041. //错误处理
  2042. }
  2043. }
  2044. }
  2045. func SyncLisWaterFc(rdb *gorm.DB, org_id int64, hospital_id string) {
  2046. // 第一步:根据机构id获取上次同步时间
  2047. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 66)
  2048. var sync_time int64
  2049. if syncLastInfo.ID > 0 {
  2050. sync_time = syncLastInfo.SyncTime
  2051. } else {
  2052. sync_time = 0
  2053. }
  2054. //透析用水游离氯检测表
  2055. waterfc, _ := service.FindOrgWaterFc(org_id, sync_time, time.Now().Unix())
  2056. var lisHdLisWaterFc []*sz.TempHdLisWaterFc
  2057. for _, item := range waterfc {
  2058. parseInt, _ := strconv.ParseInt(item.Sort, 10, 64)
  2059. disinfect := &sz.TempHdLisWaterFc{
  2060. Sn: strconv.FormatInt(item.ID, 10),
  2061. HospitalId: hospital_id,
  2062. InspectionTime: time.Unix(item.SamplingDate, 0),
  2063. IsQualified: item.PassExamination,
  2064. InspectionOrgId: item.DetectionUnit,
  2065. InspectedValue: item.DetectionResultb,
  2066. EquitmentId: strconv.FormatInt(item.EquitmentId,10),
  2067. WaterType: item.Specimenb,
  2068. CaseOrder: parseInt,
  2069. CreateTime: time.Unix(item.Ctime, 0),
  2070. UpdateTime: time.Unix(item.Ctime, 0),
  2071. Sjscsj: time.Now(),
  2072. Xgbz: 0,
  2073. }
  2074. if disinfect.WaterType == 0 {
  2075. disinfect.WaterType = 1
  2076. }
  2077. lisHdLisWaterFc = append(lisHdLisWaterFc, disinfect)
  2078. }
  2079. if len(lisHdLisWaterFc) > 0 {
  2080. err := service.CreateWaterFc(lisHdLisWaterFc, rdb)
  2081. if err == nil {
  2082. // 第三步:同步成功后,添加同步记录
  2083. upload := &sz.DataUpload{
  2084. SyncType: 66,
  2085. OrgId: org_id,
  2086. SyncTime: time.Now().Unix(),
  2087. SyncResultType: 1,
  2088. CreateTime: time.Now().Unix(),
  2089. UpdateTime: time.Now().Unix(),
  2090. }
  2091. err := service.CreateUploadRecord(upload)
  2092. if err != nil {
  2093. utils.ErrorLog("%v", err)
  2094. }
  2095. } else {
  2096. //错误处理
  2097. }
  2098. }
  2099. }
  2100. func SynLisWaterNc(rdb *gorm.DB, org_id int64, hospital_id string) {
  2101. // 第一步:根据机构id获取上次同步时间
  2102. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 67)
  2103. var sync_time int64
  2104. if syncLastInfo.ID > 0 {
  2105. sync_time = syncLastInfo.SyncTime
  2106. } else {
  2107. sync_time = 0
  2108. }
  2109. //透析用水游离氯检测表
  2110. waternc, _ := service.FindOrgWaterNc(org_id, sync_time, time.Now().Unix())
  2111. var lisHdLisWaterNc []*sz.TempHdLisWaterNc
  2112. for _, item := range waternc {
  2113. parseInt, _ := strconv.ParseInt(item.Sort, 10, 64)
  2114. disinfect := &sz.TempHdLisWaterNc{
  2115. Sn: strconv.FormatInt(item.ID, 10),
  2116. HospitalId: hospital_id,
  2117. InspectionTime: time.Unix(item.SamplingDate, 0),
  2118. IsQualified: item.PassExamination,
  2119. InspectionOrgId: item.DetectionUnit,
  2120. InspectedValue: item.DetectionResultb,
  2121. EquitmentId: strconv.FormatInt(item.EquitmentId,10),
  2122. WaterType: item.Specimenb,
  2123. CaseOrder: parseInt,
  2124. CreateTime: time.Unix(item.Ctime, 0),
  2125. UpdateTime: time.Unix(item.Ctime, 0),
  2126. Sjscsj: time.Now(),
  2127. Xgbz: 0,
  2128. }
  2129. if disinfect.WaterType == 0 {
  2130. disinfect.WaterType = 1
  2131. }
  2132. lisHdLisWaterNc = append(lisHdLisWaterNc, disinfect)
  2133. }
  2134. if len(lisHdLisWaterNc) > 0 {
  2135. err := service.CreateWaterNc(lisHdLisWaterNc, rdb)
  2136. if err == nil {
  2137. // 第三步:同步成功后,添加同步记录
  2138. upload := &sz.DataUpload{
  2139. SyncType: 67,
  2140. OrgId: org_id,
  2141. SyncTime: time.Now().Unix(),
  2142. SyncResultType: 1,
  2143. CreateTime: time.Now().Unix(),
  2144. UpdateTime: time.Now().Unix(),
  2145. }
  2146. err := service.CreateUploadRecord(upload)
  2147. if err != nil {
  2148. utils.ErrorLog("%v", err)
  2149. }
  2150. } else {
  2151. //错误处理
  2152. }
  2153. }
  2154. }
  2155. func SynLisWaterPh(rdb *gorm.DB, org_id int64, hospital_id string) {
  2156. // 第一步:根据机构id获取上次同步时间
  2157. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 68)
  2158. var sync_time int64
  2159. if syncLastInfo.ID > 0 {
  2160. sync_time = syncLastInfo.SyncTime
  2161. } else {
  2162. sync_time = 0
  2163. }
  2164. //透析用水PH值检测表
  2165. waternc, _ := service.FindOrgWaterPh(org_id, sync_time, time.Now().Unix())
  2166. var lisHdLisWaterPh []*sz.TempHdLisWaterPh
  2167. for _, item := range waternc {
  2168. parseInt, _ := strconv.ParseInt(item.Sort, 10, 64)
  2169. disinfect := &sz.TempHdLisWaterPh{
  2170. Sn: strconv.FormatInt(item.ID, 10),
  2171. HospitalId: hospital_id,
  2172. InspectionTime: time.Unix(item.SamplingDate, 0),
  2173. IsQualified: item.PassExamination,
  2174. InspectionOrgId: item.DetectionUnit,
  2175. InspectedValue: item.DetectionResultb,
  2176. EquitmentId: strconv.FormatInt(item.EquitmentId,10),
  2177. WaterType: item.Specimenb,
  2178. CaseOrder: parseInt,
  2179. CreateTime: time.Unix(item.Ctime, 0),
  2180. UpdateTime: time.Unix(item.Ctime, 0),
  2181. Sjscsj: time.Now(),
  2182. Xgbz: 0,
  2183. }
  2184. if disinfect.WaterType == 0 {
  2185. disinfect.WaterType = 1
  2186. }
  2187. lisHdLisWaterPh = append(lisHdLisWaterPh, disinfect)
  2188. }
  2189. if len(lisHdLisWaterPh) > 0 {
  2190. err := service.CreateWaterPh(lisHdLisWaterPh, rdb)
  2191. if err == nil {
  2192. // 第三步:同步成功后,添加同步记录
  2193. upload := &sz.DataUpload{
  2194. SyncType: 68,
  2195. OrgId: org_id,
  2196. SyncTime: time.Now().Unix(),
  2197. SyncResultType: 1,
  2198. CreateTime: time.Now().Unix(),
  2199. UpdateTime: time.Now().Unix(),
  2200. }
  2201. err := service.CreateUploadRecord(upload)
  2202. if err != nil {
  2203. utils.ErrorLog("%v", err)
  2204. }
  2205. } else {
  2206. //错误处理
  2207. }
  2208. }
  2209. }
  2210. func SynListHadWater(rdb *gorm.DB, org_id int64, hospital_id string) {
  2211. // 第一步:根据机构id获取上次同步时间
  2212. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 69)
  2213. var sync_time int64
  2214. if syncLastInfo.ID > 0 {
  2215. sync_time = syncLastInfo.SyncTime
  2216. } else {
  2217. sync_time = 0
  2218. }
  2219. //透析用水PH值检测表
  2220. waterwh, _ := service.FindOrgWaterWh(org_id, sync_time, time.Now().Unix())
  2221. var lisHdLisWaterWh []*sz.TempHdLisWaterWh
  2222. for _, item := range waterwh {
  2223. parseInt, _ := strconv.ParseInt(item.Sort, 10, 64)
  2224. disinfect := &sz.TempHdLisWaterWh{
  2225. Sn: strconv.FormatInt(item.ID, 10),
  2226. HospitalId: hospital_id,
  2227. InspectionTime: time.Unix(item.SamplingDate, 0),
  2228. IsQualified: item.PassExamination,
  2229. InspectionOrgId: item.DetectionUnit,
  2230. InspectedValue: item.DetectionResultb,
  2231. EquitmentId: strconv.FormatInt(item.EquitmentId,10),
  2232. WaterType: item.Specimenb,
  2233. CaseOrder: parseInt,
  2234. CreateTime: time.Unix(item.Ctime, 0),
  2235. UpdateTime: time.Unix(item.Ctime, 0),
  2236. Sjscsj: time.Now(),
  2237. Xgbz: 0,
  2238. }
  2239. if disinfect.WaterType == 0 {
  2240. disinfect.WaterType = 1
  2241. }
  2242. lisHdLisWaterWh = append(lisHdLisWaterWh, disinfect)
  2243. }
  2244. if len(lisHdLisWaterWh) > 0 {
  2245. err := service.CreateWaterWh(lisHdLisWaterWh, rdb)
  2246. if err == nil {
  2247. // 第三步:同步成功后,添加同步记录
  2248. upload := &sz.DataUpload{
  2249. SyncType: 69,
  2250. OrgId: org_id,
  2251. SyncTime: time.Now().Unix(),
  2252. SyncResultType: 1,
  2253. CreateTime: time.Now().Unix(),
  2254. UpdateTime: time.Now().Unix(),
  2255. }
  2256. err := service.CreateUploadRecord(upload)
  2257. if err != nil {
  2258. utils.ErrorLog("%v", err)
  2259. }
  2260. } else {
  2261. //错误处理
  2262. }
  2263. }
  2264. }
  2265. func SynListHdCi(rdb *gorm.DB, org_id int64, hospital_id string) {
  2266. // 第一步:根据机构id获取上次同步时间
  2267. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 70)
  2268. var sync_time int64
  2269. if syncLastInfo.ID > 0 {
  2270. sync_time = syncLastInfo.SyncTime
  2271. } else {
  2272. sync_time = 0
  2273. }
  2274. //导管感染记录表
  2275. hdci, _ := service.FindOrgHdCi(org_id, sync_time, time.Now().Unix())
  2276. var temphdci []*sz.TempHdCi
  2277. for _, item := range hdci {
  2278. ci := &sz.TempHdCi{
  2279. InfectSn: strconv.FormatInt(item.ID, 10),
  2280. HospitalId: hospital_id,
  2281. PatientNk: strconv.FormatInt(item.PatientId, 10),
  2282. AccessId: item.BloodAccessPartOperaId,
  2283. CiType: item.CiType,
  2284. BloodCulture: item.BloodCultupe,
  2285. InfectionDate: time.Unix(item.StartTime, 0),
  2286. CreateTime: time.Unix(item.Ctime, 0),
  2287. Xgbz: 0,
  2288. Sjscsj: time.Now(),
  2289. }
  2290. if ci.CiType == 0 {
  2291. ci.CiType = 1
  2292. }
  2293. temphdci = append(temphdci, ci)
  2294. }
  2295. if len(temphdci) > 0 {
  2296. err := service.CreateHdCi(temphdci, rdb)
  2297. if err == nil {
  2298. // 第三步:同步成功后,添加同步记录
  2299. upload := &sz.DataUpload{
  2300. SyncType: 70,
  2301. OrgId: org_id,
  2302. SyncTime: time.Now().Unix(),
  2303. SyncResultType: 1,
  2304. CreateTime: time.Now().Unix(),
  2305. UpdateTime: time.Now().Unix(),
  2306. }
  2307. err := service.CreateUploadRecord(upload)
  2308. if err != nil {
  2309. utils.ErrorLog("%v", err)
  2310. }
  2311. } else {
  2312. //错误处理
  2313. }
  2314. }
  2315. }
  2316. func SynLisHdCiOutCome(rdb *gorm.DB, org_id int64, hospital_id string) {
  2317. // 第一步:根据机构id获取上次同步时间
  2318. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 71)
  2319. var sync_time int64
  2320. if syncLastInfo.ID > 0 {
  2321. sync_time = syncLastInfo.SyncTime
  2322. } else {
  2323. sync_time = 0
  2324. }
  2325. //导管感染记录表
  2326. hdcioutcome, _ := service.FindOrgHdCiOutCome(org_id, sync_time, time.Now().Unix())
  2327. var temphdcioutcome []*sz.TempHdCiOutCome
  2328. for _, item := range hdcioutcome {
  2329. outcome := &sz.TempHdCiOutCome{
  2330. Sn: strconv.FormatInt(item.ID, 10),
  2331. InfectSn: strconv.FormatInt(item.ID, 10),
  2332. PatientNk: strconv.FormatInt(item.PatientId, 10),
  2333. HospitalId: hospital_id,
  2334. SequelaeType: item.SequelaeType,
  2335. Sjscsj: time.Now(),
  2336. Xgbz: 0,
  2337. CreateTime: time.Unix(item.Ctime, 0),
  2338. UpdateTime: time.Unix(item.Mtime, 0),
  2339. Ylyl1: "",
  2340. Ylyl2: "",
  2341. }
  2342. if outcome.SequelaeType == 0 {
  2343. outcome.SequelaeType = 9
  2344. }
  2345. temphdcioutcome = append(temphdcioutcome, outcome)
  2346. }
  2347. if len(temphdcioutcome) > 0 {
  2348. err := service.CreateHdCiOutCome(temphdcioutcome, rdb)
  2349. if err == nil {
  2350. // 第三步:同步成功后,添加同步记录
  2351. upload := &sz.DataUpload{
  2352. SyncType: 71,
  2353. OrgId: org_id,
  2354. SyncTime: time.Now().Unix(),
  2355. SyncResultType: 1,
  2356. CreateTime: time.Now().Unix(),
  2357. UpdateTime: time.Now().Unix(),
  2358. }
  2359. err := service.CreateUploadRecord(upload)
  2360. if err != nil {
  2361. utils.ErrorLog("%v", err)
  2362. }
  2363. } else {
  2364. //错误处理
  2365. }
  2366. }
  2367. }
  2368. func SyncLisAirDetection(rdb *gorm.DB, org_id int64, hospital_id string) {
  2369. // 第一步:根据机构id获取上次同步时间
  2370. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 72)
  2371. var sync_time int64
  2372. if syncLastInfo.ID > 0 {
  2373. sync_time = syncLastInfo.SyncTime
  2374. } else {
  2375. sync_time = 0
  2376. }
  2377. //同步透析室空气消毒记录表
  2378. detection, _ := service.FindOrgArialDetection(org_id, sync_time, time.Now().Unix())
  2379. var lisHdLisAirDisinfect []*sz.TempHdLisAirDisinfect
  2380. for _, item := range detection {
  2381. parseInt, _ := strconv.ParseInt(item.Sort, 10, 64)
  2382. disinfect := &sz.TempHdLisAirDisinfect{
  2383. Sn: strconv.FormatInt(item.ID, 10),
  2384. HospitalId: hospital_id,
  2385. InspectionTime: time.Unix(item.CreatedTime, 0),
  2386. IsQualified: item.CheckOut,
  2387. InspectedValue: item.DetectionResult,
  2388. CaseOrder: parseInt,
  2389. CreateTime: time.Unix(item.Ctime, 0),
  2390. Sjscsj: time.Now(),
  2391. Xgbz: 0,
  2392. }
  2393. lisHdLisAirDisinfect = append(lisHdLisAirDisinfect, disinfect)
  2394. }
  2395. if len(lisHdLisAirDisinfect) > 0 {
  2396. err := service.CreateAirDisinfect(lisHdLisAirDisinfect, rdb)
  2397. if err == nil {
  2398. // 第三步:同步成功后,添加同步记录
  2399. upload := &sz.DataUpload{
  2400. SyncType: 72,
  2401. OrgId: org_id,
  2402. SyncTime: time.Now().Unix(),
  2403. SyncResultType: 1,
  2404. CreateTime: time.Now().Unix(),
  2405. UpdateTime: time.Now().Unix(),
  2406. }
  2407. err := service.CreateUploadRecord(upload)
  2408. if err != nil {
  2409. utils.ErrorLog("%v", err)
  2410. }
  2411. } else {
  2412. //错误处理
  2413. }
  2414. }
  2415. }
  2416. func SyncLisWaterBc(rdb *gorm.DB, org_id int64, hospital_id string) {
  2417. // 第一步:根据机构id获取上次同步时间
  2418. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 73)
  2419. var sync_time int64
  2420. if syncLastInfo.ID > 0 {
  2421. sync_time = syncLastInfo.SyncTime
  2422. } else {
  2423. sync_time = 0
  2424. }
  2425. //同步细菌培养数据
  2426. dialysate, _ := service.FindOrgCulture(org_id, sync_time, time.Now().Unix())
  2427. var lisHdLisWaterBc []*sz.TempHdLisWaterBc
  2428. for _, item := range dialysate {
  2429. parseInt, _ := strconv.ParseInt(item.Sort, 10, 64)
  2430. waterbc := &sz.TempHdLisWaterBc{
  2431. HospitalId: hospital_id,
  2432. Sn: strconv.FormatInt(item.ID, 10),
  2433. EquitmentId: strconv.FormatInt(item.EquitmentId,10),
  2434. WaterType: item.Specimen,
  2435. InspectionOrgId: item.DetectionUnit,
  2436. InspectionTime: time.Unix(item.SpelingDate, 0),
  2437. IsQualified: item.Modifications,
  2438. InspectedValue: item.DetectionResult,
  2439. CaseOrder: parseInt,
  2440. Sjscsj: time.Now(),
  2441. Xgbz: 0,
  2442. CreateTime: time.Unix(item.Ctime, 0),
  2443. UpdateTime: time.Unix(item.Mtime, 0),
  2444. }
  2445. if waterbc.WaterType == 0 {
  2446. waterbc.WaterType = 3
  2447. }
  2448. lisHdLisWaterBc = append(lisHdLisWaterBc, waterbc)
  2449. }
  2450. if len(lisHdLisWaterBc) > 0 {
  2451. err := service.CreateLisWaterBc(lisHdLisWaterBc, rdb)
  2452. if err == nil {
  2453. // 第三步:同步成功后,添加同步记录
  2454. upload := &sz.DataUpload{
  2455. SyncType: 73,
  2456. OrgId: org_id,
  2457. SyncTime: time.Now().Unix(),
  2458. SyncResultType: 1,
  2459. CreateTime: time.Now().Unix(),
  2460. UpdateTime: time.Now().Unix(),
  2461. }
  2462. err := service.CreateUploadRecord(upload)
  2463. if err != nil {
  2464. utils.ErrorLog("%v", err)
  2465. }
  2466. } else {
  2467. //错误处理
  2468. }
  2469. }
  2470. }
  2471. func SyncLisWaterEn(rdb *gorm.DB, org_id int64, hospital_id string) {
  2472. // 第一步:根据机构id获取上次同步时间
  2473. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 74)
  2474. var sync_time int64
  2475. if syncLastInfo.ID > 0 {
  2476. sync_time = syncLastInfo.SyncTime
  2477. } else {
  2478. sync_time = 0
  2479. }
  2480. //同步细菌培养数据
  2481. dialysate, _ := service.FindOrgDialysate(org_id, sync_time, time.Now().Unix())
  2482. fmt.Println("dia", dialysate)
  2483. var lisHdLisWaterEn []*sz.TempHdLisWaterEn
  2484. for _, item := range dialysate {
  2485. parseInt, _ := strconv.ParseInt(item.Sort, 10, 64)
  2486. wateren := &sz.TempHdLisWaterEn{
  2487. HospitalId: hospital_id,
  2488. Sn: strconv.FormatInt(item.ID, 10),
  2489. EquitmentId: strconv.FormatInt(item.EquitmentId,10),
  2490. WaterType: item.Specimenb,
  2491. InspectionOrgId: item.DetectionUnit,
  2492. InspectionTime: time.Unix(item.SamplingDate, 0),
  2493. IsQualified: item.Modifications,
  2494. InspectedValue: item.DetectionResultb,
  2495. CaseOrder: parseInt,
  2496. Sjscsj: time.Now(),
  2497. Xgbz: 0,
  2498. CreateTime: time.Unix(item.Ctime, 0),
  2499. UpdateTime: time.Unix(item.Mtime, 0),
  2500. }
  2501. if wateren.WaterType == 0 {
  2502. wateren.WaterType = 3
  2503. }
  2504. lisHdLisWaterEn = append(lisHdLisWaterEn, wateren)
  2505. }
  2506. if len(lisHdLisWaterEn) > 0 {
  2507. err := service.CreateLisWaterEn(lisHdLisWaterEn, rdb)
  2508. if err == nil {
  2509. // 第三步:同步成功后,添加同步记录
  2510. upload := &sz.DataUpload{
  2511. SyncType: 74,
  2512. OrgId: org_id,
  2513. SyncTime: time.Now().Unix(),
  2514. SyncResultType: 1,
  2515. CreateTime: time.Now().Unix(),
  2516. UpdateTime: time.Now().Unix(),
  2517. }
  2518. err := service.CreateUploadRecord(upload)
  2519. if err != nil {
  2520. utils.ErrorLog("%v", err)
  2521. }
  2522. } else {
  2523. //错误处理
  2524. }
  2525. }
  2526. }
  2527. // 机构人员字典表
  2528. func SyncTBDICPractitioner(rdb *gorm.DB, org_id int64, hospital_id string) {
  2529. // 第一步:根据机构id获取上次同步时间
  2530. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1001)
  2531. var sync_time int64
  2532. if syncLastInfo.ID > 0 {
  2533. sync_time = syncLastInfo.SyncTime
  2534. } else {
  2535. sync_time = 0
  2536. }
  2537. //同步员工信息
  2538. roles, _ := service.FindOrgRolesData(org_id, sync_time, time.Now().Unix())
  2539. //waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
  2540. // var staffs []*sz.TBDICPractitioner
  2541. for _, role := range roles {
  2542. var zwdm,zhiw,zcdm,zhic,lb string
  2543. switch role.UserType {
  2544. case 2:
  2545. zwdm = "234"
  2546. zhiw = "医师"
  2547. zcdm = "420"
  2548. zhic = "中级"
  2549. lb = "11"
  2550. break
  2551. case 3:
  2552. zwdm = "255"
  2553. zhiw = "护士"
  2554. zcdm = "420"
  2555. zhic = "中级"
  2556. lb = "21"
  2557. break
  2558. }
  2559. staff := &sz.TBDICPractitioner{
  2560. GH: strconv.FormatInt(role.AdminUserId,10),
  2561. YLJGDM: hospital_id,
  2562. ZCM: role.UserName,
  2563. XM: role.UserName,
  2564. XBBM: "2",
  2565. SSKS: "1001",
  2566. SZYWKSMC: "血透中心",
  2567. ZWDM: zwdm,
  2568. ZHIW: zhiw,
  2569. ZCDM: zcdm,
  2570. ZHIC: zhic,
  2571. NNRYLDQK: "9",
  2572. BZQK: "2",
  2573. LB: lb,
  2574. YWSCSJ: time.Now(),
  2575. SJSCSJ: time.Now(),
  2576. XGBZ: 0,
  2577. }
  2578. service.BatchCreateTBDICPractitioner(staff,rdb)
  2579. }
  2580. // 第三步:同步成功后,添加同步记录
  2581. upload := &sz.DataUpload {
  2582. SyncType: 1001,
  2583. OrgId: org_id,
  2584. SyncTime: time.Now().Unix(),
  2585. SyncResultType: 1,
  2586. CreateTime: time.Now().Unix(),
  2587. UpdateTime: time.Now().Unix(),
  2588. }
  2589. service.CreateUploadRecord(upload)
  2590. }
  2591. func SyncTMDICTBED(rdb *gorm.DB, org_id int64, hospital_id string) {
  2592. // 第一步:根据机构id获取上次同步时间
  2593. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1002)
  2594. var sync_time int64
  2595. if syncLastInfo.ID > 0 {
  2596. sync_time = syncLastInfo.SyncTime
  2597. } else {
  2598. sync_time = 0
  2599. }
  2600. //同步透析床位分区
  2601. dm, _ := service.FindOrgDeviceNumber(org_id, sync_time, time.Now().Unix())
  2602. // var hdms []*sz.TM_DICT_BED
  2603. for _, item := range dm {
  2604. hdm := &sz.TM_DICT_BED{
  2605. YLJGDM: hospital_id,
  2606. CWBM: strconv.FormatInt(item.ID, 10),
  2607. CH: item.Number,
  2608. SSKSDM: "1001",
  2609. SSKSMC: "血透中心",
  2610. CWLX: "1",
  2611. CWZT: "0",
  2612. DYZLXMDJ:"0",
  2613. ZYH:"",
  2614. YWSCSJ: time.Now(),
  2615. SJSCSJ: time.Now(),
  2616. XGBZ: 0,
  2617. }
  2618. service.BatchCreateTMDICTBED(hdm,rdb)
  2619. }
  2620. upload := &sz.DataUpload{
  2621. SyncType: 1002,
  2622. OrgId: org_id,
  2623. SyncTime: time.Now().Unix(),
  2624. SyncResultType: 1,
  2625. CreateTime: time.Now().Unix(),
  2626. UpdateTime: time.Now().Unix(),
  2627. }
  2628. service.CreateUploadRecord(upload)
  2629. }
  2630. // 14. 门诊患者信息表
  2631. func SyncTBMZPatientInformation(rdb *gorm.DB, org_id int64, hospital_id string) {
  2632. // 第一步:根据机构id获取上次同步时间
  2633. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1003)
  2634. var sync_time int64
  2635. if syncLastInfo.ID > 0 {
  2636. sync_time = syncLastInfo.SyncTime
  2637. } else {
  2638. sync_time = 0
  2639. }
  2640. //同步员工信息
  2641. patients, _ := service.FindOrgPatientData(org_id, sync_time, time.Now().Unix())
  2642. for _, patient := range patients {
  2643. var xbmc string
  2644. if patient.Gender == 1 {
  2645. xbmc = "男"
  2646. } else {
  2647. xbmc = "女"
  2648. }
  2649. tm := time.Unix(patient.Birthday,0)
  2650. ghrq := tm.Format("20060102")
  2651. p := &sz.TB_MZ_Patient_Information{
  2652. KH: patient.DialysisNo,
  2653. KLX: "3",
  2654. YLJGDM: hospital_id,
  2655. FKDQ: "440300",
  2656. ZJHM: patient.IdCardNo,
  2657. ZJLXDM: "01",
  2658. ZJLXMC: "身份证",
  2659. XM: patient.Name,
  2660. CSRQ: ghrq,
  2661. MZDM: "1",
  2662. MZMC: "汉族",
  2663. GJDM: "156",
  2664. GJMC: "中国",
  2665. SJHM: patient.Phone,
  2666. XBDM: strconv.FormatInt(patient.Gender,10),
  2667. XBMC: xbmc,
  2668. HZLXDM: "1",
  2669. HZLXMC: "本市",
  2670. YWSCSJ: time.Unix(patient.CreatedTime,0),
  2671. SJSCSJ: time.Now(),
  2672. XGBZ: 0,
  2673. }
  2674. service.BatchCreateTB_MZ_Patient_Information(p,rdb)
  2675. }
  2676. upload := &sz.DataUpload{
  2677. SyncType: 1003,
  2678. OrgId: org_id,
  2679. SyncTime: time.Now().Unix(),
  2680. SyncResultType: 1,
  2681. CreateTime: time.Now().Unix(),
  2682. UpdateTime: time.Now().Unix(),
  2683. }
  2684. service.CreateUploadRecord(upload)
  2685. }
  2686. // 15. 挂号表
  2687. func SyncTBHISMZReg(rdb *gorm.DB, org_id int64, hospital_id string) {
  2688. // 第一步:根据机构id获取上次同步时间
  2689. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1004)
  2690. var sync_time int64
  2691. if syncLastInfo.ID > 0 {
  2692. sync_time = syncLastInfo.SyncTime
  2693. } else {
  2694. sync_time = 0
  2695. }
  2696. //同步员工信息
  2697. patients, _ := service.FindOrgHisPatient(org_id, sync_time, time.Now().Unix())
  2698. for _, patient := range patients {
  2699. tm := time.Unix(patient.Ctime,0)
  2700. ghrq := tm.Format("20060102")
  2701. gthsj := tm.Format("2006-01-02 15:04:05")
  2702. patientInfo,_ := service.FindOrgPatientInfoById(patient.PatientId)
  2703. p := &sz.TB_HIS_MZ_Reg{
  2704. GHRQ: ghrq,
  2705. JZLSH: strconv.FormatInt(patient.ID,10),
  2706. GTHBZ: "1",
  2707. YLJGDM: hospital_id,
  2708. STFBH: strconv.FormatInt(patient.ID,10),
  2709. GTHSJ: gthsj,
  2710. GHHX: strconv.FormatInt(patient.ID,10),
  2711. GHLB: "04",
  2712. GHMC: "专科门诊",
  2713. YLFYLYDM: "01",
  2714. YLBXLBDM: "01",
  2715. YBZHBZ: "0000000000000000",
  2716. SSJYBZ: "1",
  2717. KSBM: "1001",
  2718. KSMC: "血透中心",
  2719. YSBM: "2232",
  2720. YSXM: "黄少忠",
  2721. TXBZ: "0",
  2722. WDBZ: "0",
  2723. KH: patientInfo.DialysisNo,
  2724. KLX: "3",
  2725. SFYY: "0",
  2726. GHRCBS: "0",
  2727. GHFY: patient.RegisterCost,
  2728. JMGHF: patient.RegisterCost,
  2729. ZJF: patient.TreatmentCost,
  2730. JMZJF: patient.TreatmentCost,
  2731. QTF: "0",
  2732. CZYBM: "1001",
  2733. CZYXM: "Phony",
  2734. SJSCSJ: time.Now(),
  2735. XGBZ: 0,
  2736. }
  2737. service.BatchCreateTB_HIS_MZ_Reg(p,rdb)
  2738. }
  2739. upload := &sz.DataUpload{
  2740. SyncType: 1004,
  2741. OrgId: org_id,
  2742. SyncTime: time.Now().Unix(),
  2743. SyncResultType: 1,
  2744. CreateTime: time.Now().Unix(),
  2745. UpdateTime: time.Now().Unix(),
  2746. }
  2747. service.CreateUploadRecord(upload)
  2748. }
  2749. // 14. 16. 门诊就诊记录表
  2750. func SyncTB_YL_MZ_Medical_Record(rdb *gorm.DB, org_id int64, hospital_id string) {
  2751. // 第一步:根据机构id获取上次同步时间
  2752. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1005)
  2753. var sync_time int64
  2754. if syncLastInfo.ID > 0 {
  2755. sync_time = syncLastInfo.SyncTime
  2756. } else {
  2757. sync_time = 0
  2758. }
  2759. //同步员工信息
  2760. patients, _ := service.FindOrgHisPatient(org_id, sync_time, time.Now().Unix())
  2761. for _, patient := range patients {
  2762. patientInfo,_ := service.FindOrgPatientInfoById(patient.PatientId)
  2763. tm := time.Unix(patient.Ctime,0)
  2764. ghrq := tm.Format("2006-01-02")
  2765. p := &sz.TB_YL_MZ_Medical_Record{
  2766. YLJGDM: hospital_id,
  2767. JZLSH: strconv.FormatInt(patient.ID,10),
  2768. KH: patientInfo.DialysisNo,
  2769. KLX: "3",
  2770. MJZH: strconv.FormatInt(patient.ID,10),
  2771. HZXM: patient.Name,
  2772. JZLX: "04",
  2773. CZBZ: "2",
  2774. SFTH: "0",
  2775. YLBXLBDM: "01",
  2776. YLFKFSDM: "01",
  2777. TXBZ: "0",
  2778. YBZHBZ: "0000000000000000",
  2779. WDBZ: "1",
  2780. SFSYZYZLJS: "0",
  2781. ZYZLJSLB: "其他",
  2782. SFSYZYZHLJS: "0",
  2783. JZKSBM: "1001",
  2784. JZKSMC: "血透中心",
  2785. JZKSRQ: ghrq,
  2786. ZZYSGH: "1001",
  2787. ZZYSXM: "Phony",
  2788. YWSCSJ: time.Now(),
  2789. SJSCSJ: time.Now(),
  2790. XGBZ: 0,
  2791. }
  2792. service.BatchCreateTB_YL_MZ_Medical_Record(p,rdb)
  2793. }
  2794. upload := &sz.DataUpload{
  2795. SyncType: 1005,
  2796. OrgId: org_id,
  2797. SyncTime: time.Now().Unix(),
  2798. SyncResultType: 1,
  2799. CreateTime: time.Now().Unix(),
  2800. UpdateTime: time.Now().Unix(),
  2801. }
  2802. service.CreateUploadRecord(upload)
  2803. }
  2804. // 17. 门诊处方主表
  2805. func SyncTB_CIS_Prescription(rdb *gorm.DB, org_id int64, hospital_id string) {
  2806. // 第一步:根据机构id获取上次同步时间
  2807. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1006)
  2808. var sync_time int64
  2809. if syncLastInfo.ID > 0 {
  2810. sync_time = syncLastInfo.SyncTime
  2811. } else {
  2812. sync_time = 0
  2813. }
  2814. //同步员工信息
  2815. patients, _ := service.FindOrgHisPrescriptionInfo(org_id, sync_time, time.Now().Unix())
  2816. for _, patient := range patients {
  2817. patient_info,_ := service.FindOrgHisPatientInfo(org_id,patient.RecordDate,patient.PatientId)
  2818. patientInfo,_ := service.FindOrgPatientInfoById(patient.PatientId)
  2819. adviceinfo,_ := service.FindOrgHisDoctorAdviceInfoByPid(org_id,patient.ID)
  2820. if patient_info.ID > 0 {
  2821. var cfypje float64
  2822. for _,advice := range adviceinfo{
  2823. cfypje = cfypje + advice.PrescribingNumber * advice.Price
  2824. }
  2825. tm := time.Unix(patient.Ctime,0)
  2826. ghrq := tm.Format("2006-01-02")
  2827. p := &sz.TB_CIS_Prescription{
  2828. CYH: strconv.FormatInt(patient.ID,10),
  2829. YLJGDM: hospital_id,
  2830. JZLSH: strconv.FormatInt(patient_info.ID,10),
  2831. KH: patientInfo.DialysisNo,
  2832. KLX: "3",
  2833. CFLX: "1",
  2834. YPLX: "3",
  2835. ZYYPCFLB: "9",
  2836. CFJS: "0",
  2837. JZKSDM: "1001",
  2838. JZKSMC: "血透中心",
  2839. KFYS: "1001",
  2840. KFYSXM: "Phony",
  2841. KFRQ: ghrq,
  2842. CFLRSJ: ghrq,
  2843. SGCFBZ: "0",
  2844. CFYPJE: cfypje,
  2845. SJSCSJ: time.Now(),
  2846. XGBZ: 0,
  2847. }
  2848. service.BatchCreateTB_CIS_Prescription(p,rdb)
  2849. }
  2850. }
  2851. upload := &sz.DataUpload{
  2852. SyncType: 1006,
  2853. OrgId: org_id,
  2854. SyncTime: time.Now().Unix(),
  2855. SyncResultType: 1,
  2856. CreateTime: time.Now().Unix(),
  2857. UpdateTime: time.Now().Unix(),
  2858. }
  2859. service.CreateUploadRecord(upload)
  2860. }
  2861. // 门诊处方明细表
  2862. func SyncTB_CIS_Prescription_Detail(rdb *gorm.DB, org_id int64, hospital_id string) {
  2863. // 第一步:根据机构id获取上次同步时间
  2864. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1007)
  2865. var sync_time int64
  2866. if syncLastInfo.ID > 0 {
  2867. sync_time = syncLastInfo.SyncTime
  2868. } else {
  2869. sync_time = 0
  2870. }
  2871. //同步员工信息
  2872. patients, _ := service.FindOrgHisDoctorAdviceInfo(org_id, sync_time, time.Now().Unix())
  2873. for _, patient := range patients {
  2874. prescription,_ := service.FindOrgHisPrescriptionById(patient.PrescriptionId)
  2875. prescription_info,_ := service.FindOrgHisPrescriptionInfoByNumber(org_id,prescription.PrescriptionNumber)
  2876. patient_info,_ := service.FindOrgHisPatientInfo(org_id,prescription_info.RecordDate,prescription_info.PatientId)
  2877. basedrug,_ := service.FindBaseDrugLibById(patient.DrugId)
  2878. if patient_info.ID > 0 {
  2879. var yf,ypyf string
  2880. if len(patient.DeliveryWay) == 0 || patient.DeliveryWay =="口服" {
  2881. yf = "1"
  2882. ypyf = "口服"
  2883. } else {
  2884. yf = "4"
  2885. ypyf = "注射用药"
  2886. }
  2887. p := &sz.TB_CIS_Prescription_Detail{
  2888. CYH: strconv.FormatInt(prescription.ID,10),
  2889. CFMXH: prescription.PrescriptionNumber,
  2890. YLJGDM: hospital_id,
  2891. JZLSH: strconv.FormatInt(patient_info.ID,10),
  2892. XMBM: strconv.FormatInt(patient.DrugId,10),
  2893. XMBMYB: patient.MedListCodg,
  2894. XMMC: patient.AdviceName,
  2895. XMSL: patient.PrescribingNumber,
  2896. XMDW: patient.PrescribingNumberUnit,
  2897. XMDJ: patient.Price,
  2898. XMJE: patient.Price*patient.PrescribingNumber,
  2899. XMLB: "01",
  2900. YWFLDM: "1",
  2901. SFJJ: "0",
  2902. SFPS: "0",
  2903. YPGG: basedrug.DrugSpec,
  2904. SCPH: basedrug.SocialSecurityDirectoryCode,
  2905. YXQZ: "2023-09-01",
  2906. SYPCDM: "QD",
  2907. SYPC: "每天一次",
  2908. JL: patient.SingleDose,
  2909. DW: patient.SingleDoseUnit,
  2910. MCSL: patient.SingleDose,
  2911. MCDW: patient.SingleDoseUnit,
  2912. YF: yf,
  2913. YPYF: ypyf,
  2914. YYTS: patient.Day,
  2915. YWSYZJL: patient.PrescribingNumber,
  2916. YWSYZJLDW: patient.PrescribingNumberUnit,
  2917. SJSCSJ: time.Now(),
  2918. XGBZ: 0,
  2919. }
  2920. service.BatchCreateTB_CIS_Prescription_Detail(p,rdb)
  2921. }
  2922. }
  2923. upload := &sz.DataUpload{
  2924. SyncType: 1007,
  2925. OrgId: org_id,
  2926. SyncTime: time.Now().Unix(),
  2927. SyncResultType: 1,
  2928. CreateTime: time.Now().Unix(),
  2929. UpdateTime: time.Now().Unix(),
  2930. }
  2931. service.CreateUploadRecord(upload)
  2932. }
  2933. // 门诊处方明细表
  2934. func SyncTB_HIS_MZ_Charge(rdb *gorm.DB, org_id int64, hospital_id string) {
  2935. // 第一步:根据机构id获取上次同步时间
  2936. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1008)
  2937. var sync_time int64
  2938. if syncLastInfo.ID > 0 {
  2939. sync_time = syncLastInfo.SyncTime
  2940. } else {
  2941. sync_time = 0
  2942. }
  2943. //同步员工信息
  2944. patients, _ := service.FindOrgHisOrder(org_id, sync_time, time.Now().Unix())
  2945. for _, patient := range patients {
  2946. orderInfos, _ := service.GetHisOrderInfoByNumber(patient.Number)
  2947. patientInfo,_ := service.FindOrgPatientInfoById(patient.PatientId)
  2948. var bedCostTotal float64 = 0 //床位总费
  2949. var operationCostTotal float64 = 0 //手术费
  2950. var otherCostTotal float64 = 0 //其他费用
  2951. var materialCostTotal float64 = 0 //材料费
  2952. var westernMedicineCostTotal float64 = 0 //西药费
  2953. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  2954. var checkCostTotal float64 = 0 //检查费
  2955. var laboratoryCostTotal float64 = 0 //化验费
  2956. var treatCostTotal float64 = 0 //治疗费用
  2957. decimal.DivisionPrecision = 2
  2958. for _, item := range orderInfos {
  2959. if item.MedChrgitmType == "01" { //床位费
  2960. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2961. }
  2962. if item.MedChrgitmType == "03" { //检查费
  2963. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2964. }
  2965. if item.MedChrgitmType == "04" { //化验费
  2966. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2967. }
  2968. if item.MedChrgitmType == "05" { //治疗费
  2969. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2970. }
  2971. if item.MedChrgitmType == "06" { //手术费
  2972. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2973. }
  2974. if item.MedChrgitmType == "08" { //材料费
  2975. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2976. }
  2977. if item.MedChrgitmType == "09" { //西药费
  2978. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2979. }
  2980. if item.MedChrgitmType == "11" { //中成费
  2981. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2982. }
  2983. if item.MedChrgitmType == "14" { //其他费
  2984. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2985. }
  2986. }
  2987. tm := time.Unix(patient.SettleAccountsDate,0)
  2988. ghrq := tm.Format("20060102")
  2989. p := &sz.TB_HIS_MZ_Charge{
  2990. STFRQ: ghrq,
  2991. STFBH: patient.Number,
  2992. STFBZ: "1",
  2993. YLJGDM: hospital_id,
  2994. GHBM: strconv.FormatInt(patient.HisPatientId,10),
  2995. KH: patientInfo.DialysisNo,
  2996. KLX: "3",
  2997. FPH: "/",
  2998. YLFKFSDM: "01",
  2999. YLBXLBDM: "01",
  3000. YBZHBZ: "0000000000000000",
  3001. SSJYBZ: "1",
  3002. ZLLX: "04",
  3003. WDBZ: "1",
  3004. STFSJ: ghrq,
  3005. STFZE: patient.MedfeeSumamt,
  3006. SSJE: patient.MedfeeSumamt,
  3007. YHJE: 0,
  3008. ZFJE: patient.PsnPartAmt,
  3009. YBJZ: 0,
  3010. YBJJ: patient.FundPaySumamt,
  3011. YBZE: patient.InscpScpAmt,
  3012. YBZF: patient.AcctPay,
  3013. YBFWWZF: patient.OverlmtSelfPay,
  3014. TXFYE: "0",
  3015. TXYF: "0",
  3016. GHF: "0",
  3017. ZLF: "0",
  3018. ZHF: treatCostTotal,
  3019. JCF: checkCostTotal,
  3020. SSF: operationCostTotal,
  3021. WSCLF: operationCostTotal,
  3022. CWF: bedCostTotal,
  3023. HLF: "0",
  3024. YSFWF: "0",
  3025. YBZLF: "0",
  3026. HYF: laboratoryCostTotal,
  3027. TSF: "0",
  3028. SPF: "0",
  3029. XYF: westernMedicineCostTotal,
  3030. ZCYF: chineseTraditionalMedicineCostTotal,
  3031. ZYZJF: "0",
  3032. ZCAF: "0",
  3033. QTF: otherCostTotal,
  3034. CFZS: "1",
  3035. SJSCSJ: time.Now(),
  3036. XGBZ: 0,
  3037. }
  3038. service.BatchCreateTB_HIS_MZ_Charge(p,rdb)
  3039. }
  3040. upload := &sz.DataUpload{
  3041. SyncType: 1008,
  3042. OrgId: org_id,
  3043. SyncTime: time.Now().Unix(),
  3044. SyncResultType: 1,
  3045. CreateTime: time.Now().Unix(),
  3046. UpdateTime: time.Now().Unix(),
  3047. }
  3048. service.CreateUploadRecord(upload)
  3049. }
  3050. // 20. 门诊收费明细表
  3051. func SyncTB_HIS_MZ_Fee_Detail(rdb *gorm.DB, org_id int64, hospital_id string) {
  3052. // 第一步:根据机构id获取上次同步时间
  3053. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1009)
  3054. var sync_time int64
  3055. if syncLastInfo.ID > 0 {
  3056. sync_time = syncLastInfo.SyncTime
  3057. } else {
  3058. sync_time = 0
  3059. }
  3060. //同步员工信息
  3061. patients, _ := service.FindOrgHisOrderInfo(org_id, sync_time, time.Now().Unix())
  3062. for _, patient := range patients {
  3063. // order,_ := service.GetHisOrderByNumber(patient.OrderNumber)
  3064. advice,_ := service.GetHisDoctorAdviceInfo(patient.AdviceId)
  3065. patientInfo,_ := service.FindOrgPatientInfoById(patient.PatientId)
  3066. tm := time.Unix(patient.Ctime,0)
  3067. ghrq := tm.Format("20060102")
  3068. var mxfylb string
  3069. mxfylb = "99"
  3070. if patient.MedChrgitmType == "01" { //床位费
  3071. mxfylb = "18"
  3072. }
  3073. if patient.MedChrgitmType == "03" { //检查费
  3074. mxfylb = "06"
  3075. }
  3076. if patient.MedChrgitmType == "04" { //化验费
  3077. mxfylb = "07"
  3078. }
  3079. if patient.MedChrgitmType == "05" { //治疗费
  3080. mxfylb = "03"
  3081. }
  3082. if patient.MedChrgitmType == "06" { //手术费
  3083. mxfylb = "04"
  3084. }
  3085. if patient.MedChrgitmType == "08" { //材料费
  3086. mxfylb = "05"
  3087. }
  3088. if patient.MedChrgitmType == "09" { //西药费
  3089. mxfylb = "12"
  3090. }
  3091. if patient.MedChrgitmType == "11" { //中成费
  3092. mxfylb = "13"
  3093. }
  3094. if patient.MedChrgitmType == "14" { //其他费
  3095. mxfylb = "99"
  3096. }
  3097. p := &sz.TB_HIS_MZ_Fee_Detail{
  3098. SFMXID: strconv.FormatInt(patient.ID,10),
  3099. TFBZ: "1",
  3100. YLJGDM: hospital_id,
  3101. JZLSH: strconv.FormatInt(patient.HisPatientId,10),
  3102. STFBH: patient.OrderNumber,
  3103. KH: patientInfo.DialysisNo,
  3104. KLX: "3",
  3105. ZLLX: "04",
  3106. YLFKFSDM: "01",
  3107. FPH: "/",
  3108. STFSJ: ghrq,
  3109. MXFYLB: mxfylb,
  3110. MXXMBM: strconv.FormatInt(advice.DrugId,10),
  3111. MXXMBMYB: advice.MedListCodg,
  3112. MXXMMC: advice.AdviceName,
  3113. MXXMDW: advice.SingleDoseUnit,
  3114. MXXMDJ: patient.Pric,
  3115. MXXMSL: patient.Cnt,
  3116. MXXMJE: patient.DetItemFeeSumamt,
  3117. KDKSBM: "1001",
  3118. KDKSMC: "血透中心",
  3119. KDRGH: "1001",
  3120. KDRXM: "Phony",
  3121. ZXKSBM: "1001",
  3122. ZXKSMC: "血透中心",
  3123. SJSCSJ: time.Now(),
  3124. XGBZ: 0,
  3125. }
  3126. service.BatchCreateTB_HIS_MZ_Fee_Detail(p,rdb)
  3127. }
  3128. upload := &sz.DataUpload{
  3129. SyncType: 1009,
  3130. OrgId: org_id,
  3131. SyncTime: time.Now().Unix(),
  3132. SyncResultType: 1,
  3133. CreateTime: time.Now().Unix(),
  3134. UpdateTime: time.Now().Unix(),
  3135. }
  3136. service.CreateUploadRecord(upload)
  3137. }