schedule_api_controller.go 81KB

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