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