schedule_api_controller.go 156KB

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