schedule_api_controller.go 94KB

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