schedule_api_controller.go 81KB

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