schedule_api_controller.go 138KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375
  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. }
  1399. if filedRecordThree.IsShow == 1 {
  1400. if len(schedule.DialysisMachineName) > 0 {
  1401. DialysisMachineName = schedule.DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  1402. } else {
  1403. DialysisMachineName = so.DialyzerPerfusionApparatus
  1404. }
  1405. }
  1406. if filedRecordTwo.IsShow == 1 {
  1407. if len(DialysisMachineName) > 0 {
  1408. DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
  1409. } else {
  1410. DialysisMachineName = so.DialysisIrrigation
  1411. }
  1412. }
  1413. schedule.DialysisMachineName = DialysisMachineName
  1414. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  1415. if err != nil {
  1416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1417. return
  1418. }
  1419. if order != nil {
  1420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeMode)
  1421. return
  1422. }
  1423. } else if changeAction == "change_device" {
  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.ErrorCodeChangeDeviceNumber)
  1431. return
  1432. }
  1433. if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
  1434. utils.ErrorLog("schedule_type")
  1435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1436. return
  1437. }
  1438. scheduleType := int64(dataBody["schedule_type"].(float64))
  1439. if scheduleType < 1 || scheduleType > 3 {
  1440. utils.ErrorLog("scheduleType < 3")
  1441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1442. return
  1443. }
  1444. schedule.ScheduleType = scheduleType
  1445. if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
  1446. utils.ErrorLog("bed_id")
  1447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1448. return
  1449. }
  1450. bedId := int64(dataBody["bed_id"].(float64))
  1451. if bedId < 1 {
  1452. utils.ErrorLog("bedId < 1")
  1453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1454. return
  1455. }
  1456. schedule.BedId = bedId
  1457. if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
  1458. utils.ErrorLog("partition_id")
  1459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1460. return
  1461. }
  1462. partitionId := int64(dataBody["partition_id"].(float64))
  1463. if partitionId < 1 {
  1464. utils.ErrorLog("partitionId < 1")
  1465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1466. return
  1467. }
  1468. schedule.PartitionId = partitionId
  1469. bed, _ := service.GetDeviceNumberByID(adminINfo.CurrentOrgId, schedule.BedId)
  1470. if bed == nil {
  1471. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  1472. return
  1473. }
  1474. if bed.ZoneID != schedule.PartitionId {
  1475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  1476. return
  1477. }
  1478. startTime := schedule.ScheduleDate
  1479. endTime := startTime + 86399
  1480. //一天只有排班一次
  1481. daySchedule, err := service.GetDaySchedule(adminINfo.CurrentOrgId, startTime, endTime, schedule.PatientId)
  1482. if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
  1483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  1484. return
  1485. }
  1486. //同天同位置只能排一个
  1487. pointSchedule, err := service.GetPointSchedule(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  1488. if err != nil {
  1489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1490. return
  1491. }
  1492. if pointSchedule.ID > 0 {
  1493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  1494. return
  1495. }
  1496. } else {
  1497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1498. return
  1499. }
  1500. schedule.UpdatedTime = time.Now().Unix()
  1501. err = service.UpdateSchedule(schedule)
  1502. prescription := models.DialysisPrescription{
  1503. ModeId: schedule.ModeId,
  1504. }
  1505. _, errcode := service.GetDialysisPrescribe(schedule.UserOrgId, schedule.PatientId, schedule.ScheduleDate)
  1506. if errcode == gorm.ErrRecordNotFound {
  1507. if err != nil {
  1508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
  1509. return
  1510. }
  1511. c.ServeSuccessJSON(map[string]interface{}{
  1512. "msg": "ok",
  1513. "schedule": &schedule,
  1514. })
  1515. } else if errcode == nil {
  1516. err = service.UpdatedDialysisPrescription(&prescription, schedule.ScheduleDate, schedule.PatientId, schedule.UserOrgId)
  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. }
  1526. }
  1527. // /api/schedule/print/initdata [get]
  1528. // @param date:string yyyy-MM-dd 要打印的那一周中的任一天
  1529. func (this *ScheduleApiController) PrintInitData() {
  1530. dateStr := this.GetString("date")
  1531. //week_type, _ := this.GetInt64("type", 0)
  1532. var date *time.Time
  1533. if len(dateStr) == 0 {
  1534. now := time.Now()
  1535. date = &now
  1536. } else {
  1537. var parseErr error
  1538. date, parseErr = utils.ParseTimeStringToTime("2006-01-02", dateStr)
  1539. if parseErr != nil {
  1540. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1541. return
  1542. }
  1543. }
  1544. adminUserInfo := this.GetAdminUserInfo()
  1545. // 获取本周的排班
  1546. var monday time.Time
  1547. var sunday time.Time
  1548. //switch week_type {
  1549. //case 1:
  1550. monday, sunday = utils.GetMondayAndSundayOfWeekDate(date)
  1551. // break
  1552. //case 2:
  1553. // monday, sunday = utils.GetMondayAndSundayOfNextWeekDate(date)
  1554. //
  1555. // break
  1556. //case 3:
  1557. // monday, sunday = utils.GetMondayAndSundayOfNextNextWeekDate(date)
  1558. // break
  1559. //}
  1560. schedules, getScheduleErr := service.GetPrinitWeekSchedules(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
  1561. total, getScheduleErr := service.GetPrinitWeekTotal(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
  1562. if getScheduleErr != nil {
  1563. this.ErrorLog("获取周排班失败:%v", getScheduleErr)
  1564. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1565. return
  1566. }
  1567. thisTime := date
  1568. weekDay := int(thisTime.Weekday())
  1569. if weekDay == 0 {
  1570. weekDay = 7
  1571. }
  1572. weekEnd := 7 - weekDay
  1573. weekStart := weekEnd - 6
  1574. days := make([]string, 0)
  1575. for index := weekStart; index <= weekEnd; index++ {
  1576. theDay := thisTime.AddDate(0, 0, index)
  1577. days = append(days, theDay.Format("2006-01-02"))
  1578. }
  1579. this.ServeSuccessJSON(map[string]interface{}{
  1580. "total": total,
  1581. "schedules": schedules,
  1582. "monday": monday.Unix(),
  1583. "days": days,
  1584. })
  1585. }
  1586. func (this *ScheduleApiController) UrgentScheduleData() {
  1587. schedule_type, _ := this.GetInt("type", 0)
  1588. schedule_date := this.GetString("date")
  1589. var date *time.Time
  1590. if len(schedule_date) == 0 {
  1591. now := time.Now()
  1592. date = &now
  1593. } else {
  1594. var parseErr error
  1595. date, parseErr = utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  1596. if parseErr != nil {
  1597. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1598. return
  1599. }
  1600. }
  1601. adminUserInfo := this.GetAdminUserInfo()
  1602. deviceNumbers, getDeviceNumbersErr := service.MobileGetAllDeviceNumbersForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  1603. if getDeviceNumbersErr != nil {
  1604. this.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
  1605. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1606. return
  1607. }
  1608. // today := utils.ZeroHourTimeOfDay(time.Now())
  1609. schedules, getSchedulesErr := service.MobileGetOtherSchedulesForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  1610. if getSchedulesErr != nil {
  1611. this.ErrorLog("获取所有排班失败:%v", getSchedulesErr)
  1612. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1613. return
  1614. }
  1615. this.ServeSuccessJSON(map[string]interface{}{
  1616. "device_numbers": deviceNumbers,
  1617. "schedules": schedules,
  1618. })
  1619. }
  1620. func (this *ScheduleApiController) SearchSchedulePatients() {
  1621. keywords := this.GetString("keywords")
  1622. week_type, _ := this.GetInt64("week_type", 0)
  1623. start_sch := this.GetString("start_sch")
  1624. end_sch := this.GetString("end_sch")
  1625. thisTime1 := time.Now()
  1626. thisTime2 := time.Now()
  1627. thisTime1 = thisTime1.AddDate(0, 0, 7)
  1628. thisTime2 = thisTime2.AddDate(0, 0, 14)
  1629. var start_time string
  1630. var end_time string
  1631. switch week_type {
  1632. case 1:
  1633. timeLayout := "2006-01-02"
  1634. loc, _ := time.LoadLocation("Local")
  1635. var startSchTime int64
  1636. if len(start_sch) > 0 {
  1637. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_sch+" 00:00:00", loc)
  1638. startSchTime = theTime.Unix()
  1639. }
  1640. var endSchTime int64
  1641. if len(end_sch) > 0 {
  1642. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_sch+" 00:00:00", loc)
  1643. endSchTime = theTime.Unix()
  1644. }
  1645. adminUserInfo := this.GetAdminUserInfo()
  1646. list, _ := service.GetSchedualPatientsByKeywords(keywords, adminUserInfo.CurrentOrgId, startSchTime, endSchTime)
  1647. this.ServeSuccessJSON(map[string]interface{}{
  1648. "schdules": list,
  1649. })
  1650. break
  1651. case 2:
  1652. days := make([]string, 0)
  1653. weekDay1 := int(thisTime1.Weekday())
  1654. if weekDay1 == 0 {
  1655. weekDay1 = 7
  1656. }
  1657. weekEnd1 := 7 - weekDay1
  1658. weekStart1 := weekEnd1 - 6
  1659. for index := weekStart1; index <= weekEnd1; index++ {
  1660. fmt.Println(index)
  1661. theDay := thisTime1.AddDate(0, 0, index)
  1662. days = append(days, theDay.Format("2006-01-02"))
  1663. }
  1664. fmt.Println(days)
  1665. start_time = days[0]
  1666. end_time = days[len(days)-1]
  1667. timeLayout := "2006-01-02"
  1668. loc, _ := time.LoadLocation("Local")
  1669. var theStartTime int64
  1670. if len(start_time) > 0 {
  1671. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1672. theStartTime = theTime.Unix()
  1673. }
  1674. var theEndtTime int64
  1675. if len(end_time) > 0 {
  1676. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1677. theEndtTime = theTime.Unix()
  1678. }
  1679. adminUserInfo := this.GetAdminUserInfo()
  1680. list, _ := service.GetSchedualPatientsByKeywordsAndWeek(keywords, adminUserInfo.CurrentOrgId, theStartTime, theEndtTime)
  1681. this.ServeSuccessJSON(map[string]interface{}{
  1682. "schdules": list,
  1683. })
  1684. break
  1685. case 3:
  1686. days := make([]string, 0)
  1687. weekDay2 := int(thisTime2.Weekday())
  1688. if weekDay2 == 0 {
  1689. weekDay2 = 7
  1690. }
  1691. weekEnd2 := 7 - weekDay2
  1692. weekStart2 := weekEnd2 - 6
  1693. for index := weekStart2; index <= weekEnd2; index++ {
  1694. theDay := thisTime2.AddDate(0, 0, index)
  1695. days = append(days, theDay.Format("2006-01-02"))
  1696. }
  1697. start_time = days[0]
  1698. end_time = days[len(days)-1]
  1699. timeLayout := "2006-01-02"
  1700. loc, _ := time.LoadLocation("Local")
  1701. var theStartTime int64
  1702. if len(start_time) > 0 {
  1703. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1704. theStartTime = theTime.Unix()
  1705. }
  1706. var theEndtTime int64
  1707. if len(end_time) > 0 {
  1708. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1709. theEndtTime = theTime.Unix()
  1710. }
  1711. adminUserInfo := this.GetAdminUserInfo()
  1712. list, _ := service.GetSchedualPatientsByKeywordsAndWeek(keywords, adminUserInfo.CurrentOrgId, theStartTime, theEndtTime)
  1713. this.ServeSuccessJSON(map[string]interface{}{
  1714. "schdules": list,
  1715. })
  1716. break
  1717. }
  1718. }
  1719. func (this *ScheduleApiController) GetWeekDaySchedule() {
  1720. week_type, _ := this.GetInt64("week_type", -1)
  1721. week_time, _ := this.GetInt64("week_time")
  1722. thisTime := time.Now()
  1723. weekDay := int(thisTime.Weekday())
  1724. if weekDay == 0 {
  1725. weekDay = 7
  1726. }
  1727. weekEnd := 7 - weekDay
  1728. weekStart := weekEnd - 6
  1729. weekTitle := make([]string, 0)
  1730. days := make([]string, 0)
  1731. for index := weekStart; index <= weekEnd; index++ {
  1732. theDay := thisTime.AddDate(0, 0, index)
  1733. indexYear, indexMonthTime, indexDay := theDay.Date()
  1734. indexMonth := int(indexMonthTime)
  1735. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  1736. weekTitle = append(weekTitle, indexWeek)
  1737. days = append(days, theDay.Format("2006-01-02"))
  1738. }
  1739. fmt.Println(days)
  1740. var targetDayStr string
  1741. var startTime string
  1742. var endTime string
  1743. switch week_type {
  1744. case 0:
  1745. {
  1746. startTime = days[0]
  1747. endTime = days[6]
  1748. }
  1749. case 1:
  1750. targetDayStr = days[0]
  1751. break
  1752. case 2:
  1753. targetDayStr = days[1]
  1754. break
  1755. case 3:
  1756. targetDayStr = days[2]
  1757. break
  1758. case 4:
  1759. targetDayStr = days[3]
  1760. break
  1761. case 5:
  1762. targetDayStr = days[4]
  1763. break
  1764. case 6:
  1765. targetDayStr = days[5]
  1766. break
  1767. case 7:
  1768. targetDayStr = days[6]
  1769. break
  1770. }
  1771. targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  1772. startDay, _ := utils.ParseTimeStringToTime("2006-01-02", startTime)
  1773. endDay, _ := utils.ParseTimeStringToTime("2006-01-02", endTime)
  1774. fmt.Println(startDay, endDay)
  1775. if parseErr != nil {
  1776. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1777. return
  1778. }
  1779. orgId := this.GetAdminUserInfo().CurrentOrgId
  1780. list, _ := service.GetWeekDayScheduleTwo(orgId, targetDay.Unix(), targetDay, week_time)
  1781. this.ServeSuccessJSON(map[string]interface{}{
  1782. "schdules": list,
  1783. "day": targetDayStr,
  1784. })
  1785. }
  1786. func Struct2Map(obj interface{}) map[string]interface{} {
  1787. t := reflect.TypeOf(obj)
  1788. v := reflect.ValueOf(obj)
  1789. var data = make(map[string]interface{})
  1790. for i := 0; i < t.NumField(); i++ {
  1791. data[t.Field(i).Name] = v.Field(i).Interface()
  1792. }
  1793. return data
  1794. }
  1795. func (this *ScheduleApiController) ExportSchedule() {
  1796. dataBody := make(map[string]interface{}, 0)
  1797. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1798. if err != nil {
  1799. utils.ErrorLog(err.Error())
  1800. return
  1801. }
  1802. utils.ErrorLog("%v", dataBody)
  1803. export_time := time.Now().Unix()
  1804. var schedules []*models.Schedule
  1805. var failed_total int
  1806. var total_schedule []interface{}
  1807. var patients []*models.Patients
  1808. patients, _, _ = service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  1809. start_time := dataBody["start_time"].(string)
  1810. end_time := dataBody["end_time"].(string)
  1811. delete_type := int64(dataBody["delete_type"].(float64))
  1812. fmt.Println("delete_type", delete_type)
  1813. timeLayout := "2006-01-02"
  1814. loc, _ := time.LoadLocation("Local")
  1815. theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1816. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  1817. fmt.Println("theTimeStart23232322332322323", theTimeStart.Unix())
  1818. fmt.Println("theTimeStart23232322332322323", theTimeEnd.Unix())
  1819. if dataBody["failed_schedule"] != nil || reflect.TypeOf(dataBody["failed_schedule"]).String() == "[]interface {}" {
  1820. tempSchedule := dataBody["failed_schedule"].([]interface{})
  1821. failed_total = len(tempSchedule)
  1822. }
  1823. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  1824. tempSchedule := dataBody["schedule"].([]interface{})
  1825. total_schedule = tempSchedule
  1826. for _, schMap := range tempSchedule {
  1827. schMapM := schMap.(map[string]interface{})
  1828. var sch models.Schedule
  1829. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  1830. utils.ErrorLog("name")
  1831. return
  1832. }
  1833. name, _ := schMapM["name"].(string)
  1834. fmt.Println(name)
  1835. if len(name) == 0 { //名字为空则生成一条导入错误日志
  1836. err_log := models.ExportErrLog{
  1837. LogType: 2,
  1838. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1839. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  1840. Status: 1,
  1841. CreateTime: time.Now().Unix(),
  1842. UpdateTime: time.Now().Unix(),
  1843. ExportTime: export_time,
  1844. }
  1845. service.CreateExportErrLog(&err_log)
  1846. continue
  1847. } else {
  1848. var patient []*models.Patients
  1849. for _, item := range patients {
  1850. if strings.Replace(item.Name, " ", "", -1) == name {
  1851. patient = append(patient, item)
  1852. }
  1853. }
  1854. if len(patient) == 0 { //错误日志
  1855. err_log := models.ExportErrLog{
  1856. LogType: 2,
  1857. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1858. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  1859. Status: 1,
  1860. CreateTime: time.Now().Unix(),
  1861. UpdateTime: time.Now().Unix(),
  1862. ExportTime: export_time,
  1863. }
  1864. service.CreateExportErrLog(&err_log)
  1865. continue
  1866. } else if len(patient) == 1 { //
  1867. sch.PatientId = patient[0].ID
  1868. } else if len(patient) > 1 { //出现同名的情况
  1869. err_log := models.ExportErrLog{
  1870. LogType: 2,
  1871. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1872. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  1873. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在在当前机构中存在重名,无法确定到具体患者",
  1874. Status: 1,
  1875. CreateTime: time.Now().Unix(),
  1876. UpdateTime: time.Now().Unix(),
  1877. ExportTime: export_time,
  1878. }
  1879. service.CreateExportErrLog(&err_log)
  1880. continue
  1881. }
  1882. }
  1883. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  1884. utils.ErrorLog("schedule_type")
  1885. return
  1886. }
  1887. schedule_type := int64(schMapM["schedule_type"].(float64))
  1888. if schedule_type <= 0 { //班次格式有误,插入日志
  1889. log := models.ExportLog{
  1890. LogType: 2,
  1891. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1892. TotalNum: int64(len(total_schedule) + failed_total),
  1893. FailNum: 1 + int64(failed_total),
  1894. SuccessNum: int64(len(schedules)),
  1895. CreateTime: time.Now().Unix(),
  1896. UpdateTime: time.Now().Unix(),
  1897. ExportTime: export_time,
  1898. Status: 1,
  1899. }
  1900. service.CreateExportLog(&log)
  1901. err_log := models.ExportErrLog{
  1902. LogType: 2,
  1903. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1904. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  1905. Status: 1,
  1906. CreateTime: time.Now().Unix(),
  1907. UpdateTime: time.Now().Unix(),
  1908. ExportTime: export_time,
  1909. }
  1910. service.CreateExportErrLog(&err_log)
  1911. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1912. return
  1913. } else {
  1914. sch.ScheduleType = schedule_type
  1915. }
  1916. if schMapM["partition_name"] == nil || reflect.TypeOf(schMapM["partition_name"]).String() != "string" {
  1917. utils.ErrorLog("partition_name")
  1918. return
  1919. }
  1920. partition_name, _ := schMapM["partition_name"].(string)
  1921. if len(partition_name) == 0 { //分区为空
  1922. log := models.ExportLog{
  1923. LogType: 2,
  1924. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1925. TotalNum: int64(len(total_schedule) + failed_total),
  1926. FailNum: 1 + int64(failed_total),
  1927. SuccessNum: int64(len(schedules)),
  1928. CreateTime: time.Now().Unix(),
  1929. UpdateTime: time.Now().Unix(),
  1930. ExportTime: export_time,
  1931. Status: 1,
  1932. }
  1933. service.CreateExportLog(&log)
  1934. err_log := models.ExportErrLog{
  1935. LogType: 2,
  1936. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1937. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1938. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  1939. Status: 1,
  1940. CreateTime: time.Now().Unix(),
  1941. UpdateTime: time.Now().Unix(),
  1942. ExportTime: export_time,
  1943. }
  1944. service.CreateExportErrLog(&err_log)
  1945. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1946. return
  1947. } else {
  1948. zone, err := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  1949. if err == nil {
  1950. sch.PartitionId = zone.ID
  1951. } else if err == gorm.ErrRecordNotFound { //查不到数据,插入错误日志
  1952. log := models.ExportLog{
  1953. LogType: 2,
  1954. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1955. TotalNum: int64(len(total_schedule) + failed_total),
  1956. FailNum: 1 + int64(failed_total),
  1957. SuccessNum: int64(len(schedules)),
  1958. CreateTime: time.Now().Unix(),
  1959. UpdateTime: time.Now().Unix(),
  1960. ExportTime: export_time,
  1961. Status: 1,
  1962. }
  1963. service.CreateExportLog(&log)
  1964. err_log := models.ExportErrLog{
  1965. LogType: 2,
  1966. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1967. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1968. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  1969. Status: 1,
  1970. CreateTime: time.Now().Unix(),
  1971. UpdateTime: time.Now().Unix(),
  1972. ExportTime: export_time,
  1973. }
  1974. service.CreateExportErrLog(&err_log)
  1975. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1976. return
  1977. }
  1978. }
  1979. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  1980. utils.ErrorLog("device_number_name")
  1981. return
  1982. }
  1983. device_number_name, _ := schMapM["device_number_name"].(string)
  1984. if len(device_number_name) == 0 { //分区为空
  1985. log := models.ExportLog{
  1986. LogType: 2,
  1987. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1988. TotalNum: int64(len(total_schedule) + failed_total),
  1989. FailNum: 1 + int64(failed_total),
  1990. SuccessNum: int64(len(schedules)),
  1991. CreateTime: time.Now().Unix(),
  1992. UpdateTime: time.Now().Unix(),
  1993. ExportTime: export_time,
  1994. Status: 1,
  1995. }
  1996. service.CreateExportLog(&log)
  1997. err_log := models.ExportErrLog{
  1998. LogType: 2,
  1999. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2000. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2001. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  2002. Status: 1,
  2003. CreateTime: time.Now().Unix(),
  2004. UpdateTime: time.Now().Unix(),
  2005. ExportTime: export_time,
  2006. }
  2007. service.CreateExportErrLog(&err_log)
  2008. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2009. return
  2010. } else {
  2011. device, err := service.FindDeviceByName(device_number_name, this.GetAdminUserInfo().CurrentOrgId, sch.PartitionId)
  2012. if err == nil {
  2013. if len(device) == 0 { //没查到数据,插入错误日志
  2014. log := models.ExportLog{
  2015. LogType: 2,
  2016. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2017. TotalNum: int64(len(total_schedule) + failed_total),
  2018. FailNum: 1 + int64(failed_total),
  2019. SuccessNum: int64(len(schedules)),
  2020. CreateTime: time.Now().Unix(),
  2021. UpdateTime: time.Now().Unix(),
  2022. ExportTime: export_time,
  2023. Status: 1,
  2024. }
  2025. service.CreateExportLog(&log)
  2026. err_log := models.ExportErrLog{
  2027. LogType: 2,
  2028. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2029. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  2030. Status: 1,
  2031. CreateTime: time.Now().Unix(),
  2032. UpdateTime: time.Now().Unix(),
  2033. ExportTime: export_time,
  2034. }
  2035. service.CreateExportErrLog(&err_log)
  2036. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2037. return
  2038. } else if len(device) == 1 {
  2039. sch.BedId = device[0].ID
  2040. } else if len(device) > 1 { //出现重名,插入错误日志
  2041. log := models.ExportLog{
  2042. LogType: 2,
  2043. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2044. TotalNum: int64(len(total_schedule) + failed_total),
  2045. FailNum: 1 + int64(failed_total),
  2046. SuccessNum: int64(len(schedules)),
  2047. CreateTime: time.Now().Unix(),
  2048. UpdateTime: time.Now().Unix(),
  2049. ExportTime: export_time,
  2050. Status: 1,
  2051. }
  2052. service.CreateExportLog(&log)
  2053. err_log := models.ExportErrLog{
  2054. LogType: 2,
  2055. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2056. ErrMsg: "出现两个床位号相同的床位",
  2057. Status: 1,
  2058. CreateTime: time.Now().Unix(),
  2059. UpdateTime: time.Now().Unix(),
  2060. ExportTime: export_time,
  2061. }
  2062. service.CreateExportErrLog(&err_log)
  2063. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2064. return
  2065. }
  2066. }
  2067. }
  2068. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  2069. utils.ErrorLog("schedule_week")
  2070. return
  2071. }
  2072. schedule_week, _ := schMapM["schedule_week"].(string)
  2073. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  2074. log := models.ExportLog{
  2075. LogType: 2,
  2076. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2077. TotalNum: int64(len(total_schedule) + failed_total),
  2078. FailNum: 1 + int64(failed_total),
  2079. SuccessNum: int64(len(schedules)),
  2080. CreateTime: time.Now().Unix(),
  2081. UpdateTime: time.Now().Unix(),
  2082. ExportTime: export_time,
  2083. Status: 1,
  2084. }
  2085. service.CreateExportLog(&log)
  2086. err_log := models.ExportErrLog{
  2087. LogType: 2,
  2088. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2089. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2090. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2091. Status: 1,
  2092. CreateTime: time.Now().Unix(),
  2093. UpdateTime: time.Now().Unix(),
  2094. ExportTime: export_time,
  2095. }
  2096. service.CreateExportErrLog(&err_log)
  2097. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2098. return
  2099. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  2100. log := models.ExportLog{
  2101. LogType: 2,
  2102. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2103. TotalNum: int64(len(total_schedule) + failed_total),
  2104. FailNum: 1 + int64(failed_total),
  2105. SuccessNum: int64(len(schedules)),
  2106. CreateTime: time.Now().Unix(),
  2107. UpdateTime: time.Now().Unix(),
  2108. ExportTime: export_time,
  2109. Status: 1,
  2110. }
  2111. service.CreateExportLog(&log)
  2112. err_log := models.ExportErrLog{
  2113. LogType: 2,
  2114. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2115. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2116. Status: 1,
  2117. CreateTime: time.Now().Unix(),
  2118. UpdateTime: time.Now().Unix(),
  2119. ExportTime: export_time,
  2120. }
  2121. service.CreateExportErrLog(&err_log)
  2122. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2123. return
  2124. } else {
  2125. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  2126. sch.ScheduleWeek = schedule_week
  2127. }
  2128. if schMapM["schedule_date"] == nil || reflect.TypeOf(schMapM["schedule_date"]).String() != "string" {
  2129. utils.ErrorLog("schedule_date")
  2130. return
  2131. }
  2132. schedule_date, _ := schMapM["schedule_date"].(string)
  2133. if len(schedule_date) == 0 { //周几为空则生成一条导入错误日志
  2134. log := models.ExportLog{
  2135. LogType: 2,
  2136. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2137. TotalNum: int64(len(total_schedule) + failed_total),
  2138. FailNum: 1 + int64(failed_total),
  2139. SuccessNum: int64(len(schedules)),
  2140. CreateTime: time.Now().Unix(),
  2141. UpdateTime: time.Now().Unix(),
  2142. ExportTime: export_time,
  2143. Status: 1,
  2144. }
  2145. service.CreateExportLog(&log)
  2146. err_log := models.ExportErrLog{
  2147. LogType: 2,
  2148. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2149. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2150. Status: 1,
  2151. CreateTime: time.Now().Unix(),
  2152. UpdateTime: time.Now().Unix(),
  2153. ExportTime: export_time,
  2154. }
  2155. service.CreateExportErrLog(&err_log)
  2156. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2157. return
  2158. } else if schedule_date == "0" { //周几不符合格式则生成一条导入错误日志
  2159. log := models.ExportLog{
  2160. LogType: 2,
  2161. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2162. TotalNum: int64(len(total_schedule) + failed_total),
  2163. FailNum: 1 + int64(failed_total),
  2164. SuccessNum: int64(len(schedules)),
  2165. CreateTime: time.Now().Unix(),
  2166. UpdateTime: time.Now().Unix(),
  2167. ExportTime: export_time,
  2168. Status: 1,
  2169. }
  2170. service.CreateExportLog(&log)
  2171. err_log := models.ExportErrLog{
  2172. LogType: 2,
  2173. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2174. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2175. Status: 1,
  2176. CreateTime: time.Now().Unix(),
  2177. UpdateTime: time.Now().Unix(),
  2178. ExportTime: export_time,
  2179. }
  2180. service.CreateExportErrLog(&err_log)
  2181. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2182. return
  2183. } else {
  2184. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  2185. sch.ScheduleDate = date.Unix()
  2186. }
  2187. sch.CreatedTime = time.Now().Unix()
  2188. sch.UpdatedTime = time.Now().Unix()
  2189. sch.ModeId = 1
  2190. sch.Status = 1
  2191. sch.UserOrgId = this.GetAdminUserInfo().CurrentOrgId
  2192. sch.IsExport = 1
  2193. var DialysisMachineName string
  2194. so, _ := service.GetDialysisSolutionTwo(sch.UserOrgId, sch.PatientId, sch.ModeId)
  2195. filedRecordOne, _ := service.FindFiledBy(sch.UserOrgId, "透析器")
  2196. filedRecordTwo, _ := service.FindFiledBy(sch.UserOrgId, "灌流器")
  2197. filedRecordThree, _ := service.FindFiledBy(sch.UserOrgId, "透析器/灌流器")
  2198. if filedRecordOne.IsShow == 1 {
  2199. DialysisMachineName = so.DialysisDialyszers
  2200. }
  2201. if filedRecordThree.IsShow == 1 {
  2202. if len(DialysisMachineName) > 0 {
  2203. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  2204. } else {
  2205. DialysisMachineName = so.DialyzerPerfusionApparatus
  2206. }
  2207. }
  2208. if filedRecordTwo.IsShow == 1 {
  2209. if len(DialysisMachineName) > 0 {
  2210. DialysisMachineName = sch.DialysisMachineName + "," + so.DialysisIrrigation
  2211. } else {
  2212. DialysisMachineName = so.DialysisIrrigation
  2213. }
  2214. }
  2215. sch.DialysisMachineName = DialysisMachineName
  2216. schedules = append(schedules, &sch)
  2217. }
  2218. errLogs, _ := service.FindSchedualExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  2219. if len(schedules) > 0 {
  2220. schedule_date := time.Now().Format("2006-01-02")
  2221. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  2222. clear_schedule_date := date.Unix() //根据日期去清除,该日期未来的排班数据
  2223. service.UpdateScheduleByExport(this.GetAdminUserInfo().CurrentOrgId, clear_schedule_date)
  2224. if err == nil {
  2225. for _, item := range schedules {
  2226. if item.ScheduleDate > clear_schedule_date {
  2227. //查询该患者是否转出获取死亡
  2228. fmt.Println("11111323242423")
  2229. //查找当天日期是否存在
  2230. _, errcode := service.GetTodayScheduleIsExistOne(item.PatientId, item.ScheduleDate, item.UserOrgId)
  2231. if errcode == gorm.ErrRecordNotFound {
  2232. //查询该床位是否有患者
  2233. fmt.Println("errcodes")
  2234. sch, errcodes := service.GetPatientByBed(item.ScheduleDate, item.BedId, item.ScheduleType, item.UserOrgId)
  2235. fmt.Println("errcodes")
  2236. fmt.Println(errcodes)
  2237. fmt.Println(sch)
  2238. if errcodes == gorm.ErrRecordNotFound {
  2239. fmt.Println("1111111")
  2240. service.CreateSchedule(item)
  2241. } else if errcodes == nil {
  2242. fmt.Println("1111222222222")
  2243. //清除当天该床位已有的患者
  2244. service.ModeFyScheduleById(sch.ScheduleDate, sch.BedId, sch.ScheduleType, sch.UserOrgId)
  2245. service.CreateSchedule(item)
  2246. }
  2247. } else if errcode == nil {
  2248. schedule := models.XtSchedule{
  2249. PartitionId: item.PartitionId,
  2250. BedId: item.BedId,
  2251. PatientId: item.PatientId,
  2252. ScheduleDate: item.ScheduleDate,
  2253. ScheduleType: item.ScheduleType,
  2254. ScheduleWeek: item.ScheduleWeek,
  2255. ModeId: 1,
  2256. Status: 1,
  2257. DialysisMachineName: item.DialysisMachineName,
  2258. }
  2259. fmt.Println("1111222222223333333333333333332")
  2260. service.UpdateScheduleByOrgIdOne(item.PatientId, item.ScheduleDate, item.UserOrgId, &schedule)
  2261. }
  2262. }
  2263. }
  2264. log := models.ExportLog{
  2265. LogType: 2,
  2266. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2267. TotalNum: int64(len(total_schedule) + failed_total),
  2268. FailNum: int64(len(errLogs) + failed_total),
  2269. SuccessNum: int64(len(schedules)),
  2270. CreateTime: time.Now().Unix(),
  2271. UpdateTime: time.Now().Unix(),
  2272. ExportTime: export_time,
  2273. Status: 1,
  2274. }
  2275. service.CreateExportLog(&log)
  2276. if failed_total > 0 {
  2277. err_log := models.ExportErrLog{
  2278. LogType: 2,
  2279. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2280. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  2281. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  2282. Status: 1,
  2283. CreateTime: time.Now().Unix(),
  2284. UpdateTime: time.Now().Unix(),
  2285. ExportTime: export_time,
  2286. }
  2287. service.CreateExportErrLog(&err_log)
  2288. }
  2289. this.ServeSuccessJSON(map[string]interface{}{
  2290. "msg": "导入成功",
  2291. "total_num": len(total_schedule) + failed_total,
  2292. "success_num": len(schedules),
  2293. "fail_num": int64(len(errLogs)),
  2294. })
  2295. } else {
  2296. log := models.ExportLog{
  2297. LogType: 2,
  2298. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2299. TotalNum: int64(len(total_schedule) + failed_total),
  2300. FailNum: int64(len(errLogs) + failed_total),
  2301. SuccessNum: int64(len(schedules)),
  2302. CreateTime: time.Now().Unix(),
  2303. UpdateTime: time.Now().Unix(),
  2304. ExportTime: export_time,
  2305. Status: 1,
  2306. }
  2307. service.CreateExportLog(&log)
  2308. if failed_total > 0 {
  2309. err_log := models.ExportErrLog{
  2310. LogType: 2,
  2311. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2312. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  2313. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  2314. Status: 1,
  2315. CreateTime: time.Now().Unix(),
  2316. UpdateTime: time.Now().Unix(),
  2317. ExportTime: export_time,
  2318. }
  2319. service.CreateExportErrLog(&err_log)
  2320. }
  2321. this.ServeSuccessJSON(map[string]interface{}{
  2322. "msg": "导入成功",
  2323. "total_num": len(total_schedule),
  2324. "success_num": len(schedules),
  2325. "fail_num": int64(len(errLogs)),
  2326. })
  2327. }
  2328. } else {
  2329. log := models.ExportLog{
  2330. LogType: 2,
  2331. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2332. TotalNum: int64(len(total_schedule) + failed_total),
  2333. FailNum: int64(len(errLogs) + failed_total),
  2334. SuccessNum: int64(len(schedules)),
  2335. CreateTime: time.Now().Unix(),
  2336. UpdateTime: time.Now().Unix(),
  2337. ExportTime: export_time,
  2338. Status: 1,
  2339. }
  2340. service.CreateExportLog(&log)
  2341. if failed_total > 0 {
  2342. err_log := models.ExportErrLog{
  2343. LogType: 2,
  2344. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2345. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  2346. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  2347. Status: 1,
  2348. CreateTime: time.Now().Unix(),
  2349. UpdateTime: time.Now().Unix(),
  2350. ExportTime: export_time,
  2351. }
  2352. service.CreateExportErrLog(&err_log)
  2353. }
  2354. this.ServeSuccessJSON(map[string]interface{}{
  2355. "msg": "导入成功",
  2356. "total_num": len(total_schedule),
  2357. "success_num": len(schedules),
  2358. "fail_num": int64(len(errLogs)),
  2359. })
  2360. }
  2361. }
  2362. }
  2363. func (this *ScheduleApiController) ExportScheduleTemplate() {
  2364. dataBody := make(map[string]interface{}, 0)
  2365. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2366. if err != nil {
  2367. utils.ErrorLog(err.Error())
  2368. return
  2369. }
  2370. utils.ErrorLog("%v", dataBody)
  2371. export_time := time.Now().Unix()
  2372. var schedules []*models.PatientScheduleTemplateItem
  2373. var total_schedule []interface{}
  2374. patients, _, _ := service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  2375. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  2376. tempSchedule := dataBody["schedule"].([]interface{})
  2377. total_schedule = tempSchedule
  2378. for _, schMap := range tempSchedule {
  2379. schMapM := schMap.(map[string]interface{})
  2380. var sch models.PatientScheduleTemplateItem
  2381. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  2382. utils.ErrorLog("name")
  2383. return
  2384. }
  2385. name, _ := schMapM["name"].(string)
  2386. fmt.Println(name)
  2387. if len(name) == 0 { //名字为空则生成一条导入错误日志
  2388. err_log := models.ExportErrLog{
  2389. LogType: 3,
  2390. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2391. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  2392. Status: 1,
  2393. CreateTime: time.Now().Unix(),
  2394. UpdateTime: time.Now().Unix(),
  2395. ExportTime: export_time,
  2396. }
  2397. service.CreateExportErrLog(&err_log)
  2398. continue
  2399. } else {
  2400. var patient []*models.Patients
  2401. for _, item := range patients {
  2402. if strings.Replace(item.Name, " ", "", -1) == name {
  2403. patient = append(patient, item)
  2404. }
  2405. }
  2406. if len(patient) == 0 { //错误日志
  2407. err_log := models.ExportErrLog{
  2408. LogType: 3,
  2409. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2410. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名在系统中不存在,请在系统中添加该病人",
  2411. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  2412. Status: 1,
  2413. CreateTime: time.Now().Unix(),
  2414. UpdateTime: time.Now().Unix(),
  2415. ExportTime: export_time,
  2416. }
  2417. service.CreateExportErrLog(&err_log)
  2418. continue
  2419. } else if len(patient) == 1 { //
  2420. sch.PatientID = patient[0].ID
  2421. } else if len(patient) > 1 { //出现同名的情况
  2422. err_log := models.ExportErrLog{
  2423. LogType: 3,
  2424. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2425. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  2426. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在当前机构中存在重名,无法确定到具体患者",
  2427. Status: 1,
  2428. CreateTime: time.Now().Unix(),
  2429. UpdateTime: time.Now().Unix(),
  2430. ExportTime: export_time,
  2431. }
  2432. service.CreateExportErrLog(&err_log)
  2433. continue
  2434. }
  2435. }
  2436. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  2437. utils.ErrorLog("schedule_type")
  2438. return
  2439. }
  2440. schedule_type := int64(schMapM["schedule_type"].(float64))
  2441. if schedule_type <= 0 { //班次格式有误,插入日志
  2442. log := models.ExportLog{
  2443. LogType: 3,
  2444. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2445. TotalNum: int64(len(total_schedule)),
  2446. FailNum: 1,
  2447. SuccessNum: int64(len(schedules)),
  2448. CreateTime: time.Now().Unix(),
  2449. UpdateTime: time.Now().Unix(),
  2450. ExportTime: export_time,
  2451. Status: 1,
  2452. }
  2453. service.CreateExportLog(&log)
  2454. err_log := models.ExportErrLog{
  2455. LogType: 3,
  2456. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2457. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  2458. Status: 1,
  2459. CreateTime: time.Now().Unix(),
  2460. UpdateTime: time.Now().Unix(),
  2461. ExportTime: export_time,
  2462. }
  2463. service.CreateExportErrLog(&err_log)
  2464. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2465. return
  2466. } else {
  2467. sch.TimeType = int8(schedule_type)
  2468. }
  2469. if schMapM["template_id"] == nil && reflect.TypeOf(schMapM["template_id"]).String() != "float64" {
  2470. utils.ErrorLog("template_id")
  2471. return
  2472. }
  2473. template_id := int64(schMapM["template_id"].(float64))
  2474. sch.TemplateID = template_id
  2475. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  2476. utils.ErrorLog("device_number_name")
  2477. return
  2478. }
  2479. partition_name, _ := schMapM["partition_name"].(string)
  2480. zone, _ := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  2481. device_number_name, _ := schMapM["device_number_name"].(string)
  2482. if len(device_number_name) == 0 { //分区为空
  2483. log := models.ExportLog{
  2484. LogType: 3,
  2485. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2486. TotalNum: int64(len(total_schedule)),
  2487. FailNum: 1,
  2488. SuccessNum: int64(len(schedules)),
  2489. CreateTime: time.Now().Unix(),
  2490. UpdateTime: time.Now().Unix(),
  2491. ExportTime: export_time,
  2492. Status: 1,
  2493. }
  2494. service.CreateExportLog(&log)
  2495. err_log := models.ExportErrLog{
  2496. LogType: 3,
  2497. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2498. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2499. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  2500. Status: 1,
  2501. CreateTime: time.Now().Unix(),
  2502. UpdateTime: time.Now().Unix(),
  2503. ExportTime: export_time,
  2504. }
  2505. service.CreateExportErrLog(&err_log)
  2506. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2507. return
  2508. } else {
  2509. device, err := service.FindDeviceByNameTwo(device_number_name, this.GetAdminUserInfo().CurrentOrgId, zone.ID)
  2510. if err == nil {
  2511. if len(device) == 0 { //没查到数据,插入错误日志
  2512. log := models.ExportLog{
  2513. LogType: 3,
  2514. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2515. TotalNum: int64(len(total_schedule)),
  2516. FailNum: 1,
  2517. SuccessNum: int64(len(schedules)),
  2518. CreateTime: time.Now().Unix(),
  2519. UpdateTime: time.Now().Unix(),
  2520. ExportTime: export_time,
  2521. Status: 1,
  2522. }
  2523. service.CreateExportLog(&log)
  2524. err_log := models.ExportErrLog{
  2525. LogType: 3,
  2526. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2527. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  2528. Status: 1,
  2529. CreateTime: time.Now().Unix(),
  2530. UpdateTime: time.Now().Unix(),
  2531. ExportTime: export_time,
  2532. }
  2533. service.CreateExportErrLog(&err_log)
  2534. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2535. return
  2536. } else if len(device) == 1 {
  2537. sch.DeviceNumberID = device[0].ID
  2538. } else if len(device) > 1 { //出现重名,插入错误日志
  2539. log := models.ExportLog{
  2540. LogType: 3,
  2541. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2542. TotalNum: int64(len(total_schedule)),
  2543. FailNum: 1,
  2544. SuccessNum: int64(len(schedules)),
  2545. CreateTime: time.Now().Unix(),
  2546. UpdateTime: time.Now().Unix(),
  2547. ExportTime: export_time,
  2548. Status: 1,
  2549. }
  2550. service.CreateExportLog(&log)
  2551. err_log := models.ExportErrLog{
  2552. LogType: 3,
  2553. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2554. ErrMsg: "出现两个床位号相同的床位",
  2555. Status: 1,
  2556. CreateTime: time.Now().Unix(),
  2557. UpdateTime: time.Now().Unix(),
  2558. ExportTime: export_time,
  2559. }
  2560. service.CreateExportErrLog(&err_log)
  2561. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2562. return
  2563. }
  2564. }
  2565. }
  2566. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  2567. utils.ErrorLog("schedule_week")
  2568. return
  2569. }
  2570. schedule_week, _ := schMapM["schedule_week"].(string)
  2571. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  2572. log := models.ExportLog{
  2573. LogType: 3,
  2574. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2575. TotalNum: int64(len(total_schedule)),
  2576. FailNum: 1,
  2577. SuccessNum: int64(len(schedules)),
  2578. CreateTime: time.Now().Unix(),
  2579. UpdateTime: time.Now().Unix(),
  2580. ExportTime: export_time,
  2581. Status: 1,
  2582. }
  2583. service.CreateExportLog(&log)
  2584. err_log := models.ExportErrLog{
  2585. LogType: 3,
  2586. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2587. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2588. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2589. Status: 1,
  2590. CreateTime: time.Now().Unix(),
  2591. UpdateTime: time.Now().Unix(),
  2592. ExportTime: export_time,
  2593. }
  2594. service.CreateExportErrLog(&err_log)
  2595. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2596. return
  2597. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  2598. log := models.ExportLog{
  2599. LogType: 3,
  2600. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2601. TotalNum: int64(len(total_schedule)),
  2602. FailNum: 1,
  2603. SuccessNum: int64(len(schedules)),
  2604. CreateTime: time.Now().Unix(),
  2605. UpdateTime: time.Now().Unix(),
  2606. ExportTime: export_time,
  2607. Status: 1,
  2608. }
  2609. service.CreateExportLog(&log)
  2610. err_log := models.ExportErrLog{
  2611. LogType: 3,
  2612. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2613. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2614. Status: 1,
  2615. CreateTime: time.Now().Unix(),
  2616. UpdateTime: time.Now().Unix(),
  2617. ExportTime: export_time,
  2618. }
  2619. service.CreateExportErrLog(&err_log)
  2620. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2621. return
  2622. } else {
  2623. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  2624. sch.Weekday = int8(schedule_week)
  2625. }
  2626. treat_mode, _ := schMapM["treat_mode"].(string)
  2627. treat_mode_int, _ := strconv.ParseInt(treat_mode, 10, 64)
  2628. sch.CreateTime = time.Now().Unix()
  2629. sch.ModifyTime = time.Now().Unix()
  2630. sch.TreatMode = treat_mode_int
  2631. sch.Status = 1
  2632. sch.OrgID = this.GetAdminUserInfo().CurrentOrgId
  2633. sch.IsExport = 1
  2634. schedules = append(schedules, &sch)
  2635. }
  2636. errLogs, _ := service.FindSchedualTemplateExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  2637. //for _, item := range schedules {
  2638. //
  2639. //}
  2640. if len(schedules) > 0 {
  2641. err := service.UpdateScheduleTemplateStatus(this.GetAdminUserInfo().CurrentOrgId)
  2642. if err == nil {
  2643. for _, item := range schedules {
  2644. service.CreateScheduleTemplate(item)
  2645. }
  2646. ////查询已经转出或者死亡的患者
  2647. //patientList, _ := service.GetDeathPatient(this.GetAdminUserInfo().CurrentOrgId)
  2648. //for _, it := range patientList {
  2649. // timeStr := time.Now().Format("2006-01-02")
  2650. // timeLayout := "2006-01-02 15:04:05"
  2651. // timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  2652. // timenow := timeStringToTime.Unix()
  2653. // service.UpdateScheduleByDeathTime(it.ID, timenow)
  2654. // service.UpdateScheduleItemByPatientId(it.ID)
  2655. //}
  2656. log := models.ExportLog{
  2657. LogType: 3,
  2658. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2659. TotalNum: int64(len(total_schedule)),
  2660. FailNum: int64(len(errLogs)),
  2661. SuccessNum: int64(len(schedules)),
  2662. CreateTime: time.Now().Unix(),
  2663. UpdateTime: time.Now().Unix(),
  2664. ExportTime: export_time,
  2665. Status: 1,
  2666. }
  2667. service.CreateExportLog(&log)
  2668. this.ServeSuccessJSON(map[string]interface{}{
  2669. "msg": "导入成功",
  2670. "total_num": len(total_schedule),
  2671. "success_num": len(schedules),
  2672. "fail_num": int64(len(errLogs)),
  2673. })
  2674. } else {
  2675. log := models.ExportLog{
  2676. LogType: 3,
  2677. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2678. TotalNum: int64(len(total_schedule)),
  2679. FailNum: int64(len(errLogs)),
  2680. SuccessNum: int64(len(schedules)),
  2681. CreateTime: time.Now().Unix(),
  2682. UpdateTime: time.Now().Unix(),
  2683. ExportTime: export_time,
  2684. Status: 1,
  2685. }
  2686. service.CreateExportLog(&log)
  2687. this.ServeSuccessJSON(map[string]interface{}{
  2688. "msg": "导入成功",
  2689. "total_num": len(total_schedule),
  2690. "success_num": len(schedules),
  2691. "fail_num": int64(len(errLogs)),
  2692. })
  2693. }
  2694. } else {
  2695. log := models.ExportLog{
  2696. LogType: 3,
  2697. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2698. TotalNum: int64(len(total_schedule)),
  2699. FailNum: int64(len(errLogs)),
  2700. SuccessNum: int64(len(schedules)),
  2701. CreateTime: time.Now().Unix(),
  2702. UpdateTime: time.Now().Unix(),
  2703. ExportTime: export_time,
  2704. Status: 1,
  2705. }
  2706. service.CreateExportLog(&log)
  2707. this.ServeSuccessJSON(map[string]interface{}{
  2708. "msg": "导入成功",
  2709. "total_num": len(total_schedule),
  2710. "success_num": len(schedules),
  2711. "fail_num": int64(len(errLogs)),
  2712. })
  2713. }
  2714. }
  2715. }
  2716. func (c *ScheduleApiController) GetInitExcelInitDate() {
  2717. thisTime := time.Now()
  2718. thisTime1 := time.Now()
  2719. thisTime2 := time.Now()
  2720. thisTime3 := time.Now()
  2721. thisTime4 := time.Now()
  2722. thisTime1 = thisTime1.AddDate(0, 0, 7)
  2723. thisTime2 = thisTime2.AddDate(0, 0, 14)
  2724. thisTime3 = thisTime3.AddDate(0, 0, 21)
  2725. thisTime4 = thisTime4.AddDate(0, 0, 28)
  2726. weekDay := int(thisTime.Weekday())
  2727. if weekDay == 0 {
  2728. weekDay = 7
  2729. }
  2730. weekEnd := 7 - weekDay
  2731. weekStart := weekEnd - 6
  2732. days := make([]string, 0)
  2733. for index := weekStart; index <= weekEnd; index++ {
  2734. theDay := thisTime.AddDate(0, 0, index)
  2735. days = append(days, theDay.Format("2006-01-02"))
  2736. }
  2737. weekDay1 := int(thisTime1.Weekday())
  2738. if weekDay1 == 0 {
  2739. weekDay1 = 7
  2740. }
  2741. weekEnd1 := 7 - weekDay1
  2742. weekStart1 := weekEnd1 - 6
  2743. for index := weekStart1; index <= weekEnd1; index++ {
  2744. theDay := thisTime1.AddDate(0, 0, index)
  2745. days = append(days, theDay.Format("2006-01-02"))
  2746. }
  2747. weekDay2 := int(thisTime2.Weekday())
  2748. if weekDay2 == 0 {
  2749. weekDay2 = 7
  2750. }
  2751. weekEnd2 := 7 - weekDay2
  2752. weekStart2 := weekEnd2 - 6
  2753. for index := weekStart2; index <= weekEnd2; index++ {
  2754. theDay := thisTime2.AddDate(0, 0, index)
  2755. days = append(days, theDay.Format("2006-01-02"))
  2756. }
  2757. weekDay3 := int(thisTime3.Weekday())
  2758. if weekDay3 == 0 {
  2759. weekDay3 = 7
  2760. }
  2761. weekEnd3 := 7 - weekDay3
  2762. weekStart3 := weekEnd3 - 6
  2763. for index := weekStart3; index <= weekEnd3; index++ {
  2764. theDay := thisTime3.AddDate(0, 0, index)
  2765. days = append(days, theDay.Format("2006-01-02"))
  2766. }
  2767. weekDay4 := int(thisTime4.Weekday())
  2768. if weekDay4 == 0 {
  2769. weekDay4 = 7
  2770. }
  2771. weekEnd4 := 7 - weekDay4
  2772. weekStart4 := weekEnd4 - 6
  2773. for index := weekStart4; index <= weekEnd4; index++ {
  2774. theDay := thisTime4.AddDate(0, 0, index)
  2775. days = append(days, theDay.Format("2006-01-02"))
  2776. }
  2777. c.ServeSuccessJSON(map[string]interface{}{
  2778. "days": days,
  2779. })
  2780. return
  2781. }
  2782. func GetWeekString(week string) string {
  2783. var weekStr string
  2784. switch week {
  2785. case "Sunday":
  2786. weekStr = "周日"
  2787. break
  2788. case "Monday":
  2789. weekStr = "周一"
  2790. break
  2791. case "Tuesday":
  2792. weekStr = "周二"
  2793. break
  2794. case "Wednesday":
  2795. weekStr = "周三"
  2796. break
  2797. case "Thursday":
  2798. weekStr = "周四"
  2799. break
  2800. case "Friday":
  2801. weekStr = "周五"
  2802. break
  2803. case "Saturday":
  2804. weekStr = "周六"
  2805. break
  2806. default:
  2807. weekStr = ""
  2808. break
  2809. }
  2810. return weekStr
  2811. }
  2812. func (c *ScheduleApiController) SearchTemplateSchedulePatients() {
  2813. template_id, _ := c.GetInt64("template_id", 0)
  2814. keywords := c.GetString("keywords")
  2815. adminInfo := c.GetAdminUserInfo()
  2816. scheduleItems, _ := service.GetTemplateSchedualPatientsByKeywords(keywords, adminInfo.CurrentOrgId, template_id)
  2817. c.ServeSuccessJSON(map[string]interface{}{
  2818. "schdules": scheduleItems,
  2819. })
  2820. }
  2821. func (c *ScheduleApiController) CancelScheduleTemplate() {
  2822. item_id, _ := c.GetInt64("id")
  2823. adminInfo := c.GetAdminUserInfo()
  2824. err := service.UpdateNewScheduleTemplateStatus(item_id, adminInfo.CurrentOrgId)
  2825. if err == nil {
  2826. c.ServeSuccessJSON(map[string]interface{}{
  2827. "msg": "取消成功",
  2828. })
  2829. return
  2830. } else {
  2831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2832. return
  2833. }
  2834. }
  2835. func (this *ScheduleApiController) GetNextWeekDayScheduleOne() {
  2836. week_type, _ := this.GetInt64("week_type", -1)
  2837. week_time, _ := this.GetInt64("week_time")
  2838. record_date := this.GetString("record_date")
  2839. zons := this.GetString("zone")
  2840. zone := strings.Split(zons, ",")
  2841. start_time, _ := this.GetInt64("start_time")
  2842. end_time, _ := this.GetInt64("end_time")
  2843. timeLayout := "2006-01-02"
  2844. loc, _ := time.LoadLocation("Local")
  2845. //theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2846. //theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  2847. adminUserInfo := this.GetAdminUserInfo()
  2848. var theStartTIme int64
  2849. if len(record_date) > 0 {
  2850. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2851. if err != nil {
  2852. utils.ErrorLog(err.Error())
  2853. }
  2854. theStartTIme = theTime.Unix()
  2855. }
  2856. schedule, err := service.GetNextWeekDaySchedule(week_type, week_time, start_time, end_time, adminUserInfo.CurrentOrgId, zone, theStartTIme)
  2857. for _, item := range schedule {
  2858. order, _ := service.GetLastDialysisOrder(adminUserInfo.CurrentOrgId, item.PatientId, theStartTIme)
  2859. item.XtDialysisOrderSix = order
  2860. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  2861. dialysisprescription, _ := service.GetLastDialysisSolution(adminUserInfo.CurrentOrgId, item.PatientId, item.ModeId, item.ScheduleDate)
  2862. item.DialysisPrescription = dialysisprescription
  2863. }
  2864. }
  2865. if err != nil {
  2866. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2867. return
  2868. }
  2869. this.ServeSuccessJSON(map[string]interface{}{
  2870. "schedule": schedule,
  2871. })
  2872. }
  2873. func (this *ScheduleApiController) GetNextWeekDaySchedule() {
  2874. week_type, _ := this.GetInt64("week_type", -1)
  2875. week_time, _ := this.GetInt64("week_time")
  2876. record_date := this.GetString("record_date")
  2877. zons := this.GetString("zone")
  2878. zone := strings.Split(zons, ",")
  2879. start_time := this.GetString("start_time")
  2880. end_time := this.GetString("end_time")
  2881. timeLayout := "2006-01-02"
  2882. loc, _ := time.LoadLocation("Local")
  2883. theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2884. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  2885. adminUserInfo := this.GetAdminUserInfo()
  2886. var theStartTIme int64
  2887. if len(record_date) > 0 {
  2888. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2889. if err != nil {
  2890. utils.ErrorLog(err.Error())
  2891. }
  2892. theStartTIme = theTime.Unix()
  2893. }
  2894. schedule, err := service.GetNextWeekDaySchedule(week_type, week_time, theTimeStart.Unix(), theTimeEnd.Unix(), adminUserInfo.CurrentOrgId, zone, theStartTIme)
  2895. if err != nil {
  2896. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2897. return
  2898. }
  2899. this.ServeSuccessJSON(map[string]interface{}{
  2900. "schedule": schedule,
  2901. })
  2902. }
  2903. func (this *ScheduleApiController) GetThreeWeekList() {
  2904. start_time := this.GetString("start_time")
  2905. end_time := this.GetString("end_time")
  2906. partition_id, _ := this.GetInt64("partition_id")
  2907. schedule_type, _ := this.GetInt64("schedule_type")
  2908. fmt.Println(partition_id, schedule_type)
  2909. timeLayout := "2006-01-02"
  2910. loc, _ := time.LoadLocation("Local")
  2911. var theStartTIme int64
  2912. if len(start_time) > 0 {
  2913. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2914. if err != nil {
  2915. utils.ErrorLog(err.Error())
  2916. }
  2917. theStartTIme = theTime.Unix()
  2918. }
  2919. var theEndtTIme int64
  2920. if len(end_time) > 0 {
  2921. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  2922. if err != nil {
  2923. utils.ErrorLog(err.Error())
  2924. }
  2925. theEndtTIme = theTime.Unix()
  2926. }
  2927. adminUserInfo := this.GetAdminUserInfo()
  2928. orgId := adminUserInfo.CurrentOrgId
  2929. partitions, _ := service.GetSchedulePartitionPanel(orgId)
  2930. list, err := service.GetThreeWeekList(theStartTIme, theEndtTIme, orgId, schedule_type, partition_id)
  2931. if err != nil {
  2932. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2933. return
  2934. }
  2935. this.ServeSuccessJSON(map[string]interface{}{
  2936. "list": list,
  2937. "partitions": partitions,
  2938. })
  2939. }
  2940. func (this *ScheduleApiController) GetAllZones() {
  2941. adminUserInfo := this.GetAdminUserInfo()
  2942. orgId := adminUserInfo.CurrentOrgId
  2943. zones, err := service.GetAllZoneOne(orgId)
  2944. if err != nil {
  2945. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2946. return
  2947. }
  2948. this.ServeSuccessJSON(map[string]interface{}{
  2949. "zones": zones,
  2950. })
  2951. }
  2952. func (this *ScheduleApiController) GetCopyPatientSchedules() {
  2953. adminUserInfo := this.GetAdminUserInfo()
  2954. orgId := adminUserInfo.CurrentOrgId
  2955. start_time, _ := this.GetInt64("start_time")
  2956. fmt.Println("start_time", start_time)
  2957. end_time, _ := this.GetInt64("end_time")
  2958. fmt.Println("end_time", end_time)
  2959. copy_startime, _ := this.GetInt64("copy_startime")
  2960. fmt.Println("copy_startime", copy_startime)
  2961. copy_endtime, _ := this.GetInt64("copy_endtime")
  2962. //获取本周患者排班
  2963. schedules, _ := service.GetWeekSchedules(orgId, start_time, end_time)
  2964. //先清除复制周的排班
  2965. errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
  2966. fmt.Println(errcode)
  2967. var err error
  2968. for _, item := range schedules {
  2969. //fmt.Println(item.StartTime+604800)
  2970. //礼拜1
  2971. if item.ScheduleWeek == 1 {
  2972. item.ScheduleDate = copy_startime
  2973. }
  2974. if item.ScheduleWeek == 2 {
  2975. item.ScheduleDate = copy_startime + 86400
  2976. }
  2977. if item.ScheduleWeek == 3 {
  2978. item.ScheduleDate = copy_startime + 172800
  2979. }
  2980. if item.ScheduleWeek == 4 {
  2981. item.ScheduleDate = copy_startime + 259200
  2982. }
  2983. if item.ScheduleWeek == 5 {
  2984. item.ScheduleDate = copy_startime + 345600
  2985. }
  2986. if item.ScheduleWeek == 6 {
  2987. item.ScheduleDate = copy_startime + 432000
  2988. }
  2989. //礼拜天
  2990. if item.ScheduleWeek == 7 {
  2991. item.ScheduleDate = copy_endtime
  2992. }
  2993. schedule := models.XtSchedule{
  2994. UserOrgId: item.UserOrgId,
  2995. PartitionId: item.PartitionId,
  2996. BedId: item.BedId,
  2997. PatientId: item.PatientId,
  2998. ScheduleDate: item.ScheduleDate,
  2999. ScheduleType: item.ScheduleType,
  3000. ScheduleWeek: item.ScheduleWeek,
  3001. ModeId: item.ModeId,
  3002. Status: 1,
  3003. CreatedTime: time.Now().Unix(),
  3004. }
  3005. var DialysisMachineName string
  3006. so, _ := service.GetDialysisSolutionTwo(adminUserInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  3007. filedRecordOne, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器")
  3008. filedRecordTwo, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "灌流器")
  3009. filedRecordThree, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器/灌流器")
  3010. if filedRecordOne.IsShow == 1 {
  3011. DialysisMachineName = so.DialysisDialyszers
  3012. }
  3013. if filedRecordThree.IsShow == 1 {
  3014. if len(DialysisMachineName) > 0 {
  3015. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  3016. } else {
  3017. DialysisMachineName = so.DialyzerPerfusionApparatus
  3018. }
  3019. }
  3020. if filedRecordTwo.IsShow == 1 {
  3021. if len(DialysisMachineName) > 0 {
  3022. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  3023. } else {
  3024. DialysisMachineName = so.DialysisIrrigation
  3025. }
  3026. }
  3027. schedule.DialysisMachineName = DialysisMachineName
  3028. err = service.AddPatientSchedule(&schedule)
  3029. }
  3030. patientList, _ := service.GetDeathPatient(this.GetAdminUserInfo().CurrentOrgId)
  3031. timeStr := time.Now().Format("2006-01-02")
  3032. timeLayout := "2006-01-02 15:04:05"
  3033. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  3034. timenow := timeStringToTime.Unix()
  3035. for _, it := range patientList {
  3036. service.UpdateScheduleByDeathTime(it.ID, timenow)
  3037. service.UpdateScheduleItemByPatientId(it.ID)
  3038. }
  3039. if err != nil {
  3040. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3041. return
  3042. }
  3043. this.ServeSuccessJSON(map[string]interface{}{
  3044. "msg": "msg",
  3045. })
  3046. return
  3047. //查询复制中的排班日期是否存在
  3048. //_, errcode := service.GetLastWeekSchedule(orgId, copy_startime, copy_endtime)
  3049. //
  3050. //if errcode == gorm.ErrRecordNotFound {
  3051. // //如果没有直接新增
  3052. //
  3053. // for _, item := range schedules {
  3054. // //fmt.Println(item.StartTime+604800)
  3055. // //礼拜1
  3056. // if item.ScheduleWeek == 1 {
  3057. // item.ScheduleDate = copy_startime
  3058. // }
  3059. // if item.ScheduleWeek == 2 {
  3060. // item.ScheduleDate = copy_startime + 86400
  3061. // }
  3062. // if item.ScheduleWeek == 3 {
  3063. // item.ScheduleDate = copy_startime + 172800
  3064. // }
  3065. // if item.ScheduleWeek == 4 {
  3066. // item.ScheduleDate = copy_startime + 259200
  3067. // }
  3068. // if item.ScheduleWeek == 5 {
  3069. // item.ScheduleDate = copy_startime + 345600
  3070. // }
  3071. //
  3072. // if item.ScheduleWeek == 6 {
  3073. // item.ScheduleDate = copy_startime + 432000
  3074. // }
  3075. // //礼拜天
  3076. // if item.ScheduleWeek == 0 {
  3077. // item.ScheduleDate = copy_endtime
  3078. // }
  3079. // schedule := models.XtSchedule{
  3080. // UserOrgId: item.UserOrgId,
  3081. // PartitionId: item.PartitionId,
  3082. // BedId: item.BedId,
  3083. // PatientId: item.PatientId,
  3084. // ScheduleDate: item.ScheduleDate,
  3085. // ScheduleType: item.ScheduleType,
  3086. // ScheduleWeek: item.ScheduleWeek,
  3087. // ModeId: item.ModeId,
  3088. // Status: 1,
  3089. // CreatedTime: time.Now().Unix(),
  3090. // }
  3091. //
  3092. // err := service.AddPatientSchedule(&schedule)
  3093. // if err != nil {
  3094. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3095. // return
  3096. // }
  3097. // this.ServeSuccessJSON(map[string]interface{}{
  3098. // "schedule": schedule,
  3099. // })
  3100. // }
  3101. //} else if errcode == nil {
  3102. //
  3103. // //先清除复制周的排班
  3104. // errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
  3105. // fmt.Println(errcode)
  3106. // for _, item := range schedules {
  3107. // //fmt.Println(item.StartTime+604800)
  3108. // //礼拜1
  3109. // if item.ScheduleWeek == 1 {
  3110. // item.ScheduleDate = copy_startime
  3111. // }
  3112. // if item.ScheduleWeek == 2 {
  3113. // item.ScheduleDate = copy_startime + 86400
  3114. // }
  3115. // if item.ScheduleWeek == 3 {
  3116. // item.ScheduleDate = copy_startime + 172800
  3117. // }
  3118. // if item.ScheduleWeek == 4 {
  3119. // item.ScheduleDate = copy_startime + 259200
  3120. // }
  3121. // if item.ScheduleWeek == 5 {
  3122. // item.ScheduleDate = copy_startime + 345600
  3123. // }
  3124. //
  3125. // if item.ScheduleWeek == 6 {
  3126. // item.ScheduleDate = copy_startime + 432000
  3127. // }
  3128. // //礼拜天
  3129. // if item.ScheduleWeek == 0 {
  3130. // item.ScheduleDate = copy_endtime
  3131. // }
  3132. // schedule := models.XtSchedule{
  3133. // UserOrgId: item.UserOrgId,
  3134. // PartitionId: item.PartitionId,
  3135. // BedId: item.BedId,
  3136. // PatientId: item.PatientId,
  3137. // ScheduleDate: item.ScheduleDate,
  3138. // ScheduleType: item.ScheduleType,
  3139. // ScheduleWeek: item.ScheduleWeek,
  3140. // ModeId: item.ModeId,
  3141. // Status: 1,
  3142. // CreatedTime: time.Now().Unix(),
  3143. // }
  3144. //
  3145. // err := service.AddPatientSchedule(&schedule)
  3146. // if err != nil {
  3147. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3148. // return
  3149. // }
  3150. // this.ServeSuccessJSON(map[string]interface{}{
  3151. // "schedule": schedule,
  3152. // })
  3153. // }
  3154. //}
  3155. }
  3156. func (this *ScheduleApiController) SaveRemindPrint() {
  3157. id, _ := this.GetInt64("id")
  3158. anticoagulants, _ := this.GetInt64("anticoagulant")
  3159. anticoagulant_zongliang, _ := this.GetInt64("anticoagulant_zongliang")
  3160. classes, _ := this.GetInt64("classes")
  3161. dialyzers, _ := this.GetInt64("dialyzers")
  3162. doctor_advice, _ := this.GetInt64("doctor_advice")
  3163. mode, _ := this.GetInt64("mode")
  3164. name, _ := this.GetInt64("name")
  3165. number, _ := this.GetInt64("number")
  3166. perfusion_apparatus, _ := this.GetInt64("perfusion_apparatus")
  3167. prescription_status, _ := this.GetInt64("prescription_status")
  3168. week, _ := this.GetInt64("week")
  3169. zone, _ := this.GetInt64("zone")
  3170. adminUserInfo := this.GetAdminUserInfo()
  3171. orgId := adminUserInfo.CurrentOrgId
  3172. setting := models.XtRemindPrintSetting{
  3173. Anticoagulant: anticoagulants,
  3174. Classes: classes,
  3175. AnticoagulantZongliang: anticoagulant_zongliang,
  3176. Dialyzers: dialyzers,
  3177. DoctorAdvice: doctor_advice,
  3178. Mode: mode,
  3179. Name: name,
  3180. Number: number,
  3181. PerfusionApparatus: perfusion_apparatus,
  3182. PrescriptionStatus: prescription_status,
  3183. Week: week,
  3184. Zone: zone,
  3185. UserOrgId: orgId,
  3186. Status: 1,
  3187. Ctime: time.Now().Unix(),
  3188. }
  3189. _, errcode := service.GetSettingById(id)
  3190. if errcode == gorm.ErrRecordNotFound {
  3191. err := service.CreateSetting(&setting)
  3192. if err != nil {
  3193. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3194. return
  3195. }
  3196. this.ServeSuccessJSON(map[string]interface{}{
  3197. "setting": setting,
  3198. })
  3199. } else if errcode == nil {
  3200. err := service.UpdatedRemindPrint(&setting, id)
  3201. if err != nil {
  3202. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3203. return
  3204. }
  3205. this.ServeSuccessJSON(map[string]interface{}{
  3206. "setting": setting,
  3207. })
  3208. }
  3209. }
  3210. func (this *ScheduleApiController) GetRemindPrintList() {
  3211. adminUserInfo := this.GetAdminUserInfo()
  3212. orgId := adminUserInfo.CurrentOrgId
  3213. list, err := service.GetRemindPrintList(orgId)
  3214. if err != nil {
  3215. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3216. return
  3217. }
  3218. this.ServeSuccessJSON(map[string]interface{}{
  3219. "list": list,
  3220. })
  3221. }
  3222. func (this *ScheduleApiController) GetBloodScheduleList() {
  3223. week_type, _ := this.GetInt64("week_type", -1)
  3224. week_time, _ := this.GetInt64("week_time")
  3225. zones := this.GetString("zone")
  3226. zone := strings.Split(zones, ",")
  3227. thisTime := time.Now()
  3228. weekDay := int(thisTime.Weekday())
  3229. if weekDay == 0 {
  3230. weekDay = 7
  3231. }
  3232. weekEnd := 7 - weekDay
  3233. weekStart := weekEnd - 6
  3234. weekTitle := make([]string, 0)
  3235. days := make([]string, 0)
  3236. for index := weekStart; index <= weekEnd; index++ {
  3237. theDay := thisTime.AddDate(0, 0, index)
  3238. indexYear, indexMonthTime, indexDay := theDay.Date()
  3239. indexMonth := int(indexMonthTime)
  3240. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  3241. weekTitle = append(weekTitle, indexWeek)
  3242. days = append(days, theDay.Format("2006-01-02"))
  3243. }
  3244. fmt.Println(days)
  3245. var targetDayStr string
  3246. var startTime string
  3247. switch week_type {
  3248. case 0:
  3249. startTime = days[0]
  3250. targetDayStr = days[6]
  3251. break
  3252. case 1:
  3253. targetDayStr = days[0]
  3254. break
  3255. case 2:
  3256. targetDayStr = days[1]
  3257. break
  3258. case 3:
  3259. targetDayStr = days[2]
  3260. break
  3261. case 4:
  3262. targetDayStr = days[3]
  3263. break
  3264. case 5:
  3265. targetDayStr = days[4]
  3266. break
  3267. case 6:
  3268. targetDayStr = days[5]
  3269. break
  3270. case 7:
  3271. targetDayStr = days[6]
  3272. break
  3273. }
  3274. targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  3275. if parseErr != nil {
  3276. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3277. return
  3278. }
  3279. orgId := this.GetAdminUserInfo().CurrentOrgId
  3280. if week_type > 0 {
  3281. list, err := service.GetWeekDayScheduleByIdThee(orgId, targetDay.Unix(), week_time, zone)
  3282. for _, item := range list {
  3283. order, _ := service.GetLastDialysisOrder(orgId, item.PatientId, targetDay.Unix())
  3284. item.XtDialysisOrderSix = order
  3285. if orgId == 9671 || orgId == 9675 || orgId == 10340 {
  3286. solution, _ := service.GetLastDialysisSolution(orgId, item.PatientId, item.ModeId, item.ScheduleDate)
  3287. item.DialysisPrescription = solution
  3288. }
  3289. }
  3290. if err != nil {
  3291. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3292. return
  3293. }
  3294. this.ServeSuccessJSON(map[string]interface{}{
  3295. "list": list,
  3296. "day": targetDayStr,
  3297. })
  3298. }
  3299. if week_type == 0 {
  3300. startDate, _ := utils.ParseTimeStringToTime("2006-01-02", startTime)
  3301. list, err := service.GetWeekDayScheduleByIdTwo(orgId, targetDay.Unix(), week_time, startDate.Unix(), zone)
  3302. for _, item := range list {
  3303. order, _ := service.GetLastDialysisOrder(orgId, item.PatientId, targetDay.Unix())
  3304. item.XtDialysisOrderSix = order
  3305. if orgId == 9671 || orgId == 9675 || orgId == 10340 {
  3306. solution, _ := service.GetLastDialysisSolution(orgId, item.PatientId, item.ModeId, item.ScheduleDate)
  3307. item.DialysisPrescription = solution
  3308. }
  3309. }
  3310. if err != nil {
  3311. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3312. return
  3313. }
  3314. this.ServeSuccessJSON(map[string]interface{}{
  3315. "list": list,
  3316. "day": targetDayStr,
  3317. })
  3318. }
  3319. }
  3320. func (this *ScheduleApiController) GetPrintList() {
  3321. adminUserInfo := this.GetAdminUserInfo()
  3322. orgId := adminUserInfo.CurrentOrgId
  3323. list, err := service.GetRemindPrintList(orgId)
  3324. if err != nil {
  3325. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3326. return
  3327. }
  3328. this.ServeSuccessJSON(map[string]interface{}{
  3329. "list": list,
  3330. })
  3331. }
  3332. func (this *ScheduleApiController) GetAllZoneList() {
  3333. adminUserInfo := this.GetAdminUserInfo()
  3334. orgId := adminUserInfo.CurrentOrgId
  3335. zoneList, err := service.GetAllZoneOne(orgId)
  3336. if err != nil {
  3337. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3338. return
  3339. }
  3340. this.ServeSuccessJSON(map[string]interface{}{
  3341. "zoneList": zoneList,
  3342. })
  3343. }
  3344. func (this *ScheduleApiController) GetPatientScheduleCount() {
  3345. patitionIdStr := this.GetString("partition_id")
  3346. week, _ := this.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  3347. ids := strings.Split(patitionIdStr, ",")
  3348. adminUserInfo := this.GetAdminUserInfo()
  3349. orgId := adminUserInfo.CurrentOrgId
  3350. thisTime := time.Now()
  3351. weekDay := int(thisTime.Weekday())
  3352. if week < 1 || week > 4 {
  3353. week = 2
  3354. }
  3355. if week == 1 {
  3356. thisTime = thisTime.AddDate(0, 0, -7)
  3357. } else if week == 3 {
  3358. thisTime = thisTime.AddDate(0, 0, 7)
  3359. } else if week == 4 {
  3360. thisTime = thisTime.AddDate(0, 0, 14)
  3361. }
  3362. if weekDay == 0 {
  3363. weekDay = 7
  3364. }
  3365. weekEnd := 7 - weekDay
  3366. weekStart := weekEnd - 6
  3367. weekTitle := make([]string, 0)
  3368. days := make([]string, 0)
  3369. for index := weekStart; index <= weekEnd; index++ {
  3370. theDay := thisTime.AddDate(0, 0, index)
  3371. indexYear, indexMonthTime, indexDay := theDay.Date()
  3372. indexMonth := int(indexMonthTime)
  3373. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  3374. weekTitle = append(weekTitle, indexWeek)
  3375. days = append(days, theDay.Format("2006-01-02"))
  3376. }
  3377. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  3378. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  3379. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  3380. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  3381. timeLayout := "2006-01-02 15:04:05"
  3382. loc, _ := time.LoadLocation("Local")
  3383. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  3384. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  3385. weekStartPoint := theStarTime.Unix()
  3386. weekEndPoint := theEndTime.Unix()
  3387. list, err := service.GetPatientScheduleCount(orgId, weekStartPoint, weekEndPoint, ids)
  3388. _, total, _ := service.GetTotalBedNumber(orgId, ids)
  3389. if err != nil {
  3390. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3391. return
  3392. }
  3393. this.ServeSuccessJSON(map[string]interface{}{
  3394. "list": list,
  3395. "total": total,
  3396. })
  3397. }
  3398. func (c *ScheduleApiController) GetWeekPanelsOne() {
  3399. data, _ := c.GetInt64("data", 1)
  3400. patitionIdStr := c.GetString("patitionid")
  3401. ids := strings.Split(patitionIdStr, ",")
  3402. adminInfo := c.GetAdminUserInfo()
  3403. thisTime := time.Now()
  3404. year, monthTime, day := thisTime.Date()
  3405. month := int(monthTime)
  3406. _, theWeek := thisTime.ISOWeek()
  3407. weekDay := int(thisTime.Weekday())
  3408. if weekDay == 0 {
  3409. weekDay = 7
  3410. }
  3411. weekEnd := 7 - weekDay
  3412. weekStart := weekEnd - 6
  3413. weekDays := make([]string, 0)
  3414. for index := weekStart; index <= weekEnd; index++ {
  3415. theDay := thisTime.AddDate(0, 0, index)
  3416. indexYear, indexMonthTime, indexDay := theDay.Date()
  3417. indexMonth := int(indexMonthTime)
  3418. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  3419. weekDays = append(weekDays, indexWeek)
  3420. }
  3421. returnData := map[string]interface{}{
  3422. "year": year,
  3423. "month": month,
  3424. "day": day,
  3425. "theWeek": theWeek,
  3426. "weekDay": weekDay,
  3427. "weekDays": weekDays,
  3428. }
  3429. if data == 1 {
  3430. partitions, _ := service.GetSchedulePartitionPanelTwo(adminInfo.CurrentOrgId, ids)
  3431. returnData["partitions"] = partitions
  3432. }
  3433. c.ServeSuccessJSON(returnData)
  3434. return
  3435. }
  3436. func (c *ScheduleApiController) GetScheduleOne() {
  3437. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  3438. patitionIdStr := c.GetString("patitionid")
  3439. ids := strings.Split(patitionIdStr, ",")
  3440. fmt.Println("patitonStr", ids)
  3441. schedule_type, _ := c.GetInt64("schedule_type")
  3442. adminInfo := c.GetAdminUserInfo()
  3443. thisTime := time.Now()
  3444. today := thisTime.Format("2006-01-02")
  3445. if week < 1 || week > 4 {
  3446. week = 2
  3447. }
  3448. if week == 1 {
  3449. thisTime = thisTime.AddDate(0, 0, -7)
  3450. } else if week == 3 {
  3451. thisTime = thisTime.AddDate(0, 0, 7)
  3452. } else if week == 4 {
  3453. thisTime = thisTime.AddDate(0, 0, 14)
  3454. }
  3455. weekDay := int(thisTime.Weekday())
  3456. if weekDay == 0 {
  3457. weekDay = 7
  3458. }
  3459. weekEnd := 7 - weekDay
  3460. weekStart := weekEnd - 6
  3461. weekTitle := make([]string, 0)
  3462. days := make([]string, 0)
  3463. for index := weekStart; index <= weekEnd; index++ {
  3464. theDay := thisTime.AddDate(0, 0, index)
  3465. indexYear, indexMonthTime, indexDay := theDay.Date()
  3466. indexMonth := int(indexMonthTime)
  3467. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  3468. weekTitle = append(weekTitle, indexWeek)
  3469. days = append(days, theDay.Format("2006-01-02"))
  3470. }
  3471. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  3472. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  3473. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  3474. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  3475. timeLayout := "2006-01-02 15:04:05"
  3476. loc, _ := time.LoadLocation("Local")
  3477. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  3478. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  3479. weekStartPoint := theStarTime.Unix()
  3480. weekEndPoint := theEndTime.Unix()
  3481. schdules, _ := service.GetWeekScheduleTwo(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type)
  3482. c.ServeSuccessJSON(map[string]interface{}{
  3483. "days": days,
  3484. "weekTitle": weekTitle,
  3485. "schdules": schdules,
  3486. "today": today,
  3487. })
  3488. return
  3489. }
  3490. func (c *ScheduleApiController) GetScheduleTwo() {
  3491. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  3492. patitionIdStr := c.GetString("patitionid")
  3493. ids := strings.Split(patitionIdStr, ",")
  3494. schedule_type, _ := c.GetInt64("schedule_type")
  3495. adminInfo := c.GetAdminUserInfo()
  3496. weekDateStr := c.GetString("week_date")
  3497. WeekDayIds := strings.Split(weekDateStr, ",")
  3498. thisTime := time.Now()
  3499. today := thisTime.Format("2006-01-02")
  3500. if week < 1 || week > 4 {
  3501. week = 2
  3502. }
  3503. if week == 1 {
  3504. thisTime = thisTime.AddDate(0, 0, -7)
  3505. } else if week == 3 {
  3506. thisTime = thisTime.AddDate(0, 0, 7)
  3507. } else if week == 4 {
  3508. thisTime = thisTime.AddDate(0, 0, 14)
  3509. }
  3510. weekDay := int(thisTime.Weekday())
  3511. if weekDay == 0 {
  3512. weekDay = 7
  3513. }
  3514. weekEnd := 7 - weekDay
  3515. weekStart := weekEnd - 6
  3516. weekTitle := make([]string, 0)
  3517. days := make([]string, 0)
  3518. for index := weekStart; index <= weekEnd; index++ {
  3519. theDay := thisTime.AddDate(0, 0, index)
  3520. indexYear, indexMonthTime, indexDay := theDay.Date()
  3521. indexMonth := int(indexMonthTime)
  3522. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  3523. weekTitle = append(weekTitle, indexWeek)
  3524. days = append(days, theDay.Format("2006-01-02"))
  3525. }
  3526. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  3527. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  3528. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  3529. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  3530. timeLayout := "2006-01-02 15:04:05"
  3531. loc, _ := time.LoadLocation("Local")
  3532. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  3533. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  3534. weekStartPoint := theStarTime.Unix()
  3535. weekEndPoint := theEndTime.Unix()
  3536. schdules, _ := service.GetWeekScheduleThree(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type, WeekDayIds)
  3537. c.ServeSuccessJSON(map[string]interface{}{
  3538. "days": days,
  3539. "weekTitle": weekTitle,
  3540. "schdules": schdules,
  3541. "today": today,
  3542. })
  3543. return
  3544. }
  3545. func (c *ScheduleApiController) SaveScheduleTemplate() {
  3546. template_id, _ := c.GetInt64("template_id")
  3547. orgId := c.GetAdminUserInfo().CurrentOrgId
  3548. template := models.ScheduleTemplate{
  3549. TemplateId: template_id,
  3550. UserOrgId: orgId,
  3551. Status: 1,
  3552. Ctime: time.Now().Unix(),
  3553. }
  3554. _, errcodes := service.GetScheudleTemplateById(orgId)
  3555. if errcodes == gorm.ErrRecordNotFound {
  3556. service.CreateXtscheduleTemplate(&template)
  3557. } else if errcodes == nil {
  3558. service.UpdateXtScheduleTemplate(&template, orgId)
  3559. }
  3560. c.ServeSuccessJSON(map[string]interface{}{
  3561. "template": template,
  3562. })
  3563. return
  3564. }
  3565. func (c *ScheduleApiController) GetScheduleTemplate() {
  3566. adminUserInfo := c.GetAdminUserInfo()
  3567. orgId := adminUserInfo.CurrentOrgId
  3568. template, _ := service.GetScheduleTemplate(orgId)
  3569. c.ServeSuccessJSON(map[string]interface{}{
  3570. "template": template,
  3571. })
  3572. return
  3573. }
  3574. func (c *ScheduleApiController) ChangeFuncPrint() {
  3575. adminUserInfo := c.GetAdminUserInfo()
  3576. orgId := adminUserInfo.CurrentOrgId
  3577. is_open, _ := c.GetInt64("is_open")
  3578. dataPrint := models.XtDataPrint{
  3579. UserOrgId: orgId,
  3580. IsOpen: is_open,
  3581. Status: 1,
  3582. Ctime: time.Now().Unix(),
  3583. }
  3584. _, errcode := service.GetDataPrintByOrgId(orgId)
  3585. if errcode == gorm.ErrRecordNotFound {
  3586. service.CreateDataPrint(&dataPrint)
  3587. c.ServeSuccessJSON(map[string]interface{}{
  3588. "dataPrint": dataPrint,
  3589. })
  3590. return
  3591. } else if errcode == nil {
  3592. service.UpdteDataPrint(orgId, &dataPrint)
  3593. c.ServeSuccessJSON(map[string]interface{}{
  3594. "dataPrint": dataPrint,
  3595. })
  3596. return
  3597. }
  3598. }
  3599. func (c *ScheduleApiController) GetDataPrint() {
  3600. adminUserInfo := c.GetAdminUserInfo()
  3601. orgId := adminUserInfo.CurrentOrgId
  3602. dataPrint, _ := service.GetDataPrint(orgId)
  3603. c.ServeSuccessJSON(map[string]interface{}{
  3604. "dataPrint": dataPrint,
  3605. })
  3606. return
  3607. }
  3608. func (c *ScheduleApiController) GetNextWeekPanels() {
  3609. start_time, _ := c.GetInt64("start_time")
  3610. fmt.Println("start_time", start_time)
  3611. end_time, _ := c.GetInt64("end_time")
  3612. fmt.Println("end_time", end_time)
  3613. orgId := c.GetAdminUserInfo().CurrentOrgId
  3614. schedule, _ := service.GetNextWeekPanels(start_time, end_time, orgId)
  3615. c.ServeSuccessJSON(map[string]interface{}{
  3616. "schedule": schedule,
  3617. })
  3618. }
  3619. func (c *ScheduleApiController) SynchroSchedule() {
  3620. template_id, _ := c.GetInt64("template_id")
  3621. copy_startime, _ := c.GetInt64("copy_startime")
  3622. copy_endtime, _ := c.GetInt64("copy_endtime")
  3623. orgId := c.GetAdminUserInfo().CurrentOrgId
  3624. //根据模板ID获取模板数据
  3625. list, _ := service.GetTemplateListByTemplateId(template_id, orgId)
  3626. recordDateStr := time.Now().Format("2006-01-02")
  3627. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3628. nowtime := recordDate.Unix()
  3629. fmt.Println("今日时间", nowtime)
  3630. fmt.Println("后期日期", copy_startime)
  3631. var tuesday int64
  3632. var wednesday int64
  3633. var thursday int64
  3634. var friday int64
  3635. var saturday int64
  3636. //如果选择的开始日期大于当前日期
  3637. if copy_startime > nowtime {
  3638. //清空该时间段的所有排班数据
  3639. service.DeletePatientSchedule(copy_startime, copy_endtime, orgId)
  3640. tuesday = copy_startime + 86400
  3641. wednesday = copy_startime + 172800
  3642. thursday = copy_startime + 259200
  3643. friday = copy_startime + 345600
  3644. saturday = copy_startime + 432000
  3645. for _, item := range list {
  3646. if item.Weekday == 1 {
  3647. item.ScheduleDate = copy_startime
  3648. }
  3649. if item.Weekday == 2 {
  3650. item.ScheduleDate = tuesday
  3651. }
  3652. if item.Weekday == 3 {
  3653. item.ScheduleDate = wednesday
  3654. }
  3655. if item.Weekday == 4 {
  3656. item.ScheduleDate = thursday
  3657. }
  3658. if item.Weekday == 5 {
  3659. item.ScheduleDate = friday
  3660. }
  3661. if item.Weekday == 6 {
  3662. item.ScheduleDate = saturday
  3663. }
  3664. if item.Weekday == 7 {
  3665. item.ScheduleDate = copy_endtime
  3666. }
  3667. //根据床位号获取区号
  3668. number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
  3669. item.ZoneId = number.ZoneID
  3670. }
  3671. for _, item := range list {
  3672. schedule := models.XtSchedule{
  3673. UserOrgId: orgId,
  3674. PartitionId: item.ZoneId,
  3675. BedId: item.DeviceNumberID,
  3676. PatientId: item.PatientID,
  3677. ScheduleDate: item.ScheduleDate,
  3678. ScheduleType: item.TimeType,
  3679. ScheduleWeek: item.Weekday,
  3680. ModeId: item.TreatMode,
  3681. Status: 1,
  3682. CreatedTime: time.Now().Unix(),
  3683. UpdatedTime: 0,
  3684. }
  3685. var DialysisMachineName string
  3686. so, _ := service.GetDialysisSolutionTwo(c.GetAdminUserInfo().CurrentOrgId, schedule.PatientId, schedule.ModeId)
  3687. filedRecordOne, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器")
  3688. filedRecordTwo, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "灌流器")
  3689. filedRecordThree, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器/灌流器")
  3690. if filedRecordOne.IsShow == 1 {
  3691. DialysisMachineName = so.DialysisDialyszers
  3692. }
  3693. if filedRecordThree.IsShow == 1 {
  3694. if len(DialysisMachineName) > 0 {
  3695. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  3696. } else {
  3697. DialysisMachineName = so.DialyzerPerfusionApparatus
  3698. }
  3699. }
  3700. if filedRecordTwo.IsShow == 1 {
  3701. if len(DialysisMachineName) > 0 {
  3702. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  3703. } else {
  3704. DialysisMachineName = so.DialysisIrrigation
  3705. }
  3706. }
  3707. schedule.DialysisMachineName = DialysisMachineName
  3708. service.CreatePatientSchedule(&schedule)
  3709. }
  3710. }
  3711. //如果选择的日期小于当前日期,只同步今日以后的数据
  3712. if copy_startime <= nowtime {
  3713. //清空今日以后的数据
  3714. service.DeletePatientScheduleToday(nowtime, copy_endtime, orgId)
  3715. var tuesday int64
  3716. var wednesday int64
  3717. var thursday int64
  3718. var friday int64
  3719. var saturday int64
  3720. tuesday = copy_startime + 86400
  3721. wednesday = copy_startime + 172800
  3722. thursday = copy_startime + 259200
  3723. friday = copy_startime + 345600
  3724. saturday = copy_startime + 432000
  3725. for _, item := range list {
  3726. if item.Weekday == 1 {
  3727. item.ScheduleDate = copy_startime
  3728. }
  3729. if item.Weekday == 2 {
  3730. item.ScheduleDate = tuesday
  3731. }
  3732. if item.Weekday == 3 {
  3733. item.ScheduleDate = wednesday
  3734. }
  3735. if item.Weekday == 4 {
  3736. item.ScheduleDate = thursday
  3737. }
  3738. if item.Weekday == 5 {
  3739. item.ScheduleDate = friday
  3740. }
  3741. if item.Weekday == 6 {
  3742. item.ScheduleDate = saturday
  3743. }
  3744. if item.Weekday == 7 {
  3745. item.ScheduleDate = copy_endtime
  3746. }
  3747. //根据床位号获取区号
  3748. number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
  3749. item.ZoneId = number.ZoneID
  3750. }
  3751. for _, item := range list {
  3752. // 同步今日以后的数据
  3753. if item.ScheduleDate > nowtime {
  3754. schedule := models.XtSchedule{
  3755. UserOrgId: orgId,
  3756. PartitionId: item.ZoneId,
  3757. BedId: item.DeviceNumberID,
  3758. PatientId: item.PatientID,
  3759. ScheduleDate: item.ScheduleDate,
  3760. ScheduleType: item.TimeType,
  3761. ScheduleWeek: item.Weekday,
  3762. ModeId: item.TreatMode,
  3763. Status: 1,
  3764. CreatedTime: time.Now().Unix(),
  3765. UpdatedTime: 0,
  3766. }
  3767. var DialysisMachineName string
  3768. so, _ := service.GetDialysisSolutionTwo(c.GetAdminUserInfo().CurrentOrgId, schedule.PatientId, schedule.ModeId)
  3769. filedRecordOne, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器")
  3770. filedRecordTwo, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "灌流器")
  3771. filedRecordThree, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器/灌流器")
  3772. if filedRecordOne.IsShow == 1 {
  3773. DialysisMachineName = so.DialysisDialyszers
  3774. }
  3775. if filedRecordThree.IsShow == 1 {
  3776. if len(DialysisMachineName) > 0 {
  3777. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  3778. } else {
  3779. DialysisMachineName = so.DialyzerPerfusionApparatus
  3780. }
  3781. }
  3782. if filedRecordTwo.IsShow == 1 {
  3783. if len(schedule.DialysisMachineName) > 0 {
  3784. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  3785. } else {
  3786. DialysisMachineName = so.DialysisIrrigation
  3787. }
  3788. }
  3789. schedule.DialysisMachineName = DialysisMachineName
  3790. service.CreatePatientSchedule(&schedule)
  3791. }
  3792. }
  3793. }
  3794. returnData := make(map[string]interface{}, 0)
  3795. returnData["list"] = list
  3796. c.ServeSuccessJSON(returnData)
  3797. return
  3798. }
  3799. func (c *ScheduleApiController) GetPatientScheduleTempalate() {
  3800. orgId := c.GetAdminUserInfo().CurrentOrgId
  3801. tempalate, _ := service.GetPatientScheduleTempalate(orgId)
  3802. c.ServeSuccessJSON(map[string]interface{}{
  3803. "schedule": tempalate,
  3804. })
  3805. }
  3806. func (c *ScheduleApiController) GetSolutionSchedule() {
  3807. orgId := c.GetAdminUserInfo().CurrentOrgId
  3808. solution, _ := service.GetSolutionSchedule(orgId)
  3809. c.ServeSuccessJSON(map[string]interface{}{
  3810. "solution": solution,
  3811. })
  3812. return
  3813. }