auto_create_week_schedules_service.go 40KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255
  1. package city
  2. //
  3. //import (
  4. // "Data_Upload_Api/models/sz"
  5. // "Data_Upload_Api/service"
  6. // "XT/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. //
  17. //var createUploadDataCronJob *cron.Cron
  18. //
  19. //func init() {
  20. // utils.InfoLog("开启定时任务")
  21. // createUploadDataCronJob = cron.New()
  22. // spec := "0 0 0 * * ?" // 每天凌晨0点检测数据上报情况
  23. // createUploadDataCronJob.AddFunc(spec, func() {
  24. // AutoSZUploadData() //深圳市数据上报
  25. //
  26. // })
  27. //}
  28. //
  29. //func BeginAutoJob() {
  30. // createUploadDataCronJob.Start()
  31. //}
  32. //
  33. ////func AutoSZUploadData() {
  34. //// //查出所有需要上传到深圳市健康数据中心的机构数据上报配置
  35. //// //这里暂时用上报到深圳市的方式,来处理数据,如果以后有其他城市,需要在这里对不同城市进行不同数据处理
  36. //// sz_province, _ := beego.AppConfig.Int64("sz_province")
  37. //// sz_city, _ := beego.AppConfig.Int64("sz_city")
  38. //// configs, _ := service.FindAllDataUploadConfigOrgInfo(sz_province, sz_city, 3)
  39. //// for _, config := range configs {
  40. ////
  41. //// //机构
  42. //// _, err := service.FindDataUploadOrgInfo(config.OrgId, 1)
  43. //// if err == gorm.ErrRecordNotFound {
  44. //// if GetDiffDay(config) <= 0 {
  45. ////
  46. //// //新增
  47. //// org, _ := service.FindOrgData(config.OrgId)
  48. //// hospital := &sz.TempHdHospital{
  49. //// HospitalId: strconv.FormatInt(org.ID, 10),
  50. //// InstType: strconv.FormatInt(1, 10),
  51. //// AuthorizedBeds: int64(len(org.DeviceNumber)),
  52. //// CreateTime: time.Now(),
  53. //// UpdateTime: time.Now(),
  54. //// Sjscsj: time.Now(),
  55. //// Xgbz: 0,
  56. //// }
  57. //// err := service.CreateOrgRecord(hospital)
  58. //// if err == nil {
  59. //// upload := &sz.DataUpload{
  60. //// ModuleType: 1,
  61. //// OrgId: org.ID,
  62. //// UploadDate: time.Now().Unix(),
  63. //// UploadStatus: 1,
  64. //// UploadType: 1,
  65. //// }
  66. //// err := service.CreateUploadRecord(upload)
  67. //// if err != nil {
  68. //// utils.ErrorLog("%v", err)
  69. ////
  70. //// }
  71. //// }
  72. //// }
  73. //// }
  74. ////
  75. //// //机构人员
  76. //// record, err_two := service.FindDataUploadOrgInfo(config.OrgId, 2)
  77. //// if err_two == gorm.ErrRecordNotFound {
  78. //// if GetDiffDay(config) <= 0 {
  79. ////
  80. //// var staffs []*sz.TempHdStaff
  81. //// roles, _ := service.FindOrgRolesData(config.OrgId, 0, 0)
  82. //// for _, role := range roles {
  83. //// var title string
  84. //// switch role.UserType {
  85. //// case 2:
  86. //// title = strconv.FormatInt(1, 10)
  87. //// break
  88. //// case 3:
  89. //// title = strconv.FormatInt(2, 10)
  90. //// break
  91. //// }
  92. ////
  93. //// staff := &sz.TempHdStaff{
  94. //// HospitalId: strconv.FormatInt(role.OrgId, 10),
  95. //// StaffId: strconv.FormatInt(role.ID, 10),
  96. //// StaffName: role.UserName,
  97. //// Position: title,
  98. //// PermanentType: strconv.FormatInt(1, 10),
  99. //// CreateTime: time.Now(),
  100. //// UpdateTime: time.Now(),
  101. //// Sjscsj: time.Now(),
  102. //// Xgbz: strconv.FormatInt(0, 10),
  103. //// }
  104. //// staffs = append(staffs, staff)
  105. //// }
  106. ////
  107. //// err := service.BatchCreateStaffRecord(staffs, r)
  108. //// if err == nil {
  109. //// upload := &sz.DataUpload{
  110. //// ModuleType: 2,
  111. //// OrgId: config.OrgId,
  112. //// UploadDate: time.Now().Unix(),
  113. //// UploadStatus: 1,
  114. //// UploadType: 1,
  115. //// }
  116. //// err := service.CreateUploadRecord(upload)
  117. //// if err != nil {
  118. //// utils.ErrorLog("%v", err)
  119. ////
  120. //// }
  121. //// }
  122. //// }
  123. ////
  124. //// } else if err_two == nil {
  125. //// if GetDiffDay2(config, record) <= 0 {
  126. //// var staffs []*sz.TempHdStaff
  127. //// roles, _ := service.FindOrgRolesData(record.OrgId, record.UploadDate, time.Now().Unix())
  128. //// for _, role := range roles {
  129. //// var title string
  130. //// switch role.UserType {
  131. //// case 2:
  132. //// title = strconv.FormatInt(1, 10)
  133. //// break
  134. //// case 3:
  135. //// title = strconv.FormatInt(2, 10)
  136. //// break
  137. //// }
  138. ////
  139. //// staff := &sz.TempHdStaff{
  140. //// HospitalId: strconv.FormatInt(role.OrgId, 10),
  141. //// StaffId: strconv.FormatInt(role.ID, 10),
  142. //// StaffName: role.UserName,
  143. //// Position: title,
  144. //// PermanentType: strconv.FormatInt(1, 10),
  145. //// CreateTime: time.Now(),
  146. //// UpdateTime: time.Now(),
  147. //// Sjscsj: time.Now(),
  148. //// Xgbz: strconv.FormatInt(0, 10),
  149. //// }
  150. //// staffs = append(staffs, staff)
  151. //// }
  152. ////
  153. //// err := service.BatchCreateStaffRecord(staffs)
  154. //// if err == nil {
  155. //// upload := &sz.DataUpload{
  156. //// ModuleType: 2,
  157. //// OrgId: record.OrgId,
  158. //// UploadDate: time.Now().Unix(),
  159. //// UploadStatus: 1,
  160. //// UploadType: 1,
  161. //// }
  162. //// err := service.CreateUploadRecord(upload)
  163. //// if err != nil {
  164. //// utils.ErrorLog("%v", err)
  165. //// }
  166. //// }
  167. //// }
  168. //// }
  169. ////
  170. //// record, err_four := service.FindDataUploadOrgInfo(config.OrgId, 4)
  171. //// if err_four == gorm.ErrRecordNotFound {
  172. //// if GetDiffDay(config) <= 0 {
  173. //// var hdPatients []*sz.TempHdPatient
  174. //// patients, _ := service.FindOrgPatientData(config.OrgId, 0, 0)
  175. ////
  176. //// for _, patient := range patients {
  177. ////
  178. //// idcard_year, _ := strconv.Atoi(Substr(patient.IdCardNo, 6, 4)) // 年
  179. //// idcard_mo, _ := strconv.Atoi(Substr(patient.IdCardNo, 10, 2)) // 月
  180. //// idcard_day, _ := strconv.Atoi(Substr(patient.IdCardNo, 12, 2)) // 日
  181. ////
  182. //// date := strconv.Itoa(idcard_year) + "-" + strconv.Itoa(idcard_mo) + "-" + strconv.Itoa(idcard_day)
  183. ////
  184. //// local, _ := time.LoadLocation("Local")
  185. //// birthday, _ := time.ParseInLocation("2006-01-02", date, local)
  186. ////
  187. //// var isCKD int
  188. ////
  189. //// value := strings.Index(patient.Diagnose, "慢性肾脏病")
  190. //// value2 := strings.Index(patient.Diagnose, "CKD")
  191. //// value3 := strings.Index(patient.Diagnose, "慢性肾衰竭")
  192. ////
  193. //// if value != -1 || value2 != -1 || value3 != -1 {
  194. //// isCKD = 1
  195. //// } else {
  196. //// isCKD = 0
  197. //// }
  198. ////
  199. //// p := &sz.TempHdPatient{
  200. //// HospitalId: strconv.FormatInt(patient.UserOrgId, 10),
  201. //// PatientNk: strconv.FormatInt(patient.ID, 10),
  202. //// CardNo: "000000000000000000",
  203. //// CardType: "01",
  204. //// IdNo: patient.IdCardNo,
  205. //// IdType: "01",
  206. //// PatientName: patient.Name,
  207. //// Gender: strconv.FormatInt(patient.Gender, 10),
  208. //// BornDate: birthday,
  209. //// DiagnosisSummary: patient.Diagnose,
  210. //// IsCrf: strconv.Itoa(isCKD),
  211. //// CreatedTime: time.Now(),
  212. //// UpdateTime: time.Now(),
  213. //// Sjscsj: time.Now(),
  214. //// Xgbz: strconv.FormatInt(0, 10),
  215. //// }
  216. ////
  217. //// if patient.FirstDialysisDate != 0 {
  218. //// p.DialysisStartTime = time.Unix(patient.FirstDialysisDate, 0)
  219. //// }
  220. //// if patient.HospitalFirstDialysisDate != 0 {
  221. //// p.LocalStartTime = time.Unix(patient.HospitalFirstDialysisDate, 0)
  222. //// }
  223. ////
  224. //// hdPatients = append(hdPatients, p)
  225. //// }
  226. ////
  227. //// for _, item := range hdPatients {
  228. //// service.XTWriteDB().Model(&sz.TempHdPatient{}).Create(item)
  229. //// }
  230. ////
  231. //// upload := &sz.DataUpload{
  232. //// ModuleType: 4,
  233. //// OrgId: config.OrgId,
  234. //// UploadDate: time.Now().Unix(),
  235. //// UploadStatus: 1,
  236. //// UploadType: 1,
  237. //// }
  238. //// err := service.CreateUploadRecord(upload)
  239. //// if err != nil {
  240. //// utils.ErrorLog("%v", err)
  241. //// }
  242. //// }
  243. //// } else if err_four == nil {
  244. //// if GetDiffDay2(config, record) <= 0 {
  245. ////
  246. //// var hdPatients []*sz.TempHdPatient
  247. //// patients, _ := service.FindOrgPatientData(record.OrgId, record.UploadDate, time.Now().Unix())
  248. //// for _, patient := range patients {
  249. //// idcard_year, _ := strconv.Atoi(Substr(patient.IdCardNo, 6, 4)) // 年
  250. //// idcard_mo, _ := strconv.Atoi(Substr(patient.IdCardNo, 10, 2)) // 月
  251. //// idcard_day, _ := strconv.Atoi(Substr(patient.IdCardNo, 12, 2)) // 日
  252. //// date := strconv.Itoa(idcard_year) + "-" + strconv.Itoa(idcard_mo) + "-" + strconv.Itoa(idcard_day)
  253. //// local, _ := time.LoadLocation("Local")
  254. //// birthday, _ := time.ParseInLocation("2006-01-02", date, local)
  255. ////
  256. //// var isCKD int
  257. ////
  258. //// value := strings.Index(patient.Diagnose, "慢性肾脏病")
  259. //// value2 := strings.Index(patient.Diagnose, "CKD")
  260. //// value3 := strings.Index(patient.Diagnose, "慢性肾衰竭")
  261. ////
  262. //// if value != -1 || value2 != -1 || value3 != -1 {
  263. //// isCKD = 1
  264. //// } else {
  265. //// isCKD = 0
  266. //// }
  267. ////
  268. //// p := &sz.TempHdPatient{
  269. //// HospitalId: strconv.FormatInt(patient.UserOrgId, 10),
  270. //// PatientNk: strconv.FormatInt(patient.ID, 10),
  271. //// CardNo: "000000000000000000",
  272. //// CardType: "01",
  273. //// IdNo: patient.IdCardNo,
  274. //// IdType: "01",
  275. //// PatientName: patient.Name,
  276. //// Gender: strconv.FormatInt(patient.Gender, 10),
  277. //// BornDate: birthday,
  278. //// DiagnosisSummary: patient.Diagnose,
  279. //// IsCrf: strconv.Itoa(isCKD),
  280. //// CreatedTime: time.Now(),
  281. //// UpdateTime: time.Now(),
  282. //// Sjscsj: time.Now(),
  283. //// Xgbz: strconv.FormatInt(0, 10),
  284. //// }
  285. ////
  286. //// if patient.FirstDialysisDate != 0 {
  287. //// p.DialysisStartTime = time.Unix(patient.FirstDialysisDate, 0)
  288. //// }
  289. //// if patient.HospitalFirstDialysisDate != 0 {
  290. //// p.LocalStartTime = time.Unix(patient.HospitalFirstDialysisDate, 0)
  291. //// }
  292. ////
  293. //// hdPatients = append(hdPatients, p)
  294. //// }
  295. ////
  296. //// for _, item := range hdPatients {
  297. //// service.XTReadDB().Model(&sz.TempHdPatient{}).Create(item)
  298. //// }
  299. ////
  300. //// upload := &sz.DataUpload{
  301. //// ModuleType: 4,
  302. //// OrgId: record.OrgId,
  303. //// UploadDate: time.Now().Unix(),
  304. //// UploadStatus: 1,
  305. //// UploadType: 1,
  306. //// }
  307. //// err := service.CreateUploadRecord(upload)
  308. //// if err != nil {
  309. //// utils.ErrorLog("%v", err)
  310. //// }
  311. //// }
  312. //// }
  313. ////
  314. //// //record, err_five := service.FindDataUploadOrgInfo(config.OrgId, 5)
  315. //// //if err_five == gorm.ErrRecordNotFound {
  316. //// // if GetDiffDay(config) <= 0 {
  317. //// //
  318. //// // var hdPatientOuts []*sz.TempHdPatientOut
  319. //// // patients, _ := service.FindOrgPatientOutData(config.OrgId, 0, 0)
  320. //// ////
  321. //// // for _, patient := range patients {
  322. //// //
  323. //// // p := &sz.TempHdPatientOut{
  324. //// // Sn: strconv.FormatInt(patient.ID, 10),
  325. //// // HospitalId: strconv.FormatInt(patient.UserOrgId, 10),
  326. //// // PatientNk: strconv.FormatInt(patient.ID, 10),
  327. //// // SequelaeType: "99",
  328. //// // ExtReason: "98",
  329. //// // CreateTime: time.Now(),
  330. //// // Sjscsj: time.Now(),
  331. //// // Xgbz: 0,
  332. //// // }
  333. //// //
  334. //// // if len(patient.PatientLapseto) > 0{
  335. //// // p.SequelaeDate = time.Unix(patient.PatientLapseto[len(patient.PatientLapseto)].LapsetoTime, 0)
  336. //// // }
  337. //// //
  338. //// // hdPatientOuts = append(hdPatientOuts, p)
  339. //// // }
  340. //// //
  341. //// // for _, item := range hdPatientOuts {
  342. //// // service.XTWriteDB().Model(&sz.TempHdPatientOut{}).Create(item)
  343. //// // }
  344. //// //
  345. //// // upload := &sz.DataUpload{
  346. //// // ModuleType: 5,
  347. //// // OrgId: config.OrgId,
  348. //// // UploadDate: time.Now().Unix(),
  349. //// // UploadStatus: 1,
  350. //// // UploadType: 1,
  351. //// // }
  352. //// // err := service.CreateUploadRecord(upload)
  353. //// // if err != nil{
  354. //// // utils.ErrorLog("%v",err)
  355. //// // }
  356. //// // }
  357. //// //
  358. //// //} else if err_five == nil {
  359. //// // if GetDiffDay2(config,record) <= 0 {
  360. //// //
  361. //// // var hdPatientOuts []*sz.TempHdPatientOut
  362. //// // patients, _ := service.FindOrgPatientOutData(record.OrgId, record.UploadDate, time.Now().Unix())
  363. //// //
  364. //// // for _, patient := range patients {
  365. //// //
  366. //// // p := &sz.TempHdPatientOut{
  367. //// // Sn: strconv.FormatInt(patient.ID, 10),
  368. //// // HospitalId: strconv.FormatInt(patient.UserOrgId, 10),
  369. //// // PatientNk: strconv.FormatInt(patient.ID, 10),
  370. //// // SequelaeDate: time.Unix(patient.PatientLapseto[len(patient.PatientLapseto)].LapsetoTime, 0),
  371. //// // SequelaeType: "99",
  372. //// // ExtReason: "98",
  373. //// // CreateTime: time.Now(),
  374. //// // Sjscsj: time.Now(),
  375. //// // Xgbz: 0,
  376. //// // }
  377. //// //
  378. //// // hdPatientOuts = append(hdPatientOuts, p)
  379. //// // }
  380. //// //
  381. //// // for _, item := range hdPatientOuts {
  382. //// // service.XTWriteDB().Model(&sz.TempHdPatientOut{}).Create(item)
  383. //// // }
  384. //// //
  385. //// // upload := &sz.DataUpload{
  386. //// // ModuleType: 5,
  387. //// // OrgId: record.OrgId,
  388. //// // UploadDate: time.Now().Unix(),
  389. //// // UploadStatus: 1,
  390. //// // UploadType: 1,
  391. //// // }
  392. //// // err := service.CreateUploadRecord(upload)
  393. //// // if err != nil{
  394. //// // utils.ErrorLog("%v",err)
  395. //// // }
  396. //// // }
  397. //// //
  398. //// //}
  399. ////
  400. //// record, err_six := service.FindDataUploadOrgInfo(config.OrgId, 6)
  401. //// if err_six == gorm.ErrRecordNotFound {
  402. ////
  403. //// if GetDiffDay(config) <= 0 {
  404. ////
  405. //// var hdPrescription []*sz.TempHdPs
  406. //// prescriptions, _ := service.FindOrgDialysisPrescriptionData(config.OrgId, 0, 0)
  407. ////
  408. //// for _, item := range prescriptions {
  409. ////
  410. //// ps := &sz.TempHdPs{
  411. //// PrescribeId: strconv.FormatInt(item.ID, 10),
  412. //// HospitalId: strconv.FormatInt(item.UserOrgId, 10),
  413. //// PatientNk: strconv.FormatInt(item.PatientId, 10),
  414. //// K: item.Kalium,
  415. //// Ca: item.Calcium,
  416. //// Na: item.Sodium,
  417. //// CreateTime: time.Now(),
  418. //// Sjscsj: time.Now(),
  419. //// Xgbz: 0,
  420. //// PrescribeTime: time.Unix(item.RecordDate, 0),
  421. //// }
  422. ////
  423. //// switch item.ModeId {
  424. //// case 1:
  425. //// ps.DialysisFrequency = item.AssessmentBeforeDislysis.DialysisCount
  426. //// ps.FrequencyUnit = 1
  427. //// ps.DialysisDuration = item.DialysisDuration
  428. //// ps.Hdf = "0"
  429. //// ps.Hp = "0"
  430. ////
  431. //// break
  432. //// case 2:
  433. //// ps.Hdf = "1"
  434. //// ps.Hp = "0"
  435. //// ps.HdfFrequency = item.AssessmentBeforeDislysis.DialysisCount
  436. //// ps.HdfFrequencyUnit = 1
  437. //// ps.HpDuration = item.DialysisDuration
  438. //// break
  439. //// case 4:
  440. //// ps.Hdf = "0"
  441. //// ps.Hp = "1"
  442. //// ps.HpFrequency = item.AssessmentBeforeDislysis.DialysisCount
  443. //// ps.HpFrequencyUnit = 1
  444. //// ps.HpDuration = item.DialysisDuration
  445. //// break
  446. //// }
  447. ////
  448. //// hdPrescription = append(hdPrescription, ps)
  449. //// }
  450. ////
  451. //// for _, item := range hdPrescription {
  452. //// service.XTWriteDB().Model(&sz.TempHdPs{}).Create(item)
  453. //// }
  454. ////
  455. //// upload := &sz.DataUpload{
  456. //// ModuleType: 6,
  457. //// OrgId: config.OrgId,
  458. //// UploadDate: time.Now().Unix(),
  459. //// UploadStatus: 1,
  460. //// UploadType: 1,
  461. //// }
  462. //// err := service.CreateUploadRecord(upload)
  463. //// if err != nil {
  464. //// utils.ErrorLog("%v", err)
  465. //// }
  466. //// }
  467. ////
  468. //// } else if err_six == nil {
  469. //// if GetDiffDay2(config, record) <= 0 {
  470. ////
  471. //// var hdPrescription []*sz.TempHdPs
  472. //// prescriptions, _ := service.FindOrgDialysisPrescriptionData(record.OrgId, record.UploadDate, time.Now().Unix())
  473. ////
  474. //// for _, item := range prescriptions {
  475. ////
  476. //// ps := &sz.TempHdPs{
  477. //// PrescribeId: strconv.FormatInt(item.ID, 10),
  478. //// HospitalId: strconv.FormatInt(item.UserOrgId, 10),
  479. //// PatientNk: strconv.FormatInt(item.PatientId, 10),
  480. //// K: item.Kalium,
  481. //// Ca: item.Calcium,
  482. //// Na: item.Sodium,
  483. //// CreateTime: time.Now(),
  484. //// Sjscsj: time.Now(),
  485. //// Xgbz: 0,
  486. //// PrescribeTime: time.Unix(item.RecordDate, 0),
  487. //// }
  488. ////
  489. //// switch item.ModeId {
  490. //// case 1:
  491. //// ps.DialysisFrequency = item.AssessmentBeforeDislysis.DialysisCount
  492. //// ps.FrequencyUnit = 1
  493. //// ps.DialysisDuration = item.DialysisDuration
  494. //// ps.Hdf = "0"
  495. //// ps.Hp = "0"
  496. ////
  497. //// break
  498. //// case 2:
  499. //// ps.Hdf = "1"
  500. //// ps.Hp = "0"
  501. //// ps.HdfFrequency = item.AssessmentBeforeDislysis.DialysisCount
  502. //// ps.HdfFrequencyUnit = 1
  503. //// ps.HpDuration = item.DialysisDuration
  504. //// break
  505. //// case 4:
  506. //// ps.Hdf = "0"
  507. //// ps.Hp = "1"
  508. //// ps.HpFrequency = item.AssessmentBeforeDislysis.DialysisCount
  509. //// ps.HpFrequencyUnit = 1
  510. //// ps.HpDuration = item.DialysisDuration
  511. //// break
  512. //// }
  513. ////
  514. //// hdPrescription = append(hdPrescription, ps)
  515. //// }
  516. ////
  517. //// for _, item := range hdPrescription {
  518. //// service.XTWriteDB().Model(&sz.TempHdPs{}).Create(item)
  519. //// }
  520. ////
  521. //// upload := &sz.DataUpload{
  522. //// ModuleType: 6,
  523. //// OrgId: record.OrgId,
  524. //// UploadDate: time.Now().Unix(),
  525. //// UploadStatus: 1,
  526. //// UploadType: 1,
  527. //// }
  528. //// err := service.CreateUploadRecord(upload)
  529. //// if err != nil {
  530. //// utils.ErrorLog("%v", err)
  531. //// }
  532. //// }
  533. //// }
  534. ////
  535. //// record, err_seven := service.FindDataUploadOrgInfo(config.OrgId, 7)
  536. //// if err_seven == gorm.ErrRecordNotFound {
  537. //// if GetDiffDay(config) <= 0 {
  538. //// var hdPsMedicine []*sz.TempHdPsMedicine
  539. //// prescriptions, _ := service.FindOrgDialysisPrescriptionData(config.OrgId, 0, 0)
  540. ////
  541. //// for _, item := range prescriptions {
  542. ////
  543. //// psm := &sz.TempHdPsMedicine{
  544. //// Sn: strconv.FormatInt(item.ID, 10),
  545. //// PrescribeId: strconv.FormatInt(item.ID, 10),
  546. //// HospitalId: strconv.FormatInt(item.UserOrgId, 10),
  547. //// MedicineTypeId: "2",
  548. //// CreatedTime: time.Now(),
  549. //// Sjscsj: time.Now(),
  550. //// Xgbz: 0,
  551. //// }
  552. ////
  553. //// switch item.Anticoagulant {
  554. //// case 1:
  555. //// psm.MedicineId = "3"
  556. ////
  557. //// break
  558. //// case 2:
  559. //// psm.MedicineId = "1"
  560. ////
  561. //// break
  562. //// case 3:
  563. //// psm.MedicineId = "2"
  564. ////
  565. //// break
  566. //// case 4:
  567. //// psm.MedicineId = "5"
  568. ////
  569. //// break
  570. //// case 5:
  571. //// psm.MedicineId = "4"
  572. ////
  573. //// break
  574. //// }
  575. ////
  576. //// hdPsMedicine = append(hdPsMedicine, psm)
  577. //// }
  578. ////
  579. //// for _, item := range hdPsMedicine {
  580. //// service.XTWriteDB().Model(&sz.TempHdPsMedicine{}).Create(item)
  581. //// }
  582. ////
  583. //// upload := &sz.DataUpload{
  584. //// ModuleType: 7,
  585. //// OrgId: config.OrgId,
  586. //// UploadDate: time.Now().Unix(),
  587. //// UploadStatus: 1,
  588. //// UploadType: 1,
  589. //// }
  590. //// err := service.CreateUploadRecord(upload)
  591. //// if err != nil {
  592. //// utils.ErrorLog("%v", err)
  593. //// }
  594. //// }
  595. ////
  596. //// } else if err_seven == nil {
  597. //// if GetDiffDay2(config, record) <= 0 {
  598. //// var hdPsMedicine []*sz.TempHdPsMedicine
  599. //// prescriptions, _ := service.FindOrgDialysisPrescriptionData(record.OrgId, record.UploadDate, time.Now().Unix())
  600. ////
  601. //// for _, item := range prescriptions {
  602. ////
  603. //// psm := &sz.TempHdPsMedicine{
  604. //// Sn: strconv.FormatInt(item.ID, 10),
  605. //// PrescribeId: strconv.FormatInt(item.ID, 10),
  606. //// HospitalId: strconv.FormatInt(item.UserOrgId, 10),
  607. //// MedicineTypeId: "2",
  608. //// CreatedTime: time.Now(),
  609. //// Sjscsj: time.Now(),
  610. //// Xgbz: 0,
  611. //// }
  612. ////
  613. //// switch item.Anticoagulant {
  614. //// case 1:
  615. //// psm.MedicineId = "3"
  616. ////
  617. //// break
  618. //// case 2:
  619. //// psm.MedicineId = "1"
  620. ////
  621. //// break
  622. //// case 3:
  623. //// psm.MedicineId = "2"
  624. ////
  625. //// break
  626. //// case 4:
  627. //// psm.MedicineId = "5"
  628. ////
  629. //// break
  630. //// case 5:
  631. //// psm.MedicineId = "4"
  632. ////
  633. //// break
  634. //// }
  635. ////
  636. //// hdPsMedicine = append(hdPsMedicine, psm)
  637. //// }
  638. ////
  639. //// for _, item := range hdPsMedicine {
  640. //// service.XTWriteDB().Model(&sz.TempHdPsMedicine{}).Create(item)
  641. //// }
  642. ////
  643. //// upload := &sz.DataUpload{
  644. //// ModuleType: 7,
  645. //// OrgId: config.OrgId,
  646. //// UploadDate: time.Now().Unix(),
  647. //// UploadStatus: 1,
  648. //// UploadType: 1,
  649. //// }
  650. //// err := service.CreateUploadRecord(upload)
  651. //// if err != nil {
  652. //// utils.ErrorLog("%v", err)
  653. //// }
  654. //// }
  655. //// }
  656. //// //
  657. //// // //排班
  658. //// record, err_eight := service.FindDataUploadOrgInfo(config.OrgId, 8)
  659. //// if err_eight == gorm.ErrRecordNotFound {
  660. //// if GetDiffDay(config) <= 0 {
  661. ////
  662. //// var hdShift []*sz.TempHdShift
  663. //// schs, _ := service.FindOrgScheduleData(config.OrgId, 0, 0)
  664. ////
  665. //// for _, sch := range schs {
  666. ////
  667. //// shift := &sz.TempHdShift{
  668. //// PsId: strconv.FormatInt(sch.ID, 10),
  669. //// HospitalId: strconv.FormatInt(sch.UserOrgId, 10),
  670. //// PatientNk: strconv.FormatInt(sch.PatientId, 10),
  671. //// ScheduleDate: time.Unix(sch.ScheduleDate, 0),
  672. //// ShiftType: strconv.FormatInt(sch.ScheduleType, 10),
  673. //// SickbedNo: sch.DeviceNumber.Number,
  674. //// ScheduleStatus: "1",
  675. //// CreateTime: time.Now(),
  676. //// Sjscsj: time.Now(),
  677. //// Xgbz: 0,
  678. //// }
  679. ////
  680. //// hdShift = append(hdShift, shift)
  681. ////
  682. //// }
  683. ////
  684. //// for _, item := range hdShift {
  685. //// service.XTWriteDB().Model(&sz.TempHdShift{}).Create(item)
  686. //// }
  687. ////
  688. //// upload := &sz.DataUpload{
  689. //// ModuleType: 8,
  690. //// OrgId: config.OrgId,
  691. //// UploadDate: time.Now().Unix(),
  692. //// UploadStatus: 1,
  693. //// UploadType: 1,
  694. //// }
  695. //// err := service.CreateUploadRecord(upload)
  696. //// if err != nil {
  697. //// utils.ErrorLog("%v", err)
  698. //// }
  699. //// }
  700. ////
  701. //// } else if err_eight == nil {
  702. //// if GetDiffDay2(config, record) <= 0 {
  703. ////
  704. //// var hdShift []*sz.TempHdShift
  705. //// schs, _ := service.FindOrgScheduleData(record.OrgId, record.UploadDate, time.Now().Unix())
  706. ////
  707. //// for _, sch := range schs {
  708. ////
  709. //// shift := &sz.TempHdShift{
  710. //// PsId: strconv.FormatInt(sch.ID, 10),
  711. //// HospitalId: strconv.FormatInt(sch.UserOrgId, 10),
  712. //// PatientNk: strconv.FormatInt(sch.PatientId, 10),
  713. //// ScheduleDate: time.Unix(sch.ScheduleDate, 0),
  714. //// ShiftType: strconv.FormatInt(sch.ScheduleType, 10),
  715. //// SickbedNo: sch.DeviceNumber.Number,
  716. //// ScheduleStatus: "1",
  717. //// CreateTime: time.Now(),
  718. //// Sjscsj: time.Now(),
  719. //// Xgbz: 0,
  720. //// }
  721. ////
  722. //// hdShift = append(hdShift, shift)
  723. ////
  724. //// }
  725. ////
  726. //// for _, item := range hdShift {
  727. //// service.XTWriteDB().Model(&sz.TempHdShift{}).Create(item)
  728. //// }
  729. ////
  730. //// upload := &sz.DataUpload{
  731. //// ModuleType: 8,
  732. //// OrgId: config.OrgId,
  733. //// UploadDate: time.Now().Unix(),
  734. //// UploadStatus: 1,
  735. //// UploadType: 1,
  736. //// }
  737. //// err := service.CreateUploadRecord(upload)
  738. //// if err != nil {
  739. //// utils.ErrorLog("%v", err)
  740. //// }
  741. //// }
  742. ////
  743. //// }
  744. //// //
  745. //// record, err_nine := service.FindDataUploadOrgInfo(config.OrgId, 9)
  746. //// if err_nine == gorm.ErrRecordNotFound {
  747. ////
  748. //// if GetDiffDay(config) <= 0 {
  749. ////
  750. //// var hdDoctorAdvices []*sz.TempHdDoctorsAdvice
  751. //// dialysisPrescriptions, _ := service.FindOrgDialysisPrescriptionData(or, 0, 0)
  752. ////
  753. //// for _, dp := range dialysisPrescriptions {
  754. ////
  755. //// advice := &sz.TempHdDoctorsAdvice{
  756. //// MedicalOrDerId: strconv.FormatInt(dp.ID, 10),
  757. //// HospitalId: strconv.FormatInt(dp.UserOrgId, 10),
  758. //// DialysisId: strconv.FormatInt(dp.DialysisOrder.ID, 10),
  759. //// OrderType: "1",
  760. //// PatientNk: strconv.FormatInt(dp.PatientId, 10),
  761. //// DialysisDuration: dp.DialysisDurationHour*60 + dp.DialysisDurationMinute,
  762. //// BloodVol: int64(math.Floor(dp.BloodFlowVolume + 0/5)),
  763. //// CreateTime: time.Now(),
  764. //// Sjscsj: time.Now(),
  765. //// Xgbz: 0,
  766. //// }
  767. ////
  768. //// hdDoctorAdvices = append(hdDoctorAdvices, advice)
  769. ////
  770. //// }
  771. ////
  772. //// for _, item := range hdDoctorAdvices {
  773. //// service.XTWriteDB().Model(&sz.TempHdDoctorsAdvice{}).Create(item)
  774. //// }
  775. ////
  776. //// upload := &sz.DataUpload{
  777. //// ModuleType: 9,
  778. //// OrgId: config.OrgId,
  779. //// UploadDate: time.Now().Unix(),
  780. //// UploadStatus: 1,
  781. //// UploadType: 1,
  782. //// }
  783. //// err := service.CreateUploadRecord(upload)
  784. //// if err != nil {
  785. //// utils.ErrorLog("%v", err)
  786. //// }
  787. //// }
  788. ////
  789. //// } else if err_nine == nil {
  790. //// if GetDiffDay2(config, record) <= 0 {
  791. ////
  792. //// var hdDoctorAdvices []*sz.TempHdDoctorsAdvice
  793. //// dialysisPrescriptions, _ := service.FindOrgDialysisPrescriptionData(record.OrgId, record.UploadDate, time.Now().Unix())
  794. //// for _, dp := range dialysisPrescriptions {
  795. //// advice := &sz.TempHdDoctorsAdvice{
  796. //// MedicalOrDerId: strconv.FormatInt(dp.ID, 10),
  797. //// HospitalId: strconv.FormatInt(dp.UserOrgId, 10),
  798. //// DialysisId: strconv.FormatInt(dp.DialysisOrder.ID, 10),
  799. //// OrderType: "1",
  800. //// PatientNk: strconv.FormatInt(dp.PatientId, 10),
  801. //// DialysisDuration: dp.DialysisDurationHour*60 + dp.DialysisDurationMinute,
  802. //// BloodVol: int64(math.Floor(dp.BloodFlowVolume + 0/5)),
  803. //// CreateTime: time.Now(),
  804. //// Sjscsj: time.Now(),
  805. //// Xgbz: 0,
  806. //// }
  807. //// hdDoctorAdvices = append(hdDoctorAdvices, advice)
  808. //// }
  809. //// for _, item := range hdDoctorAdvices {
  810. //// service.XTWriteDB().Model(&sz.TempHdDoctorsAdvice{}).Create(item)
  811. //// }
  812. ////
  813. //// upload := &sz.DataUpload{
  814. //// ModuleType: 9,
  815. //// OrgId: config.OrgId,
  816. //// UploadDate: time.Now().Unix(),
  817. //// UploadStatus: 1,
  818. //// UploadType: 1,
  819. //// }
  820. //// err := service.CreateUploadRecord(upload)
  821. //// if err != nil {
  822. //// utils.ErrorLog("%v", err)
  823. //// }
  824. //// }
  825. //// }
  826. //// //
  827. //// record, err_ten := service.FindDataUploadOrgInfo(config.OrgId, 10)
  828. //// fmt.Println(err_ten)
  829. //// fmt.Println(record)
  830. ////
  831. //// if err_ten == gorm.ErrRecordNotFound {
  832. //// if GetDiffDay(config) <= 0 {
  833. ////
  834. //// var hdDialysis []*sz.TempHdDialysis
  835. //// schs, erra := service.FindOrgDialysisData(config.OrgId, 0, 0)
  836. //// fmt.Println(schs)
  837. //// fmt.Println(erra)
  838. ////
  839. //// for _, sch := range schs {
  840. ////
  841. //// dialysis := &sz.TempHdDialysis{
  842. //// PsId: strconv.FormatInt(sch.ID, 10),
  843. //// HospitalId: strconv.FormatInt(sch.UserOrgId, 10),
  844. ////
  845. //// SickbedNo: sch.DeviceNumber.Number,
  846. //// DivisionId: strconv.FormatInt(sch.DeviceNumber.ZoneId, 10),
  847. //// Ufv: int64(math.Floor(sch.VMDialysisPrescription.Ultrafiltration + 0/5)),
  848. //// TotalReplace: int64(math.Floor(sch.VMDialysisPrescription.ReplacementTotal + 0/5)),
  849. //// BeforeWeight: sch.AssessmentBeforeDislysis.WeighingBefore,
  850. ////
  851. //// PatientNk: strconv.FormatInt(sch.PatientId, 10),
  852. //// CreateTime: time.Now(),
  853. //// Sjscsj: time.Now(),
  854. //// Xgbz: 0,
  855. //// }
  856. ////
  857. //// if sch.DialysisOrder.ID > 0 {
  858. //// dialysis.DialysisId = strconv.FormatInt(sch.DialysisOrder.ID, 10)
  859. //// dialysis.DialysisDate = time.Unix(sch.DialysisOrder.DialysisDate, 0)
  860. //// if sch.DialysisOrder.StartTime > 0 {
  861. //// dialysis.StartTime = time.Unix(sch.DialysisOrder.StartTime, 0)
  862. ////
  863. //// }
  864. ////
  865. //// if sch.DialysisOrder.EndTime > 0 {
  866. //// dialysis.EndTime = time.Unix(sch.DialysisOrder.EndTime, 0)
  867. ////
  868. //// }
  869. //// }
  870. ////
  871. //// if len(sch.MonitoringRecord) > 0 {
  872. //// dialysis.BeforeDbp = int64(math.Floor(sch.MonitoringRecord[0].DiastolicBloodPressure + 0/5))
  873. //// dialysis.BeforeSbp = int64(math.Floor(sch.MonitoringRecord[0].SystolicBloodPressure + 0/5))
  874. //// dialysis.AfterDbp = int64(math.Floor(sch.MonitoringRecord[len(sch.MonitoringRecord)-1].DiastolicBloodPressure + 0/5))
  875. //// dialysis.AfterSbp = int64(math.Floor(sch.MonitoringRecord[len(sch.MonitoringRecord)-1].SystolicBloodPressure + 0/5))
  876. ////
  877. //// }
  878. ////
  879. //// hdDialysis = append(hdDialysis, dialysis)
  880. ////
  881. //// }
  882. ////
  883. //// for _, item := range hdDialysis {
  884. //// service.XTWriteDB().Model(&sz.TempHdDialysis{}).Create(item)
  885. //// }
  886. ////
  887. //// upload := &sz.DataUpload{
  888. //// ModuleType: 10,
  889. //// OrgId: config.OrgId,
  890. //// UploadDate: time.Now().Unix(),
  891. //// UploadStatus: 1,
  892. //// UploadType: 1,
  893. //// }
  894. //// err := service.CreateUploadRecord(upload)
  895. //// if err != nil {
  896. //// utils.ErrorLog("%v", err)
  897. //// }
  898. //// }
  899. ////
  900. //// } else if err_ten == nil {
  901. //// if GetDiffDay2(config, record) <= 0 {
  902. ////
  903. //// var hdDialysis []*sz.TempHdDialysis
  904. //// schs, _ := service.FindOrgDialysisData(record.OrgId, record.UploadDate, time.Now().Unix())
  905. //// for _, sch := range schs {
  906. //// dialysis := &sz.TempHdDialysis{
  907. //// PsId: strconv.FormatInt(sch.ID, 10),
  908. //// HospitalId: strconv.FormatInt(sch.UserOrgId, 10),
  909. //// DialysisId: strconv.FormatInt(sch.DialysisOrder.ID, 10),
  910. //// DialysisDate: time.Unix(sch.DialysisOrder.DialysisDate, 0),
  911. //// SickbedNo: sch.DeviceNumber.Number,
  912. //// DivisionId: strconv.FormatInt(sch.DeviceNumber.ZoneId, 10),
  913. //// Ufv: int64(math.Floor(sch.VMDialysisPrescription.Ultrafiltration + 0/5)),
  914. //// TotalReplace: int64(math.Floor(sch.VMDialysisPrescription.ReplacementTotal + 0/5)),
  915. //// BeforeDbp: int64(math.Floor(sch.MonitoringRecord[0].DiastolicBloodPressure + 0/5)),
  916. //// BeforeSbp: int64(math.Floor(sch.MonitoringRecord[0].SystolicBloodPressure + 0/5)),
  917. //// AfterDbp: int64(math.Floor(sch.MonitoringRecord[len(sch.MonitoringRecord)].DiastolicBloodPressure + 0/5)),
  918. //// AfterSbp: int64(math.Floor(sch.MonitoringRecord[len(sch.MonitoringRecord)].SystolicBloodPressure + 0/5)),
  919. //// BeforeWeight: sch.AssessmentBeforeDislysis.WeighingBefore,
  920. //// StartTime: time.Unix(sch.DialysisOrder.StartTime, 0),
  921. //// EndTime: time.Unix(sch.DialysisOrder.EndTime, 0),
  922. //// PatientNk: strconv.FormatInt(sch.PatientId, 10),
  923. //// CreateTime: time.Now(),
  924. //// Sjscsj: time.Now(),
  925. //// Xgbz: 0,
  926. //// }
  927. ////
  928. //// hdDialysis = append(hdDialysis, dialysis)
  929. ////
  930. //// }
  931. ////
  932. //// for _, item := range hdDialysis {
  933. //// service.XTWriteDB().Model(&sz.TempHdDialysis{}).Create(item)
  934. //// }
  935. ////
  936. //// upload := &sz.DataUpload{
  937. //// ModuleType: 10,
  938. //// OrgId: config.OrgId,
  939. //// UploadDate: time.Now().Unix(),
  940. //// UploadStatus: 1,
  941. //// UploadType: 1,
  942. //// }
  943. //// err := service.CreateUploadRecord(upload)
  944. //// if err != nil {
  945. //// utils.ErrorLog("%v", err)
  946. //// }
  947. //// }
  948. ////
  949. //// }
  950. //// //
  951. //// record, err_eleven := service.FindDataUploadOrgInfo(config.OrgId, 11)
  952. //// if err_eleven == gorm.ErrRecordNotFound {
  953. //// if GetDiffDay(config) <= 0 {
  954. ////
  955. //// var hdMiddle []*sz.TempHdMiddle
  956. //// monitors, _ := service.FindOrgMonitorRecordData(config.OrgId, 0, 0)
  957. ////
  958. //// for _, item := range monitors {
  959. ////
  960. //// mid := &sz.TempHdMiddle{
  961. //// HospitalId: strconv.FormatInt(item.UserOrgId, 10),
  962. //// DialysisId: strconv.FormatInt(item.DialysisOrder.ID, 10),
  963. //// MonitorTime: time.Unix(item.OperateTime, 0),
  964. //// Sbp: int64(math.Floor(item.SystolicBloodPressure + 0/5)),
  965. //// Dbp: int64(math.Floor(item.DiastolicBloodPressure + 0/5)),
  966. //// PatientNk: strconv.FormatInt(item.PatientId, 10),
  967. //// CreateTime: time.Now(),
  968. //// Sjscsj: time.Now(),
  969. //// Xgbz: 0,
  970. //// }
  971. ////
  972. //// hdMiddle = append(hdMiddle, mid)
  973. ////
  974. //// }
  975. ////
  976. //// for _, item := range hdMiddle {
  977. //// service.XTWriteDB().Model(&sz.TempHdMiddle{}).Create(item)
  978. //// }
  979. ////
  980. //// upload := &sz.DataUpload{
  981. //// ModuleType: 11,
  982. //// OrgId: config.OrgId,
  983. //// UploadDate: time.Now().Unix(),
  984. //// UploadStatus: 1,
  985. //// UploadType: 1,
  986. //// }
  987. //// err := service.CreateUploadRecord(upload)
  988. //// if err != nil {
  989. //// utils.ErrorLog("%v", err)
  990. //// }
  991. //// }
  992. ////
  993. //// } else if err == nil {
  994. //// if GetDiffDay2(config, record) <= 0 {
  995. ////
  996. //// var hdMiddle []*sz.TempHdMiddle
  997. //// monitors, _ := service.FindOrgMonitorRecordData(record.OrgId, record.UploadDate, time.Now().Unix())
  998. ////
  999. //// for _, item := range monitors {
  1000. ////
  1001. //// mid := &sz.TempHdMiddle{
  1002. //// HospitalId: strconv.FormatInt(item.UserOrgId, 10),
  1003. //// DialysisId: strconv.FormatInt(item.DialysisOrder.ID, 10),
  1004. //// MonitorTime: time.Unix(item.OperateTime, 0),
  1005. //// Sbp: int64(math.Floor(item.SystolicBloodPressure + 0/5)),
  1006. //// Dbp: int64(math.Floor(item.DiastolicBloodPressure + 0/5)),
  1007. //// PatientNk: strconv.FormatInt(item.PatientId, 10),
  1008. //// CreateTime: time.Now(),
  1009. //// Sjscsj: time.Now(),
  1010. //// Xgbz: 0,
  1011. //// }
  1012. ////
  1013. //// hdMiddle = append(hdMiddle, mid)
  1014. ////
  1015. //// }
  1016. ////
  1017. //// for _, item := range hdMiddle {
  1018. //// service.XTWriteDB().Model(&sz.TempHdMiddle{}).Create(item)
  1019. //// }
  1020. ////
  1021. //// upload := &sz.DataUpload{
  1022. //// ModuleType: 11,
  1023. //// OrgId: config.OrgId,
  1024. //// UploadDate: time.Now().Unix(),
  1025. //// UploadStatus: 1,
  1026. //// UploadType: 1,
  1027. //// }
  1028. //// err := service.CreateUploadRecord(upload)
  1029. //// if err != nil {
  1030. //// utils.ErrorLog("%v", err)
  1031. //// }
  1032. //// }
  1033. //// }
  1034. //// //
  1035. //// record, err_twelve := service.FindDataUploadOrgInfo(config.OrgId, 12)
  1036. //// if err_twelve == gorm.ErrRecordNotFound {
  1037. //// if GetDiffDay(config) <= 0 {
  1038. ////
  1039. //// var divisions []*sz.TempHdDivision
  1040. //// zones, _ := service.FindOrgDeviceZoneRecordData(config.OrgId, 0, 0)
  1041. ////
  1042. //// for _, item := range zones {
  1043. //// nowTime := time.Now()
  1044. //// div := &sz.TempHdDivision{
  1045. //// DivisionId: strconv.FormatInt(item.ID, 10),
  1046. //// HospitalId: strconv.FormatInt(item.OrgId, 10),
  1047. //// DevisionName: item.Name,
  1048. //// CreateTime: nowTime,
  1049. //// UpdateTime: nowTime,
  1050. //// UpdateFlag: strconv.FormatInt(0, 10),
  1051. //// Sjscsj: time.Now(),
  1052. //// Xgbz: 0,
  1053. //// }
  1054. ////
  1055. //// divisions = append(divisions, div)
  1056. ////
  1057. //// }
  1058. ////
  1059. //// for _, item := range divisions {
  1060. //// service.XTWriteDB().Model(&sz.TempHdDivision{}).Create(item)
  1061. //// }
  1062. ////
  1063. //// upload := &sz.DataUpload{
  1064. //// ModuleType: 12,
  1065. //// OrgId: config.OrgId,
  1066. //// UploadDate: time.Now().Unix(),
  1067. //// UploadStatus: 1,
  1068. //// UploadType: 1,
  1069. //// }
  1070. //// err := service.CreateUploadRecord(upload)
  1071. //// if err != nil {
  1072. //// utils.ErrorLog("%v", err)
  1073. //// }
  1074. //// }
  1075. ////
  1076. //// } else if err_twelve == nil {
  1077. //// if GetDiffDay2(config, record) <= 0 {
  1078. ////
  1079. //// var divisions []*sz.TempHdDivision
  1080. //// zones, _ := service.FindOrgDeviceZoneRecordData(record.OrgId, record.UploadDate, time.Now().Unix())
  1081. ////
  1082. //// for _, item := range zones {
  1083. //// nowTime := time.Now()
  1084. //// div := &sz.TempHdDivision{
  1085. //// DivisionId: strconv.FormatInt(item.ID, 10),
  1086. //// HospitalId: strconv.FormatInt(item.OrgId, 10),
  1087. //// DevisionName: item.Name,
  1088. //// CreateTime: nowTime,
  1089. //// UpdateTime: nowTime,
  1090. //// UpdateFlag: strconv.FormatInt(0, 10),
  1091. //// Sjscsj: time.Now(),
  1092. //// Xgbz: 0,
  1093. //// }
  1094. //// divisions = append(divisions, div)
  1095. //// }
  1096. ////
  1097. //// for _, item := range divisions {
  1098. //// service.XTWriteDB().Model(&sz.TempHdDivision{}).Create(item)
  1099. //// }
  1100. ////
  1101. //// upload := &sz.DataUpload{
  1102. //// ModuleType: 12,
  1103. //// OrgId: config.OrgId,
  1104. //// UploadDate: time.Now().Unix(),
  1105. //// UploadStatus: 1,
  1106. //// UploadType: 1,
  1107. //// }
  1108. //// err := service.CreateUploadRecord(upload)
  1109. //// if err != nil {
  1110. //// utils.ErrorLog("%v", err)
  1111. //// }
  1112. //// }
  1113. ////
  1114. //// }
  1115. //// //
  1116. //// }
  1117. ////
  1118. ////}
  1119. //
  1120. //func Substr(str string, start, length int) string {
  1121. // rs := []rune(str)
  1122. // rl := len(rs)
  1123. // end := 0
  1124. // if start < 0 {
  1125. // start = rl - 1 + start
  1126. // }
  1127. // end = start + length
  1128. // if start > end {
  1129. // start, end = end, start
  1130. // }
  1131. // if start < 0 {
  1132. // start = 0
  1133. // }
  1134. // if start > rl {
  1135. // start = rl
  1136. // }
  1137. // if end < 0 {
  1138. // end = 0
  1139. // }
  1140. // if end > rl {
  1141. // end = rl
  1142. // }
  1143. // return string(rs[start:end])
  1144. //
  1145. //}
  1146. //
  1147. ////没有上报数据记录的时候,使用配置创建时间来计算上报时间
  1148. //func GetDiffDay(config *sz.DataUploadConfig) float64 {
  1149. // var diffDay float64
  1150. // switch config.TimeQuantum {
  1151. // case 1:
  1152. // tm := time.Unix(config.CreateTime, 0)
  1153. // dateStr := tm.Format("2006-1-2") + " 00:00:00"
  1154. // date, _ := time.Parse("2006-1-2 15:04:05", dateStr)
  1155. // year, month, day := date.Date()
  1156. // endTime := time.Date(year, month, day+7, 0, 0, 0, 0, time.Local)
  1157. // years, months, days := time.Now().Date()
  1158. // todayTime := time.Date(years, months, days, 0, 0, 0, 0, time.Local)
  1159. // diffDay = endTime.Sub(todayTime).Hours() / 24
  1160. //
  1161. // break
  1162. // case 2:
  1163. // tm := time.Unix(config.CreateTime, 0)
  1164. // dateStr := tm.Format("2006-1-2") + " 00:00:00"
  1165. // date, _ := time.Parse("2006-1-2 15:04:05", dateStr)
  1166. // year, month, day := date.Date()
  1167. // endTime := time.Date(year, month, day+14, 0, 0, 0, 0, time.Local)
  1168. // years, months, days := time.Now().Date()
  1169. // todayTime := time.Date(years, months, days, 0, 0, 0, 0, time.Local)
  1170. // diffDay = endTime.Sub(todayTime).Hours() / 24
  1171. //
  1172. // break
  1173. // case 3:
  1174. // tm := time.Unix(config.CreateTime, 0)
  1175. // dateStr := tm.Format("2006-1-2") + " 00:00:00"
  1176. // date, _ := time.Parse("2006-1-2 15:04:05", dateStr)
  1177. // year, month, day := date.Date()
  1178. // endTime := time.Date(year, month+1, day, 0, 0, 0, 0, time.Local)
  1179. // years, months, days := time.Now().Date()
  1180. // todayTime := time.Date(years, months, days, 0, 0, 0, 0, time.Local)
  1181. // diffDay = endTime.Sub(todayTime).Hours() / 24
  1182. //
  1183. // break
  1184. // case 4:
  1185. // tm := time.Unix(config.CreateTime, 0)
  1186. // dateStr := tm.Format("2006-1-2") + " 00:00:00"
  1187. // date, _ := time.Parse("2006-1-2 15:04:05", dateStr)
  1188. // year, month, day := date.Date()
  1189. // endTime := time.Date(year, month+3, day, 0, 0, 0, 0, time.Local)
  1190. // years, months, days := time.Now().Date()
  1191. // todayTime := time.Date(years, months, days, 0, 0, 0, 0, time.Local)
  1192. // diffDay = endTime.Sub(todayTime).Hours() / 24
  1193. //
  1194. // break
  1195. // }
  1196. //
  1197. // return diffDay
  1198. //
  1199. //}
  1200. //
  1201. ////有上报数据记录的时候,使用上报时间来计算下次上报时间
  1202. //func GetDiffDay2(config *sz.DataUploadConfig, updateDate sz.DataUpload) float64 {
  1203. // var diffDay float64
  1204. // switch config.TimeQuantum {
  1205. // case 1:
  1206. // tm := time.Unix(updateDate.UploadDate, 0)
  1207. // dateStr := tm.Format("2006-1-2") + " 00:00:00"
  1208. // date, _ := time.Parse("2006-1-2 15:04:05", dateStr)
  1209. // year, month, day := date.Date()
  1210. // endTime := time.Date(year, month, day+7, 0, 0, 0, 0, time.Local)
  1211. // years, months, days := time.Now().Date()
  1212. // todayTime := time.Date(years, months, days, 0, 0, 0, 0, time.Local)
  1213. // diffDay = endTime.Sub(todayTime).Hours() / 24 //透析日期1年与当前天数差
  1214. //
  1215. // break
  1216. // case 2:
  1217. // tm := time.Unix(updateDate.UploadDate, 0)
  1218. // dateStr := tm.Format("2006-1-2") + " 00:00:00"
  1219. // date, _ := time.Parse("2006-1-2 15:04:05", dateStr)
  1220. // year, month, day := date.Date()
  1221. // endTime := time.Date(year, month, day+14, 0, 0, 0, 0, time.Local)
  1222. // years, months, days := time.Now().Date()
  1223. // todayTime := time.Date(years, months, days, 0, 0, 0, 0, time.Local)
  1224. // diffDay = endTime.Sub(todayTime).Hours() / 24 //透析日期1年与当前天数差
  1225. //
  1226. // break
  1227. // case 3:
  1228. // tm := time.Unix(updateDate.UploadDate, 0)
  1229. // dateStr := tm.Format("2006-1-2") + " 00:00:00"
  1230. // date, _ := time.Parse("2006-1-2 15:04:05", dateStr)
  1231. // year, month, day := date.Date()
  1232. // endTime := time.Date(year, month+1, day, 0, 0, 0, 0, time.Local)
  1233. // years, months, days := time.Now().Date()
  1234. // todayTime := time.Date(years, months, days, 0, 0, 0, 0, time.Local)
  1235. // diffDay = endTime.Sub(todayTime).Hours() / 24 //透析日期1年与当前天数差
  1236. //
  1237. // break
  1238. // case 4:
  1239. // tm := time.Unix(updateDate.UploadDate, 0)
  1240. // dateStr := tm.Format("2006-1-2") + " 00:00:00"
  1241. // date, _ := time.Parse("2006-1-2 15:04:05", dateStr)
  1242. // year, month, day := date.Date()
  1243. // endTime := time.Date(year, month+3, day, 0, 0, 0, 0, time.Local)
  1244. // years, months, days := time.Now().Date()
  1245. // todayTime := time.Date(years, months, days, 0, 0, 0, 0, time.Local)
  1246. // diffDay = endTime.Sub(todayTime).Hours() / 24 //透析日期1年与当前天数差
  1247. //
  1248. // break
  1249. // }
  1250. //
  1251. // return diffDay
  1252. //
  1253. //}