schedule_api_controller.go 122KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/jinzhu/gorm"
  10. "reflect"
  11. "strconv"
  12. "strings"
  13. "time"
  14. "github.com/astaxie/beego"
  15. )
  16. type ScheduleApiController struct {
  17. BaseAuthAPIController
  18. }
  19. func ScheduleApiRegistRouters() {
  20. beego.Router("/api/schedule/weekpanel", &ScheduleApiController{}, "Get:GetWeekPanels")
  21. beego.Router("/api/schedule/schedules", &ScheduleApiController{}, "Get:GetSchedules")
  22. beego.Router("/api/excel_date/init", &ScheduleApiController{}, "Get:GetInitExcelInitDate")
  23. beego.Router("/api/schedule/patients", &ScheduleApiController{}, "Get:GetPatients")
  24. beego.Router("/api/schedule/create", &ScheduleApiController{}, "Post:CreateSchedule")
  25. beego.Router("/api/schedule/delete", &ScheduleApiController{}, "Delete:DeleteSchedule")
  26. beego.Router("/api/schedule/change", &ScheduleApiController{}, "Put:ChangeSchedule")
  27. beego.Router("/api/schedule/urgentinit", &ScheduleApiController{}, "Get:UrgentScheduleData")
  28. beego.Router("/api/schedule/print/initdata", &ScheduleApiController{}, "get:PrintInitData")
  29. beego.Router("/api/schedule/search", &ScheduleApiController{}, "get:SearchSchedulePatients")
  30. beego.Router("/api/schedule/week", &ScheduleApiController{}, "get:GetWeekDaySchedule")
  31. beego.Router("/api/schedule/export", &ScheduleApiController{}, "post:ExportSchedule")
  32. beego.Router("/api/schedule_template/export", &ScheduleApiController{}, "post:ExportScheduleTemplate")
  33. beego.Router("/api/schedule_template/search", &ScheduleApiController{}, "get:SearchTemplateSchedulePatients")
  34. beego.Router("/api/schedule_template/cancel", &ScheduleApiController{}, "post:CancelScheduleTemplate")
  35. beego.Router("/api/schedule/getnextscheduleweekday", &ScheduleApiController{}, "Get:GetNextWeekDaySchedule")
  36. beego.Router("/api/schedule/getthreeweeklist", &ScheduleApiController{}, "Get:GetThreeWeekList")
  37. beego.Router("/api/schedule/getallzones", &ScheduleApiController{}, "Get:GetAllZones")
  38. beego.Router("/api/schedule/copypatientschedules", &ScheduleApiController{}, "Get:GetCopyPatientSchedules")
  39. beego.Router("/api/schedule/saveremindprint", &ScheduleApiController{}, "Get:SaveRemindPrint")
  40. beego.Router("/api/schedule/getremindprintlist", &ScheduleApiController{}, "Get:GetRemindPrintList")
  41. beego.Router("/api/schedule/getbloodschedulelist", &ScheduleApiController{}, "Get:GetBloodScheduleList")
  42. beego.Router("/api/schedule/getprintlist", &ScheduleApiController{}, "Get:GetPrintList")
  43. beego.Router("/api/schedule/getallzonelist", &ScheduleApiController{}, "Get:GetAllZoneList")
  44. beego.Router("/api/schedule/getpatientschedulecount", &ScheduleApiController{}, "Get:GetPatientScheduleCount")
  45. beego.Router("/api/schedule/weekpanelone", &ScheduleApiController{}, "Get:GetWeekPanelsOne")
  46. beego.Router("/api/schedule/schedulesone", &ScheduleApiController{}, "Get:GetScheduleOne")
  47. beego.Router("/api/schedule/postscheduletemplate", &ScheduleApiController{}, "Get:SaveScheduleTemplate")
  48. beego.Router("/api/schedule/getscheduletemplate", &ScheduleApiController{}, "Get:GetScheduleTemplate")
  49. beego.Router("/api/order/changefuncprint", &ScheduleApiController{}, "Get:ChangeFuncPrint")
  50. beego.Router("/api/order/getdataprint", &ScheduleApiController{}, "Get:GetDataPrint")
  51. beego.Router("/api/schedule/getnextweekpanels", &ScheduleApiController{}, "Get:GetNextWeekPanels")
  52. beego.Router("/api/schedule/synchroschedule", &ScheduleApiController{}, "Get:SynchroSchedule")
  53. beego.Router("/api/schedule/getpatientscheduletemplate", &ScheduleApiController{}, "Get:GetPatientScheduleTempalate")
  54. beego.Router("/api/schedule/getsolutionschedule", &ScheduleApiController{}, "Get:GetSolutionSchedule")
  55. beego.Router("/api/schedule/smartpatientsch", &ScheduleApiController{}, "Get:GetPatientSch")
  56. beego.Router("/api/schedule/smartpatientschtemplate", &ScheduleApiController{}, "Get:GetPatientSchTemplate")
  57. beego.Router("/api/patient/smartpatientsch", &ScheduleApiController{}, "Get:GetPatientSmartSch")
  58. beego.Router("/api/patient/smartpatientschtemplate", &ScheduleApiController{}, "Get:GetPatientSmartSchTemplate")
  59. beego.Router("/api/device/get", &ScheduleApiController{}, "Get:GetDevicesNumbers")
  60. beego.Router("/api/smartsch/batch", &ScheduleApiController{}, "Post:BatchPostSmartSch")
  61. }
  62. func (c *ScheduleApiController) BatchPostSmartSch() {
  63. patient_id, _ := c.GetInt64("patient_id")
  64. adminInfo := c.GetAdminUserInfo()
  65. patientInfo, _ := service.FindPatientById(adminInfo.CurrentOrgId, patient_id)
  66. if patientInfo.ID == 0 {
  67. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  68. return
  69. }
  70. dataBody := make(map[string]interface{}, 0)
  71. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  72. if err != nil {
  73. utils.ErrorLog(err.Error())
  74. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  75. return
  76. }
  77. //数据校验
  78. if dataBody["smart_schs"] != nil && reflect.TypeOf(dataBody["smart_schs"]).String() == "[]interface {}" {
  79. schs, _ := dataBody["smart_schs"].([]interface{})
  80. if len(schs) > 0 {
  81. for _, item := range schs {
  82. items := item.(map[string]interface{})
  83. if items["sch_id"] == nil || reflect.TypeOf(items["sch_id"]).String() != "float64" {
  84. utils.ErrorLog("id")
  85. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  86. return
  87. }
  88. var schedule models.Schedule
  89. //var oldSchedule *models.Schedule
  90. sch_id := int64(items["sch_id"].(float64))
  91. if sch_id > 0 { //修改排班信息
  92. schedule, _ = service.GetScheduleTwo(adminInfo.CurrentOrgId, sch_id)
  93. if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
  94. utils.ErrorLog("mode_id")
  95. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  96. return
  97. }
  98. modeId := int64(items["mode_id"].(float64))
  99. if modeId < 1 {
  100. utils.ErrorLog("modeId < 1")
  101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  102. return
  103. }
  104. schedule.ModeId = modeId
  105. order, err := service.GetOneDialysisOrder(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  106. if err != nil {
  107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  108. return
  109. }
  110. if order != nil {
  111. week_type, _ := items["week_type"].(string)
  112. week_name, _ := items["week_name"].(string)
  113. switch week_type {
  114. case "1":
  115. json := make(map[string]interface{})
  116. json["msg"] = "本周" + week_name + "的床位已经有人上机,无法保存"
  117. json["state"] = 0
  118. c.Data["json"] = json
  119. c.ServeJSON()
  120. break
  121. case "2":
  122. json := make(map[string]interface{})
  123. json["msg"] = "下周" + week_name + "的床位已经有人上机,无法保存"
  124. json["state"] = 0
  125. c.Data["json"] = json
  126. c.ServeJSON()
  127. break
  128. case "3":
  129. json := make(map[string]interface{})
  130. json["msg"] = "下周" + week_name + "的床位已经有人上机,无法保存"
  131. json["state"] = 0
  132. c.Data["json"] = json
  133. c.ServeJSON()
  134. break
  135. }
  136. return
  137. }
  138. if order != nil {
  139. week_type, _ := items["week_type"].(string)
  140. week_name, _ := items["week_name"].(string)
  141. switch week_type {
  142. case "1":
  143. json := make(map[string]interface{})
  144. json["msg"] = "本周" + week_name + "的床位已经有人上机,无法保存"
  145. json["state"] = 0
  146. c.Data["json"] = json
  147. c.ServeJSON()
  148. break
  149. case "2":
  150. json := make(map[string]interface{})
  151. json["msg"] = "下周" + week_name + "的床位已经有人上机,无法保存"
  152. json["state"] = 0
  153. c.Data["json"] = json
  154. c.ServeJSON()
  155. break
  156. case "3":
  157. json := make(map[string]interface{})
  158. json["msg"] = "下周" + week_name + "的床位已经有人上机,无法保存"
  159. json["state"] = 0
  160. c.Data["json"] = json
  161. c.ServeJSON()
  162. break
  163. }
  164. return
  165. }
  166. if items["schedule_type"] == nil || reflect.TypeOf(items["schedule_type"]).String() != "float64" {
  167. utils.ErrorLog("schedule_type")
  168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  169. return
  170. }
  171. scheduleType := int64(items["schedule_type"].(float64))
  172. if scheduleType < 1 || scheduleType > 3 {
  173. utils.ErrorLog("scheduleType < 3")
  174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  175. return
  176. }
  177. schedule.ScheduleType = scheduleType
  178. if items["bed_id"] == nil || reflect.TypeOf(items["bed_id"]).String() != "float64" {
  179. utils.ErrorLog("bed_id")
  180. fmt.Println("~~~~~~333333333")
  181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  182. return
  183. }
  184. bedId := int64(items["bed_id"].(float64))
  185. if bedId < 1 {
  186. utils.ErrorLog("bedId < 1")
  187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  188. return
  189. }
  190. schedule.BedId = bedId
  191. if items["zone_id"] == nil || reflect.TypeOf(items["zone_id"]).String() != "float64" {
  192. utils.ErrorLog("zone_id")
  193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  194. return
  195. }
  196. partitionId := int64(items["zone_id"].(float64))
  197. if partitionId < 1 {
  198. utils.ErrorLog("partitionId < 1")
  199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  200. return
  201. }
  202. schedule.PartitionId = partitionId
  203. bed, _ := service.GetDeviceNumberByID(adminInfo.CurrentOrgId, schedule.BedId)
  204. if bed == nil {
  205. week_type, _ := items["week_type"].(string)
  206. week_name, _ := items["week_name"].(string)
  207. switch week_type {
  208. case "1":
  209. json := make(map[string]interface{})
  210. json["msg"] = "本周" + week_name + "的机号不存在,无法保存"
  211. json["state"] = 0
  212. c.Data["json"] = json
  213. c.ServeJSON()
  214. break
  215. case "2":
  216. json := make(map[string]interface{})
  217. json["msg"] = "下周" + week_name + "的机号不存在,无法保存"
  218. json["state"] = 0
  219. c.Data["json"] = json
  220. c.ServeJSON()
  221. break
  222. case "3":
  223. json := make(map[string]interface{})
  224. json["msg"] = "下周" + week_name + "的机号不存在,无法保存"
  225. json["state"] = 0
  226. c.Data["json"] = json
  227. c.ServeJSON()
  228. break
  229. }
  230. return
  231. }
  232. if bed.ZoneID != schedule.PartitionId {
  233. week_type, _ := items["week_type"].(string)
  234. week_name, _ := items["week_name"].(string)
  235. switch week_type {
  236. case "1":
  237. json := make(map[string]interface{})
  238. json["msg"] = "本周" + week_name + "所选机号不在选择分区中,无法保存"
  239. json["state"] = 0
  240. c.Data["json"] = json
  241. c.ServeJSON()
  242. break
  243. case "2":
  244. json := make(map[string]interface{})
  245. json["msg"] = "下周" + week_name + "所选机号不在选择分区中,无法保存"
  246. json["state"] = 0
  247. c.Data["json"] = json
  248. c.ServeJSON()
  249. break
  250. case "3":
  251. json := make(map[string]interface{})
  252. json["msg"] = "下周" + week_name + "所选机号不在选择分区中,无法保存"
  253. json["state"] = 0
  254. c.Data["json"] = json
  255. c.ServeJSON()
  256. break
  257. }
  258. return
  259. }
  260. startTime := schedule.ScheduleDate
  261. endTime := startTime + 86399
  262. //一天只有排班一次
  263. daySchedule, err := service.GetDaySchedule(adminInfo.CurrentOrgId, startTime, endTime, schedule.PatientId)
  264. if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
  265. week_type, _ := items["week_type"].(string)
  266. week_name, _ := items["week_name"].(string)
  267. switch week_type {
  268. case "1":
  269. json := make(map[string]interface{})
  270. json["msg"] = "本周" + week_name + "已有排班,同一天不可有两次排班,无法保存"
  271. json["state"] = 0
  272. c.Data["json"] = json
  273. c.ServeJSON()
  274. break
  275. case "2":
  276. json := make(map[string]interface{})
  277. json["msg"] = "下周" + week_name + "已有排班,同一天不可有两次排班,无法保存"
  278. json["state"] = 0
  279. c.Data["json"] = json
  280. c.ServeJSON()
  281. break
  282. case "3":
  283. json := make(map[string]interface{})
  284. json["msg"] = "下下周" + week_name + "已有排班,同一天不可有两次排班,无法保存"
  285. json["state"] = 0
  286. c.Data["json"] = json
  287. c.ServeJSON()
  288. break
  289. }
  290. return
  291. }
  292. //同天同位置只能排一个
  293. pointSchedule, err := service.GetPointSchedule(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  294. if err != nil {
  295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  296. return
  297. }
  298. if pointSchedule.ID > 0 && pointSchedule.PatientId != patient_id {
  299. week_type, _ := items["week_type"].(string)
  300. week_name, _ := items["week_name"].(string)
  301. switch week_type {
  302. case "1":
  303. json := make(map[string]interface{})
  304. json["msg"] = "本周" + week_name + "所先位置排班已经存在,无法保存"
  305. json["state"] = 0
  306. c.Data["json"] = json
  307. c.ServeJSON()
  308. break
  309. case "2":
  310. json := make(map[string]interface{})
  311. json["msg"] = "下周" + week_name + "所先位置排班已经存在,无法保存"
  312. json["state"] = 0
  313. c.Data["json"] = json
  314. c.ServeJSON()
  315. break
  316. case "3":
  317. json := make(map[string]interface{})
  318. json["msg"] = "下下周" + week_name + "所先位置排班已经存在,无法保存"
  319. json["state"] = 0
  320. c.Data["json"] = json
  321. c.ServeJSON()
  322. break
  323. }
  324. return
  325. }
  326. } else { //新的排班信息
  327. if items["schedule_date"] == nil || reflect.TypeOf(items["schedule_date"]).String() != "string" {
  328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  329. return
  330. }
  331. scheduleDate, _ := items["schedule_date"].(string)
  332. if len(scheduleDate) == 0 {
  333. utils.ErrorLog("len(schedule_date) == 0")
  334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  335. return
  336. }
  337. timeLayout := "2006-01-02"
  338. loc, _ := time.LoadLocation("Local")
  339. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  340. if err != nil {
  341. utils.ErrorLog(err.Error())
  342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  343. return
  344. }
  345. schedule.ScheduleDate = theTime.Unix()
  346. timeNow := time.Now().Format("2006-01-02")
  347. if timeNow > scheduleDate {
  348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  349. return
  350. }
  351. scheduleType := int64(items["schedule_type"].(float64))
  352. if scheduleType < 1 || scheduleType > 3 {
  353. utils.ErrorLog("scheduleType < 3")
  354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  355. return
  356. }
  357. schedule.ScheduleType = scheduleType
  358. if items["bed_id"] == nil || reflect.TypeOf(items["bed_id"]).String() != "float64" {
  359. fmt.Println("~~~~~~22222")
  360. utils.ErrorLog("bed_id")
  361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  362. return
  363. }
  364. bedId := int64(items["bed_id"].(float64))
  365. if bedId < 1 {
  366. utils.ErrorLog("bedId < 1")
  367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  368. return
  369. }
  370. schedule.BedId = bedId
  371. if items["zone_id"] == nil || reflect.TypeOf(items["zone_id"]).String() != "float64" {
  372. utils.ErrorLog("zone_id")
  373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  374. return
  375. }
  376. partitionId := int64(items["zone_id"].(float64))
  377. if partitionId < 1 {
  378. utils.ErrorLog("zone_id < 1")
  379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  380. return
  381. }
  382. schedule.PartitionId = partitionId
  383. if items["schedule_week"] == nil || reflect.TypeOf(items["schedule_week"]).String() != "float64" {
  384. utils.ErrorLog("schedule_week")
  385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  386. return
  387. }
  388. scheduleWeek := int64(items["schedule_week"].(float64))
  389. if scheduleWeek < 1 || scheduleWeek > 7 {
  390. utils.ErrorLog("scheduleWeek < 1")
  391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  392. return
  393. }
  394. schedule.ScheduleWeek = scheduleWeek
  395. if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
  396. utils.ErrorLog("mode_id")
  397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  398. return
  399. }
  400. modeId := int64(items["mode_id"].(float64))
  401. if modeId < 1 && modeId > 14 {
  402. utils.ErrorLog("modeId < 1")
  403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  404. return
  405. }
  406. //校验当天改床位是否有排班,如果有排班则不能替换排班
  407. sch, _ := service.GetScheduleByZoneAndBed(adminInfo.CurrentOrgId, partitionId, bedId, schedule.ScheduleDate, schedule.ScheduleType)
  408. if sch.ID > 0 {
  409. week_type, _ := items["week_type"].(string)
  410. week_name, _ := items["week_name"].(string)
  411. switch week_type {
  412. case "1":
  413. json := make(map[string]interface{})
  414. json["msg"] = "本周" + week_name + "该床位已经有人排班,无法保存"
  415. json["state"] = 0
  416. c.Data["json"] = json
  417. c.ServeJSON()
  418. break
  419. case "2":
  420. json := make(map[string]interface{})
  421. json["msg"] = "下周" + week_name + "该床位已经有人排班,无法保存"
  422. json["state"] = 0
  423. c.Data["json"] = json
  424. c.ServeJSON()
  425. break
  426. case "3":
  427. json := make(map[string]interface{})
  428. json["msg"] = "下下周" + week_name + "该床位已经有人排班,无法保存"
  429. json["state"] = 0
  430. c.Data["json"] = json
  431. c.ServeJSON()
  432. break
  433. }
  434. return
  435. }
  436. }
  437. }
  438. }
  439. }
  440. if dataBody["smart_schs"] != nil && reflect.TypeOf(dataBody["smart_schs"]).String() == "[]interface {}" {
  441. schs, _ := dataBody["smart_schs"].([]interface{})
  442. if len(schs) > 0 {
  443. for _, item := range schs {
  444. items := item.(map[string]interface{})
  445. if items["sch_id"] == nil || reflect.TypeOf(items["sch_id"]).String() != "float64" {
  446. utils.ErrorLog("id")
  447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  448. return
  449. }
  450. var schedule models.Schedule
  451. //var oldSchedule *models.Schedule
  452. sch_id := int64(items["sch_id"].(float64))
  453. if sch_id > 0 { //修改排班信息
  454. fmt.Println("!!!!!!!")
  455. schedule, _ = service.GetScheduleTwo(adminInfo.CurrentOrgId, sch_id)
  456. if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
  457. fmt.Println(reflect.TypeOf(items["mode_id"]))
  458. utils.ErrorLog("mode_id")
  459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  460. return
  461. }
  462. modeId := int64(items["mode_id"].(float64))
  463. if modeId < 1 {
  464. utils.ErrorLog("modeId < 1")
  465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  466. return
  467. }
  468. schedule.ModeId = modeId
  469. order, err := service.GetOneDialysisOrder(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  470. if err != nil {
  471. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  472. return
  473. }
  474. if order != nil {
  475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeMode)
  476. return
  477. }
  478. if order != nil {
  479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeDeviceNumber)
  480. return
  481. }
  482. if items["schedule_type"] == nil || reflect.TypeOf(items["schedule_type"]).String() != "float64" {
  483. utils.ErrorLog("schedule_type")
  484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  485. return
  486. }
  487. scheduleType := int64(items["schedule_type"].(float64))
  488. if scheduleType < 1 || scheduleType > 3 {
  489. utils.ErrorLog("scheduleType < 3")
  490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  491. return
  492. }
  493. schedule.ScheduleType = scheduleType
  494. if items["bed_id"] == nil || reflect.TypeOf(items["bed_id"]).String() != "float64" {
  495. utils.ErrorLog("bed_id")
  496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  497. return
  498. }
  499. bedId := int64(items["bed_id"].(float64))
  500. if bedId < 1 {
  501. utils.ErrorLog("bedId < 1")
  502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  503. return
  504. }
  505. schedule.BedId = bedId
  506. if items["zone_id"] == nil || reflect.TypeOf(items["zone_id"]).String() != "float64" {
  507. utils.ErrorLog("zone_id")
  508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  509. return
  510. }
  511. partitionId := int64(items["zone_id"].(float64))
  512. if partitionId < 1 {
  513. utils.ErrorLog("partitionId < 1")
  514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  515. return
  516. }
  517. schedule.PartitionId = partitionId
  518. bed, _ := service.GetDeviceNumberByID(adminInfo.CurrentOrgId, schedule.BedId)
  519. if bed == nil {
  520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  521. return
  522. }
  523. if bed.ZoneID != schedule.PartitionId {
  524. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  525. return
  526. }
  527. startTime := schedule.ScheduleDate
  528. endTime := startTime + 86399
  529. //一天只有排班一次
  530. daySchedule, err := service.GetDaySchedule(adminInfo.CurrentOrgId, startTime, endTime, schedule.PatientId)
  531. if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
  532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  533. return
  534. }
  535. //同天同位置只能排一个
  536. pointSchedule, err := service.GetPointSchedule(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  537. if err != nil {
  538. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  539. return
  540. }
  541. if pointSchedule.ID > 0 && pointSchedule.PatientId != patient_id {
  542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  543. return
  544. }
  545. so, _ := service.GetDialysisSolutionTwo(adminInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  546. filedRecordOne, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器")
  547. filedRecordTwo, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "灌流器")
  548. filedRecordThree, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器/灌流器")
  549. if filedRecordOne.IsShow == 1 {
  550. schedule.DialysisMachineName = so.DialysisDialyszers
  551. //service.UpdateSchDName(schedule)
  552. }
  553. if filedRecordTwo.IsShow == 1 {
  554. schedule.DialysisMachineName = so.DialysisIrrigation
  555. //service.UpdateSchDName(schedule)
  556. }
  557. if filedRecordThree.IsShow == 1 {
  558. schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
  559. //service.UpdateSchDName(schedule)
  560. }
  561. service.SaveSch(schedule)
  562. } else { //新的排班信息
  563. if items["schedule_date"] == nil || reflect.TypeOf(items["schedule_date"]).String() != "string" {
  564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  565. return
  566. }
  567. scheduleDate, _ := items["schedule_date"].(string)
  568. if len(scheduleDate) == 0 {
  569. utils.ErrorLog("len(schedule_date) == 0")
  570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  571. return
  572. }
  573. timeLayout := "2006-01-02"
  574. loc, _ := time.LoadLocation("Local")
  575. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  576. if err != nil {
  577. utils.ErrorLog(err.Error())
  578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  579. return
  580. }
  581. schedule.ScheduleDate = theTime.Unix()
  582. timeNow := time.Now().Format("2006-01-02")
  583. if timeNow > scheduleDate {
  584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  585. return
  586. }
  587. scheduleType := int64(items["schedule_type"].(float64))
  588. if scheduleType < 1 || scheduleType > 3 {
  589. utils.ErrorLog("scheduleType < 3")
  590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  591. return
  592. }
  593. schedule.ScheduleType = scheduleType
  594. if items["bed_id"] == nil || reflect.TypeOf(items["bed_id"]).String() != "float64" {
  595. utils.ErrorLog("bed_id")
  596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  597. return
  598. }
  599. bedId := int64(items["bed_id"].(float64))
  600. if bedId < 1 {
  601. utils.ErrorLog("bedId < 1")
  602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  603. return
  604. }
  605. schedule.BedId = bedId
  606. if items["zone_id"] == nil || reflect.TypeOf(items["zone_id"]).String() != "float64" {
  607. utils.ErrorLog("zone_id")
  608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  609. return
  610. }
  611. partitionId := int64(items["zone_id"].(float64))
  612. if partitionId < 1 {
  613. utils.ErrorLog("zone_id < 1")
  614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  615. return
  616. }
  617. schedule.PartitionId = partitionId
  618. if items["schedule_week"] == nil || reflect.TypeOf(items["schedule_week"]).String() != "float64" {
  619. utils.ErrorLog("schedule_week")
  620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  621. return
  622. }
  623. scheduleWeek := int64(items["schedule_week"].(float64))
  624. if scheduleWeek < 1 || scheduleWeek > 7 {
  625. utils.ErrorLog("scheduleWeek < 1")
  626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  627. return
  628. }
  629. schedule.ScheduleWeek = scheduleWeek
  630. if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
  631. fmt.Println(reflect.TypeOf(items["mode_id"]))
  632. utils.ErrorLog("mode_id")
  633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  634. return
  635. }
  636. modeId := int64(items["mode_id"].(float64))
  637. if modeId < 1 && modeId > 14 {
  638. utils.ErrorLog("modeId < 1")
  639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  640. return
  641. }
  642. //校验当天改床位是否有排班,如果有排班则不能替换排班
  643. sch, _ := service.GetScheduleByZoneAndBed(adminInfo.CurrentOrgId, partitionId, bedId, schedule.ScheduleDate, schedule.ScheduleType)
  644. if sch.ID > 0 {
  645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorSchedualcRepeatBed)
  646. return
  647. }
  648. schedule.ModeId = modeId
  649. schedule.PatientId = patient_id
  650. schedule.CreatedTime = time.Now().Unix()
  651. schedule.UpdatedTime = time.Now().Unix()
  652. schedule.Status = 1
  653. schedule.UserOrgId = adminInfo.CurrentOrgId
  654. so, _ := service.GetDialysisSolutionTwo(adminInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  655. filedRecordOne, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器")
  656. filedRecordTwo, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "灌流器")
  657. filedRecordThree, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器/灌流器")
  658. if filedRecordOne.IsShow == 1 {
  659. schedule.DialysisMachineName = so.DialysisDialyszers
  660. //service.UpdateSchDName(schedule)
  661. }
  662. if filedRecordTwo.IsShow == 1 {
  663. schedule.DialysisMachineName = so.DialysisIrrigation
  664. //service.UpdateSchDName(schedule)
  665. }
  666. if filedRecordThree.IsShow == 1 {
  667. schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
  668. //service.UpdateSchDName(schedule)
  669. }
  670. service.CreateSchedule(&schedule)
  671. }
  672. c.ServeSuccessJSON(map[string]interface{}{
  673. "msg": "保存成功",
  674. })
  675. HandleRedis(adminInfo.CurrentOrgId, schedule.ScheduleDate)
  676. }
  677. }
  678. }
  679. }
  680. func HandleRedis(org_id int64, sch_date int64) {
  681. redis := service.RedisClient()
  682. //处方
  683. keyOne := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":prescriptions_list_all"
  684. redis.Set(keyOne, "", time.Second)
  685. //医嘱
  686. keyTwo := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":advice_list_all"
  687. redis.Set(keyTwo, "", time.Second)
  688. keySix := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":assessment_befores_list_all"
  689. redis.Set(keySix, "", time.Second)
  690. keyThree := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":assessment_after_dislysis_list_all"
  691. redis.Set(keyThree, "", time.Second)
  692. keyFour := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":monitor_record_list_all"
  693. redis.Set(keyFour, "", time.Second)
  694. keyFive := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":treatment_summarys_list_all"
  695. redis.Set(keyFive, "", time.Second)
  696. keySeven := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":dialysis_orders_list_all"
  697. redis.Set(keySeven, "", time.Second)
  698. defer redis.Close()
  699. }
  700. func (c *ScheduleApiController) GetPatientSch() {
  701. keyWord := c.GetString("keyword")
  702. adminUserInfo := c.GetAdminUserInfo()
  703. patient, err := service.GetSmartSchPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  704. if err != nil {
  705. utils.ErrorLog(err.Error())
  706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  707. return
  708. }
  709. c.ServeSuccessJSON(map[string]interface{}{
  710. "patient": patient,
  711. })
  712. }
  713. func (c *ScheduleApiController) GetPatientSchTemplate() {
  714. keyWord := c.GetString("keyword")
  715. adminUserInfo := c.GetAdminUserInfo()
  716. patient, err := service.GetSmartSchTemplatePatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  717. if err != nil {
  718. utils.ErrorLog(err.Error())
  719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  720. return
  721. }
  722. c.ServeSuccessJSON(map[string]interface{}{
  723. "patient": patient,
  724. })
  725. }
  726. func (c *ScheduleApiController) GetPatientSmartSch() {
  727. patient_id, _ := c.GetInt64("patient_id", 0)
  728. adminUserInfo := c.GetAdminUserInfo()
  729. schs, err := service.GetSmartSchPatientByID(adminUserInfo.CurrentOrgId, patient_id)
  730. if err != nil {
  731. utils.ErrorLog(err.Error())
  732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  733. return
  734. }
  735. c.ServeSuccessJSON(map[string]interface{}{
  736. "schedules": schs,
  737. })
  738. }
  739. func (c *ScheduleApiController) GetPatientSmartSchTemplate() {
  740. patient_id, _ := c.GetInt64("patient_id", 0)
  741. adminUserInfo := c.GetAdminUserInfo()
  742. mode, _ := service.GetOrgPatientScheduleTemplateModeTwo(adminUserInfo.CurrentOrgId)
  743. if mode.ID > 0 {
  744. if mode.Mode == 0 {
  745. //schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id)
  746. c.ServeSuccessJSON(map[string]interface{}{
  747. "status": 0,
  748. })
  749. } else if mode.Mode == 1 {
  750. schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id, 1)
  751. c.ServeSuccessJSON(map[string]interface{}{
  752. "status": 0,
  753. "schedules_template": schs,
  754. })
  755. } else if mode.Mode == 2 {
  756. schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id, 2)
  757. c.ServeSuccessJSON(map[string]interface{}{
  758. "status": 1,
  759. "schedules_template": schs,
  760. })
  761. } else if mode.Mode == 3 {
  762. schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id, 3)
  763. c.ServeSuccessJSON(map[string]interface{}{
  764. "status": 1,
  765. "schedules_template": schs,
  766. })
  767. } else if mode.Mode == 4 {
  768. schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id, 4)
  769. c.ServeSuccessJSON(map[string]interface{}{
  770. "status": 1,
  771. "schedules_template": schs,
  772. })
  773. }
  774. } else {
  775. c.ServeSuccessJSON(map[string]interface{}{
  776. "status": 0,
  777. })
  778. }
  779. }
  780. func (c *ScheduleApiController) GetDevicesNumbers() {
  781. sch_type, _ := c.GetInt("sch_type", 0)
  782. zone_id, _ := c.GetInt64("zone_id", 0)
  783. patient_id, _ := c.GetInt64("patient_id", 0)
  784. schedule_date := c.GetString("schedule_date")
  785. timeLayout := "2006-01-02"
  786. loc, _ := time.LoadLocation("Local")
  787. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  788. if err != nil {
  789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  790. return
  791. }
  792. recordDateTime := theTime.Unix()
  793. deviceNumbers, getDeviceNumbersErr := service.GetAllAvaildDeviceNumbersByZone(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, sch_type, zone_id, patient_id)
  794. if getDeviceNumbersErr != nil {
  795. c.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
  796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  797. return
  798. }
  799. c.ServeSuccessJSON(map[string]interface{}{
  800. "devices": deviceNumbers,
  801. })
  802. }
  803. func (c *ScheduleApiController) GetWeekPanels() {
  804. data, _ := c.GetInt64("data", 1)
  805. patitionId, _ := c.GetInt64("patitionid")
  806. adminInfo := c.GetAdminUserInfo()
  807. thisTime := time.Now()
  808. year, monthTime, day := thisTime.Date()
  809. month := int(monthTime)
  810. _, theWeek := thisTime.ISOWeek()
  811. weekDay := int(thisTime.Weekday())
  812. if weekDay == 0 {
  813. weekDay = 7
  814. }
  815. weekEnd := 7 - weekDay
  816. weekStart := weekEnd - 6
  817. weekDays := make([]string, 0)
  818. for index := weekStart; index <= weekEnd; index++ {
  819. theDay := thisTime.AddDate(0, 0, index)
  820. indexYear, indexMonthTime, indexDay := theDay.Date()
  821. indexMonth := int(indexMonthTime)
  822. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  823. weekDays = append(weekDays, indexWeek)
  824. }
  825. returnData := map[string]interface{}{
  826. "year": year,
  827. "month": month,
  828. "day": day,
  829. "theWeek": theWeek,
  830. "weekDay": weekDay,
  831. "weekDays": weekDays,
  832. }
  833. if data == 1 {
  834. partitions, _ := service.GetSchedulePartitionPanelOne(adminInfo.CurrentOrgId, patitionId)
  835. returnData["partitions"] = partitions
  836. }
  837. c.ServeSuccessJSON(returnData)
  838. return
  839. }
  840. func (c *ScheduleApiController) GetSchedules() {
  841. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  842. partition_id, _ := c.GetInt64("partition_id")
  843. schedule_type, _ := c.GetInt64("schedule_type")
  844. adminInfo := c.GetAdminUserInfo()
  845. thisTime := time.Now()
  846. today := thisTime.Format("2006-01-02")
  847. if week < 1 || week > 4 {
  848. week = 2
  849. }
  850. if week == 1 {
  851. thisTime = thisTime.AddDate(0, 0, -7)
  852. } else if week == 3 {
  853. thisTime = thisTime.AddDate(0, 0, 7)
  854. } else if week == 4 {
  855. thisTime = thisTime.AddDate(0, 0, 14)
  856. }
  857. weekDay := int(thisTime.Weekday())
  858. if weekDay == 0 {
  859. weekDay = 7
  860. }
  861. weekEnd := 7 - weekDay
  862. weekStart := weekEnd - 6
  863. weekTitle := make([]string, 0)
  864. days := make([]string, 0)
  865. for index := weekStart; index <= weekEnd; index++ {
  866. theDay := thisTime.AddDate(0, 0, index)
  867. indexYear, indexMonthTime, indexDay := theDay.Date()
  868. indexMonth := int(indexMonthTime)
  869. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  870. weekTitle = append(weekTitle, indexWeek)
  871. days = append(days, theDay.Format("2006-01-02"))
  872. }
  873. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  874. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  875. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  876. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  877. timeLayout := "2006-01-02 15:04:05"
  878. loc, _ := time.LoadLocation("Local")
  879. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  880. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  881. weekStartPoint := theStarTime.Unix()
  882. weekEndPoint := theEndTime.Unix()
  883. schdules, _ := service.GetWeekScheduleOne(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, partition_id, schedule_type)
  884. c.ServeSuccessJSON(map[string]interface{}{
  885. "days": days,
  886. "weekTitle": weekTitle,
  887. "schdules": schdules,
  888. "today": today,
  889. })
  890. return
  891. }
  892. func (c *ScheduleApiController) GetPatients() {
  893. keywords := c.GetString("keywords", "")
  894. schedule, _ := c.GetInt64("schedule", 0) //1已2未
  895. contagion, _ := c.GetInt64("contagion", 0)
  896. adminInfo := c.GetAdminUserInfo()
  897. thisTime := time.Now()
  898. weekDay := int(thisTime.Weekday())
  899. if weekDay == 0 {
  900. weekDay = 7
  901. }
  902. thisWeekEnd := 7 - weekDay
  903. weekStartPoint := thisWeekEnd - 6
  904. weekStartDay := thisTime.AddDate(0, 0, weekStartPoint)
  905. weekEndPoint := thisWeekEnd + 7
  906. weekEndDay := thisTime.AddDate(0, 0, weekEndPoint)
  907. fmt.Println(weekStartPoint, weekStartDay, weekEndPoint, weekEndDay)
  908. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  909. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  910. fmt.Println(weekStartTime, weekEndTime)
  911. timeLayout := "2006-01-02 15:04:05"
  912. loc, _ := time.LoadLocation("Local")
  913. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  914. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  915. weekStart := theStarTime.Unix()
  916. weekEnd := theEndTime.Unix()
  917. patients, _ := service.GetPatientWithScheduleAndSolution(adminInfo.CurrentOrgId, keywords, weekStart, weekEnd, schedule, contagion)
  918. fmt.Println("patinets23233232323232232322323wode", patients)
  919. c.ServeSuccessJSON(map[string]interface{}{
  920. "patients": patients,
  921. })
  922. return
  923. }
  924. func (c *ScheduleApiController) CreateSchedule() {
  925. patientID, _ := c.GetInt64("patient_id", 0)
  926. if patientID <= 0 {
  927. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  928. return
  929. }
  930. adminUserInfo := c.GetAdminUserInfo()
  931. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patientID)
  932. if patientInfo.ID == 0 {
  933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  934. return
  935. }
  936. var schedule models.Schedule
  937. dataBody := make(map[string]interface{}, 0)
  938. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  939. if err != nil {
  940. utils.ErrorLog(err.Error())
  941. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  942. return
  943. }
  944. if dataBody["schedule_date"] == nil || reflect.TypeOf(dataBody["schedule_date"]).String() != "string" {
  945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  946. return
  947. }
  948. scheduleDate, _ := dataBody["schedule_date"].(string)
  949. if len(scheduleDate) == 0 {
  950. utils.ErrorLog("len(schedule_date) == 0")
  951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  952. return
  953. }
  954. timeLayout := "2006-01-02"
  955. loc, _ := time.LoadLocation("Local")
  956. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  957. if err != nil {
  958. utils.ErrorLog(err.Error())
  959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  960. return
  961. }
  962. schedule.ScheduleDate = theTime.Unix()
  963. timeNow := time.Now().Format("2006-01-02")
  964. if timeNow > scheduleDate {
  965. utils.ErrorLog(timeNow)
  966. utils.ErrorLog(scheduleDate)
  967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  968. return
  969. }
  970. if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
  971. utils.ErrorLog("schedule_type")
  972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  973. return
  974. }
  975. scheduleType := int64(dataBody["schedule_type"].(float64))
  976. if scheduleType < 1 || scheduleType > 3 {
  977. utils.ErrorLog("scheduleType < 3")
  978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  979. return
  980. }
  981. schedule.ScheduleType = scheduleType
  982. if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
  983. utils.ErrorLog("bed_id")
  984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  985. return
  986. }
  987. bedId := int64(dataBody["bed_id"].(float64))
  988. if bedId < 1 {
  989. utils.ErrorLog("bedId < 1")
  990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  991. return
  992. }
  993. schedule.BedId = bedId
  994. if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
  995. utils.ErrorLog("partition_id")
  996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  997. return
  998. }
  999. partitionId := int64(dataBody["partition_id"].(float64))
  1000. if partitionId < 1 {
  1001. utils.ErrorLog("partitionId < 1")
  1002. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1003. return
  1004. }
  1005. schedule.PartitionId = partitionId
  1006. if dataBody["schedule_week"] == nil || reflect.TypeOf(dataBody["schedule_week"]).String() != "float64" {
  1007. utils.ErrorLog("schedule_week")
  1008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1009. return
  1010. }
  1011. scheduleWeek := int64(dataBody["schedule_week"].(float64))
  1012. if scheduleWeek < 1 || scheduleWeek > 7 {
  1013. utils.ErrorLog("scheduleWeek < 1")
  1014. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1015. return
  1016. }
  1017. schedule.ScheduleWeek = scheduleWeek
  1018. if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
  1019. utils.ErrorLog("mode_id")
  1020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1021. return
  1022. }
  1023. modeId := int64(dataBody["mode_id"].(float64))
  1024. if modeId < 1 && modeId > 14 {
  1025. utils.ErrorLog("modeId < 1")
  1026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1027. return
  1028. }
  1029. schedule.ModeId = modeId
  1030. schedule.PatientId = patientID
  1031. schedule.CreatedTime = time.Now().Unix()
  1032. schedule.UpdatedTime = time.Now().Unix()
  1033. schedule.Status = 1
  1034. schedule.UserOrgId = adminUserInfo.CurrentOrgId
  1035. so, _ := service.GetDialysisSolutionTwo(adminUserInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  1036. filedRecordOne, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器")
  1037. filedRecordTwo, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "灌流器")
  1038. filedRecordThree, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器/灌流器")
  1039. if filedRecordOne.IsShow == 1 {
  1040. schedule.DialysisMachineName = so.DialysisDialyszers
  1041. //service.UpdateSchDName(schedule)
  1042. }
  1043. if filedRecordTwo.IsShow == 1 {
  1044. schedule.DialysisMachineName = so.DialysisIrrigation
  1045. //service.UpdateSchDName(schedule)
  1046. }
  1047. if filedRecordThree.IsShow == 1 {
  1048. schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
  1049. //service.UpdateSchDName(schedule)
  1050. }
  1051. bed, _ := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, schedule.BedId)
  1052. if bed == nil {
  1053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  1054. return
  1055. }
  1056. if bed.ZoneID != schedule.PartitionId {
  1057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  1058. return
  1059. }
  1060. scheduleDateStart := scheduleDate + " 00:00:00"
  1061. scheduleDateEnd := scheduleDate + " 23:59:59"
  1062. timeLayout = "2006-01-02 15:04:05"
  1063. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1064. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1065. startTime := theStartTime.Unix()
  1066. endTime := theEndTime.Unix()
  1067. //一天只有排班一次
  1068. daySchedule, err := service.GetDaySchedule(adminUserInfo.CurrentOrgId, startTime, endTime, patientID)
  1069. if daySchedule.ID > 0 {
  1070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  1071. return
  1072. }
  1073. //同天同位置只能排一个
  1074. pointSchedule, err := service.GetPointSchedule(adminUserInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  1075. if err != nil {
  1076. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1077. return
  1078. }
  1079. if pointSchedule.ID > 0 {
  1080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  1081. return
  1082. }
  1083. redis := service.RedisClient()
  1084. err = service.CreateSchedule(&schedule)
  1085. key := "scheduals_" + scheduleDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1086. redis.Set(key, "", time.Second)
  1087. //处方
  1088. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
  1089. redis.Set(keyOne, "", time.Second)
  1090. //医嘱
  1091. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
  1092. redis.Set(keyTwo, "", time.Second)
  1093. keySix := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
  1094. redis.Set(keySix, "", time.Second)
  1095. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
  1096. redis.Set(keyThree, "", time.Second)
  1097. keyFour := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
  1098. redis.Set(keyFour, "", time.Second)
  1099. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
  1100. redis.Set(keyFive, "", time.Second)
  1101. keySeven := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  1102. redis.Set(keySeven, "", time.Second)
  1103. fmt.Println(err)
  1104. defer redis.Close()
  1105. if err != nil {
  1106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateScheduleFail)
  1107. return
  1108. }
  1109. schedule.Patient = patientInfo.Name
  1110. c.ServeSuccessJSON(map[string]interface{}{
  1111. "msg": "ok",
  1112. "schedule": schedule,
  1113. })
  1114. return
  1115. }
  1116. func (c *ScheduleApiController) DeleteSchedule() {
  1117. id, _ := c.GetInt64("id", 0)
  1118. if id <= 0 {
  1119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1120. return
  1121. }
  1122. adminINfo := c.GetAdminUserInfo()
  1123. schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  1124. timeNow := time.Now().Format("2006-01-02")
  1125. timeTemplate := "2006-01-02"
  1126. tm := time.Unix(int64(schedule.ScheduleDate), 0)
  1127. timeStr := tm.Format(timeTemplate)
  1128. if timeNow > timeStr {
  1129. utils.ErrorLog(timeNow)
  1130. utils.ErrorLog(timeStr)
  1131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  1132. return
  1133. }
  1134. if schedule == nil {
  1135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  1136. return
  1137. }
  1138. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  1139. if err != nil {
  1140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1141. return
  1142. }
  1143. if order != nil {
  1144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysis)
  1145. return
  1146. }
  1147. schedule.Status = 0
  1148. schedule.UpdatedTime = time.Now().Unix()
  1149. err = service.UpdateSchedule(schedule)
  1150. redis := service.RedisClient()
  1151. //处方
  1152. keyOne := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
  1153. redis.Set(keyOne, "", time.Second)
  1154. //医嘱
  1155. keyTwo := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
  1156. redis.Set(keyTwo, "", time.Second)
  1157. keySix := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
  1158. redis.Set(keySix, "", time.Second)
  1159. keyThree := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
  1160. redis.Set(keyThree, "", time.Second)
  1161. keyFour := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
  1162. redis.Set(keyFour, "", time.Second)
  1163. keyFive := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
  1164. redis.Set(keyFive, "", time.Second)
  1165. keySeven := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  1166. redis.Set(keySeven, "", time.Second)
  1167. fmt.Println(err)
  1168. defer redis.Close()
  1169. if err != nil {
  1170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteScheduleFail)
  1171. return
  1172. }
  1173. c.ServeSuccessJSON(map[string]interface{}{
  1174. "msg": "ok",
  1175. "schedule": &schedule,
  1176. })
  1177. }
  1178. func (c *ScheduleApiController) ChangeSchedule() {
  1179. id, _ := c.GetInt64("id", 0)
  1180. if id <= 0 {
  1181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1182. return
  1183. }
  1184. adminINfo := c.GetAdminUserInfo()
  1185. schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  1186. if schedule == nil {
  1187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  1188. return
  1189. }
  1190. dataBody := make(map[string]interface{}, 0)
  1191. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1192. if err != nil {
  1193. utils.ErrorLog(err.Error())
  1194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1195. return
  1196. }
  1197. if dataBody["change_action"] == nil || reflect.TypeOf(dataBody["change_action"]).String() != "string" {
  1198. utils.ErrorLog("change_action")
  1199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1200. return
  1201. }
  1202. changeAction := dataBody["change_action"].(string)
  1203. if changeAction == "change_mode" {
  1204. if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
  1205. utils.ErrorLog("mode_id")
  1206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1207. return
  1208. }
  1209. modeId := int64(dataBody["mode_id"].(float64))
  1210. if modeId < 1 {
  1211. utils.ErrorLog("modeId < 1")
  1212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1213. return
  1214. }
  1215. schedule.ModeId = modeId
  1216. so, _ := service.GetDialysisSolutionTwo(adminINfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  1217. filedRecordOne, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "透析器")
  1218. filedRecordTwo, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "灌流器")
  1219. filedRecordThree, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "透析器/灌流器")
  1220. if filedRecordOne.IsShow == 1 {
  1221. schedule.DialysisMachineName = so.DialysisDialyszers
  1222. //service.UpdateSchDName(schedule)
  1223. }
  1224. if filedRecordTwo.IsShow == 1 {
  1225. schedule.DialysisMachineName = so.DialysisIrrigation
  1226. //service.UpdateSchDName(schedule)
  1227. }
  1228. if filedRecordThree.IsShow == 1 {
  1229. schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
  1230. //service.UpdateSchDName(schedule)
  1231. }
  1232. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  1233. if err != nil {
  1234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1235. return
  1236. }
  1237. if order != nil {
  1238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeMode)
  1239. return
  1240. }
  1241. } else if changeAction == "change_device" {
  1242. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  1243. if err != nil {
  1244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1245. return
  1246. }
  1247. if order != nil {
  1248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeDeviceNumber)
  1249. return
  1250. }
  1251. if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
  1252. utils.ErrorLog("schedule_type")
  1253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1254. return
  1255. }
  1256. scheduleType := int64(dataBody["schedule_type"].(float64))
  1257. if scheduleType < 1 || scheduleType > 3 {
  1258. utils.ErrorLog("scheduleType < 3")
  1259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1260. return
  1261. }
  1262. schedule.ScheduleType = scheduleType
  1263. if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
  1264. utils.ErrorLog("bed_id")
  1265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1266. return
  1267. }
  1268. bedId := int64(dataBody["bed_id"].(float64))
  1269. if bedId < 1 {
  1270. utils.ErrorLog("bedId < 1")
  1271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1272. return
  1273. }
  1274. schedule.BedId = bedId
  1275. if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
  1276. utils.ErrorLog("partition_id")
  1277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1278. return
  1279. }
  1280. partitionId := int64(dataBody["partition_id"].(float64))
  1281. if partitionId < 1 {
  1282. utils.ErrorLog("partitionId < 1")
  1283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1284. return
  1285. }
  1286. schedule.PartitionId = partitionId
  1287. bed, _ := service.GetDeviceNumberByID(adminINfo.CurrentOrgId, schedule.BedId)
  1288. if bed == nil {
  1289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  1290. return
  1291. }
  1292. if bed.ZoneID != schedule.PartitionId {
  1293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  1294. return
  1295. }
  1296. startTime := schedule.ScheduleDate
  1297. endTime := startTime + 86399
  1298. //一天只有排班一次
  1299. daySchedule, err := service.GetDaySchedule(adminINfo.CurrentOrgId, startTime, endTime, schedule.PatientId)
  1300. if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
  1301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  1302. return
  1303. }
  1304. //同天同位置只能排一个
  1305. pointSchedule, err := service.GetPointSchedule(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  1306. if err != nil {
  1307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1308. return
  1309. }
  1310. if pointSchedule.ID > 0 {
  1311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  1312. return
  1313. }
  1314. } else {
  1315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1316. return
  1317. }
  1318. schedule.UpdatedTime = time.Now().Unix()
  1319. err = service.UpdateSchedule(schedule)
  1320. prescription := models.DialysisPrescription{
  1321. ModeId: schedule.ModeId,
  1322. }
  1323. _, errcode := service.GetDialysisPrescribe(schedule.UserOrgId, schedule.PatientId, schedule.ScheduleDate)
  1324. if errcode == gorm.ErrRecordNotFound {
  1325. if err != nil {
  1326. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
  1327. return
  1328. }
  1329. c.ServeSuccessJSON(map[string]interface{}{
  1330. "msg": "ok",
  1331. "schedule": &schedule,
  1332. })
  1333. } else if errcode == nil {
  1334. err = service.UpdatedDialysisPrescription(&prescription, schedule.ScheduleDate, schedule.PatientId, schedule.UserOrgId)
  1335. if err != nil {
  1336. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
  1337. return
  1338. }
  1339. c.ServeSuccessJSON(map[string]interface{}{
  1340. "msg": "ok",
  1341. "schedule": &schedule,
  1342. })
  1343. }
  1344. }
  1345. // /api/schedule/print/initdata [get]
  1346. // @param date:string yyyy-MM-dd 要打印的那一周中的任一天
  1347. func (this *ScheduleApiController) PrintInitData() {
  1348. dateStr := this.GetString("date")
  1349. //week_type, _ := this.GetInt64("type", 0)
  1350. var date *time.Time
  1351. if len(dateStr) == 0 {
  1352. now := time.Now()
  1353. date = &now
  1354. } else {
  1355. var parseErr error
  1356. date, parseErr = utils.ParseTimeStringToTime("2006-01-02", dateStr)
  1357. if parseErr != nil {
  1358. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1359. return
  1360. }
  1361. }
  1362. adminUserInfo := this.GetAdminUserInfo()
  1363. // 获取本周的排班
  1364. var monday time.Time
  1365. var sunday time.Time
  1366. //switch week_type {
  1367. //case 1:
  1368. monday, sunday = utils.GetMondayAndSundayOfWeekDate(date)
  1369. // break
  1370. //case 2:
  1371. // monday, sunday = utils.GetMondayAndSundayOfNextWeekDate(date)
  1372. //
  1373. // break
  1374. //case 3:
  1375. // monday, sunday = utils.GetMondayAndSundayOfNextNextWeekDate(date)
  1376. // break
  1377. //}
  1378. schedules, getScheduleErr := service.GetPrinitWeekSchedules(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
  1379. total, getScheduleErr := service.GetPrinitWeekTotal(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
  1380. if getScheduleErr != nil {
  1381. this.ErrorLog("获取周排班失败:%v", getScheduleErr)
  1382. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1383. return
  1384. }
  1385. thisTime := date
  1386. weekDay := int(thisTime.Weekday())
  1387. if weekDay == 0 {
  1388. weekDay = 7
  1389. }
  1390. weekEnd := 7 - weekDay
  1391. weekStart := weekEnd - 6
  1392. days := make([]string, 0)
  1393. for index := weekStart; index <= weekEnd; index++ {
  1394. theDay := thisTime.AddDate(0, 0, index)
  1395. days = append(days, theDay.Format("2006-01-02"))
  1396. }
  1397. this.ServeSuccessJSON(map[string]interface{}{
  1398. "total": total,
  1399. "schedules": schedules,
  1400. "monday": monday.Unix(),
  1401. "days": days,
  1402. })
  1403. }
  1404. func (this *ScheduleApiController) UrgentScheduleData() {
  1405. schedule_type, _ := this.GetInt("type", 0)
  1406. schedule_date := this.GetString("date")
  1407. var date *time.Time
  1408. if len(schedule_date) == 0 {
  1409. now := time.Now()
  1410. date = &now
  1411. } else {
  1412. var parseErr error
  1413. date, parseErr = utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  1414. if parseErr != nil {
  1415. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1416. return
  1417. }
  1418. }
  1419. adminUserInfo := this.GetAdminUserInfo()
  1420. deviceNumbers, getDeviceNumbersErr := service.MobileGetAllDeviceNumbersForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  1421. if getDeviceNumbersErr != nil {
  1422. this.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
  1423. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1424. return
  1425. }
  1426. // today := utils.ZeroHourTimeOfDay(time.Now())
  1427. schedules, getSchedulesErr := service.MobileGetOtherSchedulesForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  1428. if getSchedulesErr != nil {
  1429. this.ErrorLog("获取所有排班失败:%v", getSchedulesErr)
  1430. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1431. return
  1432. }
  1433. this.ServeSuccessJSON(map[string]interface{}{
  1434. "device_numbers": deviceNumbers,
  1435. "schedules": schedules,
  1436. })
  1437. }
  1438. func (this *ScheduleApiController) SearchSchedulePatients() {
  1439. keywords := this.GetString("keywords")
  1440. week_type, _ := this.GetInt64("week_type", 0)
  1441. start_sch := this.GetString("start_sch")
  1442. end_sch := this.GetString("end_sch")
  1443. thisTime1 := time.Now()
  1444. thisTime2 := time.Now()
  1445. thisTime1 = thisTime1.AddDate(0, 0, 7)
  1446. thisTime2 = thisTime2.AddDate(0, 0, 14)
  1447. var start_time string
  1448. var end_time string
  1449. switch week_type {
  1450. case 1:
  1451. timeLayout := "2006-01-02"
  1452. loc, _ := time.LoadLocation("Local")
  1453. var startSchTime int64
  1454. if len(start_sch) > 0 {
  1455. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_sch+" 00:00:00", loc)
  1456. startSchTime = theTime.Unix()
  1457. }
  1458. var endSchTime int64
  1459. if len(end_sch) > 0 {
  1460. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_sch+" 00:00:00", loc)
  1461. endSchTime = theTime.Unix()
  1462. }
  1463. adminUserInfo := this.GetAdminUserInfo()
  1464. list, _ := service.GetSchedualPatientsByKeywords(keywords, adminUserInfo.CurrentOrgId, startSchTime, endSchTime)
  1465. this.ServeSuccessJSON(map[string]interface{}{
  1466. "schdules": list,
  1467. })
  1468. break
  1469. case 2:
  1470. days := make([]string, 0)
  1471. weekDay1 := int(thisTime1.Weekday())
  1472. if weekDay1 == 0 {
  1473. weekDay1 = 7
  1474. }
  1475. weekEnd1 := 7 - weekDay1
  1476. weekStart1 := weekEnd1 - 6
  1477. for index := weekStart1; index <= weekEnd1; index++ {
  1478. fmt.Println(index)
  1479. theDay := thisTime1.AddDate(0, 0, index)
  1480. days = append(days, theDay.Format("2006-01-02"))
  1481. }
  1482. fmt.Println(days)
  1483. start_time = days[0]
  1484. end_time = days[len(days)-1]
  1485. timeLayout := "2006-01-02"
  1486. loc, _ := time.LoadLocation("Local")
  1487. var theStartTime int64
  1488. if len(start_time) > 0 {
  1489. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1490. theStartTime = theTime.Unix()
  1491. }
  1492. var theEndtTime int64
  1493. if len(end_time) > 0 {
  1494. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1495. theEndtTime = theTime.Unix()
  1496. }
  1497. adminUserInfo := this.GetAdminUserInfo()
  1498. list, _ := service.GetSchedualPatientsByKeywordsAndWeek(keywords, adminUserInfo.CurrentOrgId, theStartTime, theEndtTime)
  1499. this.ServeSuccessJSON(map[string]interface{}{
  1500. "schdules": list,
  1501. })
  1502. break
  1503. case 3:
  1504. days := make([]string, 0)
  1505. weekDay2 := int(thisTime2.Weekday())
  1506. if weekDay2 == 0 {
  1507. weekDay2 = 7
  1508. }
  1509. weekEnd2 := 7 - weekDay2
  1510. weekStart2 := weekEnd2 - 6
  1511. for index := weekStart2; index <= weekEnd2; index++ {
  1512. theDay := thisTime2.AddDate(0, 0, index)
  1513. days = append(days, theDay.Format("2006-01-02"))
  1514. }
  1515. start_time = days[0]
  1516. end_time = days[len(days)-1]
  1517. timeLayout := "2006-01-02"
  1518. loc, _ := time.LoadLocation("Local")
  1519. var theStartTime int64
  1520. if len(start_time) > 0 {
  1521. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1522. theStartTime = theTime.Unix()
  1523. }
  1524. var theEndtTime int64
  1525. if len(end_time) > 0 {
  1526. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1527. theEndtTime = theTime.Unix()
  1528. }
  1529. adminUserInfo := this.GetAdminUserInfo()
  1530. list, _ := service.GetSchedualPatientsByKeywordsAndWeek(keywords, adminUserInfo.CurrentOrgId, theStartTime, theEndtTime)
  1531. this.ServeSuccessJSON(map[string]interface{}{
  1532. "schdules": list,
  1533. })
  1534. break
  1535. }
  1536. }
  1537. func (this *ScheduleApiController) GetWeekDaySchedule() {
  1538. week_type, _ := this.GetInt64("week_type", -1)
  1539. week_time, _ := this.GetInt64("week_time")
  1540. thisTime := time.Now()
  1541. weekDay := int(thisTime.Weekday())
  1542. if weekDay == 0 {
  1543. weekDay = 7
  1544. }
  1545. weekEnd := 7 - weekDay
  1546. weekStart := weekEnd - 6
  1547. weekTitle := make([]string, 0)
  1548. days := make([]string, 0)
  1549. for index := weekStart; index <= weekEnd; index++ {
  1550. theDay := thisTime.AddDate(0, 0, index)
  1551. indexYear, indexMonthTime, indexDay := theDay.Date()
  1552. indexMonth := int(indexMonthTime)
  1553. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  1554. weekTitle = append(weekTitle, indexWeek)
  1555. days = append(days, theDay.Format("2006-01-02"))
  1556. }
  1557. fmt.Println(days)
  1558. var targetDayStr string
  1559. var startTime string
  1560. var endTime string
  1561. switch week_type {
  1562. case 0:
  1563. {
  1564. startTime = days[0]
  1565. endTime = days[6]
  1566. }
  1567. case 1:
  1568. targetDayStr = days[0]
  1569. break
  1570. case 2:
  1571. targetDayStr = days[1]
  1572. break
  1573. case 3:
  1574. targetDayStr = days[2]
  1575. break
  1576. case 4:
  1577. targetDayStr = days[3]
  1578. break
  1579. case 5:
  1580. targetDayStr = days[4]
  1581. break
  1582. case 6:
  1583. targetDayStr = days[5]
  1584. break
  1585. case 7:
  1586. targetDayStr = days[6]
  1587. break
  1588. }
  1589. targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  1590. startDay, _ := utils.ParseTimeStringToTime("2006-01-02", startTime)
  1591. endDay, _ := utils.ParseTimeStringToTime("2006-01-02", endTime)
  1592. fmt.Println(startDay, endDay)
  1593. if parseErr != nil {
  1594. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1595. return
  1596. }
  1597. orgId := this.GetAdminUserInfo().CurrentOrgId
  1598. list, _ := service.GetWeekDayScheduleTwo(orgId, targetDay.Unix(), targetDay, week_time)
  1599. this.ServeSuccessJSON(map[string]interface{}{
  1600. "schdules": list,
  1601. "day": targetDayStr,
  1602. })
  1603. }
  1604. func Struct2Map(obj interface{}) map[string]interface{} {
  1605. t := reflect.TypeOf(obj)
  1606. v := reflect.ValueOf(obj)
  1607. var data = make(map[string]interface{})
  1608. for i := 0; i < t.NumField(); i++ {
  1609. data[t.Field(i).Name] = v.Field(i).Interface()
  1610. }
  1611. return data
  1612. }
  1613. func (this *ScheduleApiController) ExportSchedule() {
  1614. dataBody := make(map[string]interface{}, 0)
  1615. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1616. if err != nil {
  1617. utils.ErrorLog(err.Error())
  1618. return
  1619. }
  1620. utils.ErrorLog("%v", dataBody)
  1621. export_time := time.Now().Unix()
  1622. var schedules []*models.Schedule
  1623. var failed_total int
  1624. var total_schedule []interface{}
  1625. var patients []*models.Patients
  1626. patients, _, _ = service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  1627. start_time := dataBody["start_time"].(string)
  1628. end_time := dataBody["end_time"].(string)
  1629. delete_type := int64(dataBody["delete_type"].(float64))
  1630. fmt.Println("delete_type", delete_type)
  1631. timeLayout := "2006-01-02"
  1632. loc, _ := time.LoadLocation("Local")
  1633. theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1634. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  1635. fmt.Println("theTimeStart23232322332322323", theTimeStart.Unix())
  1636. fmt.Println("theTimeStart23232322332322323", theTimeEnd.Unix())
  1637. if dataBody["failed_schedule"] != nil || reflect.TypeOf(dataBody["failed_schedule"]).String() == "[]interface {}" {
  1638. tempSchedule := dataBody["failed_schedule"].([]interface{})
  1639. failed_total = len(tempSchedule)
  1640. }
  1641. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  1642. tempSchedule := dataBody["schedule"].([]interface{})
  1643. total_schedule = tempSchedule
  1644. for _, schMap := range tempSchedule {
  1645. schMapM := schMap.(map[string]interface{})
  1646. var sch models.Schedule
  1647. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  1648. utils.ErrorLog("name")
  1649. return
  1650. }
  1651. name, _ := schMapM["name"].(string)
  1652. fmt.Println(name)
  1653. if len(name) == 0 { //名字为空则生成一条导入错误日志
  1654. err_log := models.ExportErrLog{
  1655. LogType: 2,
  1656. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1657. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  1658. Status: 1,
  1659. CreateTime: time.Now().Unix(),
  1660. UpdateTime: time.Now().Unix(),
  1661. ExportTime: export_time,
  1662. }
  1663. service.CreateExportErrLog(&err_log)
  1664. continue
  1665. } else {
  1666. var patient []*models.Patients
  1667. for _, item := range patients {
  1668. if strings.Replace(item.Name, " ", "", -1) == name {
  1669. patient = append(patient, item)
  1670. }
  1671. }
  1672. if len(patient) == 0 { //错误日志
  1673. err_log := models.ExportErrLog{
  1674. LogType: 2,
  1675. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1676. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  1677. Status: 1,
  1678. CreateTime: time.Now().Unix(),
  1679. UpdateTime: time.Now().Unix(),
  1680. ExportTime: export_time,
  1681. }
  1682. service.CreateExportErrLog(&err_log)
  1683. continue
  1684. } else if len(patient) == 1 { //
  1685. sch.PatientId = patient[0].ID
  1686. } else if len(patient) > 1 { //出现同名的情况
  1687. err_log := models.ExportErrLog{
  1688. LogType: 2,
  1689. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1690. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  1691. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在在当前机构中存在重名,无法确定到具体患者",
  1692. Status: 1,
  1693. CreateTime: time.Now().Unix(),
  1694. UpdateTime: time.Now().Unix(),
  1695. ExportTime: export_time,
  1696. }
  1697. service.CreateExportErrLog(&err_log)
  1698. continue
  1699. }
  1700. }
  1701. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  1702. utils.ErrorLog("schedule_type")
  1703. return
  1704. }
  1705. schedule_type := int64(schMapM["schedule_type"].(float64))
  1706. if schedule_type <= 0 { //班次格式有误,插入日志
  1707. log := models.ExportLog{
  1708. LogType: 2,
  1709. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1710. TotalNum: int64(len(total_schedule) + failed_total),
  1711. FailNum: 1 + int64(failed_total),
  1712. SuccessNum: int64(len(schedules)),
  1713. CreateTime: time.Now().Unix(),
  1714. UpdateTime: time.Now().Unix(),
  1715. ExportTime: export_time,
  1716. Status: 1,
  1717. }
  1718. service.CreateExportLog(&log)
  1719. err_log := models.ExportErrLog{
  1720. LogType: 2,
  1721. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1722. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  1723. Status: 1,
  1724. CreateTime: time.Now().Unix(),
  1725. UpdateTime: time.Now().Unix(),
  1726. ExportTime: export_time,
  1727. }
  1728. service.CreateExportErrLog(&err_log)
  1729. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1730. return
  1731. } else {
  1732. sch.ScheduleType = schedule_type
  1733. }
  1734. if schMapM["partition_name"] == nil || reflect.TypeOf(schMapM["partition_name"]).String() != "string" {
  1735. utils.ErrorLog("partition_name")
  1736. return
  1737. }
  1738. partition_name, _ := schMapM["partition_name"].(string)
  1739. if len(partition_name) == 0 { //分区为空
  1740. log := models.ExportLog{
  1741. LogType: 2,
  1742. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1743. TotalNum: int64(len(total_schedule) + failed_total),
  1744. FailNum: 1 + int64(failed_total),
  1745. SuccessNum: int64(len(schedules)),
  1746. CreateTime: time.Now().Unix(),
  1747. UpdateTime: time.Now().Unix(),
  1748. ExportTime: export_time,
  1749. Status: 1,
  1750. }
  1751. service.CreateExportLog(&log)
  1752. err_log := models.ExportErrLog{
  1753. LogType: 2,
  1754. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1755. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1756. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  1757. Status: 1,
  1758. CreateTime: time.Now().Unix(),
  1759. UpdateTime: time.Now().Unix(),
  1760. ExportTime: export_time,
  1761. }
  1762. service.CreateExportErrLog(&err_log)
  1763. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1764. return
  1765. } else {
  1766. zone, err := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  1767. if err == nil {
  1768. sch.PartitionId = zone.ID
  1769. } else if err == gorm.ErrRecordNotFound { //查不到数据,插入错误日志
  1770. log := models.ExportLog{
  1771. LogType: 2,
  1772. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1773. TotalNum: int64(len(total_schedule) + failed_total),
  1774. FailNum: 1 + int64(failed_total),
  1775. SuccessNum: int64(len(schedules)),
  1776. CreateTime: time.Now().Unix(),
  1777. UpdateTime: time.Now().Unix(),
  1778. ExportTime: export_time,
  1779. Status: 1,
  1780. }
  1781. service.CreateExportLog(&log)
  1782. err_log := models.ExportErrLog{
  1783. LogType: 2,
  1784. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1785. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1786. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  1787. Status: 1,
  1788. CreateTime: time.Now().Unix(),
  1789. UpdateTime: time.Now().Unix(),
  1790. ExportTime: export_time,
  1791. }
  1792. service.CreateExportErrLog(&err_log)
  1793. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1794. return
  1795. }
  1796. }
  1797. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  1798. utils.ErrorLog("device_number_name")
  1799. return
  1800. }
  1801. device_number_name, _ := schMapM["device_number_name"].(string)
  1802. if len(device_number_name) == 0 { //分区为空
  1803. log := models.ExportLog{
  1804. LogType: 2,
  1805. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1806. TotalNum: int64(len(total_schedule) + failed_total),
  1807. FailNum: 1 + int64(failed_total),
  1808. SuccessNum: int64(len(schedules)),
  1809. CreateTime: time.Now().Unix(),
  1810. UpdateTime: time.Now().Unix(),
  1811. ExportTime: export_time,
  1812. Status: 1,
  1813. }
  1814. service.CreateExportLog(&log)
  1815. err_log := models.ExportErrLog{
  1816. LogType: 2,
  1817. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1818. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1819. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  1820. Status: 1,
  1821. CreateTime: time.Now().Unix(),
  1822. UpdateTime: time.Now().Unix(),
  1823. ExportTime: export_time,
  1824. }
  1825. service.CreateExportErrLog(&err_log)
  1826. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1827. return
  1828. } else {
  1829. device, err := service.FindDeviceByName(device_number_name, this.GetAdminUserInfo().CurrentOrgId, sch.PartitionId)
  1830. if err == nil {
  1831. if len(device) == 0 { //没查到数据,插入错误日志
  1832. log := models.ExportLog{
  1833. LogType: 2,
  1834. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1835. TotalNum: int64(len(total_schedule) + failed_total),
  1836. FailNum: 1 + int64(failed_total),
  1837. SuccessNum: int64(len(schedules)),
  1838. CreateTime: time.Now().Unix(),
  1839. UpdateTime: time.Now().Unix(),
  1840. ExportTime: export_time,
  1841. Status: 1,
  1842. }
  1843. service.CreateExportLog(&log)
  1844. err_log := models.ExportErrLog{
  1845. LogType: 2,
  1846. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1847. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  1848. Status: 1,
  1849. CreateTime: time.Now().Unix(),
  1850. UpdateTime: time.Now().Unix(),
  1851. ExportTime: export_time,
  1852. }
  1853. service.CreateExportErrLog(&err_log)
  1854. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1855. return
  1856. } else if len(device) == 1 {
  1857. sch.BedId = device[0].ID
  1858. } else if len(device) > 1 { //出现重名,插入错误日志
  1859. log := models.ExportLog{
  1860. LogType: 2,
  1861. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1862. TotalNum: int64(len(total_schedule) + failed_total),
  1863. FailNum: 1 + int64(failed_total),
  1864. SuccessNum: int64(len(schedules)),
  1865. CreateTime: time.Now().Unix(),
  1866. UpdateTime: time.Now().Unix(),
  1867. ExportTime: export_time,
  1868. Status: 1,
  1869. }
  1870. service.CreateExportLog(&log)
  1871. err_log := models.ExportErrLog{
  1872. LogType: 2,
  1873. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1874. ErrMsg: "出现两个床位号相同的床位",
  1875. Status: 1,
  1876. CreateTime: time.Now().Unix(),
  1877. UpdateTime: time.Now().Unix(),
  1878. ExportTime: export_time,
  1879. }
  1880. service.CreateExportErrLog(&err_log)
  1881. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1882. return
  1883. }
  1884. }
  1885. }
  1886. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  1887. utils.ErrorLog("schedule_week")
  1888. return
  1889. }
  1890. schedule_week, _ := schMapM["schedule_week"].(string)
  1891. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  1892. log := models.ExportLog{
  1893. LogType: 2,
  1894. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1895. TotalNum: int64(len(total_schedule) + failed_total),
  1896. FailNum: 1 + int64(failed_total),
  1897. SuccessNum: int64(len(schedules)),
  1898. CreateTime: time.Now().Unix(),
  1899. UpdateTime: time.Now().Unix(),
  1900. ExportTime: export_time,
  1901. Status: 1,
  1902. }
  1903. service.CreateExportLog(&log)
  1904. err_log := models.ExportErrLog{
  1905. LogType: 2,
  1906. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1907. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1908. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1909. Status: 1,
  1910. CreateTime: time.Now().Unix(),
  1911. UpdateTime: time.Now().Unix(),
  1912. ExportTime: export_time,
  1913. }
  1914. service.CreateExportErrLog(&err_log)
  1915. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1916. return
  1917. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  1918. log := models.ExportLog{
  1919. LogType: 2,
  1920. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1921. TotalNum: int64(len(total_schedule) + failed_total),
  1922. FailNum: 1 + int64(failed_total),
  1923. SuccessNum: int64(len(schedules)),
  1924. CreateTime: time.Now().Unix(),
  1925. UpdateTime: time.Now().Unix(),
  1926. ExportTime: export_time,
  1927. Status: 1,
  1928. }
  1929. service.CreateExportLog(&log)
  1930. err_log := models.ExportErrLog{
  1931. LogType: 2,
  1932. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1933. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1934. Status: 1,
  1935. CreateTime: time.Now().Unix(),
  1936. UpdateTime: time.Now().Unix(),
  1937. ExportTime: export_time,
  1938. }
  1939. service.CreateExportErrLog(&err_log)
  1940. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1941. return
  1942. } else {
  1943. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  1944. sch.ScheduleWeek = schedule_week
  1945. }
  1946. if schMapM["schedule_date"] == nil || reflect.TypeOf(schMapM["schedule_date"]).String() != "string" {
  1947. utils.ErrorLog("schedule_date")
  1948. return
  1949. }
  1950. schedule_date, _ := schMapM["schedule_date"].(string)
  1951. if len(schedule_date) == 0 { //周几为空则生成一条导入错误日志
  1952. log := models.ExportLog{
  1953. LogType: 2,
  1954. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1955. TotalNum: int64(len(total_schedule) + failed_total),
  1956. FailNum: 1 + int64(failed_total),
  1957. SuccessNum: int64(len(schedules)),
  1958. CreateTime: time.Now().Unix(),
  1959. UpdateTime: time.Now().Unix(),
  1960. ExportTime: export_time,
  1961. Status: 1,
  1962. }
  1963. service.CreateExportLog(&log)
  1964. err_log := models.ExportErrLog{
  1965. LogType: 2,
  1966. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1967. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1968. Status: 1,
  1969. CreateTime: time.Now().Unix(),
  1970. UpdateTime: time.Now().Unix(),
  1971. ExportTime: export_time,
  1972. }
  1973. service.CreateExportErrLog(&err_log)
  1974. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1975. return
  1976. } else if schedule_date == "0" { //周几不符合格式则生成一条导入错误日志
  1977. log := models.ExportLog{
  1978. LogType: 2,
  1979. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1980. TotalNum: int64(len(total_schedule) + failed_total),
  1981. FailNum: 1 + int64(failed_total),
  1982. SuccessNum: int64(len(schedules)),
  1983. CreateTime: time.Now().Unix(),
  1984. UpdateTime: time.Now().Unix(),
  1985. ExportTime: export_time,
  1986. Status: 1,
  1987. }
  1988. service.CreateExportLog(&log)
  1989. err_log := models.ExportErrLog{
  1990. LogType: 2,
  1991. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1992. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1993. Status: 1,
  1994. CreateTime: time.Now().Unix(),
  1995. UpdateTime: time.Now().Unix(),
  1996. ExportTime: export_time,
  1997. }
  1998. service.CreateExportErrLog(&err_log)
  1999. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2000. return
  2001. } else {
  2002. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  2003. sch.ScheduleDate = date.Unix()
  2004. }
  2005. sch.CreatedTime = time.Now().Unix()
  2006. sch.UpdatedTime = time.Now().Unix()
  2007. sch.ModeId = 1
  2008. sch.Status = 1
  2009. sch.UserOrgId = this.GetAdminUserInfo().CurrentOrgId
  2010. sch.IsExport = 1
  2011. so, _ := service.GetDialysisSolutionTwo(sch.UserOrgId, sch.PatientId, sch.ModeId)
  2012. filedRecordOne, _ := service.FindFiledBy(sch.UserOrgId, "透析器")
  2013. filedRecordTwo, _ := service.FindFiledBy(sch.UserOrgId, "灌流器")
  2014. filedRecordThree, _ := service.FindFiledBy(sch.UserOrgId, "透析器/灌流器")
  2015. if filedRecordOne.IsShow == 1 {
  2016. sch.DialysisMachineName = so.DialysisDialyszers
  2017. //service.UpdateSchDName(schedule)
  2018. }
  2019. if filedRecordTwo.IsShow == 1 {
  2020. sch.DialysisMachineName = so.DialysisIrrigation
  2021. //service.UpdateSchDName(schedule)
  2022. }
  2023. if filedRecordThree.IsShow == 1 {
  2024. sch.DialysisMachineName = so.DialyzerPerfusionApparatus
  2025. //service.UpdateSchDName(schedule)
  2026. }
  2027. schedules = append(schedules, &sch)
  2028. }
  2029. errLogs, _ := service.FindSchedualExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  2030. if len(schedules) > 0 {
  2031. schedule_date := time.Now().Format("2006-01-02")
  2032. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  2033. clear_schedule_date := date.Unix() //根据日期去清除,该日期未来的排班数据
  2034. if err == nil {
  2035. for _, item := range schedules {
  2036. if item.ScheduleDate > clear_schedule_date {
  2037. //查询该患者是否转出获取死亡
  2038. //查找当天日期是否存在
  2039. _, errcode := service.GetTodayScheduleIsExistOne(item.PatientId, item.ScheduleDate, item.UserOrgId)
  2040. if errcode == gorm.ErrRecordNotFound {
  2041. //查询该床位是否有患者
  2042. sch, errcodes := service.GetPatientByBed(item.ScheduleDate, item.BedId, item.ScheduleType, item.UserOrgId)
  2043. if errcodes == gorm.ErrRecordNotFound {
  2044. service.CreateSchedule(item)
  2045. } else if errcodes == nil {
  2046. //清除当天该床位已有的患者
  2047. service.ModeFyScheduleById(sch.ScheduleDate, sch.BedId, sch.ScheduleType, sch.UserOrgId)
  2048. service.CreateSchedule(item)
  2049. }
  2050. } else if errcode == nil {
  2051. schedule := models.XtSchedule{
  2052. PartitionId: item.PartitionId,
  2053. BedId: item.BedId,
  2054. PatientId: item.PatientId,
  2055. ScheduleDate: item.ScheduleDate,
  2056. ScheduleType: item.ScheduleType,
  2057. ScheduleWeek: item.ScheduleWeek,
  2058. ModeId: item.ModeId,
  2059. Status: 1,
  2060. }
  2061. service.UpdateScheduleByOrgIdOne(item.PatientId, item.ScheduleDate, item.UserOrgId, &schedule)
  2062. }
  2063. }
  2064. }
  2065. log := models.ExportLog{
  2066. LogType: 2,
  2067. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2068. TotalNum: int64(len(total_schedule) + failed_total),
  2069. FailNum: int64(len(errLogs) + failed_total),
  2070. SuccessNum: int64(len(schedules)),
  2071. CreateTime: time.Now().Unix(),
  2072. UpdateTime: time.Now().Unix(),
  2073. ExportTime: export_time,
  2074. Status: 1,
  2075. }
  2076. service.CreateExportLog(&log)
  2077. if failed_total > 0 {
  2078. err_log := models.ExportErrLog{
  2079. LogType: 2,
  2080. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2081. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  2082. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  2083. Status: 1,
  2084. CreateTime: time.Now().Unix(),
  2085. UpdateTime: time.Now().Unix(),
  2086. ExportTime: export_time,
  2087. }
  2088. service.CreateExportErrLog(&err_log)
  2089. }
  2090. this.ServeSuccessJSON(map[string]interface{}{
  2091. "msg": "导入成功",
  2092. "total_num": len(total_schedule) + failed_total,
  2093. "success_num": len(schedules),
  2094. "fail_num": int64(len(errLogs)),
  2095. })
  2096. } else {
  2097. log := models.ExportLog{
  2098. LogType: 2,
  2099. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2100. TotalNum: int64(len(total_schedule) + failed_total),
  2101. FailNum: int64(len(errLogs) + failed_total),
  2102. SuccessNum: int64(len(schedules)),
  2103. CreateTime: time.Now().Unix(),
  2104. UpdateTime: time.Now().Unix(),
  2105. ExportTime: export_time,
  2106. Status: 1,
  2107. }
  2108. service.CreateExportLog(&log)
  2109. if failed_total > 0 {
  2110. err_log := models.ExportErrLog{
  2111. LogType: 2,
  2112. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2113. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  2114. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  2115. Status: 1,
  2116. CreateTime: time.Now().Unix(),
  2117. UpdateTime: time.Now().Unix(),
  2118. ExportTime: export_time,
  2119. }
  2120. service.CreateExportErrLog(&err_log)
  2121. }
  2122. this.ServeSuccessJSON(map[string]interface{}{
  2123. "msg": "导入成功",
  2124. "total_num": len(total_schedule),
  2125. "success_num": len(schedules),
  2126. "fail_num": int64(len(errLogs)),
  2127. })
  2128. }
  2129. } else {
  2130. log := models.ExportLog{
  2131. LogType: 2,
  2132. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2133. TotalNum: int64(len(total_schedule) + failed_total),
  2134. FailNum: int64(len(errLogs) + failed_total),
  2135. SuccessNum: int64(len(schedules)),
  2136. CreateTime: time.Now().Unix(),
  2137. UpdateTime: time.Now().Unix(),
  2138. ExportTime: export_time,
  2139. Status: 1,
  2140. }
  2141. service.CreateExportLog(&log)
  2142. if failed_total > 0 {
  2143. err_log := models.ExportErrLog{
  2144. LogType: 2,
  2145. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2146. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  2147. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  2148. Status: 1,
  2149. CreateTime: time.Now().Unix(),
  2150. UpdateTime: time.Now().Unix(),
  2151. ExportTime: export_time,
  2152. }
  2153. service.CreateExportErrLog(&err_log)
  2154. }
  2155. this.ServeSuccessJSON(map[string]interface{}{
  2156. "msg": "导入成功",
  2157. "total_num": len(total_schedule),
  2158. "success_num": len(schedules),
  2159. "fail_num": int64(len(errLogs)),
  2160. })
  2161. }
  2162. }
  2163. }
  2164. func (this *ScheduleApiController) ExportScheduleTemplate() {
  2165. dataBody := make(map[string]interface{}, 0)
  2166. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2167. if err != nil {
  2168. utils.ErrorLog(err.Error())
  2169. return
  2170. }
  2171. utils.ErrorLog("%v", dataBody)
  2172. export_time := time.Now().Unix()
  2173. var schedules []*models.PatientScheduleTemplateItem
  2174. var total_schedule []interface{}
  2175. patients, _, _ := service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  2176. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  2177. tempSchedule := dataBody["schedule"].([]interface{})
  2178. total_schedule = tempSchedule
  2179. for _, schMap := range tempSchedule {
  2180. schMapM := schMap.(map[string]interface{})
  2181. var sch models.PatientScheduleTemplateItem
  2182. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  2183. utils.ErrorLog("name")
  2184. return
  2185. }
  2186. name, _ := schMapM["name"].(string)
  2187. fmt.Println(name)
  2188. if len(name) == 0 { //名字为空则生成一条导入错误日志
  2189. err_log := models.ExportErrLog{
  2190. LogType: 3,
  2191. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2192. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  2193. Status: 1,
  2194. CreateTime: time.Now().Unix(),
  2195. UpdateTime: time.Now().Unix(),
  2196. ExportTime: export_time,
  2197. }
  2198. service.CreateExportErrLog(&err_log)
  2199. continue
  2200. } else {
  2201. var patient []*models.Patients
  2202. for _, item := range patients {
  2203. if strings.Replace(item.Name, " ", "", -1) == name {
  2204. patient = append(patient, item)
  2205. }
  2206. }
  2207. if len(patient) == 0 { //错误日志
  2208. err_log := models.ExportErrLog{
  2209. LogType: 3,
  2210. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2211. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名在系统中不存在,请在系统中添加该病人",
  2212. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  2213. Status: 1,
  2214. CreateTime: time.Now().Unix(),
  2215. UpdateTime: time.Now().Unix(),
  2216. ExportTime: export_time,
  2217. }
  2218. service.CreateExportErrLog(&err_log)
  2219. continue
  2220. } else if len(patient) == 1 { //
  2221. sch.PatientID = patient[0].ID
  2222. } else if len(patient) > 1 { //出现同名的情况
  2223. err_log := models.ExportErrLog{
  2224. LogType: 3,
  2225. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2226. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  2227. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在当前机构中存在重名,无法确定到具体患者",
  2228. Status: 1,
  2229. CreateTime: time.Now().Unix(),
  2230. UpdateTime: time.Now().Unix(),
  2231. ExportTime: export_time,
  2232. }
  2233. service.CreateExportErrLog(&err_log)
  2234. continue
  2235. }
  2236. }
  2237. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  2238. utils.ErrorLog("schedule_type")
  2239. return
  2240. }
  2241. schedule_type := int64(schMapM["schedule_type"].(float64))
  2242. if schedule_type <= 0 { //班次格式有误,插入日志
  2243. log := models.ExportLog{
  2244. LogType: 3,
  2245. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2246. TotalNum: int64(len(total_schedule)),
  2247. FailNum: 1,
  2248. SuccessNum: int64(len(schedules)),
  2249. CreateTime: time.Now().Unix(),
  2250. UpdateTime: time.Now().Unix(),
  2251. ExportTime: export_time,
  2252. Status: 1,
  2253. }
  2254. service.CreateExportLog(&log)
  2255. err_log := models.ExportErrLog{
  2256. LogType: 3,
  2257. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2258. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  2259. Status: 1,
  2260. CreateTime: time.Now().Unix(),
  2261. UpdateTime: time.Now().Unix(),
  2262. ExportTime: export_time,
  2263. }
  2264. service.CreateExportErrLog(&err_log)
  2265. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2266. return
  2267. } else {
  2268. sch.TimeType = int8(schedule_type)
  2269. }
  2270. if schMapM["template_id"] == nil && reflect.TypeOf(schMapM["template_id"]).String() != "float64" {
  2271. utils.ErrorLog("template_id")
  2272. return
  2273. }
  2274. template_id := int64(schMapM["template_id"].(float64))
  2275. sch.TemplateID = template_id
  2276. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  2277. utils.ErrorLog("device_number_name")
  2278. return
  2279. }
  2280. partition_name, _ := schMapM["partition_name"].(string)
  2281. zone, _ := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  2282. device_number_name, _ := schMapM["device_number_name"].(string)
  2283. if len(device_number_name) == 0 { //分区为空
  2284. log := models.ExportLog{
  2285. LogType: 3,
  2286. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2287. TotalNum: int64(len(total_schedule)),
  2288. FailNum: 1,
  2289. SuccessNum: int64(len(schedules)),
  2290. CreateTime: time.Now().Unix(),
  2291. UpdateTime: time.Now().Unix(),
  2292. ExportTime: export_time,
  2293. Status: 1,
  2294. }
  2295. service.CreateExportLog(&log)
  2296. err_log := models.ExportErrLog{
  2297. LogType: 3,
  2298. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2299. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2300. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  2301. Status: 1,
  2302. CreateTime: time.Now().Unix(),
  2303. UpdateTime: time.Now().Unix(),
  2304. ExportTime: export_time,
  2305. }
  2306. service.CreateExportErrLog(&err_log)
  2307. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2308. return
  2309. } else {
  2310. device, err := service.FindDeviceByNameTwo(device_number_name, this.GetAdminUserInfo().CurrentOrgId, zone.ID)
  2311. if err == nil {
  2312. if len(device) == 0 { //没查到数据,插入错误日志
  2313. log := models.ExportLog{
  2314. LogType: 3,
  2315. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2316. TotalNum: int64(len(total_schedule)),
  2317. FailNum: 1,
  2318. SuccessNum: int64(len(schedules)),
  2319. CreateTime: time.Now().Unix(),
  2320. UpdateTime: time.Now().Unix(),
  2321. ExportTime: export_time,
  2322. Status: 1,
  2323. }
  2324. service.CreateExportLog(&log)
  2325. err_log := models.ExportErrLog{
  2326. LogType: 3,
  2327. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2328. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  2329. Status: 1,
  2330. CreateTime: time.Now().Unix(),
  2331. UpdateTime: time.Now().Unix(),
  2332. ExportTime: export_time,
  2333. }
  2334. service.CreateExportErrLog(&err_log)
  2335. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2336. return
  2337. } else if len(device) == 1 {
  2338. sch.DeviceNumberID = device[0].ID
  2339. } else if len(device) > 1 { //出现重名,插入错误日志
  2340. log := models.ExportLog{
  2341. LogType: 3,
  2342. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2343. TotalNum: int64(len(total_schedule)),
  2344. FailNum: 1,
  2345. SuccessNum: int64(len(schedules)),
  2346. CreateTime: time.Now().Unix(),
  2347. UpdateTime: time.Now().Unix(),
  2348. ExportTime: export_time,
  2349. Status: 1,
  2350. }
  2351. service.CreateExportLog(&log)
  2352. err_log := models.ExportErrLog{
  2353. LogType: 3,
  2354. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2355. ErrMsg: "出现两个床位号相同的床位",
  2356. Status: 1,
  2357. CreateTime: time.Now().Unix(),
  2358. UpdateTime: time.Now().Unix(),
  2359. ExportTime: export_time,
  2360. }
  2361. service.CreateExportErrLog(&err_log)
  2362. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2363. return
  2364. }
  2365. }
  2366. }
  2367. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  2368. utils.ErrorLog("schedule_week")
  2369. return
  2370. }
  2371. schedule_week, _ := schMapM["schedule_week"].(string)
  2372. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  2373. log := models.ExportLog{
  2374. LogType: 3,
  2375. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2376. TotalNum: int64(len(total_schedule)),
  2377. FailNum: 1,
  2378. SuccessNum: int64(len(schedules)),
  2379. CreateTime: time.Now().Unix(),
  2380. UpdateTime: time.Now().Unix(),
  2381. ExportTime: export_time,
  2382. Status: 1,
  2383. }
  2384. service.CreateExportLog(&log)
  2385. err_log := models.ExportErrLog{
  2386. LogType: 3,
  2387. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2388. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2389. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2390. Status: 1,
  2391. CreateTime: time.Now().Unix(),
  2392. UpdateTime: time.Now().Unix(),
  2393. ExportTime: export_time,
  2394. }
  2395. service.CreateExportErrLog(&err_log)
  2396. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2397. return
  2398. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  2399. log := models.ExportLog{
  2400. LogType: 3,
  2401. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2402. TotalNum: int64(len(total_schedule)),
  2403. FailNum: 1,
  2404. SuccessNum: int64(len(schedules)),
  2405. CreateTime: time.Now().Unix(),
  2406. UpdateTime: time.Now().Unix(),
  2407. ExportTime: export_time,
  2408. Status: 1,
  2409. }
  2410. service.CreateExportLog(&log)
  2411. err_log := models.ExportErrLog{
  2412. LogType: 3,
  2413. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2414. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2415. Status: 1,
  2416. CreateTime: time.Now().Unix(),
  2417. UpdateTime: time.Now().Unix(),
  2418. ExportTime: export_time,
  2419. }
  2420. service.CreateExportErrLog(&err_log)
  2421. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2422. return
  2423. } else {
  2424. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  2425. sch.Weekday = int8(schedule_week)
  2426. }
  2427. sch.CreateTime = time.Now().Unix()
  2428. sch.ModifyTime = time.Now().Unix()
  2429. sch.TreatMode = 1
  2430. sch.Status = 1
  2431. sch.OrgID = this.GetAdminUserInfo().CurrentOrgId
  2432. sch.IsExport = 1
  2433. schedules = append(schedules, &sch)
  2434. }
  2435. errLogs, _ := service.FindSchedualTemplateExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  2436. if len(schedules) > 0 {
  2437. err := service.UpdateScheduleTemplateStatus(this.GetAdminUserInfo().CurrentOrgId)
  2438. if err == nil {
  2439. for _, item := range schedules {
  2440. service.CreateScheduleTemplate(item)
  2441. }
  2442. //查询已经转出或者死亡的患者
  2443. patientList, _ := service.GetDeathPatient(this.GetAdminUserInfo().CurrentOrgId)
  2444. for _, it := range patientList {
  2445. timeStr := time.Now().Format("2006-01-02")
  2446. timeLayout := "2006-01-02 15:04:05"
  2447. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  2448. timenow := timeStringToTime.Unix()
  2449. service.UpdateScheduleByDeathTime(it.ID, timenow)
  2450. service.UpdateScheduleItemByPatientId(it.ID)
  2451. }
  2452. log := models.ExportLog{
  2453. LogType: 3,
  2454. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2455. TotalNum: int64(len(total_schedule)),
  2456. FailNum: int64(len(errLogs)),
  2457. SuccessNum: int64(len(schedules)),
  2458. CreateTime: time.Now().Unix(),
  2459. UpdateTime: time.Now().Unix(),
  2460. ExportTime: export_time,
  2461. Status: 1,
  2462. }
  2463. service.CreateExportLog(&log)
  2464. this.ServeSuccessJSON(map[string]interface{}{
  2465. "msg": "导入成功",
  2466. "total_num": len(total_schedule),
  2467. "success_num": len(schedules),
  2468. "fail_num": int64(len(errLogs)),
  2469. })
  2470. } else {
  2471. log := models.ExportLog{
  2472. LogType: 3,
  2473. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2474. TotalNum: int64(len(total_schedule)),
  2475. FailNum: int64(len(errLogs)),
  2476. SuccessNum: int64(len(schedules)),
  2477. CreateTime: time.Now().Unix(),
  2478. UpdateTime: time.Now().Unix(),
  2479. ExportTime: export_time,
  2480. Status: 1,
  2481. }
  2482. service.CreateExportLog(&log)
  2483. this.ServeSuccessJSON(map[string]interface{}{
  2484. "msg": "导入成功",
  2485. "total_num": len(total_schedule),
  2486. "success_num": len(schedules),
  2487. "fail_num": int64(len(errLogs)),
  2488. })
  2489. }
  2490. } else {
  2491. log := models.ExportLog{
  2492. LogType: 3,
  2493. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2494. TotalNum: int64(len(total_schedule)),
  2495. FailNum: int64(len(errLogs)),
  2496. SuccessNum: int64(len(schedules)),
  2497. CreateTime: time.Now().Unix(),
  2498. UpdateTime: time.Now().Unix(),
  2499. ExportTime: export_time,
  2500. Status: 1,
  2501. }
  2502. service.CreateExportLog(&log)
  2503. this.ServeSuccessJSON(map[string]interface{}{
  2504. "msg": "导入成功",
  2505. "total_num": len(total_schedule),
  2506. "success_num": len(schedules),
  2507. "fail_num": int64(len(errLogs)),
  2508. })
  2509. }
  2510. }
  2511. }
  2512. func (c *ScheduleApiController) GetInitExcelInitDate() {
  2513. thisTime := time.Now()
  2514. thisTime1 := time.Now()
  2515. thisTime2 := time.Now()
  2516. thisTime1 = thisTime1.AddDate(0, 0, 7)
  2517. thisTime2 = thisTime2.AddDate(0, 0, 14)
  2518. weekDay := int(thisTime.Weekday())
  2519. if weekDay == 0 {
  2520. weekDay = 7
  2521. }
  2522. weekEnd := 7 - weekDay
  2523. weekStart := weekEnd - 6
  2524. days := make([]string, 0)
  2525. for index := weekStart; index <= weekEnd; index++ {
  2526. theDay := thisTime.AddDate(0, 0, index)
  2527. days = append(days, theDay.Format("2006-01-02"))
  2528. }
  2529. weekDay1 := int(thisTime1.Weekday())
  2530. if weekDay1 == 0 {
  2531. weekDay1 = 7
  2532. }
  2533. weekEnd1 := 7 - weekDay1
  2534. weekStart1 := weekEnd1 - 6
  2535. for index := weekStart1; index <= weekEnd1; index++ {
  2536. theDay := thisTime1.AddDate(0, 0, index)
  2537. days = append(days, theDay.Format("2006-01-02"))
  2538. }
  2539. weekDay2 := int(thisTime2.Weekday())
  2540. if weekDay2 == 0 {
  2541. weekDay2 = 7
  2542. }
  2543. weekEnd2 := 7 - weekDay2
  2544. weekStart2 := weekEnd2 - 6
  2545. for index := weekStart2; index <= weekEnd2; index++ {
  2546. theDay := thisTime2.AddDate(0, 0, index)
  2547. days = append(days, theDay.Format("2006-01-02"))
  2548. }
  2549. c.ServeSuccessJSON(map[string]interface{}{
  2550. "days": days,
  2551. })
  2552. return
  2553. }
  2554. func GetWeekString(week string) string {
  2555. var weekStr string
  2556. switch week {
  2557. case "Sunday":
  2558. weekStr = "周日"
  2559. break
  2560. case "Monday":
  2561. weekStr = "周一"
  2562. break
  2563. case "Tuesday":
  2564. weekStr = "周二"
  2565. break
  2566. case "Wednesday":
  2567. weekStr = "周三"
  2568. break
  2569. case "Thursday":
  2570. weekStr = "周四"
  2571. break
  2572. case "Friday":
  2573. weekStr = "周五"
  2574. break
  2575. case "Saturday":
  2576. weekStr = "周六"
  2577. break
  2578. default:
  2579. weekStr = ""
  2580. break
  2581. }
  2582. return weekStr
  2583. }
  2584. func (c *ScheduleApiController) SearchTemplateSchedulePatients() {
  2585. template_id, _ := c.GetInt64("template_id", 0)
  2586. keywords := c.GetString("keywords")
  2587. adminInfo := c.GetAdminUserInfo()
  2588. scheduleItems, _ := service.GetTemplateSchedualPatientsByKeywords(keywords, adminInfo.CurrentOrgId, template_id)
  2589. c.ServeSuccessJSON(map[string]interface{}{
  2590. "schdules": scheduleItems,
  2591. })
  2592. }
  2593. func (c *ScheduleApiController) CancelScheduleTemplate() {
  2594. item_id, _ := c.GetInt64("id")
  2595. adminInfo := c.GetAdminUserInfo()
  2596. err := service.UpdateNewScheduleTemplateStatus(item_id, adminInfo.CurrentOrgId)
  2597. if err == nil {
  2598. c.ServeSuccessJSON(map[string]interface{}{
  2599. "msg": "取消成功",
  2600. })
  2601. return
  2602. } else {
  2603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2604. return
  2605. }
  2606. }
  2607. func (this *ScheduleApiController) GetNextWeekDaySchedule() {
  2608. week_type, _ := this.GetInt64("week_type", -1)
  2609. week_time, _ := this.GetInt64("week_time")
  2610. //start_time, _ := this.GetInt64("start_time")
  2611. //end_time, _ := this.GetInt64("end_time")
  2612. record_date := this.GetString("record_date")
  2613. zons := this.GetString("zone")
  2614. zone := strings.Split(zons, ",")
  2615. start_time := this.GetString("start_time")
  2616. end_time := this.GetString("end_time")
  2617. timeLayout := "2006-01-02"
  2618. loc, _ := time.LoadLocation("Local")
  2619. theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2620. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  2621. adminUserInfo := this.GetAdminUserInfo()
  2622. var theStartTIme int64
  2623. if len(record_date) > 0 {
  2624. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2625. if err != nil {
  2626. utils.ErrorLog(err.Error())
  2627. }
  2628. theStartTIme = theTime.Unix()
  2629. }
  2630. schedule, err := service.GetNextWeekDaySchedule(week_type, week_time, theTimeStart.Unix(), theTimeEnd.Unix(), adminUserInfo.CurrentOrgId, zone, theStartTIme)
  2631. if err != nil {
  2632. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2633. return
  2634. }
  2635. this.ServeSuccessJSON(map[string]interface{}{
  2636. "schedule": schedule,
  2637. })
  2638. }
  2639. func (this *ScheduleApiController) GetThreeWeekList() {
  2640. start_time := this.GetString("start_time")
  2641. end_time := this.GetString("end_time")
  2642. partition_id, _ := this.GetInt64("partition_id")
  2643. schedule_type, _ := this.GetInt64("schedule_type")
  2644. fmt.Println(partition_id, schedule_type)
  2645. timeLayout := "2006-01-02"
  2646. loc, _ := time.LoadLocation("Local")
  2647. var theStartTIme int64
  2648. if len(start_time) > 0 {
  2649. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2650. if err != nil {
  2651. utils.ErrorLog(err.Error())
  2652. }
  2653. theStartTIme = theTime.Unix()
  2654. }
  2655. var theEndtTIme int64
  2656. if len(end_time) > 0 {
  2657. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  2658. if err != nil {
  2659. utils.ErrorLog(err.Error())
  2660. }
  2661. theEndtTIme = theTime.Unix()
  2662. }
  2663. adminUserInfo := this.GetAdminUserInfo()
  2664. orgId := adminUserInfo.CurrentOrgId
  2665. partitions, _ := service.GetSchedulePartitionPanel(orgId)
  2666. list, err := service.GetThreeWeekList(theStartTIme, theEndtTIme, orgId, schedule_type, partition_id)
  2667. if err != nil {
  2668. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2669. return
  2670. }
  2671. this.ServeSuccessJSON(map[string]interface{}{
  2672. "list": list,
  2673. "partitions": partitions,
  2674. })
  2675. }
  2676. func (this *ScheduleApiController) GetAllZones() {
  2677. adminUserInfo := this.GetAdminUserInfo()
  2678. orgId := adminUserInfo.CurrentOrgId
  2679. zones, err := service.GetAllZoneOne(orgId)
  2680. if err != nil {
  2681. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2682. return
  2683. }
  2684. this.ServeSuccessJSON(map[string]interface{}{
  2685. "zones": zones,
  2686. })
  2687. }
  2688. func (this *ScheduleApiController) GetCopyPatientSchedules() {
  2689. adminUserInfo := this.GetAdminUserInfo()
  2690. orgId := adminUserInfo.CurrentOrgId
  2691. start_time, _ := this.GetInt64("start_time")
  2692. fmt.Println("start_time", start_time)
  2693. end_time, _ := this.GetInt64("end_time")
  2694. fmt.Println("end_time", end_time)
  2695. copy_startime, _ := this.GetInt64("copy_startime")
  2696. fmt.Println("copy_startime", copy_startime)
  2697. copy_endtime, _ := this.GetInt64("copy_endtime")
  2698. //获取本周患者排班
  2699. schedules, _ := service.GetWeekSchedules(orgId, start_time, end_time)
  2700. //先清除复制周的排班
  2701. errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
  2702. fmt.Println(errcode)
  2703. var err error
  2704. for _, item := range schedules {
  2705. //fmt.Println(item.StartTime+604800)
  2706. //礼拜1
  2707. if item.ScheduleWeek == 1 {
  2708. item.ScheduleDate = copy_startime
  2709. }
  2710. if item.ScheduleWeek == 2 {
  2711. item.ScheduleDate = copy_startime + 86400
  2712. }
  2713. if item.ScheduleWeek == 3 {
  2714. item.ScheduleDate = copy_startime + 172800
  2715. }
  2716. if item.ScheduleWeek == 4 {
  2717. item.ScheduleDate = copy_startime + 259200
  2718. }
  2719. if item.ScheduleWeek == 5 {
  2720. item.ScheduleDate = copy_startime + 345600
  2721. }
  2722. if item.ScheduleWeek == 6 {
  2723. item.ScheduleDate = copy_startime + 432000
  2724. }
  2725. //礼拜天
  2726. if item.ScheduleWeek == 7 {
  2727. item.ScheduleDate = copy_endtime
  2728. }
  2729. schedule := models.XtSchedule{
  2730. UserOrgId: item.UserOrgId,
  2731. PartitionId: item.PartitionId,
  2732. BedId: item.BedId,
  2733. PatientId: item.PatientId,
  2734. ScheduleDate: item.ScheduleDate,
  2735. ScheduleType: item.ScheduleType,
  2736. ScheduleWeek: item.ScheduleWeek,
  2737. ModeId: item.ModeId,
  2738. Status: 1,
  2739. CreatedTime: time.Now().Unix(),
  2740. }
  2741. err = service.AddPatientSchedule(&schedule)
  2742. }
  2743. patientList, _ := service.GetDeathPatient(this.GetAdminUserInfo().CurrentOrgId)
  2744. timeStr := time.Now().Format("2006-01-02")
  2745. timeLayout := "2006-01-02 15:04:05"
  2746. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  2747. timenow := timeStringToTime.Unix()
  2748. for _, it := range patientList {
  2749. service.UpdateScheduleByDeathTime(it.ID, timenow)
  2750. service.UpdateScheduleItemByPatientId(it.ID)
  2751. }
  2752. if err != nil {
  2753. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2754. return
  2755. }
  2756. this.ServeSuccessJSON(map[string]interface{}{
  2757. "msg": "msg",
  2758. })
  2759. return
  2760. //查询复制中的排班日期是否存在
  2761. //_, errcode := service.GetLastWeekSchedule(orgId, copy_startime, copy_endtime)
  2762. //
  2763. //if errcode == gorm.ErrRecordNotFound {
  2764. // //如果没有直接新增
  2765. //
  2766. // for _, item := range schedules {
  2767. // //fmt.Println(item.StartTime+604800)
  2768. // //礼拜1
  2769. // if item.ScheduleWeek == 1 {
  2770. // item.ScheduleDate = copy_startime
  2771. // }
  2772. // if item.ScheduleWeek == 2 {
  2773. // item.ScheduleDate = copy_startime + 86400
  2774. // }
  2775. // if item.ScheduleWeek == 3 {
  2776. // item.ScheduleDate = copy_startime + 172800
  2777. // }
  2778. // if item.ScheduleWeek == 4 {
  2779. // item.ScheduleDate = copy_startime + 259200
  2780. // }
  2781. // if item.ScheduleWeek == 5 {
  2782. // item.ScheduleDate = copy_startime + 345600
  2783. // }
  2784. //
  2785. // if item.ScheduleWeek == 6 {
  2786. // item.ScheduleDate = copy_startime + 432000
  2787. // }
  2788. // //礼拜天
  2789. // if item.ScheduleWeek == 0 {
  2790. // item.ScheduleDate = copy_endtime
  2791. // }
  2792. // schedule := models.XtSchedule{
  2793. // UserOrgId: item.UserOrgId,
  2794. // PartitionId: item.PartitionId,
  2795. // BedId: item.BedId,
  2796. // PatientId: item.PatientId,
  2797. // ScheduleDate: item.ScheduleDate,
  2798. // ScheduleType: item.ScheduleType,
  2799. // ScheduleWeek: item.ScheduleWeek,
  2800. // ModeId: item.ModeId,
  2801. // Status: 1,
  2802. // CreatedTime: time.Now().Unix(),
  2803. // }
  2804. //
  2805. // err := service.AddPatientSchedule(&schedule)
  2806. // if err != nil {
  2807. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2808. // return
  2809. // }
  2810. // this.ServeSuccessJSON(map[string]interface{}{
  2811. // "schedule": schedule,
  2812. // })
  2813. // }
  2814. //} else if errcode == nil {
  2815. //
  2816. // //先清除复制周的排班
  2817. // errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
  2818. // fmt.Println(errcode)
  2819. // for _, item := range schedules {
  2820. // //fmt.Println(item.StartTime+604800)
  2821. // //礼拜1
  2822. // if item.ScheduleWeek == 1 {
  2823. // item.ScheduleDate = copy_startime
  2824. // }
  2825. // if item.ScheduleWeek == 2 {
  2826. // item.ScheduleDate = copy_startime + 86400
  2827. // }
  2828. // if item.ScheduleWeek == 3 {
  2829. // item.ScheduleDate = copy_startime + 172800
  2830. // }
  2831. // if item.ScheduleWeek == 4 {
  2832. // item.ScheduleDate = copy_startime + 259200
  2833. // }
  2834. // if item.ScheduleWeek == 5 {
  2835. // item.ScheduleDate = copy_startime + 345600
  2836. // }
  2837. //
  2838. // if item.ScheduleWeek == 6 {
  2839. // item.ScheduleDate = copy_startime + 432000
  2840. // }
  2841. // //礼拜天
  2842. // if item.ScheduleWeek == 0 {
  2843. // item.ScheduleDate = copy_endtime
  2844. // }
  2845. // schedule := models.XtSchedule{
  2846. // UserOrgId: item.UserOrgId,
  2847. // PartitionId: item.PartitionId,
  2848. // BedId: item.BedId,
  2849. // PatientId: item.PatientId,
  2850. // ScheduleDate: item.ScheduleDate,
  2851. // ScheduleType: item.ScheduleType,
  2852. // ScheduleWeek: item.ScheduleWeek,
  2853. // ModeId: item.ModeId,
  2854. // Status: 1,
  2855. // CreatedTime: time.Now().Unix(),
  2856. // }
  2857. //
  2858. // err := service.AddPatientSchedule(&schedule)
  2859. // if err != nil {
  2860. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2861. // return
  2862. // }
  2863. // this.ServeSuccessJSON(map[string]interface{}{
  2864. // "schedule": schedule,
  2865. // })
  2866. // }
  2867. //}
  2868. }
  2869. func (this *ScheduleApiController) SaveRemindPrint() {
  2870. id, _ := this.GetInt64("id")
  2871. anticoagulants, _ := this.GetInt64("anticoagulant")
  2872. anticoagulant_zongliang, _ := this.GetInt64("anticoagulant_zongliang")
  2873. classes, _ := this.GetInt64("classes")
  2874. dialyzers, _ := this.GetInt64("dialyzers")
  2875. doctor_advice, _ := this.GetInt64("doctor_advice")
  2876. mode, _ := this.GetInt64("mode")
  2877. name, _ := this.GetInt64("name")
  2878. number, _ := this.GetInt64("number")
  2879. perfusion_apparatus, _ := this.GetInt64("perfusion_apparatus")
  2880. prescription_status, _ := this.GetInt64("prescription_status")
  2881. week, _ := this.GetInt64("week")
  2882. zone, _ := this.GetInt64("zone")
  2883. adminUserInfo := this.GetAdminUserInfo()
  2884. orgId := adminUserInfo.CurrentOrgId
  2885. setting := models.XtRemindPrintSetting{
  2886. Anticoagulant: anticoagulants,
  2887. Classes: classes,
  2888. AnticoagulantZongliang: anticoagulant_zongliang,
  2889. Dialyzers: dialyzers,
  2890. DoctorAdvice: doctor_advice,
  2891. Mode: mode,
  2892. Name: name,
  2893. Number: number,
  2894. PerfusionApparatus: perfusion_apparatus,
  2895. PrescriptionStatus: prescription_status,
  2896. Week: week,
  2897. Zone: zone,
  2898. UserOrgId: orgId,
  2899. Status: 1,
  2900. Ctime: time.Now().Unix(),
  2901. }
  2902. _, errcode := service.GetSettingById(id)
  2903. if errcode == gorm.ErrRecordNotFound {
  2904. err := service.CreateSetting(&setting)
  2905. if err != nil {
  2906. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2907. return
  2908. }
  2909. this.ServeSuccessJSON(map[string]interface{}{
  2910. "setting": setting,
  2911. })
  2912. } else if errcode == nil {
  2913. err := service.UpdatedRemindPrint(&setting, id)
  2914. if err != nil {
  2915. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2916. return
  2917. }
  2918. this.ServeSuccessJSON(map[string]interface{}{
  2919. "setting": setting,
  2920. })
  2921. }
  2922. }
  2923. func (this *ScheduleApiController) GetRemindPrintList() {
  2924. adminUserInfo := this.GetAdminUserInfo()
  2925. orgId := adminUserInfo.CurrentOrgId
  2926. list, err := service.GetRemindPrintList(orgId)
  2927. if err != nil {
  2928. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2929. return
  2930. }
  2931. this.ServeSuccessJSON(map[string]interface{}{
  2932. "list": list,
  2933. })
  2934. }
  2935. func (this *ScheduleApiController) GetBloodScheduleList() {
  2936. week_type, _ := this.GetInt64("week_type", -1)
  2937. week_time, _ := this.GetInt64("week_time")
  2938. zones := this.GetString("zone")
  2939. zone := strings.Split(zones, ",")
  2940. thisTime := time.Now()
  2941. weekDay := int(thisTime.Weekday())
  2942. if weekDay == 0 {
  2943. weekDay = 7
  2944. }
  2945. weekEnd := 7 - weekDay
  2946. weekStart := weekEnd - 6
  2947. weekTitle := make([]string, 0)
  2948. days := make([]string, 0)
  2949. for index := weekStart; index <= weekEnd; index++ {
  2950. theDay := thisTime.AddDate(0, 0, index)
  2951. indexYear, indexMonthTime, indexDay := theDay.Date()
  2952. indexMonth := int(indexMonthTime)
  2953. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  2954. weekTitle = append(weekTitle, indexWeek)
  2955. days = append(days, theDay.Format("2006-01-02"))
  2956. }
  2957. fmt.Println(days)
  2958. var targetDayStr string
  2959. var startTime string
  2960. switch week_type {
  2961. case 0:
  2962. startTime = days[0]
  2963. targetDayStr = days[6]
  2964. break
  2965. case 1:
  2966. targetDayStr = days[0]
  2967. break
  2968. case 2:
  2969. targetDayStr = days[1]
  2970. break
  2971. case 3:
  2972. targetDayStr = days[2]
  2973. break
  2974. case 4:
  2975. targetDayStr = days[3]
  2976. break
  2977. case 5:
  2978. targetDayStr = days[4]
  2979. break
  2980. case 6:
  2981. targetDayStr = days[5]
  2982. break
  2983. case 7:
  2984. targetDayStr = days[6]
  2985. break
  2986. }
  2987. targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  2988. if parseErr != nil {
  2989. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2990. return
  2991. }
  2992. orgId := this.GetAdminUserInfo().CurrentOrgId
  2993. if week_type > 0 {
  2994. list, err := service.GetWeekDayScheduleByIdThee(orgId, targetDay.Unix(), week_time, zone)
  2995. if err != nil {
  2996. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2997. return
  2998. }
  2999. this.ServeSuccessJSON(map[string]interface{}{
  3000. "list": list,
  3001. "day": targetDayStr,
  3002. })
  3003. }
  3004. if week_type == 0 {
  3005. startDate, _ := utils.ParseTimeStringToTime("2006-01-02", startTime)
  3006. list, err := service.GetWeekDayScheduleByIdTwo(orgId, targetDay.Unix(), week_time, startDate.Unix(), zone)
  3007. if err != nil {
  3008. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3009. return
  3010. }
  3011. this.ServeSuccessJSON(map[string]interface{}{
  3012. "list": list,
  3013. "day": targetDayStr,
  3014. })
  3015. }
  3016. }
  3017. func (this *ScheduleApiController) GetPrintList() {
  3018. adminUserInfo := this.GetAdminUserInfo()
  3019. orgId := adminUserInfo.CurrentOrgId
  3020. list, err := service.GetRemindPrintList(orgId)
  3021. if err != nil {
  3022. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3023. return
  3024. }
  3025. this.ServeSuccessJSON(map[string]interface{}{
  3026. "list": list,
  3027. })
  3028. }
  3029. func (this *ScheduleApiController) GetAllZoneList() {
  3030. adminUserInfo := this.GetAdminUserInfo()
  3031. orgId := adminUserInfo.CurrentOrgId
  3032. zoneList, err := service.GetAllZoneOne(orgId)
  3033. if err != nil {
  3034. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3035. return
  3036. }
  3037. this.ServeSuccessJSON(map[string]interface{}{
  3038. "zoneList": zoneList,
  3039. })
  3040. }
  3041. func (this *ScheduleApiController) GetPatientScheduleCount() {
  3042. patitionIdStr := this.GetString("partition_id")
  3043. week, _ := this.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  3044. ids := strings.Split(patitionIdStr, ",")
  3045. adminUserInfo := this.GetAdminUserInfo()
  3046. orgId := adminUserInfo.CurrentOrgId
  3047. thisTime := time.Now()
  3048. weekDay := int(thisTime.Weekday())
  3049. if week < 1 || week > 4 {
  3050. week = 2
  3051. }
  3052. if week == 1 {
  3053. thisTime = thisTime.AddDate(0, 0, -7)
  3054. } else if week == 3 {
  3055. thisTime = thisTime.AddDate(0, 0, 7)
  3056. } else if week == 4 {
  3057. thisTime = thisTime.AddDate(0, 0, 14)
  3058. }
  3059. if weekDay == 0 {
  3060. weekDay = 7
  3061. }
  3062. weekEnd := 7 - weekDay
  3063. weekStart := weekEnd - 6
  3064. weekTitle := make([]string, 0)
  3065. days := make([]string, 0)
  3066. for index := weekStart; index <= weekEnd; index++ {
  3067. theDay := thisTime.AddDate(0, 0, index)
  3068. indexYear, indexMonthTime, indexDay := theDay.Date()
  3069. indexMonth := int(indexMonthTime)
  3070. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  3071. weekTitle = append(weekTitle, indexWeek)
  3072. days = append(days, theDay.Format("2006-01-02"))
  3073. }
  3074. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  3075. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  3076. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  3077. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  3078. timeLayout := "2006-01-02 15:04:05"
  3079. loc, _ := time.LoadLocation("Local")
  3080. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  3081. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  3082. weekStartPoint := theStarTime.Unix()
  3083. weekEndPoint := theEndTime.Unix()
  3084. list, err := service.GetPatientScheduleCount(orgId, weekStartPoint, weekEndPoint, ids)
  3085. _, total, _ := service.GetTotalBedNumber(orgId, ids)
  3086. if err != nil {
  3087. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3088. return
  3089. }
  3090. this.ServeSuccessJSON(map[string]interface{}{
  3091. "list": list,
  3092. "total": total,
  3093. })
  3094. }
  3095. func (c *ScheduleApiController) GetWeekPanelsOne() {
  3096. data, _ := c.GetInt64("data", 1)
  3097. patitionIdStr := c.GetString("patitionid")
  3098. ids := strings.Split(patitionIdStr, ",")
  3099. adminInfo := c.GetAdminUserInfo()
  3100. thisTime := time.Now()
  3101. year, monthTime, day := thisTime.Date()
  3102. month := int(monthTime)
  3103. _, theWeek := thisTime.ISOWeek()
  3104. weekDay := int(thisTime.Weekday())
  3105. if weekDay == 0 {
  3106. weekDay = 7
  3107. }
  3108. weekEnd := 7 - weekDay
  3109. weekStart := weekEnd - 6
  3110. weekDays := make([]string, 0)
  3111. for index := weekStart; index <= weekEnd; index++ {
  3112. theDay := thisTime.AddDate(0, 0, index)
  3113. indexYear, indexMonthTime, indexDay := theDay.Date()
  3114. indexMonth := int(indexMonthTime)
  3115. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  3116. weekDays = append(weekDays, indexWeek)
  3117. }
  3118. returnData := map[string]interface{}{
  3119. "year": year,
  3120. "month": month,
  3121. "day": day,
  3122. "theWeek": theWeek,
  3123. "weekDay": weekDay,
  3124. "weekDays": weekDays,
  3125. }
  3126. if data == 1 {
  3127. partitions, _ := service.GetSchedulePartitionPanelTwo(adminInfo.CurrentOrgId, ids)
  3128. returnData["partitions"] = partitions
  3129. }
  3130. c.ServeSuccessJSON(returnData)
  3131. return
  3132. }
  3133. func (c *ScheduleApiController) GetScheduleOne() {
  3134. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  3135. patitionIdStr := c.GetString("patitionid")
  3136. ids := strings.Split(patitionIdStr, ",")
  3137. fmt.Println("patitonStr", ids)
  3138. schedule_type, _ := c.GetInt64("schedule_type")
  3139. adminInfo := c.GetAdminUserInfo()
  3140. thisTime := time.Now()
  3141. today := thisTime.Format("2006-01-02")
  3142. if week < 1 || week > 4 {
  3143. week = 2
  3144. }
  3145. if week == 1 {
  3146. thisTime = thisTime.AddDate(0, 0, -7)
  3147. } else if week == 3 {
  3148. thisTime = thisTime.AddDate(0, 0, 7)
  3149. } else if week == 4 {
  3150. thisTime = thisTime.AddDate(0, 0, 14)
  3151. }
  3152. weekDay := int(thisTime.Weekday())
  3153. if weekDay == 0 {
  3154. weekDay = 7
  3155. }
  3156. weekEnd := 7 - weekDay
  3157. weekStart := weekEnd - 6
  3158. weekTitle := make([]string, 0)
  3159. days := make([]string, 0)
  3160. for index := weekStart; index <= weekEnd; index++ {
  3161. theDay := thisTime.AddDate(0, 0, index)
  3162. indexYear, indexMonthTime, indexDay := theDay.Date()
  3163. indexMonth := int(indexMonthTime)
  3164. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  3165. weekTitle = append(weekTitle, indexWeek)
  3166. days = append(days, theDay.Format("2006-01-02"))
  3167. }
  3168. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  3169. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  3170. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  3171. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  3172. timeLayout := "2006-01-02 15:04:05"
  3173. loc, _ := time.LoadLocation("Local")
  3174. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  3175. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  3176. weekStartPoint := theStarTime.Unix()
  3177. weekEndPoint := theEndTime.Unix()
  3178. schdules, _ := service.GetWeekScheduleTwo(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type)
  3179. c.ServeSuccessJSON(map[string]interface{}{
  3180. "days": days,
  3181. "weekTitle": weekTitle,
  3182. "schdules": schdules,
  3183. "today": today,
  3184. })
  3185. return
  3186. }
  3187. func (c *ScheduleApiController) SaveScheduleTemplate() {
  3188. template_id, _ := c.GetInt64("template_id")
  3189. orgId := c.GetAdminUserInfo().CurrentOrgId
  3190. template := models.ScheduleTemplate{
  3191. TemplateId: template_id,
  3192. UserOrgId: orgId,
  3193. Status: 1,
  3194. Ctime: time.Now().Unix(),
  3195. }
  3196. _, errcodes := service.GetScheudleTemplateById(orgId)
  3197. if errcodes == gorm.ErrRecordNotFound {
  3198. service.CreateXtscheduleTemplate(&template)
  3199. } else if errcodes == nil {
  3200. service.UpdateXtScheduleTemplate(&template, orgId)
  3201. }
  3202. c.ServeSuccessJSON(map[string]interface{}{
  3203. "template": template,
  3204. })
  3205. return
  3206. }
  3207. func (c *ScheduleApiController) GetScheduleTemplate() {
  3208. adminUserInfo := c.GetAdminUserInfo()
  3209. orgId := adminUserInfo.CurrentOrgId
  3210. template, _ := service.GetScheduleTemplate(orgId)
  3211. c.ServeSuccessJSON(map[string]interface{}{
  3212. "template": template,
  3213. })
  3214. return
  3215. }
  3216. func (c *ScheduleApiController) ChangeFuncPrint() {
  3217. adminUserInfo := c.GetAdminUserInfo()
  3218. orgId := adminUserInfo.CurrentOrgId
  3219. is_open, _ := c.GetInt64("is_open")
  3220. dataPrint := models.XtDataPrint{
  3221. UserOrgId: orgId,
  3222. IsOpen: is_open,
  3223. Status: 1,
  3224. Ctime: time.Now().Unix(),
  3225. }
  3226. _, errcode := service.GetDataPrintByOrgId(orgId)
  3227. fmt.Println("errcode222234444555556t66", errcode)
  3228. if errcode == gorm.ErrRecordNotFound {
  3229. service.CreateDataPrint(&dataPrint)
  3230. c.ServeSuccessJSON(map[string]interface{}{
  3231. "dataPrint": dataPrint,
  3232. })
  3233. return
  3234. } else if errcode == nil {
  3235. service.UpdteDataPrint(orgId, &dataPrint)
  3236. c.ServeSuccessJSON(map[string]interface{}{
  3237. "dataPrint": dataPrint,
  3238. })
  3239. return
  3240. }
  3241. }
  3242. func (c *ScheduleApiController) GetDataPrint() {
  3243. adminUserInfo := c.GetAdminUserInfo()
  3244. orgId := adminUserInfo.CurrentOrgId
  3245. dataPrint, _ := service.GetDataPrint(orgId)
  3246. c.ServeSuccessJSON(map[string]interface{}{
  3247. "dataPrint": dataPrint,
  3248. })
  3249. return
  3250. }
  3251. func (c *ScheduleApiController) GetNextWeekPanels() {
  3252. start_time, _ := c.GetInt64("start_time")
  3253. fmt.Println("start_time", start_time)
  3254. end_time, _ := c.GetInt64("end_time")
  3255. fmt.Println("end_time", end_time)
  3256. orgId := c.GetAdminUserInfo().CurrentOrgId
  3257. schedule, _ := service.GetNextWeekPanels(start_time, end_time, orgId)
  3258. c.ServeSuccessJSON(map[string]interface{}{
  3259. "schedule": schedule,
  3260. })
  3261. }
  3262. func (c *ScheduleApiController) SynchroSchedule() {
  3263. template_id, _ := c.GetInt64("template_id")
  3264. copy_startime, _ := c.GetInt64("copy_startime")
  3265. copy_endtime, _ := c.GetInt64("copy_endtime")
  3266. orgId := c.GetAdminUserInfo().CurrentOrgId
  3267. //根据模板ID获取模板数据
  3268. list, _ := service.GetTemplateListByTemplateId(template_id, orgId)
  3269. recordDateStr := time.Now().Format("2006-01-02")
  3270. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3271. nowtime := recordDate.Unix()
  3272. fmt.Println("今日时间", nowtime)
  3273. fmt.Println("后期日期", copy_startime)
  3274. var tuesday int64
  3275. var wednesday int64
  3276. var thursday int64
  3277. var friday int64
  3278. var saturday int64
  3279. //如果选择的开始日期大于当前日期
  3280. if copy_startime > nowtime {
  3281. //清空该时间段的所有排班数据
  3282. service.DeletePatientSchedule(copy_startime, copy_endtime, orgId)
  3283. tuesday = copy_startime + 86400
  3284. wednesday = copy_startime + 172800
  3285. thursday = copy_startime + 259200
  3286. friday = copy_startime + 345600
  3287. saturday = copy_startime + 432000
  3288. for _, item := range list {
  3289. if item.Weekday == 1 {
  3290. item.ScheduleDate = copy_startime
  3291. }
  3292. if item.Weekday == 2 {
  3293. item.ScheduleDate = tuesday
  3294. }
  3295. if item.Weekday == 3 {
  3296. item.ScheduleDate = wednesday
  3297. }
  3298. if item.Weekday == 4 {
  3299. item.ScheduleDate = thursday
  3300. }
  3301. if item.Weekday == 5 {
  3302. item.ScheduleDate = friday
  3303. }
  3304. if item.Weekday == 6 {
  3305. item.ScheduleDate = saturday
  3306. }
  3307. if item.Weekday == 7 {
  3308. item.ScheduleDate = copy_endtime
  3309. }
  3310. //根据床位号获取区号
  3311. number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
  3312. item.ZoneId = number.ZoneID
  3313. }
  3314. for _, item := range list {
  3315. schedule := models.XtSchedule{
  3316. UserOrgId: orgId,
  3317. PartitionId: item.ZoneId,
  3318. BedId: item.DeviceNumberID,
  3319. PatientId: item.PatientID,
  3320. ScheduleDate: item.ScheduleDate,
  3321. ScheduleType: item.TimeType,
  3322. ScheduleWeek: item.Weekday,
  3323. ModeId: item.TreatMode,
  3324. Status: 1,
  3325. CreatedTime: time.Now().Unix(),
  3326. UpdatedTime: 0,
  3327. }
  3328. service.CreatePatientSchedule(&schedule)
  3329. }
  3330. }
  3331. //如果选择的日期小于当前日期,只同步今日以后的数据
  3332. if copy_startime <= nowtime {
  3333. //清空今日以后的数据
  3334. service.DeletePatientScheduleToday(nowtime, copy_endtime, orgId)
  3335. var tuesday int64
  3336. var wednesday int64
  3337. var thursday int64
  3338. var friday int64
  3339. var saturday int64
  3340. tuesday = copy_startime + 86400
  3341. wednesday = copy_startime + 172800
  3342. thursday = copy_startime + 259200
  3343. friday = copy_startime + 345600
  3344. saturday = copy_startime + 432000
  3345. for _, item := range list {
  3346. if item.Weekday == 1 {
  3347. item.ScheduleDate = copy_startime
  3348. }
  3349. if item.Weekday == 2 {
  3350. item.ScheduleDate = tuesday
  3351. }
  3352. if item.Weekday == 3 {
  3353. item.ScheduleDate = wednesday
  3354. }
  3355. if item.Weekday == 4 {
  3356. item.ScheduleDate = thursday
  3357. }
  3358. if item.Weekday == 5 {
  3359. item.ScheduleDate = friday
  3360. }
  3361. if item.Weekday == 6 {
  3362. item.ScheduleDate = saturday
  3363. }
  3364. if item.Weekday == 7 {
  3365. item.ScheduleDate = copy_endtime
  3366. }
  3367. //根据床位号获取区号
  3368. number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
  3369. item.ZoneId = number.ZoneID
  3370. }
  3371. for _, item := range list {
  3372. // 同步今日以后的数据
  3373. if item.ScheduleDate > nowtime {
  3374. schedule := models.XtSchedule{
  3375. UserOrgId: orgId,
  3376. PartitionId: item.ZoneId,
  3377. BedId: item.DeviceNumberID,
  3378. PatientId: item.PatientID,
  3379. ScheduleDate: item.ScheduleDate,
  3380. ScheduleType: item.TimeType,
  3381. ScheduleWeek: item.Weekday,
  3382. ModeId: item.TreatMode,
  3383. Status: 1,
  3384. CreatedTime: time.Now().Unix(),
  3385. UpdatedTime: 0,
  3386. }
  3387. service.CreatePatientSchedule(&schedule)
  3388. }
  3389. }
  3390. }
  3391. returnData := make(map[string]interface{}, 0)
  3392. returnData["list"] = list
  3393. c.ServeSuccessJSON(returnData)
  3394. return
  3395. }
  3396. func (c *ScheduleApiController) GetPatientScheduleTempalate() {
  3397. orgId := c.GetAdminUserInfo().CurrentOrgId
  3398. tempalate, _ := service.GetPatientScheduleTempalate(orgId)
  3399. c.ServeSuccessJSON(map[string]interface{}{
  3400. "schedule": tempalate,
  3401. })
  3402. }
  3403. func (c *ScheduleApiController) GetSolutionSchedule() {
  3404. orgId := c.GetAdminUserInfo().CurrentOrgId
  3405. solution, _ := service.GetSolutionSchedule(orgId)
  3406. c.ServeSuccessJSON(map[string]interface{}{
  3407. "solution": solution,
  3408. })
  3409. return
  3410. }