schedule_api_controller.go 166KB

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