schedule_api_controller.go 164KB

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