auto_create_week_schedules_service.go 54KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913
  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.FindOrgPatientDataOne(org_id)
  1343. var infectionList []*sz.TempHdInfection
  1344. for _, patient := range patients {
  1345. // 查询有没有做传染病检查并返回检验检查时间
  1346. inspections, _ := service.FindOrgInspectionGroupOne(org_id, sync_time, time.Now().Unix(),patient.ID)
  1347. if len(inspections) > 0 {
  1348. for _, insp := range inspections {
  1349. inspection_arr ,_:= service.FindOrgInspectionGroupTwo(org_id,insp.InspectDate,patient.ID)
  1350. if len(inspection_arr) > 0 {
  1351. infection := &sz.TempHdInfection{
  1352. Sn : strconv.FormatInt(patient.ID,10),
  1353. HospitalId: hospital_id,
  1354. PatientNk: strconv.FormatInt(patient.ID, 10),
  1355. Hbv: 0,
  1356. Hcv: 0,
  1357. Rpr: 0,
  1358. Hiv: 0,
  1359. Hbsag: 9,
  1360. Hbsab: 9,
  1361. Hbeag: 9,
  1362. Hbeab: 9,
  1363. Hbcab: 9,
  1364. CheckDate: time.Unix(patient.CreatedTime, 0),
  1365. DoctorId: strconv.FormatInt(patient.RegistrarsId,10),
  1366. CreateTime: time.Now(),
  1367. Sjscsj: time.Now(),
  1368. Xgbz: 0,
  1369. }
  1370. for _ , infectionDiseases := range inspection_arr{
  1371. if infectionDiseases.ItemId == 60 {
  1372. infection.Hcv = 0
  1373. if infectionDiseases.InspectValue == "阳性" {
  1374. infection.Hcv = 1
  1375. }
  1376. }
  1377. if infectionDiseases.ItemId == 62 {
  1378. infection.Hbsag = 0
  1379. if infectionDiseases.InspectValue == "阳性" {
  1380. infection.Hbsag = 1
  1381. }
  1382. }
  1383. if infectionDiseases.ItemId == 63 {
  1384. infection.Hbsab = 0
  1385. if infectionDiseases.InspectValue == "阳性" {
  1386. infection.Hbsab = 1
  1387. }
  1388. }
  1389. if infectionDiseases.ItemId == 64 {
  1390. infection.Hbeag = 0
  1391. if infectionDiseases.InspectValue == "阳性" {
  1392. infection.Hbeag = 1
  1393. }
  1394. }
  1395. if infectionDiseases.ItemId == 65 {
  1396. infection.Hbeab = 0
  1397. if infectionDiseases.InspectValue == "阳性" {
  1398. infection.Hbeab = 1
  1399. }
  1400. }
  1401. if infectionDiseases.ItemId == 66 {
  1402. infection.Hbcab = 0
  1403. if infectionDiseases.InspectValue == "阳性" {
  1404. infection.Hbcab = 1
  1405. }
  1406. }
  1407. if infectionDiseases.ItemId == 111 {
  1408. infection.Hiv = 0
  1409. if infectionDiseases.InspectValue == "阳性" {
  1410. infection.Hiv = 1
  1411. }
  1412. }
  1413. if infectionDiseases.ItemId == 112 {
  1414. infection.Rpr = 0
  1415. if infectionDiseases.InspectValue == "阳性" {
  1416. infection.Rpr = 1
  1417. }
  1418. }
  1419. if infectionDiseases.ItemId == 178 {
  1420. infection.Hbv = 0
  1421. if infectionDiseases.InspectValue == "阳性" {
  1422. infection.Hbv = 1
  1423. }
  1424. }
  1425. if infectionDiseases.ItemId == 179 {
  1426. infection.Hcv = 0
  1427. if infectionDiseases.InspectValue == "阳性" {
  1428. infection.Hcv = 1
  1429. }
  1430. }
  1431. }
  1432. infectionList = append(infectionList,infection)
  1433. }
  1434. }
  1435. }
  1436. }
  1437. if len(infectionList) > 0 {
  1438. err := service.CreateInfection(infectionList, rdb)
  1439. if err == nil {
  1440. // 第三步:同步成功后,添加同步记录
  1441. upload := &sz.DataUpload{
  1442. SyncType: 59,
  1443. OrgId: org_id,
  1444. SyncTime: time.Now().Unix(),
  1445. SyncResultType: 1,
  1446. CreateTime: time.Now().Unix(),
  1447. UpdateTime: time.Now().Unix(),
  1448. }
  1449. err := service.CreateUploadRecord(upload)
  1450. if err != nil {
  1451. utils.ErrorLog("%v", err)
  1452. }
  1453. } else {
  1454. //错误处理
  1455. }
  1456. }
  1457. }
  1458. // 透析并发症记录表(T_HD_COMPLICATION)
  1459. func SyncComplication(rdb *gorm.DB, org_id int64, hospital_id string) {
  1460. // 第一步:根据机构id获取上次同步时间
  1461. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 60)
  1462. var sync_time int64
  1463. if syncLastInfo.ID > 0 {
  1464. sync_time = syncLastInfo.SyncTime
  1465. } else {
  1466. sync_time = 0
  1467. }
  1468. //同步监测记录
  1469. var complicationList []*sz.TempHdComplication
  1470. monitors, _ := service.FindOrgMonitorRecordByLike(org_id,"%肌肉痉挛%", sync_time, time.Now().Unix())
  1471. for _, monitor := range monitors {
  1472. complication := &sz.TempHdComplication{
  1473. Sn : strconv.FormatInt(monitor.ID,10),
  1474. HospitalId : hospital_id,
  1475. PatientNk : strconv.FormatInt(monitor.PatientId, 10),
  1476. DialysisId : monitor.DialysisOrderId,
  1477. MonitorId : monitor.ID,
  1478. NeopathyTime: 1,
  1479. NeopathyType: "3",
  1480. NeopathyDesc: monitor.Symptom,
  1481. CreateTime: time.Unix(monitor.CreatedTime, 0),
  1482. Sjscsj: time.Now(),
  1483. Xgbz: 0,
  1484. }
  1485. complicationList = append(complicationList,complication)
  1486. }
  1487. monitorones, _ := service.FindOrgMonitorRecordByLike(org_id,"%胸痛%", sync_time, time.Now().Unix())
  1488. for _, monitor := range monitorones {
  1489. complicationone := &sz.TempHdComplication{
  1490. Sn : strconv.FormatInt(monitor.ID,10),
  1491. HospitalId : hospital_id,
  1492. PatientNk : strconv.FormatInt(monitor.PatientId, 10),
  1493. DialysisId : monitor.DialysisOrderId,
  1494. MonitorId : monitor.ID,
  1495. NeopathyTime: 1,
  1496. NeopathyType: "6",
  1497. NeopathyDesc: monitor.Symptom,
  1498. CreateTime: time.Unix(monitor.CreatedTime, 0),
  1499. Sjscsj: time.Now(),
  1500. Xgbz: 0,
  1501. }
  1502. complicationList = append(complicationList,complicationone)
  1503. }
  1504. monitortwos, _ := service.FindOrgMonitorRecordByLike(org_id,"%恶心%", sync_time, time.Now().Unix())
  1505. for _, monitor := range monitortwos {
  1506. complicationtwo := &sz.TempHdComplication{
  1507. Sn : strconv.FormatInt(monitor.ID,10),
  1508. HospitalId : hospital_id,
  1509. PatientNk : strconv.FormatInt(monitor.PatientId, 10),
  1510. DialysisId : monitor.DialysisOrderId,
  1511. MonitorId : monitor.ID,
  1512. NeopathyTime: 1,
  1513. NeopathyType: "7",
  1514. NeopathyDesc: monitor.Symptom,
  1515. CreateTime: time.Unix(monitor.CreatedTime, 0),
  1516. Sjscsj: time.Now(),
  1517. Xgbz: 0,
  1518. }
  1519. complicationList = append(complicationList,complicationtwo)
  1520. }
  1521. monitorfours, _ := service.FindOrgMonitorRecordByLike(org_id,"%头痛%", sync_time, time.Now().Unix())
  1522. for _, monitor := range monitorfours {
  1523. complicationfour := &sz.TempHdComplication{
  1524. Sn : strconv.FormatInt(monitor.ID,10),
  1525. HospitalId : hospital_id,
  1526. PatientNk : strconv.FormatInt(monitor.PatientId, 10),
  1527. DialysisId : monitor.DialysisOrderId,
  1528. MonitorId : monitor.ID,
  1529. NeopathyTime: 1,
  1530. NeopathyType: "11",
  1531. NeopathyDesc: monitor.Symptom,
  1532. CreateTime: time.Unix(monitor.CreatedTime, 0),
  1533. Sjscsj: time.Now(),
  1534. Xgbz: 0,
  1535. }
  1536. complicationList = append(complicationList,complicationfour)
  1537. }
  1538. monitorthrees, _ := service.FindOrgMonitorRecordByLike(org_id,"%发热%", sync_time, time.Now().Unix())
  1539. for _, monitor := range monitorthrees {
  1540. complicationthree := &sz.TempHdComplication{
  1541. Sn : strconv.FormatInt(monitor.ID,10),
  1542. HospitalId : hospital_id,
  1543. PatientNk : strconv.FormatInt(monitor.PatientId, 10),
  1544. DialysisId : monitor.DialysisOrderId,
  1545. MonitorId : monitor.ID,
  1546. NeopathyTime: 1,
  1547. NeopathyType: "15",
  1548. NeopathyDesc: monitor.Symptom,
  1549. CreateTime: time.Unix(monitor.CreatedTime, 0),
  1550. Sjscsj: time.Now(),
  1551. Xgbz: 0,
  1552. }
  1553. complicationList = append(complicationList,complicationthree)
  1554. }
  1555. if len(complicationList) > 0 {
  1556. err := service.CreateComplication(complicationList, rdb)
  1557. if err == nil {
  1558. // 第三步:同步成功后,添加同步记录
  1559. upload := &sz.DataUpload{
  1560. SyncType: 60,
  1561. OrgId: org_id,
  1562. SyncTime: time.Now().Unix(),
  1563. SyncResultType: 1,
  1564. CreateTime: time.Now().Unix(),
  1565. UpdateTime: time.Now().Unix(),
  1566. }
  1567. err := service.CreateUploadRecord(upload)
  1568. if err != nil {
  1569. utils.ErrorLog("%v", err)
  1570. }
  1571. } else {
  1572. //错误处理
  1573. }
  1574. }
  1575. }
  1576. // 血透患者检测结果表(T_HD_LIS_REPORT)
  1577. func SyncLisReport(rdb *gorm.DB, org_id int64, hospital_id string) {
  1578. // 第一步:根据机构id获取上次同步时间
  1579. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 61)
  1580. var sync_time int64
  1581. if syncLastInfo.ID > 0 {
  1582. sync_time = syncLastInfo.SyncTime
  1583. } else {
  1584. sync_time = 0
  1585. }
  1586. //同步监测记录
  1587. inspections, _ := service.FindOrgInspection(org_id, sync_time, time.Now().Unix())
  1588. var lisReportList []*sz.TempHdLisReport
  1589. tempFlag := 1
  1590. for _, inspection := range inspections {
  1591. tempFlag = 1
  1592. fmt.Println("1")
  1593. for _,tempReport := range lisReportList {
  1594. // fmt.Println("2")
  1595. if tempReport.ReportDate == time.Unix(inspection.InspectDate,0) && tempReport.ApplicationType == strconv.FormatInt(inspection.ProjectId,10) && tempReport.PatientNk == strconv.FormatInt(inspection.PatientId,10) {
  1596. tempFlag = 0
  1597. break
  1598. } else {
  1599. continue
  1600. }
  1601. }
  1602. fmt.Println("3")
  1603. if tempFlag == 1 {
  1604. lisReport := &sz.TempHdLisReport{
  1605. LabSno : strconv.FormatInt(inspection.InspectType,10) + strconv.FormatInt(inspection.ProjectId,10),
  1606. HospitalId : hospital_id,
  1607. PatientNk : strconv.FormatInt(inspection.PatientId, 10),
  1608. ReportDate : time.Unix(inspection.InspectDate, 0),
  1609. CheckDate : "1",
  1610. JzNo : inspection.Patients.AdmissionNumber,
  1611. MzFlag : "1",
  1612. ZyNo : "-",
  1613. MzNo : inspection.Patients.AdmissionNumber,
  1614. DepartmentCode : "10035",
  1615. DepartmentName : "血透中心",
  1616. CardNo : inspection.Patients.IdCardNo,
  1617. CardType : "9",
  1618. PatientName : inspection.Patients.Name,
  1619. DepCode : "A03.05",
  1620. DepName : "血透中心",
  1621. InspectedType : "1",
  1622. ReportCategry : inspection.ProjectName,
  1623. ApplicationName : inspection.ProjectName,
  1624. ApplicationType : strconv.FormatInt(inspection.ProjectId,10),
  1625. CheckName : inspection.ProjectName,
  1626. CheckItemName : inspection.ItemName,
  1627. CheckItemCode : strconv.FormatInt(inspection.ItemId,10),
  1628. RecordCcount : 0,
  1629. CheckResult : inspection.InspectValue,
  1630. DiagnoseName : "-",
  1631. CreateTime : time.Unix(inspection.CreatedTime, 0),
  1632. Sjscsj: time.Now(),
  1633. Xgbz: 0,
  1634. }
  1635. lisReportList = append(lisReportList,lisReport)
  1636. } else {
  1637. continue
  1638. }
  1639. }
  1640. if len(lisReportList) > 0 {
  1641. err := service.CreateLisReport(lisReportList, rdb)
  1642. if err == nil {
  1643. // 第三步:同步成功后,添加同步记录
  1644. upload := &sz.DataUpload{
  1645. SyncType: 61,
  1646. OrgId: org_id,
  1647. SyncTime: time.Now().Unix(),
  1648. SyncResultType: 1,
  1649. CreateTime: time.Now().Unix(),
  1650. UpdateTime: time.Now().Unix(),
  1651. }
  1652. err := service.CreateUploadRecord(upload)
  1653. if err != nil {
  1654. utils.ErrorLog("%v", err)
  1655. }
  1656. } else {
  1657. //错误处理
  1658. }
  1659. }
  1660. }
  1661. // 血透患者检验结果指标表(T_HD_LIS_INDICATORS)
  1662. func SyncLisIndicators(rdb *gorm.DB, org_id int64, hospital_id string) {
  1663. // 第一步:根据机构id获取上次同步时间
  1664. syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 62)
  1665. var sync_time int64
  1666. if syncLastInfo.ID > 0 {
  1667. sync_time = syncLastInfo.SyncTime
  1668. } else {
  1669. sync_time = 0
  1670. }
  1671. //同步监测记录
  1672. inspections , _ := service.FindOrgInspectionReference(org_id, sync_time, time.Now().Unix())
  1673. var lisIndicatorsList []*sz.TempHdLisIndicators
  1674. for _, inspection := range inspections {
  1675. lisIndicators := &sz.TempHdLisIndicators{
  1676. InspectedResultNo : strconv.FormatInt(inspection.ID,10),
  1677. HospitalId : hospital_id,
  1678. LabSno : strconv.FormatInt(inspection.InspectType,10) + strconv.FormatInt(inspection.ProjectId,10),
  1679. ReportDate : time.Unix(inspection.InspectDate, 0),
  1680. CheckDate : time.Unix(inspection.InspectDate, 0),
  1681. InspectedIndicate : inspection.ProjectName,
  1682. InspectedItemEnName : strconv.FormatInt(inspection.ItemId,10),
  1683. InspectedItemCnName : inspection.ItemName,
  1684. InspectedResultDesc : inspection.InspectValue,
  1685. InspectedResultValue : inspection.InspectValue,
  1686. InspectedResultUnit : inspection.XtInspectionReference.Unit,
  1687. RefRange : "-",
  1688. UnitType : inspection.XtInspectionReference.Unit,
  1689. InspectedResult : 5,
  1690. CreateTime : time.Unix(inspection.CreatedTime, 0),
  1691. Sjscsj: time.Now(),
  1692. Xgbz: 0,
  1693. }
  1694. if len(inspection.XtInspectionReference.Unit) == 0 {
  1695. lisIndicators.InspectedResultUnit = "-"
  1696. lisIndicators.UnitType = "-"
  1697. }
  1698. if inspection.XtInspectionReference.RangeType ==1 {
  1699. lisIndicators.RefRange = inspection.XtInspectionReference.RangeMin + "-" + inspection.XtInspectionReference.RangeMax
  1700. } else {
  1701. if len(inspection.XtInspectionReference.RangeOptions) == 0 {
  1702. lisIndicators.RefRange = "-"
  1703. } else {
  1704. lisIndicators.RefRange = inspection.XtInspectionReference.RangeOptions
  1705. }
  1706. }
  1707. lisIndicatorsList = append(lisIndicatorsList,lisIndicators)
  1708. }
  1709. if len(lisIndicatorsList) > 0 {
  1710. err := service.CreateLisIndicators(lisIndicatorsList, rdb)
  1711. if err == nil {
  1712. // 第三步:同步成功后,添加同步记录
  1713. upload := &sz.DataUpload{
  1714. SyncType: 62,
  1715. OrgId: org_id,
  1716. SyncTime: time.Now().Unix(),
  1717. SyncResultType: 1,
  1718. CreateTime: time.Now().Unix(),
  1719. UpdateTime: time.Now().Unix(),
  1720. }
  1721. err := service.CreateUploadRecord(upload)
  1722. if err != nil {
  1723. utils.ErrorLog("%v", err)
  1724. }
  1725. } else {
  1726. //错误处理
  1727. }
  1728. }
  1729. }