schedule_api_controller.go 67KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/jinzhu/gorm"
  10. "reflect"
  11. "strconv"
  12. "strings"
  13. "time"
  14. "github.com/astaxie/beego"
  15. )
  16. type ScheduleApiController struct {
  17. BaseAuthAPIController
  18. }
  19. func ScheduleApiRegistRouters() {
  20. beego.Router("/api/schedule/weekpanel", &ScheduleApiController{}, "Get:GetWeekPanels")
  21. beego.Router("/api/schedule/schedules", &ScheduleApiController{}, "Get:GetSchedules")
  22. beego.Router("/api/excel_date/init", &ScheduleApiController{}, "Get:GetInitExcelInitDate")
  23. beego.Router("/api/schedule/patients", &ScheduleApiController{}, "Get:GetPatients")
  24. beego.Router("/api/schedule/create", &ScheduleApiController{}, "Post:CreateSchedule")
  25. beego.Router("/api/schedule/delete", &ScheduleApiController{}, "Delete:DeleteSchedule")
  26. beego.Router("/api/schedule/change", &ScheduleApiController{}, "Put:ChangeSchedule")
  27. beego.Router("/api/schedule/urgentinit", &ScheduleApiController{}, "Get:UrgentScheduleData")
  28. beego.Router("/api/schedule/print/initdata", &ScheduleApiController{}, "get:PrintInitData")
  29. beego.Router("/api/schedule/search", &ScheduleApiController{}, "get:SearchSchedulePatients")
  30. beego.Router("/api/schedule/week", &ScheduleApiController{}, "get:GetWeekDaySchedule")
  31. beego.Router("/api/schedule/export", &ScheduleApiController{}, "post:ExportSchedule")
  32. beego.Router("/api/schedule_template/export", &ScheduleApiController{}, "post:ExportScheduleTemplate")
  33. beego.Router("/api/schedule_template/search", &ScheduleApiController{}, "get:SearchTemplateSchedulePatients")
  34. beego.Router("/api/schedule_template/cancel", &ScheduleApiController{}, "post:CancelScheduleTemplate")
  35. beego.Router("/api/schedule/getnextscheduleweekday", &ScheduleApiController{}, "Get:GetNextWeekDaySchedule")
  36. beego.Router("/api/schedule/getthreeweeklist", &ScheduleApiController{}, "Get:GetThreeWeekList")
  37. beego.Router("/api/schedule/getallzones", &ScheduleApiController{}, "Get:GetAllZones")
  38. beego.Router("/api/schedule/copypatientschedules", &ScheduleApiController{}, "Get:GetCopyPatientSchedules")
  39. }
  40. func (c *ScheduleApiController) GetWeekPanels() {
  41. data, _ := c.GetInt64("data", 1)
  42. patitionId, _ := c.GetInt64("patitionid")
  43. adminInfo := c.GetAdminUserInfo()
  44. thisTime := time.Now()
  45. year, monthTime, day := thisTime.Date()
  46. month := int(monthTime)
  47. _, theWeek := thisTime.ISOWeek()
  48. weekDay := int(thisTime.Weekday())
  49. if weekDay == 0 {
  50. weekDay = 7
  51. }
  52. weekEnd := 7 - weekDay
  53. weekStart := weekEnd - 6
  54. weekDays := make([]string, 0)
  55. for index := weekStart; index <= weekEnd; index++ {
  56. theDay := thisTime.AddDate(0, 0, index)
  57. indexYear, indexMonthTime, indexDay := theDay.Date()
  58. indexMonth := int(indexMonthTime)
  59. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  60. weekDays = append(weekDays, indexWeek)
  61. }
  62. returnData := map[string]interface{}{
  63. "year": year,
  64. "month": month,
  65. "day": day,
  66. "theWeek": theWeek,
  67. "weekDay": weekDay,
  68. "weekDays": weekDays,
  69. }
  70. if data == 1 {
  71. partitions, _ := service.GetSchedulePartitionPanelOne(adminInfo.CurrentOrgId, patitionId)
  72. returnData["partitions"] = partitions
  73. }
  74. c.ServeSuccessJSON(returnData)
  75. return
  76. }
  77. func (c *ScheduleApiController) GetSchedules() {
  78. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  79. partition_id, _ := c.GetInt64("partition_id")
  80. schedule_type, _ := c.GetInt64("schedule_type")
  81. adminInfo := c.GetAdminUserInfo()
  82. thisTime := time.Now()
  83. today := thisTime.Format("2006-01-02")
  84. if week < 1 || week > 4 {
  85. week = 2
  86. }
  87. if week == 1 {
  88. thisTime = thisTime.AddDate(0, 0, -7)
  89. } else if week == 3 {
  90. thisTime = thisTime.AddDate(0, 0, 7)
  91. } else if week == 4 {
  92. thisTime = thisTime.AddDate(0, 0, 14)
  93. }
  94. weekDay := int(thisTime.Weekday())
  95. if weekDay == 0 {
  96. weekDay = 7
  97. }
  98. weekEnd := 7 - weekDay
  99. weekStart := weekEnd - 6
  100. weekTitle := make([]string, 0)
  101. days := make([]string, 0)
  102. for index := weekStart; index <= weekEnd; index++ {
  103. theDay := thisTime.AddDate(0, 0, index)
  104. indexYear, indexMonthTime, indexDay := theDay.Date()
  105. indexMonth := int(indexMonthTime)
  106. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  107. weekTitle = append(weekTitle, indexWeek)
  108. days = append(days, theDay.Format("2006-01-02"))
  109. }
  110. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  111. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  112. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  113. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  114. timeLayout := "2006-01-02 15:04:05"
  115. loc, _ := time.LoadLocation("Local")
  116. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  117. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  118. weekStartPoint := theStarTime.Unix()
  119. weekEndPoint := theEndTime.Unix()
  120. schdules, _ := service.GetWeekScheduleOne(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, partition_id, schedule_type)
  121. c.ServeSuccessJSON(map[string]interface{}{
  122. "days": days,
  123. "weekTitle": weekTitle,
  124. "schdules": schdules,
  125. "today": today,
  126. })
  127. return
  128. }
  129. func (c *ScheduleApiController) GetPatients() {
  130. keywords := c.GetString("keywords", "")
  131. schedule, _ := c.GetInt64("schedule", 0) //1已2未
  132. contagion, _ := c.GetInt64("contagion", 0)
  133. adminInfo := c.GetAdminUserInfo()
  134. thisTime := time.Now()
  135. weekDay := int(thisTime.Weekday())
  136. if weekDay == 0 {
  137. weekDay = 7
  138. }
  139. thisWeekEnd := 7 - weekDay
  140. weekStartPoint := thisWeekEnd - 6
  141. weekStartDay := thisTime.AddDate(0, 0, weekStartPoint)
  142. weekEndPoint := thisWeekEnd + 7
  143. weekEndDay := thisTime.AddDate(0, 0, weekEndPoint)
  144. fmt.Println(weekStartPoint, weekStartDay, weekEndPoint, weekEndDay)
  145. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  146. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  147. fmt.Println(weekStartTime, weekEndTime)
  148. timeLayout := "2006-01-02 15:04:05"
  149. loc, _ := time.LoadLocation("Local")
  150. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  151. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  152. weekStart := theStarTime.Unix()
  153. weekEnd := theEndTime.Unix()
  154. patients, _ := service.GetPatientWithScheduleAndSolution(adminInfo.CurrentOrgId, keywords, weekStart, weekEnd, schedule, contagion)
  155. c.ServeSuccessJSON(map[string]interface{}{
  156. "patients": patients,
  157. })
  158. return
  159. }
  160. func (c *ScheduleApiController) CreateSchedule() {
  161. patientID, _ := c.GetInt64("patient_id", 0)
  162. if patientID <= 0 {
  163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  164. return
  165. }
  166. adminUserInfo := c.GetAdminUserInfo()
  167. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patientID)
  168. if patientInfo.ID == 0 {
  169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  170. return
  171. }
  172. var schedule models.Schedule
  173. dataBody := make(map[string]interface{}, 0)
  174. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  175. if err != nil {
  176. utils.ErrorLog(err.Error())
  177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  178. return
  179. }
  180. if dataBody["schedule_date"] == nil || reflect.TypeOf(dataBody["schedule_date"]).String() != "string" {
  181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  182. return
  183. }
  184. scheduleDate, _ := dataBody["schedule_date"].(string)
  185. if len(scheduleDate) == 0 {
  186. utils.ErrorLog("len(schedule_date) == 0")
  187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  188. return
  189. }
  190. timeLayout := "2006-01-02"
  191. loc, _ := time.LoadLocation("Local")
  192. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  193. if err != nil {
  194. utils.ErrorLog(err.Error())
  195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  196. return
  197. }
  198. schedule.ScheduleDate = theTime.Unix()
  199. timeNow := time.Now().Format("2006-01-02")
  200. if timeNow > scheduleDate {
  201. utils.ErrorLog(timeNow)
  202. utils.ErrorLog(scheduleDate)
  203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  204. return
  205. }
  206. if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
  207. utils.ErrorLog("schedule_type")
  208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  209. return
  210. }
  211. scheduleType := int64(dataBody["schedule_type"].(float64))
  212. if scheduleType < 1 || scheduleType > 3 {
  213. utils.ErrorLog("scheduleType < 3")
  214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  215. return
  216. }
  217. schedule.ScheduleType = scheduleType
  218. if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
  219. utils.ErrorLog("bed_id")
  220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  221. return
  222. }
  223. bedId := int64(dataBody["bed_id"].(float64))
  224. if bedId < 1 {
  225. utils.ErrorLog("bedId < 1")
  226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  227. return
  228. }
  229. schedule.BedId = bedId
  230. if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
  231. utils.ErrorLog("partition_id")
  232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  233. return
  234. }
  235. partitionId := int64(dataBody["partition_id"].(float64))
  236. if partitionId < 1 {
  237. utils.ErrorLog("partitionId < 1")
  238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  239. return
  240. }
  241. schedule.PartitionId = partitionId
  242. if dataBody["schedule_week"] == nil || reflect.TypeOf(dataBody["schedule_week"]).String() != "float64" {
  243. utils.ErrorLog("schedule_week")
  244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  245. return
  246. }
  247. scheduleWeek := int64(dataBody["schedule_week"].(float64))
  248. if scheduleWeek < 1 || scheduleWeek > 7 {
  249. utils.ErrorLog("scheduleWeek < 1")
  250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  251. return
  252. }
  253. schedule.ScheduleWeek = scheduleWeek
  254. if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
  255. utils.ErrorLog("mode_id")
  256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  257. return
  258. }
  259. modeId := int64(dataBody["mode_id"].(float64))
  260. if modeId < 1 && modeId > 14 {
  261. utils.ErrorLog("modeId < 1")
  262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  263. return
  264. }
  265. schedule.ModeId = modeId
  266. schedule.PatientId = patientID
  267. schedule.CreatedTime = time.Now().Unix()
  268. schedule.UpdatedTime = time.Now().Unix()
  269. schedule.Status = 1
  270. schedule.UserOrgId = adminUserInfo.CurrentOrgId
  271. bed, _ := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, schedule.BedId)
  272. if bed == nil {
  273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  274. return
  275. }
  276. if bed.ZoneID != schedule.PartitionId {
  277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  278. return
  279. }
  280. scheduleDateStart := scheduleDate + " 00:00:00"
  281. scheduleDateEnd := scheduleDate + " 23:59:59"
  282. timeLayout = "2006-01-02 15:04:05"
  283. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  284. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  285. startTime := theStartTime.Unix()
  286. endTime := theEndTime.Unix()
  287. //一天只有排班一次
  288. daySchedule, err := service.GetDaySchedule(adminUserInfo.CurrentOrgId, startTime, endTime, patientID)
  289. if daySchedule.ID > 0 {
  290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  291. return
  292. }
  293. //同天同位置只能排一个
  294. pointSchedule, err := service.GetPointSchedule(adminUserInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  295. if err != nil {
  296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  297. return
  298. }
  299. if pointSchedule.ID > 0 {
  300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  301. return
  302. }
  303. redis := service.RedisClient()
  304. defer redis.Close()
  305. err = service.CreateSchedule(&schedule)
  306. key := "scheduals_" + scheduleDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  307. redis.Set(key, "", time.Second)
  308. fmt.Println(err)
  309. if err != nil {
  310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateScheduleFail)
  311. return
  312. }
  313. schedule.Patient = patientInfo.Name
  314. c.ServeSuccessJSON(map[string]interface{}{
  315. "msg": "ok",
  316. "schedule": schedule,
  317. })
  318. return
  319. }
  320. func (c *ScheduleApiController) DeleteSchedule() {
  321. id, _ := c.GetInt64("id", 0)
  322. if id <= 0 {
  323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  324. return
  325. }
  326. adminINfo := c.GetAdminUserInfo()
  327. schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  328. if schedule == nil {
  329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  330. return
  331. }
  332. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  333. if err != nil {
  334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  335. return
  336. }
  337. if order != nil {
  338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysis)
  339. return
  340. }
  341. schedule.Status = 0
  342. schedule.UpdatedTime = time.Now().Unix()
  343. err = service.UpdateSchedule(schedule)
  344. if err != nil {
  345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteScheduleFail)
  346. return
  347. }
  348. c.ServeSuccessJSON(map[string]interface{}{
  349. "msg": "ok",
  350. "schedule": &schedule,
  351. })
  352. }
  353. func (c *ScheduleApiController) ChangeSchedule() {
  354. id, _ := c.GetInt64("id", 0)
  355. if id <= 0 {
  356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  357. return
  358. }
  359. adminINfo := c.GetAdminUserInfo()
  360. schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  361. if schedule == nil {
  362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  363. return
  364. }
  365. dataBody := make(map[string]interface{}, 0)
  366. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  367. if err != nil {
  368. utils.ErrorLog(err.Error())
  369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  370. return
  371. }
  372. if dataBody["change_action"] == nil || reflect.TypeOf(dataBody["change_action"]).String() != "string" {
  373. utils.ErrorLog("change_action")
  374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  375. return
  376. }
  377. changeAction := dataBody["change_action"].(string)
  378. if changeAction == "change_mode" {
  379. if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
  380. utils.ErrorLog("mode_id")
  381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  382. return
  383. }
  384. modeId := int64(dataBody["mode_id"].(float64))
  385. if modeId < 1 {
  386. utils.ErrorLog("modeId < 1")
  387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  388. return
  389. }
  390. schedule.ModeId = modeId
  391. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  392. if err != nil {
  393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  394. return
  395. }
  396. if order != nil {
  397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeMode)
  398. return
  399. }
  400. } else if changeAction == "change_device" {
  401. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  402. if err != nil {
  403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  404. return
  405. }
  406. if order != nil {
  407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeDeviceNumber)
  408. return
  409. }
  410. if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
  411. utils.ErrorLog("schedule_type")
  412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  413. return
  414. }
  415. scheduleType := int64(dataBody["schedule_type"].(float64))
  416. if scheduleType < 1 || scheduleType > 3 {
  417. utils.ErrorLog("scheduleType < 3")
  418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  419. return
  420. }
  421. schedule.ScheduleType = scheduleType
  422. if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
  423. utils.ErrorLog("bed_id")
  424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  425. return
  426. }
  427. bedId := int64(dataBody["bed_id"].(float64))
  428. if bedId < 1 {
  429. utils.ErrorLog("bedId < 1")
  430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  431. return
  432. }
  433. schedule.BedId = bedId
  434. if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
  435. utils.ErrorLog("partition_id")
  436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  437. return
  438. }
  439. partitionId := int64(dataBody["partition_id"].(float64))
  440. if partitionId < 1 {
  441. utils.ErrorLog("partitionId < 1")
  442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  443. return
  444. }
  445. schedule.PartitionId = partitionId
  446. bed, _ := service.GetDeviceNumberByID(adminINfo.CurrentOrgId, schedule.BedId)
  447. if bed == nil {
  448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  449. return
  450. }
  451. if bed.ZoneID != schedule.PartitionId {
  452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  453. return
  454. }
  455. startTime := schedule.ScheduleDate
  456. endTime := startTime + 86399
  457. //一天只有排班一次
  458. daySchedule, err := service.GetDaySchedule(adminINfo.CurrentOrgId, startTime, endTime, schedule.PatientId)
  459. if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
  460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  461. return
  462. }
  463. //同天同位置只能排一个
  464. pointSchedule, err := service.GetPointSchedule(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  465. if err != nil {
  466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  467. return
  468. }
  469. if pointSchedule.ID > 0 {
  470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  471. return
  472. }
  473. } else {
  474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  475. return
  476. }
  477. schedule.UpdatedTime = time.Now().Unix()
  478. err = service.UpdateSchedule(schedule)
  479. prescription := models.DialysisPrescription{
  480. ModeId: schedule.ModeId,
  481. }
  482. _, errcode := service.GetDialysisPrescribe(schedule.UserOrgId, schedule.PatientId, schedule.ScheduleDate)
  483. if errcode == gorm.ErrRecordNotFound {
  484. if err != nil {
  485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
  486. return
  487. }
  488. c.ServeSuccessJSON(map[string]interface{}{
  489. "msg": "ok",
  490. "schedule": &schedule,
  491. })
  492. } else if errcode == nil {
  493. err = service.UpdatedDialysisPrescription(&prescription, schedule.ScheduleDate, schedule.PatientId, schedule.UserOrgId)
  494. if err != nil {
  495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
  496. return
  497. }
  498. c.ServeSuccessJSON(map[string]interface{}{
  499. "msg": "ok",
  500. "schedule": &schedule,
  501. })
  502. }
  503. }
  504. // /api/schedule/print/initdata [get]
  505. // @param date:string yyyy-MM-dd 要打印的那一周中的任一天
  506. func (this *ScheduleApiController) PrintInitData() {
  507. dateStr := this.GetString("date")
  508. //week_type, _ := this.GetInt64("type", 0)
  509. var date *time.Time
  510. if len(dateStr) == 0 {
  511. now := time.Now()
  512. date = &now
  513. } else {
  514. var parseErr error
  515. date, parseErr = utils.ParseTimeStringToTime("2006-01-02", dateStr)
  516. if parseErr != nil {
  517. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  518. return
  519. }
  520. }
  521. adminUserInfo := this.GetAdminUserInfo()
  522. // 获取本周的排班
  523. var monday time.Time
  524. var sunday time.Time
  525. //switch week_type {
  526. //case 1:
  527. monday, sunday = utils.GetMondayAndSundayOfWeekDate(date)
  528. // break
  529. //case 2:
  530. // monday, sunday = utils.GetMondayAndSundayOfNextWeekDate(date)
  531. //
  532. // break
  533. //case 3:
  534. // monday, sunday = utils.GetMondayAndSundayOfNextNextWeekDate(date)
  535. // break
  536. //}
  537. schedules, getScheduleErr := service.GetPrinitWeekSchedules(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
  538. total, getScheduleErr := service.GetPrinitWeekTotal(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
  539. if getScheduleErr != nil {
  540. this.ErrorLog("获取周排班失败:%v", getScheduleErr)
  541. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  542. return
  543. }
  544. thisTime := date
  545. weekDay := int(thisTime.Weekday())
  546. if weekDay == 0 {
  547. weekDay = 7
  548. }
  549. weekEnd := 7 - weekDay
  550. weekStart := weekEnd - 6
  551. days := make([]string, 0)
  552. for index := weekStart; index <= weekEnd; index++ {
  553. theDay := thisTime.AddDate(0, 0, index)
  554. days = append(days, theDay.Format("2006-01-02"))
  555. }
  556. this.ServeSuccessJSON(map[string]interface{}{
  557. "total": total,
  558. "schedules": schedules,
  559. "monday": monday.Unix(),
  560. "days": days,
  561. })
  562. }
  563. func (this *ScheduleApiController) UrgentScheduleData() {
  564. schedule_type, _ := this.GetInt("type", 0)
  565. schedule_date := this.GetString("date")
  566. var date *time.Time
  567. if len(schedule_date) == 0 {
  568. now := time.Now()
  569. date = &now
  570. } else {
  571. var parseErr error
  572. date, parseErr = utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  573. if parseErr != nil {
  574. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  575. return
  576. }
  577. }
  578. adminUserInfo := this.GetAdminUserInfo()
  579. deviceNumbers, getDeviceNumbersErr := service.MobileGetAllDeviceNumbersForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  580. if getDeviceNumbersErr != nil {
  581. this.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
  582. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  583. return
  584. }
  585. // today := utils.ZeroHourTimeOfDay(time.Now())
  586. schedules, getSchedulesErr := service.MobileGetOtherSchedulesForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  587. if getSchedulesErr != nil {
  588. this.ErrorLog("获取所有排班失败:%v", getSchedulesErr)
  589. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  590. return
  591. }
  592. this.ServeSuccessJSON(map[string]interface{}{
  593. "device_numbers": deviceNumbers,
  594. "schedules": schedules,
  595. })
  596. }
  597. func (this *ScheduleApiController) SearchSchedulePatients() {
  598. keywords := this.GetString("keywords")
  599. week_type, _ := this.GetInt64("week_type", 0)
  600. thisTime1 := time.Now()
  601. thisTime2 := time.Now()
  602. thisTime1 = thisTime1.AddDate(0, 0, 7)
  603. thisTime2 = thisTime2.AddDate(0, 0, 14)
  604. var start_time string
  605. var end_time string
  606. switch week_type {
  607. case 1:
  608. adminUserInfo := this.GetAdminUserInfo()
  609. list, _ := service.GetSchedualPatientsByKeywords(keywords, adminUserInfo.CurrentOrgId)
  610. this.ServeSuccessJSON(map[string]interface{}{
  611. "schdules": list,
  612. })
  613. break
  614. case 2:
  615. days := make([]string, 0)
  616. weekDay1 := int(thisTime1.Weekday())
  617. if weekDay1 == 0 {
  618. weekDay1 = 7
  619. }
  620. weekEnd1 := 7 - weekDay1
  621. weekStart1 := weekEnd1 - 6
  622. for index := weekStart1; index <= weekEnd1; index++ {
  623. fmt.Println(index)
  624. theDay := thisTime1.AddDate(0, 0, index)
  625. days = append(days, theDay.Format("2006-01-02"))
  626. }
  627. fmt.Println(days)
  628. start_time = days[0]
  629. end_time = days[len(days)-1]
  630. timeLayout := "2006-01-02"
  631. loc, _ := time.LoadLocation("Local")
  632. var theStartTime int64
  633. if len(start_time) > 0 {
  634. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  635. theStartTime = theTime.Unix()
  636. }
  637. var theEndtTime int64
  638. if len(end_time) > 0 {
  639. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  640. theEndtTime = theTime.Unix()
  641. }
  642. adminUserInfo := this.GetAdminUserInfo()
  643. list, _ := service.GetSchedualPatientsByKeywordsAndWeek(keywords, adminUserInfo.CurrentOrgId, theStartTime, theEndtTime)
  644. this.ServeSuccessJSON(map[string]interface{}{
  645. "schdules": list,
  646. })
  647. break
  648. case 3:
  649. days := make([]string, 0)
  650. weekDay2 := int(thisTime2.Weekday())
  651. if weekDay2 == 0 {
  652. weekDay2 = 7
  653. }
  654. weekEnd2 := 7 - weekDay2
  655. weekStart2 := weekEnd2 - 6
  656. for index := weekStart2; index <= weekEnd2; index++ {
  657. theDay := thisTime2.AddDate(0, 0, index)
  658. days = append(days, theDay.Format("2006-01-02"))
  659. }
  660. start_time = days[0]
  661. end_time = days[len(days)-1]
  662. timeLayout := "2006-01-02"
  663. loc, _ := time.LoadLocation("Local")
  664. var theStartTime int64
  665. if len(start_time) > 0 {
  666. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  667. theStartTime = theTime.Unix()
  668. }
  669. var theEndtTime int64
  670. if len(end_time) > 0 {
  671. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  672. theEndtTime = theTime.Unix()
  673. }
  674. adminUserInfo := this.GetAdminUserInfo()
  675. list, _ := service.GetSchedualPatientsByKeywordsAndWeek(keywords, adminUserInfo.CurrentOrgId, theStartTime, theEndtTime)
  676. this.ServeSuccessJSON(map[string]interface{}{
  677. "schdules": list,
  678. })
  679. break
  680. }
  681. }
  682. func (this *ScheduleApiController) GetWeekDaySchedule() {
  683. week_type, _ := this.GetInt64("week_type", -1)
  684. week_time, _ := this.GetInt64("week_time")
  685. thisTime := time.Now()
  686. weekDay := int(thisTime.Weekday())
  687. if weekDay == 0 {
  688. weekDay = 7
  689. }
  690. weekEnd := 7 - weekDay
  691. weekStart := weekEnd - 6
  692. weekTitle := make([]string, 0)
  693. days := make([]string, 0)
  694. for index := weekStart; index <= weekEnd; index++ {
  695. theDay := thisTime.AddDate(0, 0, index)
  696. indexYear, indexMonthTime, indexDay := theDay.Date()
  697. indexMonth := int(indexMonthTime)
  698. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  699. weekTitle = append(weekTitle, indexWeek)
  700. days = append(days, theDay.Format("2006-01-02"))
  701. }
  702. fmt.Println(days)
  703. var targetDayStr string
  704. switch week_type {
  705. case 1:
  706. targetDayStr = days[0]
  707. break
  708. case 2:
  709. targetDayStr = days[1]
  710. break
  711. case 3:
  712. targetDayStr = days[2]
  713. break
  714. case 4:
  715. targetDayStr = days[3]
  716. break
  717. case 5:
  718. targetDayStr = days[4]
  719. break
  720. case 6:
  721. targetDayStr = days[5]
  722. break
  723. case 7:
  724. targetDayStr = days[6]
  725. break
  726. }
  727. targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  728. if parseErr != nil {
  729. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  730. return
  731. }
  732. adminUserInfo := this.GetAdminUserInfo()
  733. list, _ := service.GetWeekDayScheduleTwo(adminUserInfo.CurrentOrgId, targetDay.Unix(), targetDay, week_time)
  734. this.ServeSuccessJSON(map[string]interface{}{
  735. "schdules": list,
  736. "day": targetDayStr,
  737. })
  738. }
  739. func Struct2Map(obj interface{}) map[string]interface{} {
  740. t := reflect.TypeOf(obj)
  741. v := reflect.ValueOf(obj)
  742. var data = make(map[string]interface{})
  743. for i := 0; i < t.NumField(); i++ {
  744. data[t.Field(i).Name] = v.Field(i).Interface()
  745. }
  746. return data
  747. }
  748. func (this *ScheduleApiController) ExportSchedule() {
  749. dataBody := make(map[string]interface{}, 0)
  750. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  751. if err != nil {
  752. utils.ErrorLog(err.Error())
  753. return
  754. }
  755. utils.ErrorLog("%v", dataBody)
  756. export_time := time.Now().Unix()
  757. var schedules []*models.Schedule
  758. var failed_total int
  759. var total_schedule []interface{}
  760. var patients []*models.Patients
  761. patients, _, _ = service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  762. if dataBody["failed_schedule"] != nil || reflect.TypeOf(dataBody["failed_schedule"]).String() == "[]interface {}" {
  763. tempSchedule := dataBody["failed_schedule"].([]interface{})
  764. failed_total = len(tempSchedule)
  765. }
  766. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  767. tempSchedule := dataBody["schedule"].([]interface{})
  768. total_schedule = tempSchedule
  769. for _, schMap := range tempSchedule {
  770. schMapM := schMap.(map[string]interface{})
  771. var sch models.Schedule
  772. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  773. utils.ErrorLog("name")
  774. return
  775. }
  776. name, _ := schMapM["name"].(string)
  777. fmt.Println(name)
  778. if len(name) == 0 { //名字为空则生成一条导入错误日志
  779. err_log := models.ExportErrLog{
  780. LogType: 2,
  781. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  782. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  783. Status: 1,
  784. CreateTime: time.Now().Unix(),
  785. UpdateTime: time.Now().Unix(),
  786. ExportTime: export_time,
  787. }
  788. service.CreateExportErrLog(&err_log)
  789. continue
  790. } else {
  791. var patient []*models.Patients
  792. for _, item := range patients {
  793. if strings.Replace(item.Name, " ", "", -1) == name {
  794. patient = append(patient, item)
  795. }
  796. }
  797. if len(patient) == 0 { //错误日志
  798. err_log := models.ExportErrLog{
  799. LogType: 2,
  800. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  801. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  802. Status: 1,
  803. CreateTime: time.Now().Unix(),
  804. UpdateTime: time.Now().Unix(),
  805. ExportTime: export_time,
  806. }
  807. service.CreateExportErrLog(&err_log)
  808. continue
  809. } else if len(patient) == 1 { //
  810. sch.PatientId = patient[0].ID
  811. } else if len(patient) > 1 { //出现同名的情况
  812. err_log := models.ExportErrLog{
  813. LogType: 2,
  814. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  815. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  816. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在在当前机构中存在重名,无法确定到具体患者",
  817. Status: 1,
  818. CreateTime: time.Now().Unix(),
  819. UpdateTime: time.Now().Unix(),
  820. ExportTime: export_time,
  821. }
  822. service.CreateExportErrLog(&err_log)
  823. continue
  824. }
  825. }
  826. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  827. utils.ErrorLog("schedule_type")
  828. return
  829. }
  830. schedule_type := int64(schMapM["schedule_type"].(float64))
  831. if schedule_type <= 0 { //班次格式有误,插入日志
  832. log := models.ExportLog{
  833. LogType: 2,
  834. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  835. TotalNum: int64(len(total_schedule) + failed_total),
  836. FailNum: 1 + int64(failed_total),
  837. SuccessNum: int64(len(schedules)),
  838. CreateTime: time.Now().Unix(),
  839. UpdateTime: time.Now().Unix(),
  840. ExportTime: export_time,
  841. Status: 1,
  842. }
  843. service.CreateExportLog(&log)
  844. err_log := models.ExportErrLog{
  845. LogType: 2,
  846. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  847. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  848. Status: 1,
  849. CreateTime: time.Now().Unix(),
  850. UpdateTime: time.Now().Unix(),
  851. ExportTime: export_time,
  852. }
  853. service.CreateExportErrLog(&err_log)
  854. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  855. return
  856. } else {
  857. sch.ScheduleType = schedule_type
  858. }
  859. if schMapM["partition_name"] == nil || reflect.TypeOf(schMapM["partition_name"]).String() != "string" {
  860. utils.ErrorLog("partition_name")
  861. return
  862. }
  863. partition_name, _ := schMapM["partition_name"].(string)
  864. if len(partition_name) == 0 { //分区为空
  865. log := models.ExportLog{
  866. LogType: 2,
  867. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  868. TotalNum: int64(len(total_schedule) + failed_total),
  869. FailNum: 1 + int64(failed_total),
  870. SuccessNum: int64(len(schedules)),
  871. CreateTime: time.Now().Unix(),
  872. UpdateTime: time.Now().Unix(),
  873. ExportTime: export_time,
  874. Status: 1,
  875. }
  876. service.CreateExportLog(&log)
  877. err_log := models.ExportErrLog{
  878. LogType: 2,
  879. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  880. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  881. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  882. Status: 1,
  883. CreateTime: time.Now().Unix(),
  884. UpdateTime: time.Now().Unix(),
  885. ExportTime: export_time,
  886. }
  887. service.CreateExportErrLog(&err_log)
  888. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  889. return
  890. } else {
  891. zone, err := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  892. if err == nil {
  893. sch.PartitionId = zone.ID
  894. } else if err == gorm.ErrRecordNotFound { //查不到数据,插入错误日志
  895. log := models.ExportLog{
  896. LogType: 2,
  897. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  898. TotalNum: int64(len(total_schedule) + failed_total),
  899. FailNum: 1 + int64(failed_total),
  900. SuccessNum: int64(len(schedules)),
  901. CreateTime: time.Now().Unix(),
  902. UpdateTime: time.Now().Unix(),
  903. ExportTime: export_time,
  904. Status: 1,
  905. }
  906. service.CreateExportLog(&log)
  907. err_log := models.ExportErrLog{
  908. LogType: 2,
  909. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  910. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  911. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  912. Status: 1,
  913. CreateTime: time.Now().Unix(),
  914. UpdateTime: time.Now().Unix(),
  915. ExportTime: export_time,
  916. }
  917. service.CreateExportErrLog(&err_log)
  918. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  919. return
  920. }
  921. }
  922. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  923. utils.ErrorLog("device_number_name")
  924. return
  925. }
  926. device_number_name, _ := schMapM["device_number_name"].(string)
  927. if len(device_number_name) == 0 { //分区为空
  928. log := models.ExportLog{
  929. LogType: 2,
  930. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  931. TotalNum: int64(len(total_schedule) + failed_total),
  932. FailNum: 1 + int64(failed_total),
  933. SuccessNum: int64(len(schedules)),
  934. CreateTime: time.Now().Unix(),
  935. UpdateTime: time.Now().Unix(),
  936. ExportTime: export_time,
  937. Status: 1,
  938. }
  939. service.CreateExportLog(&log)
  940. err_log := models.ExportErrLog{
  941. LogType: 2,
  942. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  943. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  944. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  945. Status: 1,
  946. CreateTime: time.Now().Unix(),
  947. UpdateTime: time.Now().Unix(),
  948. ExportTime: export_time,
  949. }
  950. service.CreateExportErrLog(&err_log)
  951. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  952. return
  953. } else {
  954. device, err := service.FindDeviceByName(device_number_name, this.GetAdminUserInfo().CurrentOrgId, sch.PartitionId)
  955. if err == nil {
  956. if len(device) == 0 { //没查到数据,插入错误日志
  957. log := models.ExportLog{
  958. LogType: 2,
  959. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  960. TotalNum: int64(len(total_schedule) + failed_total),
  961. FailNum: 1 + int64(failed_total),
  962. SuccessNum: int64(len(schedules)),
  963. CreateTime: time.Now().Unix(),
  964. UpdateTime: time.Now().Unix(),
  965. ExportTime: export_time,
  966. Status: 1,
  967. }
  968. service.CreateExportLog(&log)
  969. err_log := models.ExportErrLog{
  970. LogType: 2,
  971. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  972. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  973. Status: 1,
  974. CreateTime: time.Now().Unix(),
  975. UpdateTime: time.Now().Unix(),
  976. ExportTime: export_time,
  977. }
  978. service.CreateExportErrLog(&err_log)
  979. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  980. return
  981. } else if len(device) == 1 {
  982. sch.BedId = device[0].ID
  983. } else if len(device) > 1 { //出现重名,插入错误日志
  984. log := models.ExportLog{
  985. LogType: 2,
  986. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  987. TotalNum: int64(len(total_schedule) + failed_total),
  988. FailNum: 1 + int64(failed_total),
  989. SuccessNum: int64(len(schedules)),
  990. CreateTime: time.Now().Unix(),
  991. UpdateTime: time.Now().Unix(),
  992. ExportTime: export_time,
  993. Status: 1,
  994. }
  995. service.CreateExportLog(&log)
  996. err_log := models.ExportErrLog{
  997. LogType: 2,
  998. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  999. ErrMsg: "出现两个床位号相同的床位",
  1000. Status: 1,
  1001. CreateTime: time.Now().Unix(),
  1002. UpdateTime: time.Now().Unix(),
  1003. ExportTime: export_time,
  1004. }
  1005. service.CreateExportErrLog(&err_log)
  1006. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1007. return
  1008. }
  1009. }
  1010. }
  1011. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  1012. utils.ErrorLog("schedule_week")
  1013. return
  1014. }
  1015. schedule_week, _ := schMapM["schedule_week"].(string)
  1016. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  1017. log := models.ExportLog{
  1018. LogType: 2,
  1019. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1020. TotalNum: int64(len(total_schedule) + failed_total),
  1021. FailNum: 1 + int64(failed_total),
  1022. SuccessNum: int64(len(schedules)),
  1023. CreateTime: time.Now().Unix(),
  1024. UpdateTime: time.Now().Unix(),
  1025. ExportTime: export_time,
  1026. Status: 1,
  1027. }
  1028. service.CreateExportLog(&log)
  1029. err_log := models.ExportErrLog{
  1030. LogType: 2,
  1031. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1032. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1033. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1034. Status: 1,
  1035. CreateTime: time.Now().Unix(),
  1036. UpdateTime: time.Now().Unix(),
  1037. ExportTime: export_time,
  1038. }
  1039. service.CreateExportErrLog(&err_log)
  1040. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1041. return
  1042. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  1043. log := models.ExportLog{
  1044. LogType: 2,
  1045. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1046. TotalNum: int64(len(total_schedule) + failed_total),
  1047. FailNum: 1 + int64(failed_total),
  1048. SuccessNum: int64(len(schedules)),
  1049. CreateTime: time.Now().Unix(),
  1050. UpdateTime: time.Now().Unix(),
  1051. ExportTime: export_time,
  1052. Status: 1,
  1053. }
  1054. service.CreateExportLog(&log)
  1055. err_log := models.ExportErrLog{
  1056. LogType: 2,
  1057. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1058. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1059. Status: 1,
  1060. CreateTime: time.Now().Unix(),
  1061. UpdateTime: time.Now().Unix(),
  1062. ExportTime: export_time,
  1063. }
  1064. service.CreateExportErrLog(&err_log)
  1065. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1066. return
  1067. } else {
  1068. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  1069. sch.ScheduleWeek = schedule_week
  1070. }
  1071. if schMapM["schedule_date"] == nil || reflect.TypeOf(schMapM["schedule_date"]).String() != "string" {
  1072. utils.ErrorLog("schedule_date")
  1073. return
  1074. }
  1075. schedule_date, _ := schMapM["schedule_date"].(string)
  1076. if len(schedule_date) == 0 { //周几为空则生成一条导入错误日志
  1077. log := models.ExportLog{
  1078. LogType: 2,
  1079. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1080. TotalNum: int64(len(total_schedule) + failed_total),
  1081. FailNum: 1 + int64(failed_total),
  1082. SuccessNum: int64(len(schedules)),
  1083. CreateTime: time.Now().Unix(),
  1084. UpdateTime: time.Now().Unix(),
  1085. ExportTime: export_time,
  1086. Status: 1,
  1087. }
  1088. service.CreateExportLog(&log)
  1089. err_log := models.ExportErrLog{
  1090. LogType: 2,
  1091. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1092. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1093. Status: 1,
  1094. CreateTime: time.Now().Unix(),
  1095. UpdateTime: time.Now().Unix(),
  1096. ExportTime: export_time,
  1097. }
  1098. service.CreateExportErrLog(&err_log)
  1099. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1100. return
  1101. } else if schedule_date == "0" { //周几不符合格式则生成一条导入错误日志
  1102. log := models.ExportLog{
  1103. LogType: 2,
  1104. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1105. TotalNum: int64(len(total_schedule) + failed_total),
  1106. FailNum: 1 + int64(failed_total),
  1107. SuccessNum: int64(len(schedules)),
  1108. CreateTime: time.Now().Unix(),
  1109. UpdateTime: time.Now().Unix(),
  1110. ExportTime: export_time,
  1111. Status: 1,
  1112. }
  1113. service.CreateExportLog(&log)
  1114. err_log := models.ExportErrLog{
  1115. LogType: 2,
  1116. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1117. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1118. Status: 1,
  1119. CreateTime: time.Now().Unix(),
  1120. UpdateTime: time.Now().Unix(),
  1121. ExportTime: export_time,
  1122. }
  1123. service.CreateExportErrLog(&err_log)
  1124. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1125. return
  1126. } else {
  1127. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  1128. sch.ScheduleDate = date.Unix()
  1129. }
  1130. sch.CreatedTime = time.Now().Unix()
  1131. sch.UpdatedTime = time.Now().Unix()
  1132. sch.ModeId = 1
  1133. sch.Status = 1
  1134. sch.UserOrgId = this.GetAdminUserInfo().CurrentOrgId
  1135. sch.IsExport = 1
  1136. schedules = append(schedules, &sch)
  1137. }
  1138. errLogs, _ := service.FindSchedualExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  1139. if len(schedules) > 0 {
  1140. //schedule_date := time.Now().Format("2006-01-02")
  1141. //date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  1142. //clear_schedule_date := date.Unix() //根据日期去清除,该日期未来的排班数据
  1143. //err := service.UpdateScheduleStatus(clear_schedule_date, this.GetAdminUserInfo().CurrentOrgId)
  1144. if err == nil {
  1145. for _, item := range schedules {
  1146. //查找当天日期是否存在
  1147. _, errcode := service.GetTodayScheduleIsExist(item.PatientId, item.ScheduleDate, item.UserOrgId)
  1148. if errcode == gorm.ErrRecordNotFound {
  1149. service.CreateSchedule(item)
  1150. } else if errcode == nil {
  1151. schedule := models.XtSchedule{
  1152. PartitionId: item.PartitionId,
  1153. BedId: item.BedId,
  1154. PatientId: item.PatientId,
  1155. ScheduleDate: item.ScheduleDate,
  1156. ScheduleType: item.ScheduleType,
  1157. ScheduleWeek: item.ScheduleWeek,
  1158. ModeId: item.ModeId,
  1159. Status: 1,
  1160. }
  1161. service.UpdateScheduleByOrgId(item.PatientId, item.ScheduleDate, item.UserOrgId, &schedule)
  1162. }
  1163. }
  1164. log := models.ExportLog{
  1165. LogType: 2,
  1166. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1167. TotalNum: int64(len(total_schedule) + failed_total),
  1168. FailNum: int64(len(errLogs) + failed_total),
  1169. SuccessNum: int64(len(schedules)),
  1170. CreateTime: time.Now().Unix(),
  1171. UpdateTime: time.Now().Unix(),
  1172. ExportTime: export_time,
  1173. Status: 1,
  1174. }
  1175. service.CreateExportLog(&log)
  1176. if failed_total > 0 {
  1177. err_log := models.ExportErrLog{
  1178. LogType: 2,
  1179. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1180. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  1181. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  1182. Status: 1,
  1183. CreateTime: time.Now().Unix(),
  1184. UpdateTime: time.Now().Unix(),
  1185. ExportTime: export_time,
  1186. }
  1187. service.CreateExportErrLog(&err_log)
  1188. }
  1189. this.ServeSuccessJSON(map[string]interface{}{
  1190. "msg": "导入成功",
  1191. "total_num": len(total_schedule) + failed_total,
  1192. "success_num": len(schedules),
  1193. "fail_num": int64(len(errLogs)),
  1194. })
  1195. } else {
  1196. log := models.ExportLog{
  1197. LogType: 2,
  1198. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1199. TotalNum: int64(len(total_schedule) + failed_total),
  1200. FailNum: int64(len(errLogs) + failed_total),
  1201. SuccessNum: int64(len(schedules)),
  1202. CreateTime: time.Now().Unix(),
  1203. UpdateTime: time.Now().Unix(),
  1204. ExportTime: export_time,
  1205. Status: 1,
  1206. }
  1207. service.CreateExportLog(&log)
  1208. if failed_total > 0 {
  1209. err_log := models.ExportErrLog{
  1210. LogType: 2,
  1211. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1212. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  1213. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  1214. Status: 1,
  1215. CreateTime: time.Now().Unix(),
  1216. UpdateTime: time.Now().Unix(),
  1217. ExportTime: export_time,
  1218. }
  1219. service.CreateExportErrLog(&err_log)
  1220. }
  1221. this.ServeSuccessJSON(map[string]interface{}{
  1222. "msg": "导入成功",
  1223. "total_num": len(total_schedule),
  1224. "success_num": len(schedules),
  1225. "fail_num": int64(len(errLogs)),
  1226. })
  1227. }
  1228. } else {
  1229. log := models.ExportLog{
  1230. LogType: 2,
  1231. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1232. TotalNum: int64(len(total_schedule) + failed_total),
  1233. FailNum: int64(len(errLogs) + failed_total),
  1234. SuccessNum: int64(len(schedules)),
  1235. CreateTime: time.Now().Unix(),
  1236. UpdateTime: time.Now().Unix(),
  1237. ExportTime: export_time,
  1238. Status: 1,
  1239. }
  1240. service.CreateExportLog(&log)
  1241. if failed_total > 0 {
  1242. err_log := models.ExportErrLog{
  1243. LogType: 2,
  1244. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1245. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  1246. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  1247. Status: 1,
  1248. CreateTime: time.Now().Unix(),
  1249. UpdateTime: time.Now().Unix(),
  1250. ExportTime: export_time,
  1251. }
  1252. service.CreateExportErrLog(&err_log)
  1253. }
  1254. this.ServeSuccessJSON(map[string]interface{}{
  1255. "msg": "导入成功",
  1256. "total_num": len(total_schedule),
  1257. "success_num": len(schedules),
  1258. "fail_num": int64(len(errLogs)),
  1259. })
  1260. }
  1261. }
  1262. }
  1263. func (this *ScheduleApiController) ExportScheduleTemplate() {
  1264. dataBody := make(map[string]interface{}, 0)
  1265. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1266. if err != nil {
  1267. utils.ErrorLog(err.Error())
  1268. return
  1269. }
  1270. utils.ErrorLog("%v", dataBody)
  1271. export_time := time.Now().Unix()
  1272. var schedules []*models.PatientScheduleTemplateItem
  1273. var total_schedule []interface{}
  1274. patients, _, _ := service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  1275. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  1276. tempSchedule := dataBody["schedule"].([]interface{})
  1277. total_schedule = tempSchedule
  1278. for _, schMap := range tempSchedule {
  1279. schMapM := schMap.(map[string]interface{})
  1280. var sch models.PatientScheduleTemplateItem
  1281. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  1282. utils.ErrorLog("name")
  1283. return
  1284. }
  1285. name, _ := schMapM["name"].(string)
  1286. fmt.Println(name)
  1287. if len(name) == 0 { //名字为空则生成一条导入错误日志
  1288. err_log := models.ExportErrLog{
  1289. LogType: 3,
  1290. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1291. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  1292. Status: 1,
  1293. CreateTime: time.Now().Unix(),
  1294. UpdateTime: time.Now().Unix(),
  1295. ExportTime: export_time,
  1296. }
  1297. service.CreateExportErrLog(&err_log)
  1298. continue
  1299. } else {
  1300. var patient []*models.Patients
  1301. for _, item := range patients {
  1302. if strings.Replace(item.Name, " ", "", -1) == name {
  1303. patient = append(patient, item)
  1304. }
  1305. }
  1306. if len(patient) == 0 { //错误日志
  1307. err_log := models.ExportErrLog{
  1308. LogType: 3,
  1309. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1310. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名在系统中不存在,请在系统中添加该病人",
  1311. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  1312. Status: 1,
  1313. CreateTime: time.Now().Unix(),
  1314. UpdateTime: time.Now().Unix(),
  1315. ExportTime: export_time,
  1316. }
  1317. service.CreateExportErrLog(&err_log)
  1318. continue
  1319. } else if len(patient) == 1 { //
  1320. sch.PatientID = patient[0].ID
  1321. } else if len(patient) > 1 { //出现同名的情况
  1322. err_log := models.ExportErrLog{
  1323. LogType: 3,
  1324. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1325. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  1326. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在当前机构中存在重名,无法确定到具体患者",
  1327. Status: 1,
  1328. CreateTime: time.Now().Unix(),
  1329. UpdateTime: time.Now().Unix(),
  1330. ExportTime: export_time,
  1331. }
  1332. service.CreateExportErrLog(&err_log)
  1333. continue
  1334. }
  1335. }
  1336. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  1337. utils.ErrorLog("schedule_type")
  1338. return
  1339. }
  1340. schedule_type := int64(schMapM["schedule_type"].(float64))
  1341. if schedule_type <= 0 { //班次格式有误,插入日志
  1342. log := models.ExportLog{
  1343. LogType: 3,
  1344. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1345. TotalNum: int64(len(total_schedule)),
  1346. FailNum: 1,
  1347. SuccessNum: int64(len(schedules)),
  1348. CreateTime: time.Now().Unix(),
  1349. UpdateTime: time.Now().Unix(),
  1350. ExportTime: export_time,
  1351. Status: 1,
  1352. }
  1353. service.CreateExportLog(&log)
  1354. err_log := models.ExportErrLog{
  1355. LogType: 3,
  1356. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1357. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  1358. Status: 1,
  1359. CreateTime: time.Now().Unix(),
  1360. UpdateTime: time.Now().Unix(),
  1361. ExportTime: export_time,
  1362. }
  1363. service.CreateExportErrLog(&err_log)
  1364. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1365. return
  1366. } else {
  1367. sch.TimeType = int8(schedule_type)
  1368. }
  1369. if schMapM["template_id"] == nil && reflect.TypeOf(schMapM["template_id"]).String() != "float64" {
  1370. utils.ErrorLog("template_id")
  1371. return
  1372. }
  1373. template_id := int64(schMapM["template_id"].(float64))
  1374. sch.TemplateID = template_id
  1375. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  1376. utils.ErrorLog("device_number_name")
  1377. return
  1378. }
  1379. partition_name, _ := schMapM["partition_name"].(string)
  1380. zone, _ := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  1381. device_number_name, _ := schMapM["device_number_name"].(string)
  1382. if len(device_number_name) == 0 { //分区为空
  1383. log := models.ExportLog{
  1384. LogType: 3,
  1385. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1386. TotalNum: int64(len(total_schedule)),
  1387. FailNum: 1,
  1388. SuccessNum: int64(len(schedules)),
  1389. CreateTime: time.Now().Unix(),
  1390. UpdateTime: time.Now().Unix(),
  1391. ExportTime: export_time,
  1392. Status: 1,
  1393. }
  1394. service.CreateExportLog(&log)
  1395. err_log := models.ExportErrLog{
  1396. LogType: 3,
  1397. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1398. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1399. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  1400. Status: 1,
  1401. CreateTime: time.Now().Unix(),
  1402. UpdateTime: time.Now().Unix(),
  1403. ExportTime: export_time,
  1404. }
  1405. service.CreateExportErrLog(&err_log)
  1406. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1407. return
  1408. } else {
  1409. device, err := service.FindDeviceByNameTwo(device_number_name, this.GetAdminUserInfo().CurrentOrgId, zone.ID)
  1410. if err == nil {
  1411. if len(device) == 0 { //没查到数据,插入错误日志
  1412. log := models.ExportLog{
  1413. LogType: 3,
  1414. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1415. TotalNum: int64(len(total_schedule)),
  1416. FailNum: 1,
  1417. SuccessNum: int64(len(schedules)),
  1418. CreateTime: time.Now().Unix(),
  1419. UpdateTime: time.Now().Unix(),
  1420. ExportTime: export_time,
  1421. Status: 1,
  1422. }
  1423. service.CreateExportLog(&log)
  1424. err_log := models.ExportErrLog{
  1425. LogType: 3,
  1426. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1427. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  1428. Status: 1,
  1429. CreateTime: time.Now().Unix(),
  1430. UpdateTime: time.Now().Unix(),
  1431. ExportTime: export_time,
  1432. }
  1433. service.CreateExportErrLog(&err_log)
  1434. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1435. return
  1436. } else if len(device) == 1 {
  1437. sch.DeviceNumberID = device[0].ID
  1438. } else if len(device) > 1 { //出现重名,插入错误日志
  1439. log := models.ExportLog{
  1440. LogType: 3,
  1441. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1442. TotalNum: int64(len(total_schedule)),
  1443. FailNum: 1,
  1444. SuccessNum: int64(len(schedules)),
  1445. CreateTime: time.Now().Unix(),
  1446. UpdateTime: time.Now().Unix(),
  1447. ExportTime: export_time,
  1448. Status: 1,
  1449. }
  1450. service.CreateExportLog(&log)
  1451. err_log := models.ExportErrLog{
  1452. LogType: 3,
  1453. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1454. ErrMsg: "出现两个床位号相同的床位",
  1455. Status: 1,
  1456. CreateTime: time.Now().Unix(),
  1457. UpdateTime: time.Now().Unix(),
  1458. ExportTime: export_time,
  1459. }
  1460. service.CreateExportErrLog(&err_log)
  1461. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1462. return
  1463. }
  1464. }
  1465. }
  1466. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  1467. utils.ErrorLog("schedule_week")
  1468. return
  1469. }
  1470. schedule_week, _ := schMapM["schedule_week"].(string)
  1471. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  1472. log := models.ExportLog{
  1473. LogType: 3,
  1474. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1475. TotalNum: int64(len(total_schedule)),
  1476. FailNum: 1,
  1477. SuccessNum: int64(len(schedules)),
  1478. CreateTime: time.Now().Unix(),
  1479. UpdateTime: time.Now().Unix(),
  1480. ExportTime: export_time,
  1481. Status: 1,
  1482. }
  1483. service.CreateExportLog(&log)
  1484. err_log := models.ExportErrLog{
  1485. LogType: 3,
  1486. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1487. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1488. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1489. Status: 1,
  1490. CreateTime: time.Now().Unix(),
  1491. UpdateTime: time.Now().Unix(),
  1492. ExportTime: export_time,
  1493. }
  1494. service.CreateExportErrLog(&err_log)
  1495. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1496. return
  1497. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  1498. log := models.ExportLog{
  1499. LogType: 3,
  1500. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1501. TotalNum: int64(len(total_schedule)),
  1502. FailNum: 1,
  1503. SuccessNum: int64(len(schedules)),
  1504. CreateTime: time.Now().Unix(),
  1505. UpdateTime: time.Now().Unix(),
  1506. ExportTime: export_time,
  1507. Status: 1,
  1508. }
  1509. service.CreateExportLog(&log)
  1510. err_log := models.ExportErrLog{
  1511. LogType: 3,
  1512. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1513. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1514. Status: 1,
  1515. CreateTime: time.Now().Unix(),
  1516. UpdateTime: time.Now().Unix(),
  1517. ExportTime: export_time,
  1518. }
  1519. service.CreateExportErrLog(&err_log)
  1520. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1521. return
  1522. } else {
  1523. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  1524. sch.Weekday = int8(schedule_week)
  1525. }
  1526. sch.CreateTime = time.Now().Unix()
  1527. sch.ModifyTime = time.Now().Unix()
  1528. sch.TreatMode = 1
  1529. sch.Status = 1
  1530. sch.OrgID = this.GetAdminUserInfo().CurrentOrgId
  1531. sch.IsExport = 1
  1532. schedules = append(schedules, &sch)
  1533. }
  1534. errLogs, _ := service.FindSchedualTemplateExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  1535. if len(schedules) > 0 {
  1536. err := service.UpdateScheduleTemplateStatus(this.GetAdminUserInfo().CurrentOrgId)
  1537. if err == nil {
  1538. for _, item := range schedules {
  1539. service.CreateScheduleTemplate(item)
  1540. }
  1541. log := models.ExportLog{
  1542. LogType: 3,
  1543. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1544. TotalNum: int64(len(total_schedule)),
  1545. FailNum: int64(len(errLogs)),
  1546. SuccessNum: int64(len(schedules)),
  1547. CreateTime: time.Now().Unix(),
  1548. UpdateTime: time.Now().Unix(),
  1549. ExportTime: export_time,
  1550. Status: 1,
  1551. }
  1552. service.CreateExportLog(&log)
  1553. this.ServeSuccessJSON(map[string]interface{}{
  1554. "msg": "导入成功",
  1555. "total_num": len(total_schedule),
  1556. "success_num": len(schedules),
  1557. "fail_num": int64(len(errLogs)),
  1558. })
  1559. } else {
  1560. log := models.ExportLog{
  1561. LogType: 3,
  1562. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1563. TotalNum: int64(len(total_schedule)),
  1564. FailNum: int64(len(errLogs)),
  1565. SuccessNum: int64(len(schedules)),
  1566. CreateTime: time.Now().Unix(),
  1567. UpdateTime: time.Now().Unix(),
  1568. ExportTime: export_time,
  1569. Status: 1,
  1570. }
  1571. service.CreateExportLog(&log)
  1572. this.ServeSuccessJSON(map[string]interface{}{
  1573. "msg": "导入成功",
  1574. "total_num": len(total_schedule),
  1575. "success_num": len(schedules),
  1576. "fail_num": int64(len(errLogs)),
  1577. })
  1578. }
  1579. } else {
  1580. log := models.ExportLog{
  1581. LogType: 3,
  1582. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1583. TotalNum: int64(len(total_schedule)),
  1584. FailNum: int64(len(errLogs)),
  1585. SuccessNum: int64(len(schedules)),
  1586. CreateTime: time.Now().Unix(),
  1587. UpdateTime: time.Now().Unix(),
  1588. ExportTime: export_time,
  1589. Status: 1,
  1590. }
  1591. service.CreateExportLog(&log)
  1592. this.ServeSuccessJSON(map[string]interface{}{
  1593. "msg": "导入成功",
  1594. "total_num": len(total_schedule),
  1595. "success_num": len(schedules),
  1596. "fail_num": int64(len(errLogs)),
  1597. })
  1598. }
  1599. }
  1600. }
  1601. func (c *ScheduleApiController) GetInitExcelInitDate() {
  1602. thisTime := time.Now()
  1603. thisTime1 := time.Now()
  1604. thisTime2 := time.Now()
  1605. thisTime1 = thisTime1.AddDate(0, 0, 7)
  1606. thisTime2 = thisTime2.AddDate(0, 0, 14)
  1607. weekDay := int(thisTime.Weekday())
  1608. if weekDay == 0 {
  1609. weekDay = 7
  1610. }
  1611. weekEnd := 7 - weekDay
  1612. weekStart := weekEnd - 6
  1613. days := make([]string, 0)
  1614. for index := weekStart; index <= weekEnd; index++ {
  1615. theDay := thisTime.AddDate(0, 0, index)
  1616. days = append(days, theDay.Format("2006-01-02"))
  1617. }
  1618. weekDay1 := int(thisTime1.Weekday())
  1619. if weekDay1 == 0 {
  1620. weekDay1 = 7
  1621. }
  1622. weekEnd1 := 7 - weekDay1
  1623. weekStart1 := weekEnd1 - 6
  1624. for index := weekStart1; index <= weekEnd1; index++ {
  1625. theDay := thisTime1.AddDate(0, 0, index)
  1626. days = append(days, theDay.Format("2006-01-02"))
  1627. }
  1628. weekDay2 := int(thisTime2.Weekday())
  1629. if weekDay2 == 0 {
  1630. weekDay2 = 7
  1631. }
  1632. weekEnd2 := 7 - weekDay2
  1633. weekStart2 := weekEnd2 - 6
  1634. for index := weekStart2; index <= weekEnd2; index++ {
  1635. theDay := thisTime2.AddDate(0, 0, index)
  1636. days = append(days, theDay.Format("2006-01-02"))
  1637. }
  1638. c.ServeSuccessJSON(map[string]interface{}{
  1639. "days": days,
  1640. })
  1641. return
  1642. }
  1643. func GetWeekString(week string) string {
  1644. var weekStr string
  1645. switch week {
  1646. case "Sunday":
  1647. weekStr = "周日"
  1648. break
  1649. case "Monday":
  1650. weekStr = "周一"
  1651. break
  1652. case "Tuesday":
  1653. weekStr = "周二"
  1654. break
  1655. case "Wednesday":
  1656. weekStr = "周三"
  1657. break
  1658. case "Thursday":
  1659. weekStr = "周四"
  1660. break
  1661. case "Friday":
  1662. weekStr = "周五"
  1663. break
  1664. case "Saturday":
  1665. weekStr = "周六"
  1666. break
  1667. default:
  1668. weekStr = ""
  1669. break
  1670. }
  1671. return weekStr
  1672. }
  1673. func (c *ScheduleApiController) SearchTemplateSchedulePatients() {
  1674. template_id, _ := c.GetInt64("template_id", 0)
  1675. keywords := c.GetString("keywords")
  1676. adminInfo := c.GetAdminUserInfo()
  1677. scheduleItems, _ := service.GetTemplateSchedualPatientsByKeywords(keywords, adminInfo.CurrentOrgId, template_id)
  1678. c.ServeSuccessJSON(map[string]interface{}{
  1679. "schdules": scheduleItems,
  1680. })
  1681. }
  1682. func (c *ScheduleApiController) CancelScheduleTemplate() {
  1683. item_id, _ := c.GetInt64("id")
  1684. adminInfo := c.GetAdminUserInfo()
  1685. err := service.UpdateNewScheduleTemplateStatus(item_id, adminInfo.CurrentOrgId)
  1686. if err == nil {
  1687. c.ServeSuccessJSON(map[string]interface{}{
  1688. "msg": "取消成功",
  1689. })
  1690. return
  1691. } else {
  1692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1693. return
  1694. }
  1695. }
  1696. func (this *ScheduleApiController) GetNextWeekDaySchedule() {
  1697. week_type, _ := this.GetInt64("week_type", -1)
  1698. week_time, _ := this.GetInt64("week_time")
  1699. start_time, _ := this.GetInt64("start_time")
  1700. end_time, _ := this.GetInt64("end_time")
  1701. adminUserInfo := this.GetAdminUserInfo()
  1702. schedule, err := service.GetNextWeekDaySchedule(week_type, week_time, start_time, end_time, adminUserInfo.CurrentOrgId)
  1703. if err != nil {
  1704. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1705. return
  1706. }
  1707. this.ServeSuccessJSON(map[string]interface{}{
  1708. "schedule": schedule,
  1709. })
  1710. }
  1711. func (this *ScheduleApiController) GetThreeWeekList() {
  1712. start_time := this.GetString("start_time")
  1713. end_time := this.GetString("end_time")
  1714. partition_id, _ := this.GetInt64("partition_id")
  1715. schedule_type, _ := this.GetInt64("schedule_type")
  1716. fmt.Println(partition_id, schedule_type)
  1717. timeLayout := "2006-01-02"
  1718. loc, _ := time.LoadLocation("Local")
  1719. var theStartTIme int64
  1720. if len(start_time) > 0 {
  1721. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1722. if err != nil {
  1723. utils.ErrorLog(err.Error())
  1724. }
  1725. theStartTIme = theTime.Unix()
  1726. }
  1727. var theEndtTIme int64
  1728. if len(end_time) > 0 {
  1729. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  1730. if err != nil {
  1731. utils.ErrorLog(err.Error())
  1732. }
  1733. theEndtTIme = theTime.Unix()
  1734. }
  1735. adminUserInfo := this.GetAdminUserInfo()
  1736. orgId := adminUserInfo.CurrentOrgId
  1737. partitions, _ := service.GetSchedulePartitionPanel(orgId)
  1738. list, err := service.GetThreeWeekList(theStartTIme, theEndtTIme, orgId, schedule_type, partition_id)
  1739. if err != nil {
  1740. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1741. return
  1742. }
  1743. this.ServeSuccessJSON(map[string]interface{}{
  1744. "list": list,
  1745. "partitions": partitions,
  1746. })
  1747. }
  1748. func (this *ScheduleApiController) GetAllZones() {
  1749. adminUserInfo := this.GetAdminUserInfo()
  1750. orgId := adminUserInfo.CurrentOrgId
  1751. zones, err := service.GetAllZoneOne(orgId)
  1752. if err != nil {
  1753. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1754. return
  1755. }
  1756. this.ServeSuccessJSON(map[string]interface{}{
  1757. "zones": zones,
  1758. })
  1759. }
  1760. func (this *ScheduleApiController) GetCopyPatientSchedules() {
  1761. adminUserInfo := this.GetAdminUserInfo()
  1762. orgId := adminUserInfo.CurrentOrgId
  1763. start_time, _ := this.GetInt64("start_time")
  1764. fmt.Println("start_time", start_time)
  1765. end_time, _ := this.GetInt64("end_time")
  1766. fmt.Println("end_time", end_time)
  1767. copy_startime, _ := this.GetInt64("copy_startime")
  1768. fmt.Println("copy_startime", copy_startime)
  1769. copy_endtime, _ := this.GetInt64("copy_endtime")
  1770. //获取本周患者排班
  1771. schedules, _ := service.GetWeekSchedules(orgId, start_time, end_time)
  1772. //先清除复制周的排班
  1773. errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
  1774. fmt.Println(errcode)
  1775. for _, item := range schedules {
  1776. //fmt.Println(item.StartTime+604800)
  1777. //礼拜1
  1778. if item.ScheduleWeek == 1 {
  1779. item.ScheduleDate = copy_startime
  1780. }
  1781. if item.ScheduleWeek == 2 {
  1782. item.ScheduleDate = copy_startime + 86400
  1783. }
  1784. if item.ScheduleWeek == 3 {
  1785. item.ScheduleDate = copy_startime + 172800
  1786. }
  1787. if item.ScheduleWeek == 4 {
  1788. item.ScheduleDate = copy_startime + 259200
  1789. }
  1790. if item.ScheduleWeek == 5 {
  1791. item.ScheduleDate = copy_startime + 345600
  1792. }
  1793. if item.ScheduleWeek == 6 {
  1794. item.ScheduleDate = copy_startime + 432000
  1795. }
  1796. //礼拜天
  1797. if item.ScheduleWeek == 0 {
  1798. item.ScheduleDate = copy_endtime
  1799. }
  1800. schedule := models.XtSchedule{
  1801. UserOrgId: item.UserOrgId,
  1802. PartitionId: item.PartitionId,
  1803. BedId: item.BedId,
  1804. PatientId: item.PatientId,
  1805. ScheduleDate: item.ScheduleDate,
  1806. ScheduleType: item.ScheduleType,
  1807. ScheduleWeek: item.ScheduleWeek,
  1808. ModeId: item.ModeId,
  1809. Status: 1,
  1810. CreatedTime: time.Now().Unix(),
  1811. }
  1812. err := service.AddPatientSchedule(&schedule)
  1813. if err != nil {
  1814. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1815. return
  1816. }
  1817. this.ServeSuccessJSON(map[string]interface{}{
  1818. "schedule": schedule,
  1819. })
  1820. }
  1821. //查询复制中的排班日期是否存在
  1822. //_, errcode := service.GetLastWeekSchedule(orgId, copy_startime, copy_endtime)
  1823. //
  1824. //if errcode == gorm.ErrRecordNotFound {
  1825. // //如果没有直接新增
  1826. //
  1827. // for _, item := range schedules {
  1828. // //fmt.Println(item.StartTime+604800)
  1829. // //礼拜1
  1830. // if item.ScheduleWeek == 1 {
  1831. // item.ScheduleDate = copy_startime
  1832. // }
  1833. // if item.ScheduleWeek == 2 {
  1834. // item.ScheduleDate = copy_startime + 86400
  1835. // }
  1836. // if item.ScheduleWeek == 3 {
  1837. // item.ScheduleDate = copy_startime + 172800
  1838. // }
  1839. // if item.ScheduleWeek == 4 {
  1840. // item.ScheduleDate = copy_startime + 259200
  1841. // }
  1842. // if item.ScheduleWeek == 5 {
  1843. // item.ScheduleDate = copy_startime + 345600
  1844. // }
  1845. //
  1846. // if item.ScheduleWeek == 6 {
  1847. // item.ScheduleDate = copy_startime + 432000
  1848. // }
  1849. // //礼拜天
  1850. // if item.ScheduleWeek == 0 {
  1851. // item.ScheduleDate = copy_endtime
  1852. // }
  1853. // schedule := models.XtSchedule{
  1854. // UserOrgId: item.UserOrgId,
  1855. // PartitionId: item.PartitionId,
  1856. // BedId: item.BedId,
  1857. // PatientId: item.PatientId,
  1858. // ScheduleDate: item.ScheduleDate,
  1859. // ScheduleType: item.ScheduleType,
  1860. // ScheduleWeek: item.ScheduleWeek,
  1861. // ModeId: item.ModeId,
  1862. // Status: 1,
  1863. // CreatedTime: time.Now().Unix(),
  1864. // }
  1865. //
  1866. // err := service.AddPatientSchedule(&schedule)
  1867. // if err != nil {
  1868. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1869. // return
  1870. // }
  1871. // this.ServeSuccessJSON(map[string]interface{}{
  1872. // "schedule": schedule,
  1873. // })
  1874. // }
  1875. //} else if errcode == nil {
  1876. //
  1877. // //先清除复制周的排班
  1878. // errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
  1879. // fmt.Println(errcode)
  1880. // for _, item := range schedules {
  1881. // //fmt.Println(item.StartTime+604800)
  1882. // //礼拜1
  1883. // if item.ScheduleWeek == 1 {
  1884. // item.ScheduleDate = copy_startime
  1885. // }
  1886. // if item.ScheduleWeek == 2 {
  1887. // item.ScheduleDate = copy_startime + 86400
  1888. // }
  1889. // if item.ScheduleWeek == 3 {
  1890. // item.ScheduleDate = copy_startime + 172800
  1891. // }
  1892. // if item.ScheduleWeek == 4 {
  1893. // item.ScheduleDate = copy_startime + 259200
  1894. // }
  1895. // if item.ScheduleWeek == 5 {
  1896. // item.ScheduleDate = copy_startime + 345600
  1897. // }
  1898. //
  1899. // if item.ScheduleWeek == 6 {
  1900. // item.ScheduleDate = copy_startime + 432000
  1901. // }
  1902. // //礼拜天
  1903. // if item.ScheduleWeek == 0 {
  1904. // item.ScheduleDate = copy_endtime
  1905. // }
  1906. // schedule := models.XtSchedule{
  1907. // UserOrgId: item.UserOrgId,
  1908. // PartitionId: item.PartitionId,
  1909. // BedId: item.BedId,
  1910. // PatientId: item.PatientId,
  1911. // ScheduleDate: item.ScheduleDate,
  1912. // ScheduleType: item.ScheduleType,
  1913. // ScheduleWeek: item.ScheduleWeek,
  1914. // ModeId: item.ModeId,
  1915. // Status: 1,
  1916. // CreatedTime: time.Now().Unix(),
  1917. // }
  1918. //
  1919. // err := service.AddPatientSchedule(&schedule)
  1920. // if err != nil {
  1921. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1922. // return
  1923. // }
  1924. // this.ServeSuccessJSON(map[string]interface{}{
  1925. // "schedule": schedule,
  1926. // })
  1927. // }
  1928. //}
  1929. }