schedule_api_controller.go 138KB

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