auto_create_week_schedules_service.go 52KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848
  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. "math"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. var createUploadDataCronJob *cron.Cron
  17. func init() {
  18. utils.InfoLog("开启定时任务")
  19. createUploadDataCronJob = cron.New()
  20. spec := "0 0 0 * * ?" // 每天凌晨0点检测数据上报情况
  21. // spec1 := "0 10 0 * * ?" // 每天凌晨0点检测数据上报情况
  22. // spec2 := "0 20 0 * * ?" // 每天凌晨0点检测数据上报情况
  23. createUploadDataCronJob.AddFunc(spec, func() {
  24. SyncToLg2h() //深圳市数据上报
  25. })
  26. // createUploadDataCronJob.AddFunc(spec1, func() {
  27. // SyncToHqyy() //深圳市数据上报
  28. // })
  29. // createUploadDataCronJob.AddFunc(spec2, func() {
  30. // SyncToSmzy() //深圳市数据上报
  31. // })
  32. }
  33. //
  34. func BeginAutoJob() {
  35. createUploadDataCronJob.Start()
  36. }
  37. func SyncToLg2h() {
  38. // 第一步:到上报配置表中找到深圳需要上报的机构
  39. // sz_province, _ := beego.AppConfig.Int64("sz_province")
  40. // sz_city, _ := beego.AppConfig.Int64("sz_city")
  41. // configs, _ := service.FindAllDataUploadConfigOrgInfo(sz_province, sz_city, 3)
  42. org := &sz.DataUploadConfig{
  43. OrgId: 9598,
  44. ProvinceId: 19,
  45. CityId: 291,
  46. DepartmentName: "深圳市龙岗区第二人民医院",
  47. HospitalId: "455835506",
  48. InstType: 1,
  49. DbHost: "183.62.158.36",
  50. DbPort: "61433",
  51. DbPass: "LG2H+9897",
  52. DbUser: "sa",
  53. DbName: "xtzk",
  54. }
  55. // for _, org := range configs {
  56. // 第二步:跟进配置,创建数据库连接
  57. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  58. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  59. if err != nil {
  60. utils.ErrorLog("创建数据库连接失败:%v", err)
  61. return
  62. }
  63. // 第三步:开始同步数据
  64. // 同步医院信息 t_hd_hospital
  65. SyncHospital(orgDb, org.OrgId, org.HospitalId, org.InstType, org.DepartmentName)
  66. // 同步水处理器 t_hd_wm
  67. SyncWMS(orgDb, org.OrgId, org.HospitalId)
  68. // // 同步员工 t_hd_staff
  69. SyncStaff(orgDb, org.OrgId, org.HospitalId)
  70. // // 同步病人 t_hd_patient
  71. SyncPatient(orgDb, org.OrgId, org.HospitalId)
  72. // // 同步排班 t_hd_shift
  73. SyncShift(orgDb, org.OrgId, org.HospitalId)
  74. // 同步处方 t_hd_ps
  75. SyncPs(orgDb, org.OrgId, org.HospitalId)
  76. // 同步处方药品 t_hd_ps
  77. SyncPsMedicine(orgDb, org.OrgId, org.HospitalId)
  78. // // 同步转院信息 t_hd_patient_out
  79. SyncPatientOut(orgDb, org.OrgId, org.HospitalId)
  80. // 同步处方信息 t_hd_doctors_advice
  81. SyncDoctorAdvice(orgDb, org.OrgId, org.HospitalId)
  82. // 同步透中信息 t_hd_middle
  83. SyncMiddle(orgDb, org.OrgId, org.HospitalId)
  84. // // 同步设备 t_hd_other_machine
  85. SyncOtherMachine(orgDb, org.OrgId, org.HospitalId)
  86. // // 同步维修 t_hd_maintain
  87. SyncMachineRepair(orgDb, org.OrgId, org.HospitalId)
  88. // // 同步设备 t_hd_dm
  89. SyncDM(orgDb, org.OrgId, org.HospitalId)
  90. // // 同步患者透析记录 t_hd_dialysis
  91. SyncDialysis(orgDb, org.OrgId, org.HospitalId)
  92. // 同步透析床位分区 t_hd_division
  93. SyncDivision(orgDb, org.OrgId, org.HospitalId)
  94. // 患者通路信息表(T_HD_ACCESS)
  95. SyncAccess(orgDb, org.OrgId, org.HospitalId)
  96. // 透析床位表(T_HD_SICKBED)
  97. SyncSickbed(orgDb, org.OrgId, org.HospitalId)
  98. // 患者诊断信息表(T_HD_DIAGNOSIS)
  99. SyncDiagnosis(orgDb, org.OrgId, org.HospitalId)
  100. // 患者传染病检查记录表(T_HD_INFECTION
  101. SyncInfection(orgDb, org.OrgId, org.HospitalId)
  102. // 透析并发症记录表(T_HD_COMPLICATION)
  103. SyncComplication(orgDb, org.OrgId, org.HospitalId)
  104. // 血透患者检测结果表(T_HD_LIS_REPORT)
  105. SyncLisReport(orgDb, org.OrgId, org.HospitalId)
  106. // 血透患者检验结果指标表(T_HD_LIS_INDICATORS)
  107. SyncLisIndicators(orgDb, org.OrgId, org.HospitalId)
  108. // 第四步:关闭数据库连接
  109. service.CloseDB(orgDb)
  110. }
  111. // }
  112. return
  113. }
  114. func SyncToHqyy() {
  115. // 第一步:到上报配置表中找到深圳需要上报的机构
  116. // sz_province, _ := beego.AppConfig.Int64("sz_province")
  117. // sz_city, _ := beego.AppConfig.Int64("sz_city")
  118. // configs, _ := service.FindAllDataUploadConfigOrgInfo(sz_province, sz_city, 3)
  119. org := &sz.DataUploadConfig{
  120. OrgId: 9442,
  121. ProvinceId: 19,
  122. CityId: 291,
  123. DepartmentName: "暨南大学附属深圳华侨医院",
  124. HospitalId: "73307826X",
  125. InstType: 1,
  126. DbHost: "183.11.232.26",
  127. DbPort: "3306",
  128. DbPass: "1Q2W3e4r!@#$",
  129. DbUser: "sa",
  130. DbName: "xtzk",
  131. }
  132. // for _, org := range configs {
  133. // 第二步:跟进配置,创建数据库连接
  134. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  135. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  136. if err != nil {
  137. utils.ErrorLog("创建数据库连接失败:%v", err)
  138. return
  139. }
  140. // 第三步:开始同步数据
  141. // 同步医院信息 t_hd_hospital
  142. SyncHospital(orgDb, org.OrgId, org.HospitalId, org.InstType, org.DepartmentName)
  143. // 同步水处理器 t_hd_wm
  144. SyncWMS(orgDb, org.OrgId, org.HospitalId)
  145. // // 同步员工 t_hd_staff
  146. SyncStaff(orgDb, org.OrgId, org.HospitalId)
  147. // // 同步病人 t_hd_patient
  148. SyncPatient(orgDb, org.OrgId, org.HospitalId)
  149. // // 同步排班 t_hd_shift
  150. SyncShift(orgDb, org.OrgId, org.HospitalId)
  151. // 同步处方 t_hd_ps
  152. SyncPs(orgDb, org.OrgId, org.HospitalId)
  153. // 同步处方药品 t_hd_ps
  154. SyncPsMedicine(orgDb, org.OrgId, org.HospitalId)
  155. // // 同步转院信息 t_hd_patient_out
  156. SyncPatientOut(orgDb, org.OrgId, org.HospitalId)
  157. // 同步处方信息 t_hd_doctors_advice
  158. SyncDoctorAdvice(orgDb, org.OrgId, org.HospitalId)
  159. // 同步透中信息 t_hd_middle
  160. SyncMiddle(orgDb, org.OrgId, org.HospitalId)
  161. // // 同步设备 t_hd_other_machine
  162. SyncOtherMachine(orgDb, org.OrgId, org.HospitalId)
  163. // // 同步维修 t_hd_maintain
  164. SyncMachineRepair(orgDb, org.OrgId, org.HospitalId)
  165. // // 同步设备 t_hd_dm
  166. SyncDM(orgDb, org.OrgId, org.HospitalId)
  167. // // 同步患者透析记录 t_hd_dialysis
  168. SyncDialysis(orgDb, org.OrgId, org.HospitalId)
  169. // 同步透析床位分区 t_hd_division
  170. SyncDivision(orgDb, org.OrgId, org.HospitalId)
  171. // 患者通路信息表(T_HD_ACCESS)
  172. SyncAccess(orgDb, org.OrgId, org.HospitalId)
  173. // 透析床位表(T_HD_SICKBED)
  174. SyncSickbed(orgDb, org.OrgId, org.HospitalId)
  175. // 患者诊断信息表(T_HD_DIAGNOSIS)
  176. SyncDiagnosis(orgDb, org.OrgId, org.HospitalId)
  177. // 患者传染病检查记录表(T_HD_INFECTION
  178. SyncInfection(orgDb, org.OrgId, org.HospitalId)
  179. // 透析并发症记录表(T_HD_COMPLICATION)
  180. SyncComplication(orgDb, org.OrgId, org.HospitalId)
  181. // 血透患者检测结果表(T_HD_LIS_REPORT)
  182. SyncLisReport(orgDb, org.OrgId, org.HospitalId)
  183. // 血透患者检验结果指标表(T_HD_LIS_INDICATORS)
  184. SyncLisIndicators(orgDb, org.OrgId, org.HospitalId)
  185. // 第四步:关闭数据库连接
  186. service.CloseDB(orgDb)
  187. }
  188. // }
  189. return
  190. }
  191. func SyncToSmzy() {
  192. // 第一步:到上报配置表中找到深圳需要上报的机构
  193. // sz_province, _ := beego.AppConfig.Int64("sz_province")
  194. // sz_city, _ := beego.AppConfig.Int64("sz_city")
  195. // configs, _ := service.FindAllDataUploadConfigOrgInfo(sz_province, sz_city, 3)
  196. org := &sz.DataUploadConfig{
  197. OrgId: 9504,
  198. ProvinceId: 19,
  199. CityId: 291,
  200. DepartmentName: "深圳生命之源血液透析中心",
  201. HospitalId: "MA5EU4PC0",
  202. InstType: 1,
  203. DbHost: "localhost",
  204. DbPort: "1433",
  205. DbPass: "1Q2W3e4r!@#$",
  206. DbUser: "sa",
  207. DbName: "xtzk",
  208. }
  209. // for _, org := range configs {
  210. // 第二步:跟进配置,创建数据库连接
  211. if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
  212. orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
  213. if err != nil {
  214. utils.ErrorLog("创建数据库连接失败:%v", err)
  215. return
  216. }
  217. // 第三步:开始同步数据
  218. // 同步医院信息 t_hd_hospital
  219. SyncHospital(orgDb, org.OrgId, org.HospitalId, org.InstType, org.DepartmentName)
  220. // 同步水处理器 t_hd_wm
  221. SyncWMS(orgDb, org.OrgId, org.HospitalId)
  222. // // 同步员工 t_hd_staff
  223. SyncStaff(orgDb, org.OrgId, org.HospitalId)
  224. // // 同步病人 t_hd_patient
  225. SyncPatient(orgDb, org.OrgId, org.HospitalId)
  226. // // 同步排班 t_hd_shift
  227. SyncShift(orgDb, org.OrgId, org.HospitalId)
  228. // 同步处方 t_hd_ps
  229. SyncPs(orgDb, org.OrgId, org.HospitalId)
  230. // 同步处方药品 t_hd_ps
  231. SyncPsMedicine(orgDb, org.OrgId, org.HospitalId)
  232. // // 同步转院信息 t_hd_patient_out
  233. SyncPatientOut(orgDb, org.OrgId, org.HospitalId)
  234. // 同步处方信息 t_hd_doctors_advice
  235. SyncDoctorAdvice(orgDb, org.OrgId, org.HospitalId)
  236. // 同步透中信息 t_hd_middle
  237. SyncMiddle(orgDb, org.OrgId, org.HospitalId)
  238. // // 同步设备 t_hd_other_machine
  239. SyncOtherMachine(orgDb, org.OrgId, org.HospitalId)
  240. // // 同步维修 t_hd_maintain
  241. SyncMachineRepair(orgDb, org.OrgId, org.HospitalId)
  242. // // 同步设备 t_hd_dm
  243. SyncDM(orgDb, org.OrgId, org.HospitalId)
  244. // // 同步患者透析记录 t_hd_dialysis
  245. SyncDialysis(orgDb, org.OrgId, org.HospitalId)
  246. // 同步透析床位分区 t_hd_division
  247. SyncDivision(orgDb, org.OrgId, org.HospitalId)
  248. // 患者通路信息表(T_HD_ACCESS)
  249. SyncAccess(orgDb, org.OrgId, org.HospitalId)
  250. // 透析床位表(T_HD_SICKBED)
  251. SyncSickbed(orgDb, org.OrgId, org.HospitalId)
  252. // 患者诊断信息表(T_HD_DIAGNOSIS)
  253. SyncDiagnosis(orgDb, org.OrgId, org.HospitalId)
  254. // 患者传染病检查记录表(T_HD_INFECTION
  255. SyncInfection(orgDb, org.OrgId, org.HospitalId)
  256. // 透析并发症记录表(T_HD_COMPLICATION)
  257. SyncComplication(orgDb, org.OrgId, org.HospitalId)
  258. // 血透患者检测结果表(T_HD_LIS_REPORT)
  259. SyncLisReport(orgDb, org.OrgId, org.HospitalId)
  260. // 血透患者检验结果指标表(T_HD_LIS_INDICATORS)
  261. SyncLisIndicators(orgDb, org.OrgId, org.HospitalId)
  262. // 第四步:关闭数据库连接
  263. service.CloseDB(orgDb)
  264. }
  265. // }
  266. return
  267. }
  268. // 同步医院信息
  269. func SyncHospital(rdb *gorm.DB, org_id int64, hospital_id string, inst_type int64, department_name string) {
  270. // 第一步:根据机构id获取上次同步时间
  271. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1)
  272. var sync_time int64
  273. if syncLastInfo.ID > 0 {
  274. sync_time = syncLastInfo.SyncTime
  275. } else {
  276. sync_time = 0
  277. }
  278. // 第二步:跟进上次同步时间找出这个时间段内增加的数据
  279. org, _ := service.FindOrgData(org_id, sync_time)
  280. if org.ID > 0 {
  281. hospital := &sz.TempHdHospital{
  282. HospitalId: hospital_id,
  283. InstType: strconv.FormatInt(inst_type, 10),
  284. DepartmentName: department_name,
  285. AuthorizedBeds: int64(len(org.DeviceNumber)),
  286. CreateTime: time.Now(),
  287. UpdateTime: time.Now(),
  288. Sjscsj: time.Now(),
  289. Xgbz: 0,
  290. }
  291. err := service.CreateOrgRecord(rdb, hospital)
  292. if err == nil {
  293. // 第三步:同步成功后,添加同步记录
  294. upload := &sz.DataUpload{
  295. SyncType: 1,
  296. OrgId: org_id,
  297. SyncTime: time.Now().Unix(),
  298. SyncResultType: 1,
  299. CreateTime: time.Now().Unix(),
  300. UpdateTime: time.Now().Unix(),
  301. }
  302. err := service.CreateUploadRecord(upload)
  303. if err != nil {
  304. utils.ErrorLog("%v", err)
  305. }
  306. }
  307. }
  308. }
  309. // 同步水处理器
  310. func SyncWMS(rdb *gorm.DB, org_id int64, hospital_id string) {
  311. // 第一步:根据机构id获取上次同步时间
  312. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 22)
  313. var sync_time int64
  314. if syncLastInfo.ID > 0 {
  315. sync_time = syncLastInfo.SyncTime
  316. } else {
  317. sync_time = 0
  318. }
  319. //同步水处理机
  320. waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
  321. var wms []*sz.TempHdWm
  322. for _, item := range waterMachine {
  323. wm := &sz.TempHdWm{
  324. HospitalId: hospital_id,
  325. EquipmentId: strconv.FormatInt(item.ID, 10),
  326. EquipmentBrand: item.ManufactureFactory,
  327. EquipmentModel: strconv.FormatInt(item.UnitType, 10),
  328. EnableTime: time.Unix(item.StartDate, 0),
  329. DiscardedTime: time.Unix(item.RubbishDate, 0),
  330. EquipmentType: item.DeviceType,
  331. CreateTime: time.Now(),
  332. UpdateTime: time.Now(),
  333. Sjscsj: time.Now(),
  334. Xgbz: 0,
  335. }
  336. wms = append(wms, wm)
  337. }
  338. err := service.BatchCreateWMsRecord(wms, rdb)
  339. if err == nil {
  340. // 第三步:同步成功后,添加同步记录
  341. upload := &sz.DataUpload{
  342. SyncType: 22,
  343. OrgId: org_id,
  344. SyncTime: time.Now().Unix(),
  345. SyncResultType: 1,
  346. CreateTime: time.Now().Unix(),
  347. UpdateTime: time.Now().Unix(),
  348. }
  349. err := service.CreateUploadRecord(upload)
  350. if err != nil {
  351. utils.ErrorLog("%v", err)
  352. }
  353. } else {
  354. //错误处理
  355. }
  356. }
  357. // 同步员工
  358. func SyncStaff(rdb *gorm.DB, org_id int64, hospital_id string) {
  359. // 第一步:根据机构id获取上次同步时间
  360. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 21)
  361. var sync_time int64
  362. if syncLastInfo.ID > 0 {
  363. sync_time = syncLastInfo.SyncTime
  364. } else {
  365. sync_time = 0
  366. }
  367. //同步员工信息
  368. roles, _ := service.FindOrgRolesData(org_id, sync_time, time.Now().Unix())
  369. //waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
  370. var staffs []*sz.TempHdStaff
  371. for _, role := range roles {
  372. var title int
  373. switch role.UserType {
  374. case 2:
  375. title = 1
  376. break
  377. case 3:
  378. title = 2
  379. break
  380. }
  381. staff := &sz.TempHdStaff{
  382. ID: role.AdminUserId,
  383. HospitalId: hospital_id,
  384. StaffId: strconv.FormatInt(role.ID, 10),
  385. StaffName: role.UserName,
  386. Position: int64(title),
  387. PermanentType: 1,
  388. CreateTime: time.Now(),
  389. UpdateTime: time.Now(),
  390. Sjscsj: time.Now(),
  391. Xgbz: 0,
  392. }
  393. staffs = append(staffs, staff)
  394. }
  395. err := service.BatchCreateStaffRecord(staffs, rdb)
  396. if err == nil {
  397. // 第三步:同步成功后,添加同步记录
  398. upload := &sz.DataUpload{
  399. SyncType: 21,
  400. OrgId: org_id,
  401. SyncTime: time.Now().Unix(),
  402. SyncResultType: 1,
  403. CreateTime: time.Now().Unix(),
  404. UpdateTime: time.Now().Unix(),
  405. }
  406. err := service.CreateUploadRecord(upload)
  407. if err != nil {
  408. utils.ErrorLog("%v", err)
  409. }
  410. } else {
  411. //错误处理
  412. }
  413. }
  414. // 同步病人
  415. func SyncPatient(rdb *gorm.DB, org_id int64, hospital_id string) {
  416. // 第一步:根据机构id获取上次同步时间
  417. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 15)
  418. var sync_time int64
  419. if syncLastInfo.ID > 0 {
  420. sync_time = syncLastInfo.SyncTime
  421. } else {
  422. sync_time = 0
  423. }
  424. //同步员工信息
  425. patients, _ := service.FindOrgPatientData(org_id, sync_time, time.Now().Unix())
  426. //waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
  427. var hdPatients []*sz.TempHdPatient
  428. for _, patient := range patients {
  429. idcard_year, _ := strconv.Atoi(Substr(patient.IdCardNo, 6, 4)) // 年
  430. idcard_mo, _ := strconv.Atoi(Substr(patient.IdCardNo, 10, 2)) // 月
  431. idcard_day, _ := strconv.Atoi(Substr(patient.IdCardNo, 12, 2)) // 日
  432. date := strconv.Itoa(idcard_year)
  433. if idcard_mo < 10 {
  434. date = date + "-0" + strconv.Itoa(idcard_mo)
  435. } else {
  436. date = date + "-" + strconv.Itoa(idcard_mo)
  437. }
  438. if idcard_day < 10 {
  439. date = date + "-0" + strconv.Itoa(idcard_day)
  440. } else {
  441. date = date + "-" + strconv.Itoa(idcard_day)
  442. }
  443. local, _ := time.LoadLocation("Local")
  444. birthday, _ := time.ParseInLocation("2006-01-02", date, local)
  445. fmt.Println(birthday)
  446. var isCKD int
  447. value := strings.Index(patient.Diagnose, "慢性肾脏病")
  448. value2 := strings.Index(patient.Diagnose, "CKD")
  449. value3 := strings.Index(patient.Diagnose, "慢性肾衰竭")
  450. if value != -1 || value2 != -1 || value3 != -1 {
  451. isCKD = 1
  452. } else {
  453. isCKD = 0
  454. }
  455. p := &sz.TempHdPatient{
  456. HospitalId: hospital_id,
  457. PatientNk: patient.ID,
  458. CardNo: "000000000000000000",
  459. CardType: 1,
  460. IdNo: patient.IdCardNo,
  461. IdType: "01",
  462. PatientName: patient.Name,
  463. Gender: strconv.FormatInt(patient.Gender, 10),
  464. BornDate: birthday,
  465. DiagnosisSummary: patient.Diagnose,
  466. IsCrf: strconv.Itoa(isCKD),
  467. DialysisStartTime: time.Unix(patient.FirstDialysisDate,0),
  468. LocalStartTime: time.Unix(patient.HospitalFirstDialysisDate,0),
  469. OutpatientNo: patient.DialysisNo,
  470. HospitalizedNo: patient.AdmissionNumber,
  471. CreateTime: time.Now(),
  472. UpdateTime: time.Now(),
  473. Sjscsj: time.Now(),
  474. Xgbz: 0,
  475. }
  476. if patient.FirstDialysisDate != 0 {
  477. p.DialysisStartTime = time.Unix(patient.FirstDialysisDate, 0)
  478. }
  479. if patient.HospitalFirstDialysisDate != 0 {
  480. p.LocalStartTime = time.Unix(patient.HospitalFirstDialysisDate, 0)
  481. }
  482. hdPatients = append(hdPatients, p)
  483. }
  484. err := service.BatchCreatePatinet(hdPatients, rdb)
  485. if err == nil {
  486. // 第三步:同步成功后,添加同步记录
  487. upload := &sz.DataUpload{
  488. SyncType: 15,
  489. OrgId: org_id,
  490. SyncTime: time.Now().Unix(),
  491. SyncResultType: 1,
  492. CreateTime: time.Now().Unix(),
  493. UpdateTime: time.Now().Unix(),
  494. }
  495. err := service.CreateUploadRecord(upload)
  496. if err != nil {
  497. utils.ErrorLog("%v", err)
  498. }
  499. } else {
  500. //错误处理
  501. }
  502. }
  503. func Substr(str string, start, length int) string {
  504. rs := []rune(str)
  505. rl := len(rs)
  506. end := 0
  507. if start < 0 {
  508. start = rl - 1 + start
  509. }
  510. end = start + length
  511. if start > end {
  512. start, end = end, start
  513. }
  514. if start < 0 {
  515. start = 0
  516. }
  517. if start > rl {
  518. start = rl
  519. }
  520. if end < 0 {
  521. end = 0
  522. }
  523. if end > rl {
  524. end = rl
  525. }
  526. return string(rs[start:end])
  527. }
  528. // 同步排班
  529. func SyncShift(rdb *gorm.DB, org_id int64, hospital_id string) {
  530. // 第一步:根据机构id获取上次同步时间
  531. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 19)
  532. var sync_time int64
  533. if syncLastInfo.ID > 0 {
  534. sync_time = syncLastInfo.SyncTime
  535. } else {
  536. sync_time = 0
  537. }
  538. var hdShift []*sz.TempHdShift
  539. schs, _ := service.FindOrgScheduleData(org_id, sync_time, time.Now().Unix())
  540. for _, sch := range schs {
  541. shift := &sz.TempHdShift{
  542. PsId: strconv.FormatInt(sch.ID, 10),
  543. HospitalId: hospital_id,
  544. PatientNk: strconv.FormatInt(sch.PatientId, 10),
  545. ScheduleDate: time.Unix(sch.ScheduleDate, 0),
  546. ShiftType: strconv.FormatInt(sch.ScheduleType, 10),
  547. SickbedNo: sch.DeviceNumber.ID,
  548. ScheduleStatus: "1",
  549. CreateTime: time.Now(),
  550. Sjscsj: time.Now(),
  551. Xgbz: 0,
  552. }
  553. hdShift = append(hdShift, shift)
  554. }
  555. err := service.BatchCreateSchedual(hdShift, rdb)
  556. if err == nil {
  557. // 第三步:同步成功后,添加同步记录
  558. upload := &sz.DataUpload{
  559. SyncType: 19,
  560. OrgId: org_id,
  561. SyncTime: time.Now().Unix(),
  562. SyncResultType: 1,
  563. CreateTime: time.Now().Unix(),
  564. UpdateTime: time.Now().Unix(),
  565. }
  566. err := service.CreateUploadRecord(upload)
  567. if err != nil {
  568. utils.ErrorLog("%v", err)
  569. }
  570. } else {
  571. //错误处理
  572. }
  573. }
  574. // 同步处方
  575. func SyncPs(rdb *gorm.DB, org_id int64, hospital_id string) {
  576. // 第一步:根据机构id获取上次同步时间
  577. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 17)
  578. var sync_time int64
  579. if syncLastInfo.ID > 0 {
  580. sync_time = syncLastInfo.SyncTime
  581. } else {
  582. sync_time = 0
  583. }
  584. var hdPrescription []*sz.TempHdPs
  585. prescriptions, _ := service.FindOrgDialysisPrescriptionData(org_id, sync_time, time.Now().Unix())
  586. for _, item := range prescriptions {
  587. ps := &sz.TempHdPs{
  588. PrescribeId: strconv.FormatInt(item.ID, 10),
  589. HospitalId: hospital_id,
  590. PatientNk: strconv.FormatInt(item.PatientId, 10),
  591. Sjscsj: time.Now(),
  592. Xgbz: 0,
  593. PrescribeTime: time.Unix(item.RecordDate, 0),
  594. CreateTime: time.Unix(item.CreatedTime,0),
  595. }
  596. switch item.ModeId {
  597. case 1:
  598. ps.DialysisFrequency = 5
  599. ps.FrequencyUnit = 2
  600. ps.RrtTypeName = "HD"
  601. ps.RrtType = 1
  602. break
  603. case 2:
  604. ps.DialysisFrequency = 5
  605. ps.FrequencyUnit = 2
  606. ps.RrtTypeName = "HDF"
  607. ps.RrtType = 3
  608. break
  609. case 4:
  610. ps.DialysisFrequency = 5
  611. ps.FrequencyUnit = 2
  612. ps.RrtTypeName = "HP"
  613. ps.RrtType = 5
  614. break
  615. case 5:
  616. ps.DialysisFrequency = 5
  617. ps.FrequencyUnit = 2
  618. ps.RrtTypeName = "HF"
  619. ps.RrtType = 2
  620. break
  621. case 7:
  622. ps.DialysisFrequency = 5
  623. ps.FrequencyUnit = 2
  624. ps.RrtTypeName = "IUF"
  625. ps.RrtType = 6
  626. break
  627. default:
  628. ps.DialysisFrequency = 5
  629. ps.FrequencyUnit = 2
  630. ps.RrtTypeName = "HD"
  631. ps.RrtType = 1
  632. break
  633. }
  634. hdPrescription = append(hdPrescription, ps)
  635. }
  636. var err error
  637. for _, hdps := range hdPrescription{
  638. err = service.BatchCreatePsOther(hdps, rdb)
  639. }
  640. // err := service.BatchCreatePs(hdPrescription, rdb)
  641. if err == nil {
  642. // 第三步:同步成功后,添加同步记录
  643. upload := &sz.DataUpload{
  644. SyncType: 17,
  645. OrgId: org_id,
  646. SyncTime: time.Now().Unix(),
  647. SyncResultType: 1,
  648. CreateTime: time.Now().Unix(),
  649. UpdateTime: time.Now().Unix(),
  650. }
  651. err := service.CreateUploadRecord(upload)
  652. if err != nil {
  653. utils.ErrorLog("%v", err)
  654. }
  655. } else {
  656. //错误处理
  657. }
  658. }
  659. // 同步处方药物
  660. func SyncPsMedicine(rdb *gorm.DB, org_id int64, hospital_id string) {
  661. // 第一步:根据机构id获取上次同步时间
  662. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 18)
  663. var sync_time int64
  664. if syncLastInfo.ID > 0 {
  665. sync_time = syncLastInfo.SyncTime
  666. } else {
  667. sync_time = 0
  668. }
  669. var tempPsmedicine []*sz.TempHdPsMedicine
  670. prescriptions, _ := service.FindOrgDoctorAdviceTemplateData(org_id, sync_time, time.Now().Unix())
  671. for _, item := range prescriptions {
  672. psm := &sz.TempHdPsMedicine{
  673. Sn : item.ID,
  674. HospitalId: hospital_id,
  675. MedicineTypeId: "2",
  676. MedicineId: strconv.FormatInt(item.ID,10),
  677. CreateTime: time.Now(),
  678. Sjscsj: time.Now(),
  679. Xgbz: 0,
  680. }
  681. tempPsmedicine = append(tempPsmedicine, psm)
  682. }
  683. err := service.BatchCreatePsm(tempPsmedicine, rdb)
  684. if err == nil {
  685. // 第三步:同步成功后,添加同步记录
  686. upload := &sz.DataUpload{
  687. SyncType: 18,
  688. OrgId: org_id,
  689. SyncTime: time.Now().Unix(),
  690. SyncResultType: 1,
  691. CreateTime: time.Now().Unix(),
  692. UpdateTime: time.Now().Unix(),
  693. }
  694. err := service.CreateUploadRecord(upload)
  695. if err != nil {
  696. utils.ErrorLog("%v", err)
  697. }
  698. } else {
  699. //错误处理
  700. }
  701. }
  702. // 同步转院信息
  703. func SyncPatientOut(rdb *gorm.DB, org_id int64, hospital_id string) {
  704. // 第一步:根据机构id获取上次同步时间
  705. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 16)
  706. var sync_time int64
  707. if syncLastInfo.ID > 0 {
  708. sync_time = syncLastInfo.SyncTime
  709. } else {
  710. sync_time = 0
  711. }
  712. var hdPatientOuts []*sz.TempHdPatientOut
  713. patients, _ := service.FindOrgPatientOutData(org_id, sync_time, time.Now().Unix())
  714. //
  715. for _, patient := range patients {
  716. p := &sz.TempHdPatientOut{
  717. Sn: strconv.FormatInt(patient.PatientLapseto.ID,10),
  718. HospitalId: hospital_id,
  719. PatientNk: strconv.FormatInt(patient.ID, 10),
  720. SequelaeDate: time.Unix(patient.PatientLapseto.LapsetoTime,0),
  721. SequelaeType: "99",
  722. CreateTime: time.Unix(patient.PatientLapseto.CreatedTime,0),
  723. DeathReason: "99",
  724. ExtReason: "99",
  725. Sjscsj: time.Now(),
  726. Xgbz: 0,
  727. }
  728. hdPatientOuts = append(hdPatientOuts, p)
  729. }
  730. err := service.BatchCreatePatientOut(hdPatientOuts, rdb)
  731. if err == nil {
  732. // 第三步:同步成功后,添加同步记录
  733. upload := &sz.DataUpload{
  734. SyncType: 16,
  735. OrgId: org_id,
  736. SyncTime: time.Now().Unix(),
  737. SyncResultType: 1,
  738. CreateTime: time.Now().Unix(),
  739. UpdateTime: time.Now().Unix(),
  740. }
  741. err := service.CreateUploadRecord(upload)
  742. if err != nil {
  743. utils.ErrorLog("%v", err)
  744. }
  745. } else {
  746. //错误处理
  747. }
  748. }
  749. // 同步处方信息
  750. func SyncDoctorAdvice(rdb *gorm.DB, org_id int64, hospital_id string) {
  751. // 第一步:根据机构id获取上次同步时间
  752. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 6)
  753. var sync_time int64
  754. if syncLastInfo.ID > 0 {
  755. sync_time = syncLastInfo.SyncTime
  756. } else {
  757. sync_time = 0
  758. }
  759. var hdDoctorAdvices []*sz.TempHdDoctorsAdvice
  760. dialysisPrescriptions, _ := service.FindOrgDialysisPrescriptionData(org_id, sync_time, time.Now().Unix())
  761. for _, dp := range dialysisPrescriptions {
  762. if dp.DialysisOrder.ID > 0 {
  763. advice := &sz.TempHdDoctorsAdvice{
  764. MedicalOrderId: strconv.FormatInt(dp.ID, 10),
  765. HospitalId: hospital_id,
  766. DialysisId: strconv.FormatInt(dp.DialysisOrder.ID, 10),
  767. OrderType: "1",
  768. PatientNk: strconv.FormatInt(dp.PatientId, 10),
  769. DialysisDuration: dp.DialysisDurationHour*60 + dp.DialysisDurationMinute,
  770. BloodVol: int64(math.Floor(dp.BloodFlowVolume + 0/5)),
  771. Anticoagulant: dp.Anticoagulant,
  772. CreateTime: time.Now(),
  773. Sjscsj: time.Now(),
  774. Xgbz: 0,
  775. DryWeight: dp.AssessmentBeforeDislysis.DryWeight,
  776. }
  777. switch dp.ModeId {
  778. case 1:
  779. advice.RrtTypeName = "HD"
  780. advice.RrtType = 1
  781. break
  782. case 2:
  783. advice.RrtTypeName = "HDF"
  784. advice.RrtType = 3
  785. break
  786. case 4:
  787. advice.RrtTypeName = "HP"
  788. advice.RrtType = 5
  789. break
  790. case 5:
  791. advice.RrtTypeName = "HF"
  792. advice.RrtType = 2
  793. break
  794. case 7:
  795. advice.RrtTypeName = "IUF"
  796. advice.RrtType = 6
  797. break
  798. default:
  799. advice.RrtTypeName = "HD"
  800. advice.RrtType = 1
  801. }
  802. if advice.RrtType == 0 {
  803. continue
  804. }
  805. hdDoctorAdvices = append(hdDoctorAdvices, advice)
  806. }
  807. }
  808. err := service.BatchCreateDoctorsAdvice(hdDoctorAdvices, rdb)
  809. if err == nil {
  810. // 第三步:同步成功后,添加同步记录
  811. upload := &sz.DataUpload{
  812. SyncType: 6,
  813. OrgId: org_id,
  814. SyncTime: time.Now().Unix(),
  815. SyncResultType: 1,
  816. CreateTime: time.Now().Unix(),
  817. UpdateTime: time.Now().Unix(),
  818. }
  819. err := service.CreateUploadRecord(upload)
  820. if err != nil {
  821. utils.ErrorLog("%v", err)
  822. }
  823. } else {
  824. //错误处理
  825. }
  826. }
  827. //
  828. func SyncMiddle(rdb *gorm.DB, org_id int64, hospital_id string) {
  829. // 第一步:根据机构id获取上次同步时间
  830. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 36)
  831. var sync_time int64
  832. if syncLastInfo.ID > 0 {
  833. sync_time = syncLastInfo.SyncTime
  834. } else {
  835. sync_time = 0
  836. }
  837. var hdMiddle []*sz.TempHdMiddle
  838. monitors, _ := service.FindOrgMonitorRecordData(org_id, sync_time, time.Now().Unix())
  839. for _, item := range monitors {
  840. mid := &sz.TempHdMiddle{
  841. Sn : item.ID,
  842. HospitalId: hospital_id,
  843. DialysisId: strconv.FormatInt(item.DialysisOrder.ID, 10),
  844. MonitorTime: time.Unix(item.OperateTime, 0),
  845. Sbp: int64(math.Floor(item.SystolicBloodPressure + 0/5)),
  846. Dbp: int64(math.Floor(item.DiastolicBloodPressure + 0/5)),
  847. PatientNk: strconv.FormatInt(item.PatientId, 10),
  848. CreateTime: time.Now(),
  849. Sjscsj: time.Now(),
  850. Xgbz: 0,
  851. }
  852. if mid.Sbp > 999 {
  853. continue
  854. }
  855. if mid.Dbp > 999 {
  856. continue
  857. }
  858. hdMiddle = append(hdMiddle, mid)
  859. }
  860. err := service.BatchCreateMonitor(hdMiddle, rdb)
  861. if err == nil {
  862. // 第三步:同步成功后,添加同步记录
  863. upload := &sz.DataUpload{
  864. SyncType: 36,
  865. OrgId: org_id,
  866. SyncTime: time.Now().Unix(),
  867. SyncResultType: 1,
  868. CreateTime: time.Now().Unix(),
  869. UpdateTime: time.Now().Unix(),
  870. }
  871. err := service.CreateUploadRecord(upload)
  872. if err != nil {
  873. utils.ErrorLog("%v", err)
  874. }
  875. } else {
  876. //错误处理
  877. }
  878. }
  879. // 同步设备
  880. func SyncOtherMachine(rdb *gorm.DB, org_id int64, hospital_id string) {
  881. // 第一步:根据机构id获取上次同步时间
  882. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 13)
  883. var sync_time int64
  884. if syncLastInfo.ID > 0 {
  885. sync_time = syncLastInfo.SyncTime
  886. } else {
  887. sync_time = 0
  888. }
  889. //同步设备
  890. waterMachine, _ := service.FindOrgOtherMachineData(org_id, sync_time, time.Now().Unix())
  891. var wms []*sz.TempHdOtherMachine
  892. for _, item := range waterMachine {
  893. wm := &sz.TempHdOtherMachine{
  894. HospitalId: hospital_id,
  895. EquipmentId: strconv.FormatInt(item.ID, 10),
  896. EquipmentBrand: item.ManufactureFactory,
  897. EquipmentModel: strconv.FormatInt(item.UnitType, 10),
  898. EnableTime: time.Unix(item.BuyDate, 0),
  899. Status: 1,
  900. EquipmentType: 11,
  901. CreateTime: time.Now(),
  902. UpdateTime: time.Now(),
  903. Sjscsj: time.Now(),
  904. Xgbz: strconv.FormatInt(0, 10),
  905. }
  906. switch item.MachineStatus {
  907. case 1:
  908. wm.Status = 1
  909. break
  910. case 4:
  911. wm.Status = 3
  912. break
  913. }
  914. wms = append(wms, wm)
  915. }
  916. err := service.BatchCreateOtherMachineRecord(wms, rdb)
  917. if err == nil {
  918. // 第三步:同步成功后,添加同步记录
  919. upload := &sz.DataUpload{
  920. SyncType: 13,
  921. OrgId: org_id,
  922. SyncTime: time.Now().Unix(),
  923. SyncResultType: 1,
  924. CreateTime: time.Now().Unix(),
  925. UpdateTime: time.Now().Unix(),
  926. }
  927. err := service.CreateUploadRecord(upload)
  928. if err != nil {
  929. utils.ErrorLog("%v", err)
  930. }
  931. } else {
  932. //错误处理
  933. }
  934. }
  935. // 同步维修
  936. func SyncMachineRepair(rdb *gorm.DB, org_id int64, hospital_id string) {
  937. // 第一步:根据机构id获取上次同步时间
  938. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 11)
  939. var sync_time int64
  940. if syncLastInfo.ID > 0 {
  941. sync_time = syncLastInfo.SyncTime
  942. } else {
  943. sync_time = 0
  944. }
  945. //同步设备
  946. hdMaintain, _ := service.FindOrgMachineRepairData(org_id, sync_time, time.Now().Unix())
  947. var maintain []*sz.TempHdMaintain
  948. for _, item := range hdMaintain {
  949. mt := &sz.TempHdMaintain{
  950. HospitalId: hospital_id,
  951. EquipmentId: strconv.FormatInt(item.VMDeviceAddmacher.ID, 10),
  952. RepairTime: time.Unix(item.GuaranteeDate, 0),
  953. CreateTime: time.Now(),
  954. Sjscsj: time.Now(),
  955. Xgbz: 0,
  956. }
  957. switch item.VMDeviceAddmacher.DeviceType {
  958. case 1:
  959. mt.EquipmentType = "11"
  960. break
  961. case 2:
  962. mt.EquipmentType = "21"
  963. break
  964. case 3:
  965. mt.EquipmentType = "99"
  966. break
  967. }
  968. maintain = append(maintain, mt)
  969. }
  970. err := service.BatchCreateMainTain(maintain, rdb)
  971. if err == nil {
  972. // 第三步:同步成功后,添加同步记录
  973. upload := &sz.DataUpload{
  974. SyncType: 11,
  975. OrgId: org_id,
  976. SyncTime: time.Now().Unix(),
  977. SyncResultType: 1,
  978. CreateTime: time.Now().Unix(),
  979. UpdateTime: time.Now().Unix(),
  980. }
  981. err := service.CreateUploadRecord(upload)
  982. if err != nil {
  983. utils.ErrorLog("%v", err)
  984. }
  985. } else {
  986. //错误处理
  987. }
  988. }
  989. // 同步设备
  990. func SyncDM(rdb *gorm.DB, org_id int64, hospital_id string) {
  991. // 第一步:根据机构id获取上次同步时间
  992. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 5)
  993. var sync_time int64
  994. if syncLastInfo.ID > 0 {
  995. sync_time = syncLastInfo.SyncTime
  996. } else {
  997. sync_time = 0
  998. }
  999. //同步设备
  1000. dm, _ := service.FindOrgMachineData(org_id, sync_time, time.Now().Unix())
  1001. var hdms []*sz.TempHdDm
  1002. for _, item := range dm {
  1003. hdm := &sz.TempHdDm{
  1004. HospitalId: hospital_id,
  1005. EquipmentId: strconv.FormatInt(item.ID, 10),
  1006. SickbedNo: strconv.FormatInt(item.DeviceNumber.ID, 10),
  1007. SickbedType: "0",
  1008. EquipmentBrand: item.ManufactureFactory,
  1009. EquipmentModel: strconv.FormatInt(item.UnitType, 10),
  1010. EnableTime: time.Unix(item.BuyDate, 0),
  1011. // EquipmentType: "11",
  1012. Bbp: "0",
  1013. CreateTime: time.Now(),
  1014. UpdateTime: time.Now(),
  1015. Sjscsj: time.Now(),
  1016. Xgbz: strconv.FormatInt(0, 10),
  1017. }
  1018. switch item.MachineStatus {
  1019. case 1:
  1020. hdm.Status = "1"
  1021. break
  1022. case 4:
  1023. hdm.Status = "3"
  1024. break
  1025. }
  1026. switch item.DeviceType {
  1027. case 1:
  1028. hdm.EquipmentType = "11"
  1029. break
  1030. case 3:
  1031. hdm.EquipmentType = "99"
  1032. break
  1033. }
  1034. hdms = append(hdms, hdm)
  1035. }
  1036. err := service.BatchCreateHDMRecord(hdms, rdb)
  1037. if err == nil {
  1038. // 第三步:同步成功后,添加同步记录
  1039. upload := &sz.DataUpload{
  1040. SyncType: 5,
  1041. OrgId: org_id,
  1042. SyncTime: time.Now().Unix(),
  1043. SyncResultType: 1,
  1044. CreateTime: time.Now().Unix(),
  1045. UpdateTime: time.Now().Unix(),
  1046. }
  1047. err := service.CreateUploadRecord(upload)
  1048. if err != nil {
  1049. utils.ErrorLog("%v", err)
  1050. }
  1051. } else {
  1052. //错误处理
  1053. }
  1054. }
  1055. // 同步患者透析记录
  1056. func SyncDialysis(rdb *gorm.DB, org_id int64, hospital_id string) {
  1057. // 第一步:根据机构id获取上次同步时间
  1058. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 2)
  1059. var sync_time int64
  1060. if syncLastInfo.ID > 0 {
  1061. sync_time = syncLastInfo.SyncTime
  1062. } else {
  1063. sync_time = 0
  1064. }
  1065. var tempDialysis []*sz.TempHdDialysis
  1066. dialysisData, _ := service.FindOrgDialysisData(org_id, sync_time, time.Now().Unix())
  1067. for _, item := range dialysisData {
  1068. psm := &sz.TempHdDialysis{
  1069. DialysisId: strconv.FormatInt(item.ID, 10),
  1070. HospitalId: hospital_id,
  1071. PatientNk: strconv.FormatInt(item.PatientId, 10),
  1072. PsId: strconv.FormatInt(item.Schedule.ID, 10),
  1073. DialysisDate: time.Unix(item.DialysisDate, 0),
  1074. SickbedNo: item.DeviceNumber.Number,
  1075. DivisionId: strconv.FormatInt(item.Schedule.PartitionId, 10),
  1076. EquipmentId: strconv.FormatInt(item.DeviceNumber.ID, 10),
  1077. MixDialysis: "0",
  1078. TotalTreatDuration: item.AssessmentAfterDislysis.ActualTreatmentHour*60 + item.AssessmentAfterDislysis.ActualTreatmentMinute,
  1079. IsHospitalization: "0",
  1080. IsEmergency: "0",
  1081. IsPerioperativePeriod: "0",
  1082. BeforeSbp: int64(item.AssessmentBeforeDislysis.SystolicBloodPressure),
  1083. BeforeDbp: int64(item.AssessmentBeforeDislysis.DiastolicBloodPressure),
  1084. AfterSbp: int64(item.AssessmentAfterDislysis.SystolicBloodPressure),
  1085. AfterDbp: int64(item.AssessmentAfterDislysis.DiastolicBloodPressure),
  1086. BeforeWeight: item.AssessmentBeforeDislysis.WeightBefore,
  1087. AfterWeight: item.AssessmentAfterDislysis.WeightAfter,
  1088. UpNurseId: strconv.FormatInt(item.StartNurse,10),
  1089. DownNurseId: strconv.FormatInt(item.FinishNurse,10),
  1090. CheckNurseId: strconv.FormatInt(item.FinishNurse,10),
  1091. PunctureNurseId: strconv.FormatInt(item.PunctureNurse,10),
  1092. StartTime: time.Unix(item.StartTime, 0),
  1093. EndTime: time.Unix(item.EndTime, 0),
  1094. CreateTime: time.Unix(item.CreatedTime, 0),
  1095. Sjscsj: time.Now(),
  1096. Xgbz: 0,
  1097. }
  1098. if item.AssessmentAfterDislysis.ActualUltrafiltration < 10 {
  1099. psm.ActualufMl = int64(item.AssessmentAfterDislysis.ActualUltrafiltration * 1000)
  1100. } else {
  1101. psm.ActualufMl = int64(item.AssessmentAfterDislysis.ActualUltrafiltration)
  1102. }
  1103. if item.VMDialysisPrescription.TargetUltrafiltration < 10 {
  1104. psm.Ufv = int64(item.VMDialysisPrescription.TargetUltrafiltration * 1000)
  1105. } else {
  1106. psm.Ufv = int64(item.VMDialysisPrescription.TargetUltrafiltration)
  1107. }
  1108. if item.AssessmentAfterDislysis.ActualDisplacement < 10 {
  1109. psm.TotalReplace = int64(item.AssessmentAfterDislysis.ActualDisplacement * 1000)
  1110. } else {
  1111. psm.TotalReplace = int64(item.AssessmentAfterDislysis.ActualDisplacement)
  1112. }
  1113. tempDialysis = append(tempDialysis, psm)
  1114. }
  1115. err := service.BatchCreateDialysis(tempDialysis, rdb)
  1116. if err == nil {
  1117. // 第三步:同步成功后,添加同步记录
  1118. upload := &sz.DataUpload{
  1119. SyncType: 2,
  1120. OrgId: org_id,
  1121. SyncTime: time.Now().Unix(),
  1122. SyncResultType: 1,
  1123. CreateTime: time.Now().Unix(),
  1124. UpdateTime: time.Now().Unix(),
  1125. }
  1126. err := service.CreateUploadRecord(upload)
  1127. if err != nil {
  1128. utils.ErrorLog("%v", err)
  1129. }
  1130. } else {
  1131. //错误处理
  1132. }
  1133. }
  1134. // 同步透析床位分区
  1135. func SyncDivision(rdb *gorm.DB, org_id int64, hospital_id string) {
  1136. // 第一步:根据机构id获取上次同步时间
  1137. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 55)
  1138. var sync_time int64
  1139. if syncLastInfo.ID > 0 {
  1140. sync_time = syncLastInfo.SyncTime
  1141. } else {
  1142. sync_time = 0
  1143. }
  1144. //同步透析床位分区
  1145. dm, _ := service.FindOrgDeviceZoneRecordData(org_id, sync_time, time.Now().Unix())
  1146. var hdms []*sz.TempHdDivision
  1147. for _, item := range dm {
  1148. hdm := &sz.TempHdDivision{
  1149. DivisionId: strconv.FormatInt(item.ID,10),
  1150. HospitalId: hospital_id,
  1151. DivisionName: item.Name,
  1152. DivisionType: strconv.FormatInt(item.Type,10),
  1153. CreateTime: time.Now(),
  1154. UpdateTime: time.Now(),
  1155. Sjscsj: time.Now(),
  1156. Xgbz: strconv.FormatInt(0, 10),
  1157. }
  1158. hdms = append(hdms, hdm)
  1159. }
  1160. err := service.CreateHDDivision(hdms, rdb)
  1161. if err == nil {
  1162. // 第三步:同步成功后,添加同步记录
  1163. upload := &sz.DataUpload{
  1164. SyncType: 55,
  1165. OrgId: org_id,
  1166. SyncTime: time.Now().Unix(),
  1167. SyncResultType: 1,
  1168. CreateTime: time.Now().Unix(),
  1169. UpdateTime: time.Now().Unix(),
  1170. }
  1171. err := service.CreateUploadRecord(upload)
  1172. if err != nil {
  1173. utils.ErrorLog("%v", err)
  1174. }
  1175. } else {
  1176. //错误处理
  1177. }
  1178. }
  1179. // 患者通路信息表
  1180. func SyncAccess(rdb *gorm.DB, org_id int64, hospital_id string) {
  1181. // 第一步:根据机构id获取上次同步时间
  1182. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 56)
  1183. var sync_time int64
  1184. if syncLastInfo.ID > 0 {
  1185. sync_time = syncLastInfo.SyncTime
  1186. } else {
  1187. sync_time = 0
  1188. }
  1189. //同步员工信息
  1190. patients, _ := service.FindOrgPatientData(org_id, sync_time, time.Now().Unix())
  1191. var accessList []*sz.TempHdAccess
  1192. for _, patient := range patients {
  1193. before,_ := service.FindAssessmentBeforeDislysis(org_id,patient.ID)
  1194. if before.ID > 0{
  1195. access := &sz.TempHdAccess{
  1196. AccessId : before.ID,
  1197. HospitalId: hospital_id,
  1198. PatientNk: strconv.FormatInt(before.PatientId, 10),
  1199. AccessType: 1,
  1200. AccessTypeName: "自体动静脉内瘘",
  1201. AccessStatus: 1,
  1202. SetupDate: time.Unix(patient.FirstDialysisDate, 0),
  1203. FirstUseTime: time.Unix(patient.FirstDialysisDate, 0),
  1204. CreateTime: time.Now(),
  1205. UpdateTime: time.Now(),
  1206. Sjscsj: time.Now(),
  1207. Xgbz: 0,
  1208. }
  1209. accessList = append(accessList,access)
  1210. }
  1211. }
  1212. if len(accessList) > 0 {
  1213. err := service.CreateAccess(accessList, rdb)
  1214. if err == nil {
  1215. // 第三步:同步成功后,添加同步记录
  1216. upload := &sz.DataUpload{
  1217. SyncType: 56,
  1218. OrgId: org_id,
  1219. SyncTime: time.Now().Unix(),
  1220. SyncResultType: 1,
  1221. CreateTime: time.Now().Unix(),
  1222. UpdateTime: time.Now().Unix(),
  1223. }
  1224. err := service.CreateUploadRecord(upload)
  1225. if err != nil {
  1226. utils.ErrorLog("%v", err)
  1227. }
  1228. } else {
  1229. //错误处理
  1230. }
  1231. }
  1232. }
  1233. // 透析床位表
  1234. func SyncSickbed(rdb *gorm.DB, org_id int64, hospital_id string) {
  1235. // 第一步:根据机构id获取上次同步时间
  1236. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 57)
  1237. var sync_time int64
  1238. if syncLastInfo.ID > 0 {
  1239. sync_time = syncLastInfo.SyncTime
  1240. } else {
  1241. sync_time = 0
  1242. }
  1243. //同步床位
  1244. devices, _ := service.FindOrgDeviceNumber(org_id, sync_time, time.Now().Unix())
  1245. var sickbedList []*sz.TempHdSickbed
  1246. for _, device := range devices {
  1247. sickbed := &sz.TempHdSickbed{
  1248. SickbedNo : device.ID,
  1249. HospitalId: hospital_id,
  1250. DivisionId: strconv.FormatInt(device.ZoneId,10),
  1251. SickbedCode: device.Number,
  1252. SickbedType: "0",
  1253. CreateTime: time.Now(),
  1254. UpdateTime: time.Now(),
  1255. Sjscsj: time.Now(),
  1256. Xgbz: 0,
  1257. }
  1258. sickbedList = append(sickbedList,sickbed)
  1259. }
  1260. if len(sickbedList) > 0 {
  1261. err := service.CreateSickbed(sickbedList, rdb)
  1262. if err == nil {
  1263. // 第三步:同步成功后,添加同步记录
  1264. upload := &sz.DataUpload{
  1265. SyncType: 57,
  1266. OrgId: org_id,
  1267. SyncTime: time.Now().Unix(),
  1268. SyncResultType: 1,
  1269. CreateTime: time.Now().Unix(),
  1270. UpdateTime: time.Now().Unix(),
  1271. }
  1272. err := service.CreateUploadRecord(upload)
  1273. if err != nil {
  1274. utils.ErrorLog("%v", err)
  1275. }
  1276. } else {
  1277. //错误处理
  1278. }
  1279. }
  1280. }
  1281. // 患者诊断信息表(T_HD_DIAGNOSIS)
  1282. func SyncDiagnosis(rdb *gorm.DB, org_id int64, hospital_id string) {
  1283. // 第一步:根据机构id获取上次同步时间
  1284. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 58)
  1285. var sync_time int64
  1286. if syncLastInfo.ID > 0 {
  1287. sync_time = syncLastInfo.SyncTime
  1288. } else {
  1289. sync_time = 0
  1290. }
  1291. //同步患者
  1292. patients, _ := service.FindOrgPatientData(org_id, sync_time, time.Now().Unix())
  1293. var diagnosisList []*sz.TempHdDiagnosis
  1294. for _, patient := range patients {
  1295. diagnosis := &sz.TempHdDiagnosis{
  1296. DiagnosisId : patient.ID,
  1297. HospitalId: hospital_id,
  1298. PatientNk: strconv.FormatInt(patient.ID, 10),
  1299. DiagnosisTime: time.Unix(patient.CreatedTime, 0),
  1300. DiagnosisType: "10",
  1301. DiagnosisTypeItem: "1001",
  1302. DiagnosisTypeDetail: "100113",
  1303. CreateTime: time.Now(),
  1304. UpdateTime: time.Now(),
  1305. Sjscsj: time.Now(),
  1306. Xgbz: 0,
  1307. }
  1308. diagnosisList = append(diagnosisList,diagnosis)
  1309. }
  1310. if len(diagnosisList) > 0 {
  1311. err := service.CreateDiagnosis(diagnosisList, rdb)
  1312. if err == nil {
  1313. // 第三步:同步成功后,添加同步记录
  1314. upload := &sz.DataUpload{
  1315. SyncType: 58,
  1316. OrgId: org_id,
  1317. SyncTime: time.Now().Unix(),
  1318. SyncResultType: 1,
  1319. CreateTime: time.Now().Unix(),
  1320. UpdateTime: time.Now().Unix(),
  1321. }
  1322. err := service.CreateUploadRecord(upload)
  1323. if err != nil {
  1324. utils.ErrorLog("%v", err)
  1325. }
  1326. } else {
  1327. //错误处理
  1328. }
  1329. }
  1330. }
  1331. // 患者传染病检查记录表(T_HD_INFECTION
  1332. func SyncInfection(rdb *gorm.DB, org_id int64, hospital_id string) {
  1333. // 第一步:根据机构id获取上次同步时间
  1334. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 59)
  1335. var sync_time int64
  1336. if syncLastInfo.ID > 0 {
  1337. sync_time = syncLastInfo.SyncTime
  1338. } else {
  1339. sync_time = 0
  1340. }
  1341. //同步患者
  1342. patients, _ := service.FindOrgPatientInfectious(org_id, sync_time, time.Now().Unix())
  1343. var infectionList []*sz.TempHdInfection
  1344. for _, patient := range patients {
  1345. if len(patient.InfectiousDiseases) > 0 {
  1346. infection := &sz.TempHdInfection{
  1347. Sn : strconv.FormatInt(patient.ID,10),
  1348. HospitalId: hospital_id,
  1349. PatientNk: strconv.FormatInt(patient.ID, 10),
  1350. Hbv: 0,
  1351. Hcv: 0,
  1352. Rpr: 0,
  1353. Hiv: 0,
  1354. Hbsag: 9,
  1355. Hbsab: 9,
  1356. Hbeag: 9,
  1357. Hbeab: 9,
  1358. Hbcab: 9,
  1359. CheckDate: time.Unix(patient.CreatedTime, 0),
  1360. DoctorId: strconv.FormatInt(patient.RegistrarsId,10),
  1361. CreateTime: time.Now(),
  1362. Sjscsj: time.Now(),
  1363. Xgbz: 0,
  1364. }
  1365. for _ , infectionDiseases := range patient.InfectiousDiseases{
  1366. if infectionDiseases.DiseaseId == 2 {
  1367. infection.Hbv = 1
  1368. }
  1369. if infectionDiseases.DiseaseId == 3 {
  1370. infection.Hcv = 1
  1371. }
  1372. if infectionDiseases.DiseaseId == 4 {
  1373. infection.Hiv = 1
  1374. }
  1375. if infectionDiseases.DiseaseId == 6 {
  1376. infection.Rpr = 1
  1377. }
  1378. }
  1379. infectionList = append(infectionList,infection)
  1380. }
  1381. }
  1382. if len(infectionList) > 0 {
  1383. err := service.CreateInfection(infectionList, rdb)
  1384. if err == nil {
  1385. // 第三步:同步成功后,添加同步记录
  1386. upload := &sz.DataUpload{
  1387. SyncType: 59,
  1388. OrgId: org_id,
  1389. SyncTime: time.Now().Unix(),
  1390. SyncResultType: 1,
  1391. CreateTime: time.Now().Unix(),
  1392. UpdateTime: time.Now().Unix(),
  1393. }
  1394. err := service.CreateUploadRecord(upload)
  1395. if err != nil {
  1396. utils.ErrorLog("%v", err)
  1397. }
  1398. } else {
  1399. //错误处理
  1400. }
  1401. }
  1402. }
  1403. // 透析并发症记录表(T_HD_COMPLICATION)
  1404. func SyncComplication(rdb *gorm.DB, org_id int64, hospital_id string) {
  1405. // 第一步:根据机构id获取上次同步时间
  1406. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 60)
  1407. var sync_time int64
  1408. if syncLastInfo.ID > 0 {
  1409. sync_time = syncLastInfo.SyncTime
  1410. } else {
  1411. sync_time = 0
  1412. }
  1413. //同步监测记录
  1414. var complicationList []*sz.TempHdComplication
  1415. monitors, _ := service.FindOrgMonitorRecordByLike(org_id,"%肌肉痉挛%", sync_time, time.Now().Unix())
  1416. for _, monitor := range monitors {
  1417. complication := &sz.TempHdComplication{
  1418. Sn : strconv.FormatInt(monitor.ID,10),
  1419. HospitalId : hospital_id,
  1420. PatientNk : strconv.FormatInt(monitor.PatientId, 10),
  1421. DialysisId : monitor.DialysisOrderId,
  1422. MonitorId : monitor.ID,
  1423. NeopathyTime: 1,
  1424. NeopathyType: "3",
  1425. NeopathyDesc: monitor.Symptom,
  1426. CreateTime: time.Unix(monitor.CreatedTime, 0),
  1427. Sjscsj: time.Now(),
  1428. Xgbz: 0,
  1429. }
  1430. complicationList = append(complicationList,complication)
  1431. }
  1432. monitorones, _ := service.FindOrgMonitorRecordByLike(org_id,"%胸痛%", sync_time, time.Now().Unix())
  1433. for _, monitor := range monitorones {
  1434. complicationone := &sz.TempHdComplication{
  1435. Sn : strconv.FormatInt(monitor.ID,10),
  1436. HospitalId : hospital_id,
  1437. PatientNk : strconv.FormatInt(monitor.PatientId, 10),
  1438. DialysisId : monitor.DialysisOrderId,
  1439. MonitorId : monitor.ID,
  1440. NeopathyTime: 1,
  1441. NeopathyType: "6",
  1442. NeopathyDesc: monitor.Symptom,
  1443. CreateTime: time.Unix(monitor.CreatedTime, 0),
  1444. Sjscsj: time.Now(),
  1445. Xgbz: 0,
  1446. }
  1447. complicationList = append(complicationList,complicationone)
  1448. }
  1449. monitortwos, _ := service.FindOrgMonitorRecordByLike(org_id,"%恶心%", sync_time, time.Now().Unix())
  1450. for _, monitor := range monitortwos {
  1451. complicationtwo := &sz.TempHdComplication{
  1452. Sn : strconv.FormatInt(monitor.ID,10),
  1453. HospitalId : hospital_id,
  1454. PatientNk : strconv.FormatInt(monitor.PatientId, 10),
  1455. DialysisId : monitor.DialysisOrderId,
  1456. MonitorId : monitor.ID,
  1457. NeopathyTime: 1,
  1458. NeopathyType: "7",
  1459. NeopathyDesc: monitor.Symptom,
  1460. CreateTime: time.Unix(monitor.CreatedTime, 0),
  1461. Sjscsj: time.Now(),
  1462. Xgbz: 0,
  1463. }
  1464. complicationList = append(complicationList,complicationtwo)
  1465. }
  1466. monitorfours, _ := service.FindOrgMonitorRecordByLike(org_id,"%头痛%", sync_time, time.Now().Unix())
  1467. for _, monitor := range monitorfours {
  1468. complicationfour := &sz.TempHdComplication{
  1469. Sn : strconv.FormatInt(monitor.ID,10),
  1470. HospitalId : hospital_id,
  1471. PatientNk : strconv.FormatInt(monitor.PatientId, 10),
  1472. DialysisId : monitor.DialysisOrderId,
  1473. MonitorId : monitor.ID,
  1474. NeopathyTime: 1,
  1475. NeopathyType: "11",
  1476. NeopathyDesc: monitor.Symptom,
  1477. CreateTime: time.Unix(monitor.CreatedTime, 0),
  1478. Sjscsj: time.Now(),
  1479. Xgbz: 0,
  1480. }
  1481. complicationList = append(complicationList,complicationfour)
  1482. }
  1483. monitorthrees, _ := service.FindOrgMonitorRecordByLike(org_id,"%发热%", sync_time, time.Now().Unix())
  1484. for _, monitor := range monitorthrees {
  1485. complicationthree := &sz.TempHdComplication{
  1486. Sn : strconv.FormatInt(monitor.ID,10),
  1487. HospitalId : hospital_id,
  1488. PatientNk : strconv.FormatInt(monitor.PatientId, 10),
  1489. DialysisId : monitor.DialysisOrderId,
  1490. MonitorId : monitor.ID,
  1491. NeopathyTime: 1,
  1492. NeopathyType: "15",
  1493. NeopathyDesc: monitor.Symptom,
  1494. CreateTime: time.Unix(monitor.CreatedTime, 0),
  1495. Sjscsj: time.Now(),
  1496. Xgbz: 0,
  1497. }
  1498. complicationList = append(complicationList,complicationthree)
  1499. }
  1500. if len(complicationList) > 0 {
  1501. err := service.CreateComplication(complicationList, rdb)
  1502. if err == nil {
  1503. // 第三步:同步成功后,添加同步记录
  1504. upload := &sz.DataUpload{
  1505. SyncType: 60,
  1506. OrgId: org_id,
  1507. SyncTime: time.Now().Unix(),
  1508. SyncResultType: 1,
  1509. CreateTime: time.Now().Unix(),
  1510. UpdateTime: time.Now().Unix(),
  1511. }
  1512. err := service.CreateUploadRecord(upload)
  1513. if err != nil {
  1514. utils.ErrorLog("%v", err)
  1515. }
  1516. } else {
  1517. //错误处理
  1518. }
  1519. }
  1520. }
  1521. // 血透患者检测结果表(T_HD_LIS_REPORT)
  1522. func SyncLisReport(rdb *gorm.DB, org_id int64, hospital_id string) {
  1523. // 第一步:根据机构id获取上次同步时间
  1524. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 61)
  1525. var sync_time int64
  1526. if syncLastInfo.ID > 0 {
  1527. sync_time = syncLastInfo.SyncTime
  1528. } else {
  1529. sync_time = 0
  1530. }
  1531. //同步监测记录
  1532. inspections, _ := service.FindOrgInspection(org_id, sync_time, time.Now().Unix())
  1533. var lisReportList []*sz.TempHdLisReport
  1534. tempFlag := 1
  1535. for _, inspection := range inspections {
  1536. tempFlag = 1
  1537. fmt.Println("1")
  1538. for _,tempReport := range lisReportList {
  1539. // fmt.Println("2")
  1540. if tempReport.ReportDate == time.Unix(inspection.InspectDate,0) && tempReport.ApplicationType == strconv.FormatInt(inspection.ProjectId,10) && tempReport.PatientNk == strconv.FormatInt(inspection.PatientId,10) {
  1541. tempFlag = 0
  1542. break
  1543. } else {
  1544. continue
  1545. }
  1546. }
  1547. fmt.Println("3")
  1548. if tempFlag == 1 {
  1549. lisReport := &sz.TempHdLisReport{
  1550. LabSno : strconv.FormatInt(inspection.InspectType,10) + strconv.FormatInt(inspection.ProjectId,10),
  1551. HospitalId : hospital_id,
  1552. PatientNk : strconv.FormatInt(inspection.PatientId, 10),
  1553. ReportDate : time.Unix(inspection.InspectDate, 0),
  1554. CheckDate : "1",
  1555. JzNo : inspection.Patients.AdmissionNumber,
  1556. MzFlag : "1",
  1557. ZyNo : "-",
  1558. MzNo : inspection.Patients.AdmissionNumber,
  1559. DepartmentCode : "10035",
  1560. DepartmentName : "血透中心",
  1561. CardNo : inspection.Patients.IdCardNo,
  1562. CardType : "9",
  1563. PatientName : inspection.Patients.Name,
  1564. DepCode : "A03.05",
  1565. DepName : "血透中心",
  1566. InspectedType : "1",
  1567. ReportCategry : inspection.ProjectName,
  1568. ApplicationName : inspection.ProjectName,
  1569. ApplicationType : strconv.FormatInt(inspection.ProjectId,10),
  1570. CheckName : inspection.ProjectName,
  1571. CheckItemName : inspection.ItemName,
  1572. CheckItemCode : strconv.FormatInt(inspection.ItemId,10),
  1573. RecordCcount : 0,
  1574. CheckResult : inspection.InspectValue,
  1575. DiagnoseName : "-",
  1576. CreateTime : time.Unix(inspection.CreatedTime, 0),
  1577. Sjscsj: time.Now(),
  1578. Xgbz: 0,
  1579. }
  1580. lisReportList = append(lisReportList,lisReport)
  1581. } else {
  1582. continue
  1583. }
  1584. }
  1585. if len(lisReportList) > 0 {
  1586. err := service.CreateLisReport(lisReportList, rdb)
  1587. if err == nil {
  1588. // 第三步:同步成功后,添加同步记录
  1589. upload := &sz.DataUpload{
  1590. SyncType: 61,
  1591. OrgId: org_id,
  1592. SyncTime: time.Now().Unix(),
  1593. SyncResultType: 1,
  1594. CreateTime: time.Now().Unix(),
  1595. UpdateTime: time.Now().Unix(),
  1596. }
  1597. err := service.CreateUploadRecord(upload)
  1598. if err != nil {
  1599. utils.ErrorLog("%v", err)
  1600. }
  1601. } else {
  1602. //错误处理
  1603. }
  1604. }
  1605. }
  1606. // 血透患者检验结果指标表(T_HD_LIS_INDICATORS)
  1607. func SyncLisIndicators(rdb *gorm.DB, org_id int64, hospital_id string) {
  1608. // 第一步:根据机构id获取上次同步时间
  1609. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 62)
  1610. var sync_time int64
  1611. if syncLastInfo.ID > 0 {
  1612. sync_time = syncLastInfo.SyncTime
  1613. } else {
  1614. sync_time = 0
  1615. }
  1616. //同步监测记录
  1617. inspections , _ := service.FindOrgInspectionReference(org_id, sync_time, time.Now().Unix())
  1618. var lisIndicatorsList []*sz.TempHdLisIndicators
  1619. for _, inspection := range inspections {
  1620. lisIndicators := &sz.TempHdLisIndicators{
  1621. InspectedResultNo : strconv.FormatInt(inspection.ID,10),
  1622. HospitalId : hospital_id,
  1623. LabSno : strconv.FormatInt(inspection.InspectType,10) + strconv.FormatInt(inspection.ProjectId,10),
  1624. ReportDate : time.Unix(inspection.InspectDate, 0),
  1625. CheckDate : time.Unix(inspection.InspectDate, 0),
  1626. InspectedIndicate : inspection.ProjectName,
  1627. InspectedItemEnName : strconv.FormatInt(inspection.ItemId,10),
  1628. InspectedItemCnName : inspection.ItemName,
  1629. InspectedResultDesc : inspection.InspectValue,
  1630. InspectedResultValue : inspection.InspectValue,
  1631. InspectedResultUnit : inspection.XtInspectionReference.Unit,
  1632. RefRange : "-",
  1633. UnitType : inspection.XtInspectionReference.Unit,
  1634. InspectedResult : 5,
  1635. CreateTime : time.Unix(inspection.CreatedTime, 0),
  1636. Sjscsj: time.Now(),
  1637. Xgbz: 0,
  1638. }
  1639. if len(inspection.XtInspectionReference.Unit) == 0 {
  1640. lisIndicators.InspectedResultUnit = "-"
  1641. lisIndicators.UnitType = "-"
  1642. }
  1643. if inspection.XtInspectionReference.RangeType ==1 {
  1644. lisIndicators.RefRange = inspection.XtInspectionReference.RangeMin + "-" + inspection.XtInspectionReference.RangeMax
  1645. } else {
  1646. if len(inspection.XtInspectionReference.RangeOptions) == 0 {
  1647. lisIndicators.RefRange = "-"
  1648. } else {
  1649. lisIndicators.RefRange = inspection.XtInspectionReference.RangeOptions
  1650. }
  1651. }
  1652. lisIndicatorsList = append(lisIndicatorsList,lisIndicators)
  1653. }
  1654. if len(lisIndicatorsList) > 0 {
  1655. err := service.CreateLisIndicators(lisIndicatorsList, rdb)
  1656. if err == nil {
  1657. // 第三步:同步成功后,添加同步记录
  1658. upload := &sz.DataUpload{
  1659. SyncType: 62,
  1660. OrgId: org_id,
  1661. SyncTime: time.Now().Unix(),
  1662. SyncResultType: 1,
  1663. CreateTime: time.Now().Unix(),
  1664. UpdateTime: time.Now().Unix(),
  1665. }
  1666. err := service.CreateUploadRecord(upload)
  1667. if err != nil {
  1668. utils.ErrorLog("%v", err)
  1669. }
  1670. } else {
  1671. //错误处理
  1672. }
  1673. }
  1674. }