schedule_api_controller.go 136KB

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