schedule_api_controller.go 81KB

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