schedule_api_controller.go 136KB

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