schedule_api_controller.go 79KB

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