schedule_api_controller.go 81KB

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