schedule_api_controller.go 90KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953
  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. thisTime1 := time.Now()
  652. thisTime2 := time.Now()
  653. thisTime1 = thisTime1.AddDate(0, 0, 7)
  654. thisTime2 = thisTime2.AddDate(0, 0, 14)
  655. var start_time string
  656. var end_time string
  657. switch week_type {
  658. case 1:
  659. adminUserInfo := this.GetAdminUserInfo()
  660. list, _ := service.GetSchedualPatientsByKeywords(keywords, adminUserInfo.CurrentOrgId)
  661. this.ServeSuccessJSON(map[string]interface{}{
  662. "schdules": list,
  663. })
  664. break
  665. case 2:
  666. days := make([]string, 0)
  667. weekDay1 := int(thisTime1.Weekday())
  668. if weekDay1 == 0 {
  669. weekDay1 = 7
  670. }
  671. weekEnd1 := 7 - weekDay1
  672. weekStart1 := weekEnd1 - 6
  673. for index := weekStart1; index <= weekEnd1; index++ {
  674. fmt.Println(index)
  675. theDay := thisTime1.AddDate(0, 0, index)
  676. days = append(days, theDay.Format("2006-01-02"))
  677. }
  678. fmt.Println(days)
  679. start_time = days[0]
  680. end_time = days[len(days)-1]
  681. timeLayout := "2006-01-02"
  682. loc, _ := time.LoadLocation("Local")
  683. var theStartTime int64
  684. if len(start_time) > 0 {
  685. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  686. theStartTime = theTime.Unix()
  687. }
  688. var theEndtTime int64
  689. if len(end_time) > 0 {
  690. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  691. theEndtTime = theTime.Unix()
  692. }
  693. adminUserInfo := this.GetAdminUserInfo()
  694. list, _ := service.GetSchedualPatientsByKeywordsAndWeek(keywords, adminUserInfo.CurrentOrgId, theStartTime, theEndtTime)
  695. this.ServeSuccessJSON(map[string]interface{}{
  696. "schdules": list,
  697. })
  698. break
  699. case 3:
  700. days := make([]string, 0)
  701. weekDay2 := int(thisTime2.Weekday())
  702. if weekDay2 == 0 {
  703. weekDay2 = 7
  704. }
  705. weekEnd2 := 7 - weekDay2
  706. weekStart2 := weekEnd2 - 6
  707. for index := weekStart2; index <= weekEnd2; index++ {
  708. theDay := thisTime2.AddDate(0, 0, index)
  709. days = append(days, theDay.Format("2006-01-02"))
  710. }
  711. start_time = days[0]
  712. end_time = days[len(days)-1]
  713. timeLayout := "2006-01-02"
  714. loc, _ := time.LoadLocation("Local")
  715. var theStartTime int64
  716. if len(start_time) > 0 {
  717. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  718. theStartTime = theTime.Unix()
  719. }
  720. var theEndtTime int64
  721. if len(end_time) > 0 {
  722. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  723. theEndtTime = theTime.Unix()
  724. }
  725. adminUserInfo := this.GetAdminUserInfo()
  726. list, _ := service.GetSchedualPatientsByKeywordsAndWeek(keywords, adminUserInfo.CurrentOrgId, theStartTime, theEndtTime)
  727. this.ServeSuccessJSON(map[string]interface{}{
  728. "schdules": list,
  729. })
  730. break
  731. }
  732. }
  733. func (this *ScheduleApiController) GetWeekDaySchedule() {
  734. week_type, _ := this.GetInt64("week_type", -1)
  735. week_time, _ := this.GetInt64("week_time")
  736. thisTime := time.Now()
  737. weekDay := int(thisTime.Weekday())
  738. if weekDay == 0 {
  739. weekDay = 7
  740. }
  741. weekEnd := 7 - weekDay
  742. weekStart := weekEnd - 6
  743. weekTitle := make([]string, 0)
  744. days := make([]string, 0)
  745. for index := weekStart; index <= weekEnd; index++ {
  746. theDay := thisTime.AddDate(0, 0, index)
  747. indexYear, indexMonthTime, indexDay := theDay.Date()
  748. indexMonth := int(indexMonthTime)
  749. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  750. weekTitle = append(weekTitle, indexWeek)
  751. days = append(days, theDay.Format("2006-01-02"))
  752. }
  753. fmt.Println(days)
  754. var targetDayStr string
  755. var startTime string
  756. var endTime string
  757. switch week_type {
  758. case 0:
  759. {
  760. startTime = days[0]
  761. endTime = days[6]
  762. }
  763. case 1:
  764. targetDayStr = days[0]
  765. break
  766. case 2:
  767. targetDayStr = days[1]
  768. break
  769. case 3:
  770. targetDayStr = days[2]
  771. break
  772. case 4:
  773. targetDayStr = days[3]
  774. break
  775. case 5:
  776. targetDayStr = days[4]
  777. break
  778. case 6:
  779. targetDayStr = days[5]
  780. break
  781. case 7:
  782. targetDayStr = days[6]
  783. break
  784. }
  785. targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  786. startDay, _ := utils.ParseTimeStringToTime("2006-01-02", startTime)
  787. endDay, _ := utils.ParseTimeStringToTime("2006-01-02", endTime)
  788. fmt.Println(startDay, endDay)
  789. if parseErr != nil {
  790. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  791. return
  792. }
  793. orgId := this.GetAdminUserInfo().CurrentOrgId
  794. list, _ := service.GetWeekDayScheduleTwo(orgId, targetDay.Unix(), targetDay, week_time)
  795. this.ServeSuccessJSON(map[string]interface{}{
  796. "schdules": list,
  797. "day": targetDayStr,
  798. })
  799. }
  800. func Struct2Map(obj interface{}) map[string]interface{} {
  801. t := reflect.TypeOf(obj)
  802. v := reflect.ValueOf(obj)
  803. var data = make(map[string]interface{})
  804. for i := 0; i < t.NumField(); i++ {
  805. data[t.Field(i).Name] = v.Field(i).Interface()
  806. }
  807. return data
  808. }
  809. func (this *ScheduleApiController) ExportSchedule() {
  810. dataBody := make(map[string]interface{}, 0)
  811. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  812. if err != nil {
  813. utils.ErrorLog(err.Error())
  814. return
  815. }
  816. utils.ErrorLog("%v", dataBody)
  817. export_time := time.Now().Unix()
  818. var schedules []*models.Schedule
  819. var failed_total int
  820. var total_schedule []interface{}
  821. var patients []*models.Patients
  822. patients, _, _ = service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  823. start_time := dataBody["start_time"].(string)
  824. end_time := dataBody["end_time"].(string)
  825. delete_type := int64(dataBody["delete_type"].(float64))
  826. fmt.Println("delete_type", delete_type)
  827. timeLayout := "2006-01-02"
  828. loc, _ := time.LoadLocation("Local")
  829. theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  830. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  831. fmt.Println("theTimeStart23232322332322323", theTimeStart.Unix())
  832. fmt.Println("theTimeStart23232322332322323", theTimeEnd.Unix())
  833. if dataBody["failed_schedule"] != nil || reflect.TypeOf(dataBody["failed_schedule"]).String() == "[]interface {}" {
  834. tempSchedule := dataBody["failed_schedule"].([]interface{})
  835. failed_total = len(tempSchedule)
  836. }
  837. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  838. tempSchedule := dataBody["schedule"].([]interface{})
  839. total_schedule = tempSchedule
  840. for _, schMap := range tempSchedule {
  841. schMapM := schMap.(map[string]interface{})
  842. var sch models.Schedule
  843. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  844. utils.ErrorLog("name")
  845. return
  846. }
  847. name, _ := schMapM["name"].(string)
  848. fmt.Println(name)
  849. if len(name) == 0 { //名字为空则生成一条导入错误日志
  850. err_log := models.ExportErrLog{
  851. LogType: 2,
  852. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  853. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  854. Status: 1,
  855. CreateTime: time.Now().Unix(),
  856. UpdateTime: time.Now().Unix(),
  857. ExportTime: export_time,
  858. }
  859. service.CreateExportErrLog(&err_log)
  860. continue
  861. } else {
  862. var patient []*models.Patients
  863. for _, item := range patients {
  864. if strings.Replace(item.Name, " ", "", -1) == name {
  865. patient = append(patient, item)
  866. }
  867. }
  868. if len(patient) == 0 { //错误日志
  869. err_log := models.ExportErrLog{
  870. LogType: 2,
  871. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  872. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  873. Status: 1,
  874. CreateTime: time.Now().Unix(),
  875. UpdateTime: time.Now().Unix(),
  876. ExportTime: export_time,
  877. }
  878. service.CreateExportErrLog(&err_log)
  879. continue
  880. } else if len(patient) == 1 { //
  881. sch.PatientId = patient[0].ID
  882. } else if len(patient) > 1 { //出现同名的情况
  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. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在在当前机构中存在重名,无法确定到具体患者",
  888. Status: 1,
  889. CreateTime: time.Now().Unix(),
  890. UpdateTime: time.Now().Unix(),
  891. ExportTime: export_time,
  892. }
  893. service.CreateExportErrLog(&err_log)
  894. continue
  895. }
  896. }
  897. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  898. utils.ErrorLog("schedule_type")
  899. return
  900. }
  901. schedule_type := int64(schMapM["schedule_type"].(float64))
  902. if schedule_type <= 0 { //班次格式有误,插入日志
  903. log := models.ExportLog{
  904. LogType: 2,
  905. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  906. TotalNum: int64(len(total_schedule) + failed_total),
  907. FailNum: 1 + int64(failed_total),
  908. SuccessNum: int64(len(schedules)),
  909. CreateTime: time.Now().Unix(),
  910. UpdateTime: time.Now().Unix(),
  911. ExportTime: export_time,
  912. Status: 1,
  913. }
  914. service.CreateExportLog(&log)
  915. err_log := models.ExportErrLog{
  916. LogType: 2,
  917. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  918. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  919. Status: 1,
  920. CreateTime: time.Now().Unix(),
  921. UpdateTime: time.Now().Unix(),
  922. ExportTime: export_time,
  923. }
  924. service.CreateExportErrLog(&err_log)
  925. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  926. return
  927. } else {
  928. sch.ScheduleType = schedule_type
  929. }
  930. if schMapM["partition_name"] == nil || reflect.TypeOf(schMapM["partition_name"]).String() != "string" {
  931. utils.ErrorLog("partition_name")
  932. return
  933. }
  934. partition_name, _ := schMapM["partition_name"].(string)
  935. if len(partition_name) == 0 { //分区为空
  936. log := models.ExportLog{
  937. LogType: 2,
  938. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  939. TotalNum: int64(len(total_schedule) + failed_total),
  940. FailNum: 1 + int64(failed_total),
  941. SuccessNum: int64(len(schedules)),
  942. CreateTime: time.Now().Unix(),
  943. UpdateTime: time.Now().Unix(),
  944. ExportTime: export_time,
  945. Status: 1,
  946. }
  947. service.CreateExportLog(&log)
  948. err_log := models.ExportErrLog{
  949. LogType: 2,
  950. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  951. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  952. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  953. Status: 1,
  954. CreateTime: time.Now().Unix(),
  955. UpdateTime: time.Now().Unix(),
  956. ExportTime: export_time,
  957. }
  958. service.CreateExportErrLog(&err_log)
  959. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  960. return
  961. } else {
  962. zone, err := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  963. if err == nil {
  964. sch.PartitionId = zone.ID
  965. } else if err == gorm.ErrRecordNotFound { //查不到数据,插入错误日志
  966. log := models.ExportLog{
  967. LogType: 2,
  968. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  969. TotalNum: int64(len(total_schedule) + failed_total),
  970. FailNum: 1 + int64(failed_total),
  971. SuccessNum: int64(len(schedules)),
  972. CreateTime: time.Now().Unix(),
  973. UpdateTime: time.Now().Unix(),
  974. ExportTime: export_time,
  975. Status: 1,
  976. }
  977. service.CreateExportLog(&log)
  978. err_log := models.ExportErrLog{
  979. LogType: 2,
  980. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  981. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  982. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  983. Status: 1,
  984. CreateTime: time.Now().Unix(),
  985. UpdateTime: time.Now().Unix(),
  986. ExportTime: export_time,
  987. }
  988. service.CreateExportErrLog(&err_log)
  989. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  990. return
  991. }
  992. }
  993. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  994. utils.ErrorLog("device_number_name")
  995. return
  996. }
  997. device_number_name, _ := schMapM["device_number_name"].(string)
  998. if len(device_number_name) == 0 { //分区为空
  999. log := models.ExportLog{
  1000. LogType: 2,
  1001. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1002. TotalNum: int64(len(total_schedule) + failed_total),
  1003. FailNum: 1 + int64(failed_total),
  1004. SuccessNum: int64(len(schedules)),
  1005. CreateTime: time.Now().Unix(),
  1006. UpdateTime: time.Now().Unix(),
  1007. ExportTime: export_time,
  1008. Status: 1,
  1009. }
  1010. service.CreateExportLog(&log)
  1011. err_log := models.ExportErrLog{
  1012. LogType: 2,
  1013. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1014. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1015. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  1016. Status: 1,
  1017. CreateTime: time.Now().Unix(),
  1018. UpdateTime: time.Now().Unix(),
  1019. ExportTime: export_time,
  1020. }
  1021. service.CreateExportErrLog(&err_log)
  1022. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1023. return
  1024. } else {
  1025. device, err := service.FindDeviceByName(device_number_name, this.GetAdminUserInfo().CurrentOrgId, sch.PartitionId)
  1026. if err == nil {
  1027. if len(device) == 0 { //没查到数据,插入错误日志
  1028. log := models.ExportLog{
  1029. LogType: 2,
  1030. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1031. TotalNum: int64(len(total_schedule) + failed_total),
  1032. FailNum: 1 + int64(failed_total),
  1033. SuccessNum: int64(len(schedules)),
  1034. CreateTime: time.Now().Unix(),
  1035. UpdateTime: time.Now().Unix(),
  1036. ExportTime: export_time,
  1037. Status: 1,
  1038. }
  1039. service.CreateExportLog(&log)
  1040. err_log := models.ExportErrLog{
  1041. LogType: 2,
  1042. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1043. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  1044. Status: 1,
  1045. CreateTime: time.Now().Unix(),
  1046. UpdateTime: time.Now().Unix(),
  1047. ExportTime: export_time,
  1048. }
  1049. service.CreateExportErrLog(&err_log)
  1050. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1051. return
  1052. } else if len(device) == 1 {
  1053. sch.BedId = device[0].ID
  1054. } else if len(device) > 1 { //出现重名,插入错误日志
  1055. log := models.ExportLog{
  1056. LogType: 2,
  1057. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1058. TotalNum: int64(len(total_schedule) + failed_total),
  1059. FailNum: 1 + int64(failed_total),
  1060. SuccessNum: int64(len(schedules)),
  1061. CreateTime: time.Now().Unix(),
  1062. UpdateTime: time.Now().Unix(),
  1063. ExportTime: export_time,
  1064. Status: 1,
  1065. }
  1066. service.CreateExportLog(&log)
  1067. err_log := models.ExportErrLog{
  1068. LogType: 2,
  1069. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1070. ErrMsg: "出现两个床位号相同的床位",
  1071. Status: 1,
  1072. CreateTime: time.Now().Unix(),
  1073. UpdateTime: time.Now().Unix(),
  1074. ExportTime: export_time,
  1075. }
  1076. service.CreateExportErrLog(&err_log)
  1077. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1078. return
  1079. }
  1080. }
  1081. }
  1082. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  1083. utils.ErrorLog("schedule_week")
  1084. return
  1085. }
  1086. schedule_week, _ := schMapM["schedule_week"].(string)
  1087. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  1088. log := models.ExportLog{
  1089. LogType: 2,
  1090. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1091. TotalNum: int64(len(total_schedule) + failed_total),
  1092. FailNum: 1 + int64(failed_total),
  1093. SuccessNum: int64(len(schedules)),
  1094. CreateTime: time.Now().Unix(),
  1095. UpdateTime: time.Now().Unix(),
  1096. ExportTime: export_time,
  1097. Status: 1,
  1098. }
  1099. service.CreateExportLog(&log)
  1100. err_log := models.ExportErrLog{
  1101. LogType: 2,
  1102. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1103. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1104. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1105. Status: 1,
  1106. CreateTime: time.Now().Unix(),
  1107. UpdateTime: time.Now().Unix(),
  1108. ExportTime: export_time,
  1109. }
  1110. service.CreateExportErrLog(&err_log)
  1111. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1112. return
  1113. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  1114. log := models.ExportLog{
  1115. LogType: 2,
  1116. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1117. TotalNum: int64(len(total_schedule) + failed_total),
  1118. FailNum: 1 + int64(failed_total),
  1119. SuccessNum: int64(len(schedules)),
  1120. CreateTime: time.Now().Unix(),
  1121. UpdateTime: time.Now().Unix(),
  1122. ExportTime: export_time,
  1123. Status: 1,
  1124. }
  1125. service.CreateExportLog(&log)
  1126. err_log := models.ExportErrLog{
  1127. LogType: 2,
  1128. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1129. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1130. Status: 1,
  1131. CreateTime: time.Now().Unix(),
  1132. UpdateTime: time.Now().Unix(),
  1133. ExportTime: export_time,
  1134. }
  1135. service.CreateExportErrLog(&err_log)
  1136. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1137. return
  1138. } else {
  1139. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  1140. sch.ScheduleWeek = schedule_week
  1141. }
  1142. if schMapM["schedule_date"] == nil || reflect.TypeOf(schMapM["schedule_date"]).String() != "string" {
  1143. utils.ErrorLog("schedule_date")
  1144. return
  1145. }
  1146. schedule_date, _ := schMapM["schedule_date"].(string)
  1147. if len(schedule_date) == 0 { //周几为空则生成一条导入错误日志
  1148. log := models.ExportLog{
  1149. LogType: 2,
  1150. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1151. TotalNum: int64(len(total_schedule) + failed_total),
  1152. FailNum: 1 + int64(failed_total),
  1153. SuccessNum: int64(len(schedules)),
  1154. CreateTime: time.Now().Unix(),
  1155. UpdateTime: time.Now().Unix(),
  1156. ExportTime: export_time,
  1157. Status: 1,
  1158. }
  1159. service.CreateExportLog(&log)
  1160. err_log := models.ExportErrLog{
  1161. LogType: 2,
  1162. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1163. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1164. Status: 1,
  1165. CreateTime: time.Now().Unix(),
  1166. UpdateTime: time.Now().Unix(),
  1167. ExportTime: export_time,
  1168. }
  1169. service.CreateExportErrLog(&err_log)
  1170. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1171. return
  1172. } else if schedule_date == "0" { //周几不符合格式则生成一条导入错误日志
  1173. log := models.ExportLog{
  1174. LogType: 2,
  1175. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1176. TotalNum: int64(len(total_schedule) + failed_total),
  1177. FailNum: 1 + int64(failed_total),
  1178. SuccessNum: int64(len(schedules)),
  1179. CreateTime: time.Now().Unix(),
  1180. UpdateTime: time.Now().Unix(),
  1181. ExportTime: export_time,
  1182. Status: 1,
  1183. }
  1184. service.CreateExportLog(&log)
  1185. err_log := models.ExportErrLog{
  1186. LogType: 2,
  1187. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1188. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1189. Status: 1,
  1190. CreateTime: time.Now().Unix(),
  1191. UpdateTime: time.Now().Unix(),
  1192. ExportTime: export_time,
  1193. }
  1194. service.CreateExportErrLog(&err_log)
  1195. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1196. return
  1197. } else {
  1198. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  1199. sch.ScheduleDate = date.Unix()
  1200. }
  1201. sch.CreatedTime = time.Now().Unix()
  1202. sch.UpdatedTime = time.Now().Unix()
  1203. sch.ModeId = 1
  1204. sch.Status = 1
  1205. sch.UserOrgId = this.GetAdminUserInfo().CurrentOrgId
  1206. sch.IsExport = 1
  1207. schedules = append(schedules, &sch)
  1208. }
  1209. errLogs, _ := service.FindSchedualExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  1210. if len(schedules) > 0 {
  1211. schedule_date := time.Now().Format("2006-01-02")
  1212. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  1213. clear_schedule_date := date.Unix() //根据日期去清除,该日期未来的排班数据
  1214. if err == nil {
  1215. for _, item := range schedules {
  1216. if item.ScheduleDate > clear_schedule_date {
  1217. //查询已经存在的所有排班
  1218. //查找当天日期是否存在
  1219. _, errcode := service.GetTodayScheduleIsExistOne(item.PatientId, item.ScheduleDate, item.UserOrgId)
  1220. if errcode == gorm.ErrRecordNotFound {
  1221. //查询该床位是否有患者
  1222. sch, errcodes := service.GetPatientByBed(item.ScheduleDate, item.BedId, item.ScheduleType, item.UserOrgId)
  1223. if errcodes == gorm.ErrRecordNotFound {
  1224. service.CreateSchedule(item)
  1225. } else if errcodes == nil {
  1226. //清除当天该床位已有的患者
  1227. service.ModeFyScheduleById(sch.ScheduleDate, sch.BedId, sch.ScheduleType, sch.UserOrgId)
  1228. service.CreateSchedule(item)
  1229. }
  1230. } else if errcode == nil {
  1231. schedule := models.XtSchedule{
  1232. PartitionId: item.PartitionId,
  1233. BedId: item.BedId,
  1234. PatientId: item.PatientId,
  1235. ScheduleDate: item.ScheduleDate,
  1236. ScheduleType: item.ScheduleType,
  1237. ScheduleWeek: item.ScheduleWeek,
  1238. ModeId: item.ModeId,
  1239. Status: 1,
  1240. }
  1241. service.UpdateScheduleByOrgIdOne(item.PatientId, item.ScheduleDate, item.UserOrgId, &schedule)
  1242. }
  1243. }
  1244. }
  1245. log := models.ExportLog{
  1246. LogType: 2,
  1247. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1248. TotalNum: int64(len(total_schedule) + failed_total),
  1249. FailNum: int64(len(errLogs) + failed_total),
  1250. SuccessNum: int64(len(schedules)),
  1251. CreateTime: time.Now().Unix(),
  1252. UpdateTime: time.Now().Unix(),
  1253. ExportTime: export_time,
  1254. Status: 1,
  1255. }
  1256. service.CreateExportLog(&log)
  1257. if failed_total > 0 {
  1258. err_log := models.ExportErrLog{
  1259. LogType: 2,
  1260. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1261. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  1262. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  1263. Status: 1,
  1264. CreateTime: time.Now().Unix(),
  1265. UpdateTime: time.Now().Unix(),
  1266. ExportTime: export_time,
  1267. }
  1268. service.CreateExportErrLog(&err_log)
  1269. }
  1270. this.ServeSuccessJSON(map[string]interface{}{
  1271. "msg": "导入成功",
  1272. "total_num": len(total_schedule) + failed_total,
  1273. "success_num": len(schedules),
  1274. "fail_num": int64(len(errLogs)),
  1275. })
  1276. } else {
  1277. log := models.ExportLog{
  1278. LogType: 2,
  1279. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1280. TotalNum: int64(len(total_schedule) + failed_total),
  1281. FailNum: int64(len(errLogs) + failed_total),
  1282. SuccessNum: int64(len(schedules)),
  1283. CreateTime: time.Now().Unix(),
  1284. UpdateTime: time.Now().Unix(),
  1285. ExportTime: export_time,
  1286. Status: 1,
  1287. }
  1288. service.CreateExportLog(&log)
  1289. if failed_total > 0 {
  1290. err_log := models.ExportErrLog{
  1291. LogType: 2,
  1292. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1293. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  1294. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  1295. Status: 1,
  1296. CreateTime: time.Now().Unix(),
  1297. UpdateTime: time.Now().Unix(),
  1298. ExportTime: export_time,
  1299. }
  1300. service.CreateExportErrLog(&err_log)
  1301. }
  1302. this.ServeSuccessJSON(map[string]interface{}{
  1303. "msg": "导入成功",
  1304. "total_num": len(total_schedule),
  1305. "success_num": len(schedules),
  1306. "fail_num": int64(len(errLogs)),
  1307. })
  1308. }
  1309. } else {
  1310. log := models.ExportLog{
  1311. LogType: 2,
  1312. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1313. TotalNum: int64(len(total_schedule) + failed_total),
  1314. FailNum: int64(len(errLogs) + failed_total),
  1315. SuccessNum: int64(len(schedules)),
  1316. CreateTime: time.Now().Unix(),
  1317. UpdateTime: time.Now().Unix(),
  1318. ExportTime: export_time,
  1319. Status: 1,
  1320. }
  1321. service.CreateExportLog(&log)
  1322. if failed_total > 0 {
  1323. err_log := models.ExportErrLog{
  1324. LogType: 2,
  1325. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1326. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  1327. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  1328. Status: 1,
  1329. CreateTime: time.Now().Unix(),
  1330. UpdateTime: time.Now().Unix(),
  1331. ExportTime: export_time,
  1332. }
  1333. service.CreateExportErrLog(&err_log)
  1334. }
  1335. this.ServeSuccessJSON(map[string]interface{}{
  1336. "msg": "导入成功",
  1337. "total_num": len(total_schedule),
  1338. "success_num": len(schedules),
  1339. "fail_num": int64(len(errLogs)),
  1340. })
  1341. }
  1342. }
  1343. }
  1344. func (this *ScheduleApiController) ExportScheduleTemplate() {
  1345. dataBody := make(map[string]interface{}, 0)
  1346. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1347. if err != nil {
  1348. utils.ErrorLog(err.Error())
  1349. return
  1350. }
  1351. utils.ErrorLog("%v", dataBody)
  1352. export_time := time.Now().Unix()
  1353. var schedules []*models.PatientScheduleTemplateItem
  1354. var total_schedule []interface{}
  1355. patients, _, _ := service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  1356. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  1357. tempSchedule := dataBody["schedule"].([]interface{})
  1358. total_schedule = tempSchedule
  1359. for _, schMap := range tempSchedule {
  1360. schMapM := schMap.(map[string]interface{})
  1361. var sch models.PatientScheduleTemplateItem
  1362. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  1363. utils.ErrorLog("name")
  1364. return
  1365. }
  1366. name, _ := schMapM["name"].(string)
  1367. fmt.Println(name)
  1368. if len(name) == 0 { //名字为空则生成一条导入错误日志
  1369. err_log := models.ExportErrLog{
  1370. LogType: 3,
  1371. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1372. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  1373. Status: 1,
  1374. CreateTime: time.Now().Unix(),
  1375. UpdateTime: time.Now().Unix(),
  1376. ExportTime: export_time,
  1377. }
  1378. service.CreateExportErrLog(&err_log)
  1379. continue
  1380. } else {
  1381. var patient []*models.Patients
  1382. for _, item := range patients {
  1383. if strings.Replace(item.Name, " ", "", -1) == name {
  1384. patient = append(patient, item)
  1385. }
  1386. }
  1387. if len(patient) == 0 { //错误日志
  1388. err_log := models.ExportErrLog{
  1389. LogType: 3,
  1390. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1391. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名在系统中不存在,请在系统中添加该病人",
  1392. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  1393. Status: 1,
  1394. CreateTime: time.Now().Unix(),
  1395. UpdateTime: time.Now().Unix(),
  1396. ExportTime: export_time,
  1397. }
  1398. service.CreateExportErrLog(&err_log)
  1399. continue
  1400. } else if len(patient) == 1 { //
  1401. sch.PatientID = patient[0].ID
  1402. } else if len(patient) > 1 { //出现同名的情况
  1403. err_log := models.ExportErrLog{
  1404. LogType: 3,
  1405. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1406. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  1407. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在当前机构中存在重名,无法确定到具体患者",
  1408. Status: 1,
  1409. CreateTime: time.Now().Unix(),
  1410. UpdateTime: time.Now().Unix(),
  1411. ExportTime: export_time,
  1412. }
  1413. service.CreateExportErrLog(&err_log)
  1414. continue
  1415. }
  1416. }
  1417. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  1418. utils.ErrorLog("schedule_type")
  1419. return
  1420. }
  1421. schedule_type := int64(schMapM["schedule_type"].(float64))
  1422. if schedule_type <= 0 { //班次格式有误,插入日志
  1423. log := models.ExportLog{
  1424. LogType: 3,
  1425. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1426. TotalNum: int64(len(total_schedule)),
  1427. FailNum: 1,
  1428. SuccessNum: int64(len(schedules)),
  1429. CreateTime: time.Now().Unix(),
  1430. UpdateTime: time.Now().Unix(),
  1431. ExportTime: export_time,
  1432. Status: 1,
  1433. }
  1434. service.CreateExportLog(&log)
  1435. err_log := models.ExportErrLog{
  1436. LogType: 3,
  1437. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1438. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  1439. Status: 1,
  1440. CreateTime: time.Now().Unix(),
  1441. UpdateTime: time.Now().Unix(),
  1442. ExportTime: export_time,
  1443. }
  1444. service.CreateExportErrLog(&err_log)
  1445. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1446. return
  1447. } else {
  1448. sch.TimeType = int8(schedule_type)
  1449. }
  1450. if schMapM["template_id"] == nil && reflect.TypeOf(schMapM["template_id"]).String() != "float64" {
  1451. utils.ErrorLog("template_id")
  1452. return
  1453. }
  1454. template_id := int64(schMapM["template_id"].(float64))
  1455. sch.TemplateID = template_id
  1456. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  1457. utils.ErrorLog("device_number_name")
  1458. return
  1459. }
  1460. partition_name, _ := schMapM["partition_name"].(string)
  1461. zone, _ := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  1462. device_number_name, _ := schMapM["device_number_name"].(string)
  1463. if len(device_number_name) == 0 { //分区为空
  1464. log := models.ExportLog{
  1465. LogType: 3,
  1466. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1467. TotalNum: int64(len(total_schedule)),
  1468. FailNum: 1,
  1469. SuccessNum: int64(len(schedules)),
  1470. CreateTime: time.Now().Unix(),
  1471. UpdateTime: time.Now().Unix(),
  1472. ExportTime: export_time,
  1473. Status: 1,
  1474. }
  1475. service.CreateExportLog(&log)
  1476. err_log := models.ExportErrLog{
  1477. LogType: 3,
  1478. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1479. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1480. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  1481. Status: 1,
  1482. CreateTime: time.Now().Unix(),
  1483. UpdateTime: time.Now().Unix(),
  1484. ExportTime: export_time,
  1485. }
  1486. service.CreateExportErrLog(&err_log)
  1487. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1488. return
  1489. } else {
  1490. device, err := service.FindDeviceByNameTwo(device_number_name, this.GetAdminUserInfo().CurrentOrgId, zone.ID)
  1491. if err == nil {
  1492. if len(device) == 0 { //没查到数据,插入错误日志
  1493. log := models.ExportLog{
  1494. LogType: 3,
  1495. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1496. TotalNum: int64(len(total_schedule)),
  1497. FailNum: 1,
  1498. SuccessNum: int64(len(schedules)),
  1499. CreateTime: time.Now().Unix(),
  1500. UpdateTime: time.Now().Unix(),
  1501. ExportTime: export_time,
  1502. Status: 1,
  1503. }
  1504. service.CreateExportLog(&log)
  1505. err_log := models.ExportErrLog{
  1506. LogType: 3,
  1507. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1508. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  1509. Status: 1,
  1510. CreateTime: time.Now().Unix(),
  1511. UpdateTime: time.Now().Unix(),
  1512. ExportTime: export_time,
  1513. }
  1514. service.CreateExportErrLog(&err_log)
  1515. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1516. return
  1517. } else if len(device) == 1 {
  1518. sch.DeviceNumberID = device[0].ID
  1519. } else if len(device) > 1 { //出现重名,插入错误日志
  1520. log := models.ExportLog{
  1521. LogType: 3,
  1522. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1523. TotalNum: int64(len(total_schedule)),
  1524. FailNum: 1,
  1525. SuccessNum: int64(len(schedules)),
  1526. CreateTime: time.Now().Unix(),
  1527. UpdateTime: time.Now().Unix(),
  1528. ExportTime: export_time,
  1529. Status: 1,
  1530. }
  1531. service.CreateExportLog(&log)
  1532. err_log := models.ExportErrLog{
  1533. LogType: 3,
  1534. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1535. ErrMsg: "出现两个床位号相同的床位",
  1536. Status: 1,
  1537. CreateTime: time.Now().Unix(),
  1538. UpdateTime: time.Now().Unix(),
  1539. ExportTime: export_time,
  1540. }
  1541. service.CreateExportErrLog(&err_log)
  1542. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1543. return
  1544. }
  1545. }
  1546. }
  1547. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  1548. utils.ErrorLog("schedule_week")
  1549. return
  1550. }
  1551. schedule_week, _ := schMapM["schedule_week"].(string)
  1552. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  1553. log := models.ExportLog{
  1554. LogType: 3,
  1555. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1556. TotalNum: int64(len(total_schedule)),
  1557. FailNum: 1,
  1558. SuccessNum: int64(len(schedules)),
  1559. CreateTime: time.Now().Unix(),
  1560. UpdateTime: time.Now().Unix(),
  1561. ExportTime: export_time,
  1562. Status: 1,
  1563. }
  1564. service.CreateExportLog(&log)
  1565. err_log := models.ExportErrLog{
  1566. LogType: 3,
  1567. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1568. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1569. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1570. Status: 1,
  1571. CreateTime: time.Now().Unix(),
  1572. UpdateTime: time.Now().Unix(),
  1573. ExportTime: export_time,
  1574. }
  1575. service.CreateExportErrLog(&err_log)
  1576. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1577. return
  1578. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  1579. log := models.ExportLog{
  1580. LogType: 3,
  1581. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1582. TotalNum: int64(len(total_schedule)),
  1583. FailNum: 1,
  1584. SuccessNum: int64(len(schedules)),
  1585. CreateTime: time.Now().Unix(),
  1586. UpdateTime: time.Now().Unix(),
  1587. ExportTime: export_time,
  1588. Status: 1,
  1589. }
  1590. service.CreateExportLog(&log)
  1591. err_log := models.ExportErrLog{
  1592. LogType: 3,
  1593. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1594. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1595. Status: 1,
  1596. CreateTime: time.Now().Unix(),
  1597. UpdateTime: time.Now().Unix(),
  1598. ExportTime: export_time,
  1599. }
  1600. service.CreateExportErrLog(&err_log)
  1601. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1602. return
  1603. } else {
  1604. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  1605. sch.Weekday = int8(schedule_week)
  1606. }
  1607. sch.CreateTime = time.Now().Unix()
  1608. sch.ModifyTime = time.Now().Unix()
  1609. sch.TreatMode = 1
  1610. sch.Status = 1
  1611. sch.OrgID = this.GetAdminUserInfo().CurrentOrgId
  1612. sch.IsExport = 1
  1613. schedules = append(schedules, &sch)
  1614. }
  1615. errLogs, _ := service.FindSchedualTemplateExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  1616. if len(schedules) > 0 {
  1617. err := service.UpdateScheduleTemplateStatus(this.GetAdminUserInfo().CurrentOrgId)
  1618. if err == nil {
  1619. for _, item := range schedules {
  1620. service.CreateScheduleTemplate(item)
  1621. }
  1622. log := models.ExportLog{
  1623. LogType: 3,
  1624. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1625. TotalNum: int64(len(total_schedule)),
  1626. FailNum: int64(len(errLogs)),
  1627. SuccessNum: int64(len(schedules)),
  1628. CreateTime: time.Now().Unix(),
  1629. UpdateTime: time.Now().Unix(),
  1630. ExportTime: export_time,
  1631. Status: 1,
  1632. }
  1633. service.CreateExportLog(&log)
  1634. this.ServeSuccessJSON(map[string]interface{}{
  1635. "msg": "导入成功",
  1636. "total_num": len(total_schedule),
  1637. "success_num": len(schedules),
  1638. "fail_num": int64(len(errLogs)),
  1639. })
  1640. } else {
  1641. log := models.ExportLog{
  1642. LogType: 3,
  1643. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1644. TotalNum: int64(len(total_schedule)),
  1645. FailNum: int64(len(errLogs)),
  1646. SuccessNum: int64(len(schedules)),
  1647. CreateTime: time.Now().Unix(),
  1648. UpdateTime: time.Now().Unix(),
  1649. ExportTime: export_time,
  1650. Status: 1,
  1651. }
  1652. service.CreateExportLog(&log)
  1653. this.ServeSuccessJSON(map[string]interface{}{
  1654. "msg": "导入成功",
  1655. "total_num": len(total_schedule),
  1656. "success_num": len(schedules),
  1657. "fail_num": int64(len(errLogs)),
  1658. })
  1659. }
  1660. } else {
  1661. log := models.ExportLog{
  1662. LogType: 3,
  1663. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1664. TotalNum: int64(len(total_schedule)),
  1665. FailNum: int64(len(errLogs)),
  1666. SuccessNum: int64(len(schedules)),
  1667. CreateTime: time.Now().Unix(),
  1668. UpdateTime: time.Now().Unix(),
  1669. ExportTime: export_time,
  1670. Status: 1,
  1671. }
  1672. service.CreateExportLog(&log)
  1673. this.ServeSuccessJSON(map[string]interface{}{
  1674. "msg": "导入成功",
  1675. "total_num": len(total_schedule),
  1676. "success_num": len(schedules),
  1677. "fail_num": int64(len(errLogs)),
  1678. })
  1679. }
  1680. }
  1681. }
  1682. func (c *ScheduleApiController) GetInitExcelInitDate() {
  1683. thisTime := time.Now()
  1684. thisTime1 := time.Now()
  1685. thisTime2 := time.Now()
  1686. thisTime1 = thisTime1.AddDate(0, 0, 7)
  1687. thisTime2 = thisTime2.AddDate(0, 0, 14)
  1688. weekDay := int(thisTime.Weekday())
  1689. if weekDay == 0 {
  1690. weekDay = 7
  1691. }
  1692. weekEnd := 7 - weekDay
  1693. weekStart := weekEnd - 6
  1694. days := make([]string, 0)
  1695. for index := weekStart; index <= weekEnd; index++ {
  1696. theDay := thisTime.AddDate(0, 0, index)
  1697. days = append(days, theDay.Format("2006-01-02"))
  1698. }
  1699. weekDay1 := int(thisTime1.Weekday())
  1700. if weekDay1 == 0 {
  1701. weekDay1 = 7
  1702. }
  1703. weekEnd1 := 7 - weekDay1
  1704. weekStart1 := weekEnd1 - 6
  1705. for index := weekStart1; index <= weekEnd1; index++ {
  1706. theDay := thisTime1.AddDate(0, 0, index)
  1707. days = append(days, theDay.Format("2006-01-02"))
  1708. }
  1709. weekDay2 := int(thisTime2.Weekday())
  1710. if weekDay2 == 0 {
  1711. weekDay2 = 7
  1712. }
  1713. weekEnd2 := 7 - weekDay2
  1714. weekStart2 := weekEnd2 - 6
  1715. for index := weekStart2; index <= weekEnd2; index++ {
  1716. theDay := thisTime2.AddDate(0, 0, index)
  1717. days = append(days, theDay.Format("2006-01-02"))
  1718. }
  1719. c.ServeSuccessJSON(map[string]interface{}{
  1720. "days": days,
  1721. })
  1722. return
  1723. }
  1724. func GetWeekString(week string) string {
  1725. var weekStr string
  1726. switch week {
  1727. case "Sunday":
  1728. weekStr = "周日"
  1729. break
  1730. case "Monday":
  1731. weekStr = "周一"
  1732. break
  1733. case "Tuesday":
  1734. weekStr = "周二"
  1735. break
  1736. case "Wednesday":
  1737. weekStr = "周三"
  1738. break
  1739. case "Thursday":
  1740. weekStr = "周四"
  1741. break
  1742. case "Friday":
  1743. weekStr = "周五"
  1744. break
  1745. case "Saturday":
  1746. weekStr = "周六"
  1747. break
  1748. default:
  1749. weekStr = ""
  1750. break
  1751. }
  1752. return weekStr
  1753. }
  1754. func (c *ScheduleApiController) SearchTemplateSchedulePatients() {
  1755. template_id, _ := c.GetInt64("template_id", 0)
  1756. keywords := c.GetString("keywords")
  1757. adminInfo := c.GetAdminUserInfo()
  1758. scheduleItems, _ := service.GetTemplateSchedualPatientsByKeywords(keywords, adminInfo.CurrentOrgId, template_id)
  1759. c.ServeSuccessJSON(map[string]interface{}{
  1760. "schdules": scheduleItems,
  1761. })
  1762. }
  1763. func (c *ScheduleApiController) CancelScheduleTemplate() {
  1764. item_id, _ := c.GetInt64("id")
  1765. adminInfo := c.GetAdminUserInfo()
  1766. err := service.UpdateNewScheduleTemplateStatus(item_id, adminInfo.CurrentOrgId)
  1767. if err == nil {
  1768. c.ServeSuccessJSON(map[string]interface{}{
  1769. "msg": "取消成功",
  1770. })
  1771. return
  1772. } else {
  1773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1774. return
  1775. }
  1776. }
  1777. func (this *ScheduleApiController) GetNextWeekDaySchedule() {
  1778. week_type, _ := this.GetInt64("week_type", -1)
  1779. week_time, _ := this.GetInt64("week_time")
  1780. //start_time, _ := this.GetInt64("start_time")
  1781. //end_time, _ := this.GetInt64("end_time")
  1782. record_date := this.GetString("record_date")
  1783. zons := this.GetString("zone")
  1784. zone := strings.Split(zons, ",")
  1785. start_time := this.GetString("start_time")
  1786. end_time := this.GetString("end_time")
  1787. timeLayout := "2006-01-02"
  1788. loc, _ := time.LoadLocation("Local")
  1789. theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1790. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  1791. adminUserInfo := this.GetAdminUserInfo()
  1792. var theStartTIme int64
  1793. if len(record_date) > 0 {
  1794. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1795. if err != nil {
  1796. utils.ErrorLog(err.Error())
  1797. }
  1798. theStartTIme = theTime.Unix()
  1799. }
  1800. schedule, err := service.GetNextWeekDaySchedule(week_type, week_time, theTimeStart.Unix(), theTimeEnd.Unix(), adminUserInfo.CurrentOrgId, zone, theStartTIme)
  1801. if err != nil {
  1802. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1803. return
  1804. }
  1805. this.ServeSuccessJSON(map[string]interface{}{
  1806. "schedule": schedule,
  1807. })
  1808. }
  1809. func (this *ScheduleApiController) GetThreeWeekList() {
  1810. start_time := this.GetString("start_time")
  1811. end_time := this.GetString("end_time")
  1812. partition_id, _ := this.GetInt64("partition_id")
  1813. schedule_type, _ := this.GetInt64("schedule_type")
  1814. fmt.Println(partition_id, schedule_type)
  1815. timeLayout := "2006-01-02"
  1816. loc, _ := time.LoadLocation("Local")
  1817. var theStartTIme int64
  1818. if len(start_time) > 0 {
  1819. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1820. if err != nil {
  1821. utils.ErrorLog(err.Error())
  1822. }
  1823. theStartTIme = theTime.Unix()
  1824. }
  1825. var theEndtTIme int64
  1826. if len(end_time) > 0 {
  1827. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  1828. if err != nil {
  1829. utils.ErrorLog(err.Error())
  1830. }
  1831. theEndtTIme = theTime.Unix()
  1832. }
  1833. adminUserInfo := this.GetAdminUserInfo()
  1834. orgId := adminUserInfo.CurrentOrgId
  1835. partitions, _ := service.GetSchedulePartitionPanel(orgId)
  1836. list, err := service.GetThreeWeekList(theStartTIme, theEndtTIme, orgId, schedule_type, partition_id)
  1837. if err != nil {
  1838. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1839. return
  1840. }
  1841. this.ServeSuccessJSON(map[string]interface{}{
  1842. "list": list,
  1843. "partitions": partitions,
  1844. })
  1845. }
  1846. func (this *ScheduleApiController) GetAllZones() {
  1847. adminUserInfo := this.GetAdminUserInfo()
  1848. orgId := adminUserInfo.CurrentOrgId
  1849. zones, err := service.GetAllZoneOne(orgId)
  1850. if err != nil {
  1851. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1852. return
  1853. }
  1854. this.ServeSuccessJSON(map[string]interface{}{
  1855. "zones": zones,
  1856. })
  1857. }
  1858. func (this *ScheduleApiController) GetCopyPatientSchedules() {
  1859. adminUserInfo := this.GetAdminUserInfo()
  1860. orgId := adminUserInfo.CurrentOrgId
  1861. start_time, _ := this.GetInt64("start_time")
  1862. fmt.Println("start_time", start_time)
  1863. end_time, _ := this.GetInt64("end_time")
  1864. fmt.Println("end_time", end_time)
  1865. copy_startime, _ := this.GetInt64("copy_startime")
  1866. fmt.Println("copy_startime", copy_startime)
  1867. copy_endtime, _ := this.GetInt64("copy_endtime")
  1868. //获取本周患者排班
  1869. schedules, _ := service.GetWeekSchedules(orgId, start_time, end_time)
  1870. //先清除复制周的排班
  1871. errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
  1872. fmt.Println(errcode)
  1873. for _, item := range schedules {
  1874. //fmt.Println(item.StartTime+604800)
  1875. //礼拜1
  1876. if item.ScheduleWeek == 1 {
  1877. item.ScheduleDate = copy_startime
  1878. }
  1879. if item.ScheduleWeek == 2 {
  1880. item.ScheduleDate = copy_startime + 86400
  1881. }
  1882. if item.ScheduleWeek == 3 {
  1883. item.ScheduleDate = copy_startime + 172800
  1884. }
  1885. if item.ScheduleWeek == 4 {
  1886. item.ScheduleDate = copy_startime + 259200
  1887. }
  1888. if item.ScheduleWeek == 5 {
  1889. item.ScheduleDate = copy_startime + 345600
  1890. }
  1891. if item.ScheduleWeek == 6 {
  1892. item.ScheduleDate = copy_startime + 432000
  1893. }
  1894. //礼拜天
  1895. if item.ScheduleWeek == 7 {
  1896. item.ScheduleDate = copy_endtime
  1897. }
  1898. schedule := models.XtSchedule{
  1899. UserOrgId: item.UserOrgId,
  1900. PartitionId: item.PartitionId,
  1901. BedId: item.BedId,
  1902. PatientId: item.PatientId,
  1903. ScheduleDate: item.ScheduleDate,
  1904. ScheduleType: item.ScheduleType,
  1905. ScheduleWeek: item.ScheduleWeek,
  1906. ModeId: item.ModeId,
  1907. Status: 1,
  1908. CreatedTime: time.Now().Unix(),
  1909. }
  1910. err := service.AddPatientSchedule(&schedule)
  1911. if err != nil {
  1912. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1913. return
  1914. }
  1915. this.ServeSuccessJSON(map[string]interface{}{
  1916. "schedule": schedule,
  1917. })
  1918. }
  1919. //查询复制中的排班日期是否存在
  1920. //_, errcode := service.GetLastWeekSchedule(orgId, copy_startime, copy_endtime)
  1921. //
  1922. //if errcode == gorm.ErrRecordNotFound {
  1923. // //如果没有直接新增
  1924. //
  1925. // for _, item := range schedules {
  1926. // //fmt.Println(item.StartTime+604800)
  1927. // //礼拜1
  1928. // if item.ScheduleWeek == 1 {
  1929. // item.ScheduleDate = copy_startime
  1930. // }
  1931. // if item.ScheduleWeek == 2 {
  1932. // item.ScheduleDate = copy_startime + 86400
  1933. // }
  1934. // if item.ScheduleWeek == 3 {
  1935. // item.ScheduleDate = copy_startime + 172800
  1936. // }
  1937. // if item.ScheduleWeek == 4 {
  1938. // item.ScheduleDate = copy_startime + 259200
  1939. // }
  1940. // if item.ScheduleWeek == 5 {
  1941. // item.ScheduleDate = copy_startime + 345600
  1942. // }
  1943. //
  1944. // if item.ScheduleWeek == 6 {
  1945. // item.ScheduleDate = copy_startime + 432000
  1946. // }
  1947. // //礼拜天
  1948. // if item.ScheduleWeek == 0 {
  1949. // item.ScheduleDate = copy_endtime
  1950. // }
  1951. // schedule := models.XtSchedule{
  1952. // UserOrgId: item.UserOrgId,
  1953. // PartitionId: item.PartitionId,
  1954. // BedId: item.BedId,
  1955. // PatientId: item.PatientId,
  1956. // ScheduleDate: item.ScheduleDate,
  1957. // ScheduleType: item.ScheduleType,
  1958. // ScheduleWeek: item.ScheduleWeek,
  1959. // ModeId: item.ModeId,
  1960. // Status: 1,
  1961. // CreatedTime: time.Now().Unix(),
  1962. // }
  1963. //
  1964. // err := service.AddPatientSchedule(&schedule)
  1965. // if err != nil {
  1966. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1967. // return
  1968. // }
  1969. // this.ServeSuccessJSON(map[string]interface{}{
  1970. // "schedule": schedule,
  1971. // })
  1972. // }
  1973. //} else if errcode == nil {
  1974. //
  1975. // //先清除复制周的排班
  1976. // errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
  1977. // fmt.Println(errcode)
  1978. // for _, item := range schedules {
  1979. // //fmt.Println(item.StartTime+604800)
  1980. // //礼拜1
  1981. // if item.ScheduleWeek == 1 {
  1982. // item.ScheduleDate = copy_startime
  1983. // }
  1984. // if item.ScheduleWeek == 2 {
  1985. // item.ScheduleDate = copy_startime + 86400
  1986. // }
  1987. // if item.ScheduleWeek == 3 {
  1988. // item.ScheduleDate = copy_startime + 172800
  1989. // }
  1990. // if item.ScheduleWeek == 4 {
  1991. // item.ScheduleDate = copy_startime + 259200
  1992. // }
  1993. // if item.ScheduleWeek == 5 {
  1994. // item.ScheduleDate = copy_startime + 345600
  1995. // }
  1996. //
  1997. // if item.ScheduleWeek == 6 {
  1998. // item.ScheduleDate = copy_startime + 432000
  1999. // }
  2000. // //礼拜天
  2001. // if item.ScheduleWeek == 0 {
  2002. // item.ScheduleDate = copy_endtime
  2003. // }
  2004. // schedule := models.XtSchedule{
  2005. // UserOrgId: item.UserOrgId,
  2006. // PartitionId: item.PartitionId,
  2007. // BedId: item.BedId,
  2008. // PatientId: item.PatientId,
  2009. // ScheduleDate: item.ScheduleDate,
  2010. // ScheduleType: item.ScheduleType,
  2011. // ScheduleWeek: item.ScheduleWeek,
  2012. // ModeId: item.ModeId,
  2013. // Status: 1,
  2014. // CreatedTime: time.Now().Unix(),
  2015. // }
  2016. //
  2017. // err := service.AddPatientSchedule(&schedule)
  2018. // if err != nil {
  2019. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2020. // return
  2021. // }
  2022. // this.ServeSuccessJSON(map[string]interface{}{
  2023. // "schedule": schedule,
  2024. // })
  2025. // }
  2026. //}
  2027. }
  2028. func (this *ScheduleApiController) SaveRemindPrint() {
  2029. id, _ := this.GetInt64("id")
  2030. anticoagulants, _ := this.GetInt64("anticoagulant")
  2031. anticoagulant_zongliang, _ := this.GetInt64("anticoagulant_zongliang")
  2032. classes, _ := this.GetInt64("classes")
  2033. dialyzers, _ := this.GetInt64("dialyzers")
  2034. doctor_advice, _ := this.GetInt64("doctor_advice")
  2035. mode, _ := this.GetInt64("mode")
  2036. name, _ := this.GetInt64("name")
  2037. number, _ := this.GetInt64("number")
  2038. perfusion_apparatus, _ := this.GetInt64("perfusion_apparatus")
  2039. prescription_status, _ := this.GetInt64("prescription_status")
  2040. week, _ := this.GetInt64("week")
  2041. zone, _ := this.GetInt64("zone")
  2042. adminUserInfo := this.GetAdminUserInfo()
  2043. orgId := adminUserInfo.CurrentOrgId
  2044. setting := models.XtRemindPrintSetting{
  2045. Anticoagulant: anticoagulants,
  2046. Classes: classes,
  2047. AnticoagulantZongliang: anticoagulant_zongliang,
  2048. Dialyzers: dialyzers,
  2049. DoctorAdvice: doctor_advice,
  2050. Mode: mode,
  2051. Name: name,
  2052. Number: number,
  2053. PerfusionApparatus: perfusion_apparatus,
  2054. PrescriptionStatus: prescription_status,
  2055. Week: week,
  2056. Zone: zone,
  2057. UserOrgId: orgId,
  2058. Status: 1,
  2059. Ctime: time.Now().Unix(),
  2060. }
  2061. _, errcode := service.GetSettingById(id)
  2062. if errcode == gorm.ErrRecordNotFound {
  2063. err := service.CreateSetting(&setting)
  2064. if err != nil {
  2065. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2066. return
  2067. }
  2068. this.ServeSuccessJSON(map[string]interface{}{
  2069. "setting": setting,
  2070. })
  2071. } else if errcode == nil {
  2072. err := service.UpdatedRemindPrint(&setting, id)
  2073. if err != nil {
  2074. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2075. return
  2076. }
  2077. this.ServeSuccessJSON(map[string]interface{}{
  2078. "setting": setting,
  2079. })
  2080. }
  2081. }
  2082. func (this *ScheduleApiController) GetRemindPrintList() {
  2083. adminUserInfo := this.GetAdminUserInfo()
  2084. orgId := adminUserInfo.CurrentOrgId
  2085. list, err := service.GetRemindPrintList(orgId)
  2086. if err != nil {
  2087. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2088. return
  2089. }
  2090. this.ServeSuccessJSON(map[string]interface{}{
  2091. "list": list,
  2092. })
  2093. }
  2094. func (this *ScheduleApiController) GetBloodScheduleList() {
  2095. week_type, _ := this.GetInt64("week_type", -1)
  2096. week_time, _ := this.GetInt64("week_time")
  2097. zones := this.GetString("zone")
  2098. zone := strings.Split(zones, ",")
  2099. thisTime := time.Now()
  2100. weekDay := int(thisTime.Weekday())
  2101. if weekDay == 0 {
  2102. weekDay = 7
  2103. }
  2104. weekEnd := 7 - weekDay
  2105. weekStart := weekEnd - 6
  2106. weekTitle := make([]string, 0)
  2107. days := make([]string, 0)
  2108. for index := weekStart; index <= weekEnd; index++ {
  2109. theDay := thisTime.AddDate(0, 0, index)
  2110. indexYear, indexMonthTime, indexDay := theDay.Date()
  2111. indexMonth := int(indexMonthTime)
  2112. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  2113. weekTitle = append(weekTitle, indexWeek)
  2114. days = append(days, theDay.Format("2006-01-02"))
  2115. }
  2116. fmt.Println(days)
  2117. var targetDayStr string
  2118. var startTime string
  2119. switch week_type {
  2120. case 0:
  2121. startTime = days[0]
  2122. targetDayStr = days[6]
  2123. break
  2124. case 1:
  2125. targetDayStr = days[0]
  2126. break
  2127. case 2:
  2128. targetDayStr = days[1]
  2129. break
  2130. case 3:
  2131. targetDayStr = days[2]
  2132. break
  2133. case 4:
  2134. targetDayStr = days[3]
  2135. break
  2136. case 5:
  2137. targetDayStr = days[4]
  2138. break
  2139. case 6:
  2140. targetDayStr = days[5]
  2141. break
  2142. case 7:
  2143. targetDayStr = days[6]
  2144. break
  2145. }
  2146. targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  2147. if parseErr != nil {
  2148. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2149. return
  2150. }
  2151. orgId := this.GetAdminUserInfo().CurrentOrgId
  2152. if week_type > 0 {
  2153. list, err := service.GetWeekDayScheduleByIdThee(orgId, targetDay.Unix(), week_time, zone)
  2154. if err != nil {
  2155. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2156. return
  2157. }
  2158. this.ServeSuccessJSON(map[string]interface{}{
  2159. "list": list,
  2160. "day": targetDayStr,
  2161. })
  2162. }
  2163. if week_type == 0 {
  2164. startDate, _ := utils.ParseTimeStringToTime("2006-01-02", startTime)
  2165. list, err := service.GetWeekDayScheduleByIdTwo(orgId, targetDay.Unix(), week_time, startDate.Unix(), zone)
  2166. if err != nil {
  2167. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2168. return
  2169. }
  2170. this.ServeSuccessJSON(map[string]interface{}{
  2171. "list": list,
  2172. "day": targetDayStr,
  2173. })
  2174. }
  2175. }
  2176. func (this *ScheduleApiController) GetPrintList() {
  2177. adminUserInfo := this.GetAdminUserInfo()
  2178. orgId := adminUserInfo.CurrentOrgId
  2179. list, err := service.GetRemindPrintList(orgId)
  2180. if err != nil {
  2181. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2182. return
  2183. }
  2184. this.ServeSuccessJSON(map[string]interface{}{
  2185. "list": list,
  2186. })
  2187. }
  2188. func (this *ScheduleApiController) GetAllZoneList() {
  2189. adminUserInfo := this.GetAdminUserInfo()
  2190. orgId := adminUserInfo.CurrentOrgId
  2191. zoneList, err := service.GetAllZoneOne(orgId)
  2192. if err != nil {
  2193. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2194. return
  2195. }
  2196. this.ServeSuccessJSON(map[string]interface{}{
  2197. "zoneList": zoneList,
  2198. })
  2199. }
  2200. func (this *ScheduleApiController) GetPatientScheduleCount() {
  2201. patitionIdStr := this.GetString("partition_id")
  2202. week, _ := this.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  2203. ids := strings.Split(patitionIdStr, ",")
  2204. adminUserInfo := this.GetAdminUserInfo()
  2205. orgId := adminUserInfo.CurrentOrgId
  2206. thisTime := time.Now()
  2207. weekDay := int(thisTime.Weekday())
  2208. if week < 1 || week > 4 {
  2209. week = 2
  2210. }
  2211. if week == 1 {
  2212. thisTime = thisTime.AddDate(0, 0, -7)
  2213. } else if week == 3 {
  2214. thisTime = thisTime.AddDate(0, 0, 7)
  2215. } else if week == 4 {
  2216. thisTime = thisTime.AddDate(0, 0, 14)
  2217. }
  2218. if weekDay == 0 {
  2219. weekDay = 7
  2220. }
  2221. weekEnd := 7 - weekDay
  2222. weekStart := weekEnd - 6
  2223. weekTitle := make([]string, 0)
  2224. days := make([]string, 0)
  2225. for index := weekStart; index <= weekEnd; index++ {
  2226. theDay := thisTime.AddDate(0, 0, index)
  2227. indexYear, indexMonthTime, indexDay := theDay.Date()
  2228. indexMonth := int(indexMonthTime)
  2229. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  2230. weekTitle = append(weekTitle, indexWeek)
  2231. days = append(days, theDay.Format("2006-01-02"))
  2232. }
  2233. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  2234. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  2235. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  2236. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  2237. timeLayout := "2006-01-02 15:04:05"
  2238. loc, _ := time.LoadLocation("Local")
  2239. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  2240. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  2241. weekStartPoint := theStarTime.Unix()
  2242. weekEndPoint := theEndTime.Unix()
  2243. list, err := service.GetPatientScheduleCount(orgId, weekStartPoint, weekEndPoint, ids)
  2244. _, total, _ := service.GetTotalBedNumber(orgId, ids)
  2245. if err != nil {
  2246. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2247. return
  2248. }
  2249. this.ServeSuccessJSON(map[string]interface{}{
  2250. "list": list,
  2251. "total": total,
  2252. })
  2253. }
  2254. func (c *ScheduleApiController) GetWeekPanelsOne() {
  2255. data, _ := c.GetInt64("data", 1)
  2256. patitionIdStr := c.GetString("patitionid")
  2257. ids := strings.Split(patitionIdStr, ",")
  2258. adminInfo := c.GetAdminUserInfo()
  2259. thisTime := time.Now()
  2260. year, monthTime, day := thisTime.Date()
  2261. month := int(monthTime)
  2262. _, theWeek := thisTime.ISOWeek()
  2263. weekDay := int(thisTime.Weekday())
  2264. if weekDay == 0 {
  2265. weekDay = 7
  2266. }
  2267. weekEnd := 7 - weekDay
  2268. weekStart := weekEnd - 6
  2269. weekDays := make([]string, 0)
  2270. for index := weekStart; index <= weekEnd; index++ {
  2271. theDay := thisTime.AddDate(0, 0, index)
  2272. indexYear, indexMonthTime, indexDay := theDay.Date()
  2273. indexMonth := int(indexMonthTime)
  2274. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  2275. weekDays = append(weekDays, indexWeek)
  2276. }
  2277. returnData := map[string]interface{}{
  2278. "year": year,
  2279. "month": month,
  2280. "day": day,
  2281. "theWeek": theWeek,
  2282. "weekDay": weekDay,
  2283. "weekDays": weekDays,
  2284. }
  2285. if data == 1 {
  2286. partitions, _ := service.GetSchedulePartitionPanelTwo(adminInfo.CurrentOrgId, ids)
  2287. returnData["partitions"] = partitions
  2288. }
  2289. c.ServeSuccessJSON(returnData)
  2290. return
  2291. }
  2292. func (c *ScheduleApiController) GetScheduleOne() {
  2293. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  2294. patitionIdStr := c.GetString("patitionid")
  2295. ids := strings.Split(patitionIdStr, ",")
  2296. fmt.Println("patitonStr", ids)
  2297. schedule_type, _ := c.GetInt64("schedule_type")
  2298. adminInfo := c.GetAdminUserInfo()
  2299. thisTime := time.Now()
  2300. today := thisTime.Format("2006-01-02")
  2301. if week < 1 || week > 4 {
  2302. week = 2
  2303. }
  2304. if week == 1 {
  2305. thisTime = thisTime.AddDate(0, 0, -7)
  2306. } else if week == 3 {
  2307. thisTime = thisTime.AddDate(0, 0, 7)
  2308. } else if week == 4 {
  2309. thisTime = thisTime.AddDate(0, 0, 14)
  2310. }
  2311. weekDay := int(thisTime.Weekday())
  2312. if weekDay == 0 {
  2313. weekDay = 7
  2314. }
  2315. weekEnd := 7 - weekDay
  2316. weekStart := weekEnd - 6
  2317. weekTitle := make([]string, 0)
  2318. days := make([]string, 0)
  2319. for index := weekStart; index <= weekEnd; index++ {
  2320. theDay := thisTime.AddDate(0, 0, index)
  2321. indexYear, indexMonthTime, indexDay := theDay.Date()
  2322. indexMonth := int(indexMonthTime)
  2323. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  2324. weekTitle = append(weekTitle, indexWeek)
  2325. days = append(days, theDay.Format("2006-01-02"))
  2326. }
  2327. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  2328. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  2329. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  2330. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  2331. timeLayout := "2006-01-02 15:04:05"
  2332. loc, _ := time.LoadLocation("Local")
  2333. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  2334. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  2335. weekStartPoint := theStarTime.Unix()
  2336. weekEndPoint := theEndTime.Unix()
  2337. schdules, _ := service.GetWeekScheduleTwo(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type)
  2338. c.ServeSuccessJSON(map[string]interface{}{
  2339. "days": days,
  2340. "weekTitle": weekTitle,
  2341. "schdules": schdules,
  2342. "today": today,
  2343. })
  2344. return
  2345. }
  2346. func (c *ScheduleApiController) SaveScheduleTemplate() {
  2347. template_id, _ := c.GetInt64("template_id")
  2348. orgId := c.GetAdminUserInfo().CurrentOrgId
  2349. template := models.ScheduleTemplate{
  2350. TemplateId: template_id,
  2351. UserOrgId: orgId,
  2352. Status: 1,
  2353. Ctime: time.Now().Unix(),
  2354. }
  2355. _, errcodes := service.GetScheudleTemplateById(orgId)
  2356. if errcodes == gorm.ErrRecordNotFound {
  2357. service.CreateXtscheduleTemplate(&template)
  2358. } else if errcodes == nil {
  2359. service.UpdateXtScheduleTemplate(&template, orgId)
  2360. }
  2361. c.ServeSuccessJSON(map[string]interface{}{
  2362. "template": template,
  2363. })
  2364. return
  2365. }
  2366. func (c *ScheduleApiController) GetScheduleTemplate() {
  2367. adminUserInfo := c.GetAdminUserInfo()
  2368. orgId := adminUserInfo.CurrentOrgId
  2369. template, _ := service.GetScheduleTemplate(orgId)
  2370. c.ServeSuccessJSON(map[string]interface{}{
  2371. "template": template,
  2372. })
  2373. return
  2374. }
  2375. func (c *ScheduleApiController) ChangeFuncPrint() {
  2376. adminUserInfo := c.GetAdminUserInfo()
  2377. orgId := adminUserInfo.CurrentOrgId
  2378. is_open, _ := c.GetInt64("is_open")
  2379. dataPrint := models.XtDataPrint{
  2380. UserOrgId: orgId,
  2381. IsOpen: is_open,
  2382. Status: 1,
  2383. Ctime: time.Now().Unix(),
  2384. }
  2385. _, errcode := service.GetDataPrintByOrgId(orgId)
  2386. fmt.Println("errcode222234444555556t66", errcode)
  2387. if errcode == gorm.ErrRecordNotFound {
  2388. service.CreateDataPrint(&dataPrint)
  2389. c.ServeSuccessJSON(map[string]interface{}{
  2390. "dataPrint": dataPrint,
  2391. })
  2392. return
  2393. } else if errcode == nil {
  2394. service.UpdteDataPrint(orgId, &dataPrint)
  2395. c.ServeSuccessJSON(map[string]interface{}{
  2396. "dataPrint": dataPrint,
  2397. })
  2398. return
  2399. }
  2400. }
  2401. func (c *ScheduleApiController) GetDataPrint() {
  2402. adminUserInfo := c.GetAdminUserInfo()
  2403. orgId := adminUserInfo.CurrentOrgId
  2404. dataPrint, _ := service.GetDataPrint(orgId)
  2405. c.ServeSuccessJSON(map[string]interface{}{
  2406. "dataPrint": dataPrint,
  2407. })
  2408. return
  2409. }
  2410. func (c *ScheduleApiController) GetNextWeekPanels() {
  2411. start_time, _ := c.GetInt64("start_time")
  2412. fmt.Println("start_time", start_time)
  2413. end_time, _ := c.GetInt64("end_time")
  2414. fmt.Println("end_time", end_time)
  2415. orgId := c.GetAdminUserInfo().CurrentOrgId
  2416. schedule, _ := service.GetNextWeekPanels(start_time, end_time, orgId)
  2417. c.ServeSuccessJSON(map[string]interface{}{
  2418. "schedule": schedule,
  2419. })
  2420. }
  2421. func (c *ScheduleApiController) SynchroSchedule() {
  2422. template_id, _ := c.GetInt64("template_id")
  2423. copy_startime, _ := c.GetInt64("copy_startime")
  2424. copy_endtime, _ := c.GetInt64("copy_endtime")
  2425. orgId := c.GetAdminUserInfo().CurrentOrgId
  2426. //根据模板ID获取模板数据
  2427. list, _ := service.GetTemplateListByTemplateId(template_id, orgId)
  2428. recordDateStr := time.Now().Format("2006-01-02")
  2429. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2430. nowtime := recordDate.Unix()
  2431. fmt.Println("今日时间", nowtime)
  2432. fmt.Println("后期日期", copy_startime)
  2433. var tuesday int64
  2434. var wednesday int64
  2435. var thursday int64
  2436. var friday int64
  2437. var saturday int64
  2438. //如果选择的开始日期大于当前日期
  2439. if copy_startime > nowtime {
  2440. //清空该时间段的所有排班数据
  2441. service.DeletePatientSchedule(copy_startime, copy_endtime, orgId)
  2442. tuesday = copy_startime + 86400
  2443. wednesday = copy_startime + 172800
  2444. thursday = copy_startime + 259200
  2445. friday = copy_startime + 345600
  2446. saturday = copy_startime + 432000
  2447. for _, item := range list {
  2448. if item.Weekday == 1 {
  2449. item.ScheduleDate = copy_startime
  2450. }
  2451. if item.Weekday == 2 {
  2452. item.ScheduleDate = tuesday
  2453. }
  2454. if item.Weekday == 3 {
  2455. item.ScheduleDate = wednesday
  2456. }
  2457. if item.Weekday == 4 {
  2458. item.ScheduleDate = thursday
  2459. }
  2460. if item.Weekday == 5 {
  2461. item.ScheduleDate = friday
  2462. }
  2463. if item.Weekday == 6 {
  2464. item.ScheduleDate = saturday
  2465. }
  2466. if item.Weekday == 7 {
  2467. item.ScheduleDate = copy_endtime
  2468. }
  2469. //根据床位号获取区号
  2470. number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
  2471. item.ZoneId = number.ZoneID
  2472. }
  2473. for _, item := range list {
  2474. schedule := models.XtSchedule{
  2475. UserOrgId: orgId,
  2476. PartitionId: item.ZoneId,
  2477. BedId: item.DeviceNumberID,
  2478. PatientId: item.PatientID,
  2479. ScheduleDate: item.ScheduleDate,
  2480. ScheduleType: item.TimeType,
  2481. ScheduleWeek: item.Weekday,
  2482. ModeId: item.TreatMode,
  2483. Status: 1,
  2484. CreatedTime: time.Now().Unix(),
  2485. UpdatedTime: 0,
  2486. }
  2487. service.CreatePatientSchedule(&schedule)
  2488. }
  2489. }
  2490. //如果选择的日期小于当前日期,只同步今日以后的数据
  2491. if copy_startime <= nowtime {
  2492. //清空今日以后的数据
  2493. service.DeletePatientScheduleToday(nowtime, copy_endtime, orgId)
  2494. var tuesday int64
  2495. var wednesday int64
  2496. var thursday int64
  2497. var friday int64
  2498. var saturday int64
  2499. tuesday = copy_startime + 86400
  2500. wednesday = copy_startime + 172800
  2501. thursday = copy_startime + 259200
  2502. friday = copy_startime + 345600
  2503. saturday = copy_startime + 432000
  2504. for _, item := range list {
  2505. if item.Weekday == 1 {
  2506. item.ScheduleDate = copy_startime
  2507. }
  2508. if item.Weekday == 2 {
  2509. item.ScheduleDate = tuesday
  2510. }
  2511. if item.Weekday == 3 {
  2512. item.ScheduleDate = wednesday
  2513. }
  2514. if item.Weekday == 4 {
  2515. item.ScheduleDate = thursday
  2516. }
  2517. if item.Weekday == 5 {
  2518. item.ScheduleDate = friday
  2519. }
  2520. if item.Weekday == 6 {
  2521. item.ScheduleDate = saturday
  2522. }
  2523. if item.Weekday == 7 {
  2524. item.ScheduleDate = copy_endtime
  2525. }
  2526. //根据床位号获取区号
  2527. number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
  2528. item.ZoneId = number.ZoneID
  2529. }
  2530. for _, item := range list {
  2531. // 同步今日以后的数据
  2532. if item.ScheduleDate > nowtime {
  2533. schedule := models.XtSchedule{
  2534. UserOrgId: orgId,
  2535. PartitionId: item.ZoneId,
  2536. BedId: item.DeviceNumberID,
  2537. PatientId: item.PatientID,
  2538. ScheduleDate: item.ScheduleDate,
  2539. ScheduleType: item.TimeType,
  2540. ScheduleWeek: item.Weekday,
  2541. ModeId: item.TreatMode,
  2542. Status: 1,
  2543. CreatedTime: time.Now().Unix(),
  2544. UpdatedTime: 0,
  2545. }
  2546. service.CreatePatientSchedule(&schedule)
  2547. }
  2548. }
  2549. }
  2550. returnData := make(map[string]interface{}, 0)
  2551. returnData["list"] = list
  2552. c.ServeSuccessJSON(returnData)
  2553. return
  2554. }
  2555. func (c *ScheduleApiController) GetPatientScheduleTempalate() {
  2556. orgId := c.GetAdminUserInfo().CurrentOrgId
  2557. tempalate, _ := service.GetPatientScheduleTempalate(orgId)
  2558. c.ServeSuccessJSON(map[string]interface{}{
  2559. "schedule": tempalate,
  2560. })
  2561. }
  2562. func (c *ScheduleApiController) GetSolutionSchedule() {
  2563. orgId := c.GetAdminUserInfo().CurrentOrgId
  2564. solution, _ := service.GetSolutionSchedule(orgId)
  2565. c.ServeSuccessJSON(map[string]interface{}{
  2566. "solution": solution,
  2567. })
  2568. return
  2569. }