schedule_api_controller.go 90KB

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