schedule_api_controller.go 131KB

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