schedule_api_controller.go 90KB

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