schedule_api_controller.go 91KB

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