1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591 |
- package controllers
-
- import (
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "encoding/json"
- "fmt"
- "github.com/jinzhu/gorm"
- "reflect"
- "strconv"
- "strings"
- "time"
-
- "github.com/astaxie/beego"
- )
-
- type ScheduleApiController struct {
- BaseAuthAPIController
- }
-
- func ScheduleApiRegistRouters() {
- beego.Router("/api/schedule/weekpanel", &ScheduleApiController{}, "Get:GetWeekPanels")
-
- beego.Router("/api/schedule/schedules", &ScheduleApiController{}, "Get:GetSchedules")
- beego.Router("/api/excel_date/init", &ScheduleApiController{}, "Get:GetInitExcelInitDate")
-
- beego.Router("/api/schedule/patients", &ScheduleApiController{}, "Get:GetPatients")
- beego.Router("/api/schedule/create", &ScheduleApiController{}, "Post:CreateSchedule")
- beego.Router("/api/schedule/delete", &ScheduleApiController{}, "Delete:DeleteSchedule")
- beego.Router("/api/schedule/change", &ScheduleApiController{}, "Put:ChangeSchedule")
- beego.Router("/api/schedule/urgentinit", &ScheduleApiController{}, "Get:UrgentScheduleData")
- beego.Router("/api/schedule/print/initdata", &ScheduleApiController{}, "get:PrintInitData")
- beego.Router("/api/schedule/search", &ScheduleApiController{}, "get:SearchSchedulePatients")
- beego.Router("/api/schedule/week", &ScheduleApiController{}, "get:GetWeekDaySchedule")
- beego.Router("/api/schedule/export", &ScheduleApiController{}, "post:ExportSchedule")
- beego.Router("/api/schedule_template/export", &ScheduleApiController{}, "post:ExportScheduleTemplate")
- beego.Router("/api/schedule_template/search", &ScheduleApiController{}, "get:SearchTemplateSchedulePatients")
- beego.Router("/api/schedule_template/cancel", &ScheduleApiController{}, "post:CancelScheduleTemplate")
- beego.Router("/api/schedule/getnextscheduleweekday", &ScheduleApiController{}, "Get:GetNextWeekDaySchedule")
- beego.Router("/api/schedule/getnextscheduleweekdayone", &ScheduleApiController{}, "Get:GetNextWeekDayScheduleOne")
-
- beego.Router("/api/schedule/getthreeweeklist", &ScheduleApiController{}, "Get:GetThreeWeekList")
-
- beego.Router("/api/schedule/getallzones", &ScheduleApiController{}, "Get:GetAllZones")
-
- beego.Router("/api/schedule/copypatientschedules", &ScheduleApiController{}, "Get:GetCopyPatientSchedules")
-
- beego.Router("/api/schedule/saveremindprint", &ScheduleApiController{}, "Get:SaveRemindPrint")
-
- beego.Router("/api/schedule/getremindprintlist", &ScheduleApiController{}, "Get:GetRemindPrintList")
-
- beego.Router("/api/schedule/getbloodschedulelist", &ScheduleApiController{}, "Get:GetBloodScheduleList")
-
- beego.Router("/api/schedule/getprintlist", &ScheduleApiController{}, "Get:GetPrintList")
-
- beego.Router("/api/schedule/getallzonelist", &ScheduleApiController{}, "Get:GetAllZoneList")
-
- beego.Router("/api/schedule/getpatientschedulecount", &ScheduleApiController{}, "Get:GetPatientScheduleCount")
-
- beego.Router("/api/schedule/weekpanelone", &ScheduleApiController{}, "Get:GetWeekPanelsOne")
- beego.Router("/api/schedule/schedulesone", &ScheduleApiController{}, "Get:GetScheduleOne")
- beego.Router("/api/schedule/scheduletwo", &ScheduleApiController{}, "Get:GetScheduleTwo")
- beego.Router("/api/schedule/postscheduletemplate", &ScheduleApiController{}, "Get:SaveScheduleTemplate")
- beego.Router("/api/schedule/getscheduletemplate", &ScheduleApiController{}, "Get:GetScheduleTemplate")
- beego.Router("/api/order/changefuncprint", &ScheduleApiController{}, "Get:ChangeFuncPrint")
- beego.Router("/api/order/getdataprint", &ScheduleApiController{}, "Get:GetDataPrint")
- beego.Router("/api/schedule/getnextweekpanels", &ScheduleApiController{}, "Get:GetNextWeekPanels")
- beego.Router("/api/schedule/synchroschedule", &ScheduleApiController{}, "Get:SynchroSchedule")
- beego.Router("/api/schedule/getpatientscheduletemplate", &ScheduleApiController{}, "Get:GetPatientScheduleTempalate")
- beego.Router("/api/schedule/getsolutionschedule", &ScheduleApiController{}, "Get:GetSolutionSchedule")
-
- beego.Router("/api/schedule/smartpatientsch", &ScheduleApiController{}, "Get:GetPatient")
- beego.Router("/api/schedule/smartpatientschtemplate", &ScheduleApiController{}, "Get:GetPatientSchTemplate")
-
- beego.Router("/api/patient/smartpatientsch", &ScheduleApiController{}, "Get:GetPatientSmartSch")
-
- beego.Router("/api/patient/smartpatientschtemplate", &ScheduleApiController{}, "Get:GetPatientSmartSchTemplate")
-
- beego.Router("/api/device/get", &ScheduleApiController{}, "Get:GetDevicesNumbers")
-
- beego.Router("/api/smartsch/batch", &ScheduleApiController{}, "Post:BatchPostSmartSch")
-
- beego.Router("/api/smartsch/get", &ScheduleApiController{}, "Get:GetSmartSch")
-
- beego.Router("/api/sch/exchange", &ScheduleApiController{}, "Get:ExchangeSch")
- beego.Router("/api/sch/coversch", &ScheduleApiController{}, "Get:CoverSch")
- beego.Router("/api/schedule/delete_two", &ScheduleApiController{}, "Delete:DeleteScheduleTwo")
-
- }
- func (c *ScheduleApiController) CoverSch() {
- id_one, _ := c.GetInt64("id_one")
- id_two, _ := c.GetInt64("id_two")
- sch, _ := service.GetScheduleTen(c.GetAdminUserInfo().CurrentOrgId, id_one)
- sch_two, _ := service.GetScheduleTen(c.GetAdminUserInfo().CurrentOrgId, id_two)
- order, _ := service.GetDialysisOrder(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
- if order.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
- return
- }
- order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
- if order2.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
- return
- }
- //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
- if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
- count, _ := service.GetScheduleCountByDate(c.GetAdminUserInfo().CurrentOrgId, sch_two.ScheduleDate, sch.PatientId)
- if count > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
- return
- }
- }
-
- var new_sch models.Schedule
- new_sch = sch
- new_sch.BedId = sch_two.BedId
- new_sch.ScheduleDate = sch_two.ScheduleDate
- new_sch.ScheduleWeek = sch_two.ScheduleWeek
- new_sch.PartitionId = sch_two.PartitionId
- new_sch.ScheduleType = sch_two.ScheduleType
- new_sch.ID = 0
- //删除原来的排班
- service.SaveSchTwo(sch, sch_two)
- //生成新的排班
- service.SaveSch(new_sch)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "覆盖成功",
- })
-
- }
- func (c *ScheduleApiController) ExchangeSch() {
- id_one, _ := c.GetInt64("id_one")
- id_two, _ := c.GetInt64("id_two")
- sch, _ := service.GetSchedule(c.GetAdminUserInfo().CurrentOrgId, id_one)
- sch_two, _ := service.GetSchedule(c.GetAdminUserInfo().CurrentOrgId, id_two)
- order, _ := service.GetDialysisOrder(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
- if order.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
- return
- }
- order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
- if order2.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
- return
- }
-
- //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
- if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
- count, _ := service.GetScheduleCountByDate(c.GetAdminUserInfo().CurrentOrgId, sch_two.ScheduleDate, sch.PatientId)
- if count > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
- return
- }
-
- count1, _ := service.GetScheduleCountByDate(c.GetAdminUserInfo().CurrentOrgId, sch.ScheduleDate, sch_two.PatientId)
- if count1 > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
- return
- }
- }
-
- service.UpdateScheduleThree(sch, sch_two)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "交换成功",
- })
- }
- func (c *ScheduleApiController) BatchPostSmartSch() {
- patient_id, _ := c.GetInt64("patient_id")
- adminInfo := c.GetAdminUserInfo()
-
- patientInfo, _ := service.FindPatientById(adminInfo.CurrentOrgId, patient_id)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- //数据校验
- if dataBody["smart_schs"] != nil && reflect.TypeOf(dataBody["smart_schs"]).String() == "[]interface {}" {
-
- schs, _ := dataBody["smart_schs"].([]interface{})
- if len(schs) > 0 {
- for _, item := range schs {
- items := item.(map[string]interface{})
- if items["sch_id"] == nil || reflect.TypeOf(items["sch_id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- var schedule models.Schedule
- //var oldSchedule *models.Schedule
- sch_id := int64(items["sch_id"].(float64))
- if sch_id > 0 { //修改排班信息
- schedule, _ = service.GetScheduleTwo(adminInfo.CurrentOrgId, sch_id)
- fmt.Println("2222222")
-
- if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
- utils.ErrorLog("mode_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- modeId := int64(items["mode_id"].(float64))
- if modeId < 1 {
- utils.ErrorLog("modeId < 1")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.ModeId = modeId
-
- order, err := service.GetOneDialysisOrder(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- if order != nil {
- week_type, _ := items["week_type"].(string)
- week_name, _ := items["week_name"].(string)
-
- switch week_type {
- case "1":
- json := make(map[string]interface{})
- json["msg"] = "本周" + week_name + "的床位已经有人上机,无法保存"
- json["state"] = 0
- c.Data["json"] = json
- c.ServeJSON()
- break
- case "2":
- json := make(map[string]interface{})
- json["msg"] = "下周" + week_name + "的床位已经有人上机,无法保存"
- json["state"] = 0
- c.Data["json"] = json
- c.ServeJSON()
- break
- case "3":
- json := make(map[string]interface{})
- json["msg"] = "下周" + week_name + "的床位已经有人上机,无法保存"
- json["state"] = 0
- c.Data["json"] = json
- c.ServeJSON()
- break
-
- }
-
- return
- }
-
- if order != nil {
- week_type, _ := items["week_type"].(string)
- week_name, _ := items["week_name"].(string)
-
- switch week_type {
- case "1":
- json := make(map[string]interface{})
- json["msg"] = "本周" + week_name + "的床位已经有人上机,无法保存"
- json["state"] = 0
- c.Data["json"] = json
- c.ServeJSON()
- break
- case "2":
- json := make(map[string]interface{})
- json["msg"] = "下周" + week_name + "的床位已经有人上机,无法保存"
- json["state"] = 0
- c.Data["json"] = json
- c.ServeJSON()
- break
- case "3":
- json := make(map[string]interface{})
- json["msg"] = "下周" + week_name + "的床位已经有人上机,无法保存"
- json["state"] = 0
- c.Data["json"] = json
- c.ServeJSON()
- break
- }
- return
- }
-
- if items["schedule_type"] == nil || reflect.TypeOf(items["schedule_type"]).String() != "float64" {
- utils.ErrorLog("schedule_type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- scheduleType := int64(items["schedule_type"].(float64))
- if scheduleType < 1 || scheduleType > 3 {
- utils.ErrorLog("scheduleType < 3")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.ScheduleType = scheduleType
-
- if items["bed_id"] == nil || reflect.TypeOf(items["bed_id"]).String() != "float64" {
- utils.ErrorLog("bed_id")
- fmt.Println("~~~~~~333333333")
-
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- bedId := int64(items["bed_id"].(float64))
- if bedId < 1 {
- utils.ErrorLog("bedId < 1")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.BedId = bedId
-
- if items["zone_id"] == nil || reflect.TypeOf(items["zone_id"]).String() != "float64" {
- utils.ErrorLog("zone_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- partitionId := int64(items["zone_id"].(float64))
- if partitionId < 1 {
- utils.ErrorLog("partitionId < 1")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.PartitionId = partitionId
-
- bed, _ := service.GetDeviceNumberByID(adminInfo.CurrentOrgId, schedule.BedId)
- if bed == nil {
-
- week_type, _ := items["week_type"].(string)
- week_name, _ := items["week_name"].(string)
-
- switch week_type {
- case "1":
- json := make(map[string]interface{})
- json["msg"] = "本周" + week_name + "的机号不存在,无法保存"
- json["state"] = 0
- c.Data["json"] = json
- c.ServeJSON()
- break
- case "2":
- json := make(map[string]interface{})
- json["msg"] = "下周" + week_name + "的机号不存在,无法保存"
- json["state"] = 0
- c.Data["json"] = json
- c.ServeJSON()
- break
- case "3":
- json := make(map[string]interface{})
- json["msg"] = "下周" + week_name + "的机号不存在,无法保存"
- json["state"] = 0
- c.Data["json"] = json
- c.ServeJSON()
- break
- }
-
- return
- }
- if bed.ZoneID != schedule.PartitionId {
-
- week_type, _ := items["week_type"].(string)
- week_name, _ := items["week_name"].(string)
-
- switch week_type {
- case "1":
- json := make(map[string]interface{})
- json["msg"] = "本周" + week_name + "所选机号不在选择分区中,无法保存"
- json["state"] = 0
- c.Data["json"] = json
- c.ServeJSON()
- break
- case "2":
- json := make(map[string]interface{})
- json["msg"] = "下周" + week_name + "所选机号不在选择分区中,无法保存"
- json["state"] = 0
- c.Data["json"] = json
- c.ServeJSON()
- break
- case "3":
- json := make(map[string]interface{})
- json["msg"] = "下周" + week_name + "所选机号不在选择分区中,无法保存"
- json["state"] = 0
- c.Data["json"] = json
- c.ServeJSON()
- break
- }
-
- return
- }
-
- startTime := schedule.ScheduleDate
- endTime := startTime + 86399
-
- //一天只有排班一次
- daySchedule, err := service.GetDaySchedule(adminInfo.CurrentOrgId, startTime, endTime, schedule.PatientId)
- if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
- week_type, _ := items["week_type"].(string)
- week_name, _ := items["week_name"].(string)
-
- switch week_type {
- case "1":
- json := make(map[string]interface{})
- json["msg"] = "本周" + week_name + "已有排班,同一天不可有两次排班,无法保存"
- json["state"] = 0
- c.Data["json"] = json
- c.ServeJSON()
- break
- case "2":
- json := make(map[string]interface{})
- json["msg"] = "下周" + week_name + "已有排班,同一天不可有两次排班,无法保存"
- json["state"] = 0
- c.Data["json"] = json
- c.ServeJSON()
- break
- case "3":
- json := make(map[string]interface{})
- json["msg"] = "下下周" + week_name + "已有排班,同一天不可有两次排班,无法保存"
- json["state"] = 0
- c.Data["json"] = json
- c.ServeJSON()
- break
- }
-
- return
- }
-
- //同天同位置只能排一个
- pointSchedule, err := service.GetPointSchedule(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- if pointSchedule.ID > 0 && pointSchedule.PatientId != patient_id {
- week_type, _ := items["week_type"].(string)
- week_name, _ := items["week_name"].(string)
-
- switch week_type {
- case "1":
- json := make(map[string]interface{})
- json["msg"] = "本周" + week_name + "所先位置排班已经存在,无法保存"
- json["state"] = 0
- c.Data["json"] = json
- c.ServeJSON()
- break
- case "2":
- json := make(map[string]interface{})
- json["msg"] = "下周" + week_name + "所先位置排班已经存在,无法保存"
- json["state"] = 0
- c.Data["json"] = json
- c.ServeJSON()
- break
- case "3":
- json := make(map[string]interface{})
- json["msg"] = "下下周" + week_name + "所先位置排班已经存在,无法保存"
- json["state"] = 0
- c.Data["json"] = json
- c.ServeJSON()
- break
- }
-
- return
- }
-
- } else { //新的排班信息
-
- fmt.Println("111111111")
- if items["schedule_date"] == nil || reflect.TypeOf(items["schedule_date"]).String() != "string" {
- fmt.Println("33333333")
-
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- scheduleDate, _ := items["schedule_date"].(string)
- if len(scheduleDate) == 0 {
- utils.ErrorLog("len(schedule_date) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.ScheduleDate = theTime.Unix()
- //existSch,_ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId,schedule.ScheduleDate,patient_id)
- //
- //if existSch.ID > 0{
- // fmt.Println("555555555")
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- //
- //}
-
- timeNow := time.Now().Format("2006-01-02")
- if timeNow > scheduleDate {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
- return
- }
- scheduleType := int64(items["schedule_type"].(float64))
- if scheduleType < 1 || scheduleType > 3 {
- utils.ErrorLog("scheduleType < 3")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.ScheduleType = scheduleType
-
- if items["bed_id"] == nil || reflect.TypeOf(items["bed_id"]).String() != "float64" {
- fmt.Println("~~~~~~22222")
- utils.ErrorLog("bed_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- bedId := int64(items["bed_id"].(float64))
- if bedId < 1 {
- utils.ErrorLog("bedId < 1")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.BedId = bedId
-
- if items["zone_id"] == nil || reflect.TypeOf(items["zone_id"]).String() != "float64" {
- utils.ErrorLog("zone_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- partitionId := int64(items["zone_id"].(float64))
- if partitionId < 1 {
- utils.ErrorLog("zone_id < 1")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.PartitionId = partitionId
-
- if items["schedule_week"] == nil || reflect.TypeOf(items["schedule_week"]).String() != "float64" {
- utils.ErrorLog("schedule_week")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- scheduleWeek := int64(items["schedule_week"].(float64))
- if scheduleWeek < 1 || scheduleWeek > 7 {
- utils.ErrorLog("scheduleWeek < 1")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.ScheduleWeek = scheduleWeek
-
- if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
- utils.ErrorLog("mode_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- modeId := int64(items["mode_id"].(float64))
- if modeId < 1 && modeId > 14 {
- utils.ErrorLog("modeId < 1")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- //校验当天改床位是否有排班,如果有排班则不能替换排班
-
- sch, _ := service.GetScheduleByZoneAndBed(adminInfo.CurrentOrgId, partitionId, bedId, schedule.ScheduleDate, schedule.ScheduleType)
-
- fmt.Println(sch.PatientId)
- fmt.Println(schedule.PatientId)
-
- if sch.ID > 0 && sch.PatientId != patient_id {
- week_type, _ := items["week_type"].(string)
- week_name, _ := items["week_name"].(string)
-
- switch week_type {
- case "1":
- json := make(map[string]interface{})
- json["msg"] = "本周" + week_name + "该床位已经有人排班,无法保存"
- json["state"] = 0
- c.Data["json"] = json
- c.ServeJSON()
- break
- case "2":
- json := make(map[string]interface{})
- json["msg"] = "下周" + week_name + "该床位已经有人排班,无法保存"
- json["state"] = 0
- c.Data["json"] = json
- c.ServeJSON()
- break
- case "3":
- json := make(map[string]interface{})
- json["msg"] = "下下周" + week_name + "该床位已经有人排班,无法保存"
- json["state"] = 0
- c.Data["json"] = json
- c.ServeJSON()
- break
- }
-
- return
- }
-
- //daySchedule, err := service.GetDaySchedule(adminInfo.CurrentOrgId, theTime.Unix(), theTime.Unix(), patient_id)
- //if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
- // week_type, _ := items["week_type"].(string)
- // week_name, _ := items["week_name"].(string)
- //
- // switch week_type {
- // case "1":
- // json := make(map[string]interface{})
- // json["msg"] = "本周" + week_name + "该床位已经有人排班,无法保存"
- // json["state"] = 0
- // c.Data["json"] = json
- // c.ServeJSON()
- // break
- // case "2":
- // json := make(map[string]interface{})
- // json["msg"] = "下周" + week_name + "当天该患者已经排班,无法保存"
- // json["state"] = 0
- // c.Data["json"] = json
- // c.ServeJSON()
- // break
- // case "3":
- // json := make(map[string]interface{})
- // json["msg"] = "下下周" + week_name + "当天该患者已经排班,无法保存"
- // json["state"] = 0
- // c.Data["json"] = json
- // c.ServeJSON()
- // break
- // }
- //
- // return
- //
- //
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
- // return
- //}
- //
- }
-
- }
- }
- }
- ////删除数据
- if dataBody["del_schs"] != nil && reflect.TypeOf(dataBody["del_schs"]).String() == "[]interface {}" {
-
- schs, _ := dataBody["del_schs"].([]interface{})
- if len(schs) > 0 {
- for _, item := range schs {
- items := item.(map[string]interface{})
- if items["sch_id"] == nil || reflect.TypeOf(items["sch_id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- var schedule models.Schedule
- sch_id := int64(items["sch_id"].(float64))
- if sch_id > 0 { //修改排班信息
- schedule, _ = service.GetScheduleTwo(adminInfo.CurrentOrgId, sch_id)
-
- order, _ := service.GetDialysisOrderByPatientAndBed(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.BedId, schedule.PatientId)
- if order.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysis)
- return
- }
-
- schedule.Status = 0
- service.SaveSch(schedule)
- }
- HandleRedis(adminInfo.CurrentOrgId, schedule.ScheduleDate)
- }
- }
- }
- ////修改或保存数据
- if dataBody["smart_schs"] != nil && reflect.TypeOf(dataBody["smart_schs"]).String() == "[]interface {}" {
-
- schs, _ := dataBody["smart_schs"].([]interface{})
- if len(schs) > 0 {
- for _, item := range schs {
- items := item.(map[string]interface{})
- if items["sch_id"] == nil || reflect.TypeOf(items["sch_id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- var schedule models.Schedule
- //var oldSchedule *models.Schedule
- sch_id := int64(items["sch_id"].(float64))
- if sch_id > 0 { //修改排班信息
- fmt.Println("!!!!!!!")
- schedule, _ = service.GetScheduleTwo(adminInfo.CurrentOrgId, sch_id)
- if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
- fmt.Println(reflect.TypeOf(items["mode_id"]))
-
- utils.ErrorLog("mode_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- modeId := int64(items["mode_id"].(float64))
- if modeId < 1 {
- utils.ErrorLog("modeId < 1")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.ModeId = modeId
-
- order, err := service.GetOneDialysisOrder(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- if order != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeMode)
- return
- }
-
- if order != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeDeviceNumber)
- return
- }
-
- if items["schedule_type"] == nil || reflect.TypeOf(items["schedule_type"]).String() != "float64" {
- utils.ErrorLog("schedule_type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- scheduleType := int64(items["schedule_type"].(float64))
- if scheduleType < 1 || scheduleType > 3 {
- utils.ErrorLog("scheduleType < 3")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.ScheduleType = scheduleType
-
- if items["bed_id"] == nil || reflect.TypeOf(items["bed_id"]).String() != "float64" {
- utils.ErrorLog("bed_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- bedId := int64(items["bed_id"].(float64))
- if bedId < 1 {
- utils.ErrorLog("bedId < 1")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.BedId = bedId
-
- if items["zone_id"] == nil || reflect.TypeOf(items["zone_id"]).String() != "float64" {
- utils.ErrorLog("zone_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- partitionId := int64(items["zone_id"].(float64))
- if partitionId < 1 {
- utils.ErrorLog("partitionId < 1")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.PartitionId = partitionId
-
- bed, _ := service.GetDeviceNumberByID(adminInfo.CurrentOrgId, schedule.BedId)
- if bed == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
- return
- }
- if bed.ZoneID != schedule.PartitionId {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
- return
- }
-
- startTime := schedule.ScheduleDate
- endTime := startTime + 86399
-
- //一天只有排班一次
- daySchedule, err := service.GetDaySchedule(adminInfo.CurrentOrgId, startTime, endTime, schedule.PatientId)
- if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
- return
- }
-
- //同天同位置只能排一个
- pointSchedule, err := service.GetPointSchedule(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- if pointSchedule.ID > 0 && pointSchedule.PatientId != patient_id {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
- return
- }
- var DialysisMachineName string
- so, _ := service.GetDialysisSolutionTwo(adminInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
- filedRecordOne, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器")
- filedRecordTwo, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "灌流器")
- filedRecordThree, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器/灌流器")
-
- if filedRecordOne.IsShow == 1 {
- DialysisMachineName = so.DialysisDialyszers
- }
- if filedRecordThree.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
-
- } else {
- DialysisMachineName = so.DialyzerPerfusionApparatus
-
- }
- }
- if filedRecordTwo.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
-
- } else {
- DialysisMachineName = so.DialysisIrrigation
-
- }
- }
- schedule.DialysisMachineName = DialysisMachineName
- schedule.IsExport = 3000
- service.SaveSch(schedule)
- } else { //新的排班信息
-
- if items["schedule_date"] == nil || reflect.TypeOf(items["schedule_date"]).String() != "string" {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- scheduleDate, _ := items["schedule_date"].(string)
- if len(scheduleDate) == 0 {
- utils.ErrorLog("len(schedule_date) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.ScheduleDate = theTime.Unix()
-
- timeNow := time.Now().Format("2006-01-02")
- if timeNow > scheduleDate {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
- return
- }
- scheduleType := int64(items["schedule_type"].(float64))
- if scheduleType < 1 || scheduleType > 3 {
- utils.ErrorLog("scheduleType < 3")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.ScheduleType = scheduleType
-
- if items["bed_id"] == nil || reflect.TypeOf(items["bed_id"]).String() != "float64" {
- utils.ErrorLog("bed_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- bedId := int64(items["bed_id"].(float64))
- if bedId < 1 {
- utils.ErrorLog("bedId < 1")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.BedId = bedId
-
- if items["zone_id"] == nil || reflect.TypeOf(items["zone_id"]).String() != "float64" {
- utils.ErrorLog("zone_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- partitionId := int64(items["zone_id"].(float64))
- if partitionId < 1 {
- utils.ErrorLog("zone_id < 1")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.PartitionId = partitionId
-
- if items["schedule_week"] == nil || reflect.TypeOf(items["schedule_week"]).String() != "float64" {
- utils.ErrorLog("schedule_week")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- scheduleWeek := int64(items["schedule_week"].(float64))
- if scheduleWeek < 1 || scheduleWeek > 7 {
- utils.ErrorLog("scheduleWeek < 1")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.ScheduleWeek = scheduleWeek
-
- if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
- fmt.Println(reflect.TypeOf(items["mode_id"]))
-
- utils.ErrorLog("mode_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- modeId := int64(items["mode_id"].(float64))
- if modeId < 1 && modeId > 14 {
- utils.ErrorLog("modeId < 1")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- //校验当天改床位是否有排班,如果有排班则不能替换排班
-
- sch, _ := service.GetScheduleByZoneAndBed(adminInfo.CurrentOrgId, partitionId, bedId, schedule.ScheduleDate, schedule.ScheduleType)
-
- if sch.ID > 0 && sch.PatientId != patient_id {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorSchedualcRepeatBed)
- return
- }
- var DialysisMachineName string
-
- so, _ := service.GetDialysisSolutionTwo(adminInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
- filedRecordOne, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器")
- filedRecordTwo, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "灌流器")
- filedRecordThree, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器/灌流器")
-
- if filedRecordOne.IsShow == 1 {
- DialysisMachineName = so.DialysisDialyszers
- }
- if filedRecordThree.IsShow == 1 {
- if len(schedule.DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
-
- } else {
- DialysisMachineName = so.DialyzerPerfusionApparatus
-
- }
- }
- if filedRecordTwo.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
-
- } else {
- DialysisMachineName = so.DialysisIrrigation
-
- }
- }
- schedule.DialysisMachineName = DialysisMachineName
-
- //判断当前保存的患者是否已经有排班
- existSchedule, _ := service.GetScheduleByDate(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
- if existSchedule.ID > 0 {
- existSchedule.ModeId = modeId
- existSchedule.BedId = schedule.BedId
- existSchedule.PartitionId = schedule.PartitionId
- existSchedule.ScheduleType = schedule.ScheduleType
- existSchedule.DialysisMachineName = schedule.DialysisMachineName
- existSchedule.IsExport = 3001
- service.SaveSmartSch(existSchedule)
-
- } else {
- schedule.ModeId = modeId
- schedule.PatientId = patient_id
- schedule.CreatedTime = time.Now().Unix()
- schedule.UpdatedTime = time.Now().Unix()
- schedule.Status = 1
- schedule.UserOrgId = adminInfo.CurrentOrgId
-
- var DialysisMachineName string
- so, _ := service.GetDialysisSolutionTwo(adminInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
- filedRecordOne, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器")
- filedRecordTwo, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "灌流器")
- filedRecordThree, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器/灌流器")
-
- if filedRecordOne.IsShow == 1 {
- DialysisMachineName = so.DialysisDialyszers
- }
- if filedRecordThree.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
-
- } else {
- DialysisMachineName = so.DialyzerPerfusionApparatus
-
- }
- }
- if filedRecordTwo.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
-
- } else {
- DialysisMachineName = so.DialysisIrrigation
-
- }
- }
- schedule.DialysisMachineName = DialysisMachineName
- //schedule.DialysisMachineName = schedule.DialysisMachineName
- daySchedule, _ := service.GetDaySchedule(adminInfo.CurrentOrgId, theTime.Unix(), theTime.Unix(), patient_id)
- if daySchedule.ID > 0 {
- daySchedule.ModeId = schedule.ModeId
- daySchedule.ScheduleType = schedule.ScheduleType
- daySchedule.PartitionId = schedule.PartitionId
- daySchedule.BedId = schedule.BedId
- daySchedule.DialysisMachineName = schedule.DialysisMachineName
- existSchedule.IsExport = 3002
- service.SaveSch(daySchedule)
- } else {
- existSchedule.IsExport = 3003
- service.CreateSchedule(&schedule)
- }
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "保存成功",
- })
- HandleRedis(adminInfo.CurrentOrgId, schedule.ScheduleDate)
-
- }
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "保存成功",
- })
- }
- }
-
- }
- func HandleRedis(org_id int64, sch_date int64) {
- redis := service.RedisClient()
- //处方
- keyOne := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":prescriptions_list_all"
- redis.Set(keyOne, "", time.Second)
- //医嘱
- keyTwo := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keySix := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":assessment_befores_list_all"
- redis.Set(keySix, "", time.Second)
- keyThree := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":assessment_after_dislysis_list_all"
- redis.Set(keyThree, "", time.Second)
- keyFour := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":monitor_record_list_all"
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":treatment_summarys_list_all"
- redis.Set(keyFive, "", time.Second)
- keySeven := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":dialysis_orders_list_all"
- redis.Set(keySeven, "", time.Second)
- defer redis.Close()
-
- }
-
- func (c *ScheduleApiController) GetSmartSch() {
- patient_id, _ := c.GetInt64("patient_id")
- fmt.Println("~~~~~~")
- fmt.Println(patient_id)
- fmt.Println("~~~~~~")
-
- adminUserInfo := c.GetAdminUserInfo()
- sch, err := service.GetSmartSchPatientByPatientID(adminUserInfo.CurrentOrgId, patient_id)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "sch": sch,
- })
- }
-
- func (c *ScheduleApiController) GetPatient() {
- keyWord := c.GetString("keyword")
- adminUserInfo := c.GetAdminUserInfo()
- patient, err := service.GetSmartSchPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "patient": patient,
- })
- }
-
- func (c *ScheduleApiController) GetPatientSchTemplate() {
- //patient_id, _ := c.GetInt64("patient_id",0)
- keyWord := c.GetString("keyword")
- adminUserInfo := c.GetAdminUserInfo()
- patient, err := service.GetSmartSchTemplatePatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "patient": patient,
- })
- }
-
- func (c *ScheduleApiController) GetPatientSmartSch() {
- patient_id, _ := c.GetInt64("patient_id", 0)
- adminUserInfo := c.GetAdminUserInfo()
- schs, err := service.GetSmartSchPatientByID(adminUserInfo.CurrentOrgId, patient_id)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "schedules": schs,
- })
- }
- func (c *ScheduleApiController) GetPatientSmartSchTemplate() {
- patient_id, _ := c.GetInt64("patient_id", 0)
- adminUserInfo := c.GetAdminUserInfo()
- mode, _ := service.GetOrgPatientScheduleTemplateModeTwo(adminUserInfo.CurrentOrgId)
- if mode.ID > 0 {
- if mode.Mode == 0 {
- //schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id)
- c.ServeSuccessJSON(map[string]interface{}{
- "status": 0,
- })
-
- } else if mode.Mode == 1 {
- schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id, 1)
- c.ServeSuccessJSON(map[string]interface{}{
- "status": 0,
- "schedules_template": schs,
- })
-
- } else if mode.Mode == 2 {
- schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id, 2)
- c.ServeSuccessJSON(map[string]interface{}{
- "status": 1,
- "schedules_template": schs,
- })
-
- } else if mode.Mode == 3 {
-
- schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id, 3)
- c.ServeSuccessJSON(map[string]interface{}{
- "status": 1,
- "schedules_template": schs,
- })
- } else if mode.Mode == 4 {
-
- schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id, 4)
- c.ServeSuccessJSON(map[string]interface{}{
- "status": 1,
- "schedules_template": schs,
- })
- }
-
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "status": 0,
- })
-
- }
- }
-
- func (c *ScheduleApiController) GetDevicesNumbers() {
- sch_type, _ := c.GetInt("sch_type", 0)
- zone_id, _ := c.GetInt64("zone_id", 0)
- patient_id, _ := c.GetInt64("patient_id", 0)
-
- schedule_date := c.GetString("schedule_date")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
-
- deviceNumbers, getDeviceNumbersErr := service.GetAllAvaildDeviceNumbersByZone(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, sch_type, zone_id, patient_id)
- if getDeviceNumbersErr != nil {
- c.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "devices": deviceNumbers,
- })
-
- }
-
- func (c *ScheduleApiController) GetWeekPanels() {
-
- data, _ := c.GetInt64("data", 1)
- patitionIdStr := c.GetString("patitionid")
- var ids []string
- if len(patitionIdStr) > 0 {
- ids = strings.Split(patitionIdStr, ",")
- }
-
- adminInfo := c.GetAdminUserInfo()
- thisTime := time.Now()
- year, monthTime, day := thisTime.Date()
- month := int(monthTime)
- _, theWeek := thisTime.ISOWeek()
-
- lastWeek := thisTime.AddDate(0, 0, -7)
-
- nextWeek := thisTime.AddDate(0, 0, 7)
- nextSecWeek := thisTime.AddDate(0, 0, 14)
-
- _, theLastWeek := lastWeek.ISOWeek()
- _, theNextWeek := nextWeek.ISOWeek()
- _, theNextSecWeek := nextSecWeek.ISOWeek()
-
- weekDay := int(thisTime.Weekday())
- if weekDay == 0 {
- weekDay = 7
- }
- weekEnd := 7 - weekDay
- weekStart := weekEnd - 6
- weekDays := make([]string, 0)
- for index := weekStart; index <= weekEnd; index++ {
- theDay := thisTime.AddDate(0, 0, index)
- indexYear, indexMonthTime, indexDay := theDay.Date()
- indexMonth := int(indexMonthTime)
- indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
- weekDays = append(weekDays, indexWeek)
- }
-
- returnData := map[string]interface{}{
- "year": year,
- "month": month,
- "day": day,
- "theWeek": theWeek,
- "theNextWeek": theNextWeek,
- "theNextSecWeek": theNextSecWeek,
- "theLastWeek": theLastWeek,
- "weekDay": weekDay,
- "weekDays": weekDays,
- }
-
- if data == 1 {
-
- partitions, _ := service.GetSchedulePartitionPanelOne(adminInfo.CurrentOrgId, ids)
-
- returnData["partitions"] = partitions
- }
-
- c.ServeSuccessJSON(returnData)
- return
- }
-
- func (c *ScheduleApiController) GetSchedules() {
- week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
- partition_id, _ := c.GetInt64("partition_id")
- schedule_type, _ := c.GetInt64("schedule_type")
-
- adminInfo := c.GetAdminUserInfo()
-
- thisTime := time.Now()
- today := thisTime.Format("2006-01-02")
- if week < 1 || week > 4 {
- week = 2
- }
- if week == 1 {
- thisTime = thisTime.AddDate(0, 0, -7)
- } else if week == 3 {
- thisTime = thisTime.AddDate(0, 0, 7)
- } else if week == 4 {
- thisTime = thisTime.AddDate(0, 0, 14)
- }
-
- weekDay := int(thisTime.Weekday())
- if weekDay == 0 {
- weekDay = 7
- }
- weekEnd := 7 - weekDay
- weekStart := weekEnd - 6
- weekTitle := make([]string, 0)
- days := make([]string, 0)
- for index := weekStart; index <= weekEnd; index++ {
- theDay := thisTime.AddDate(0, 0, index)
- indexYear, indexMonthTime, indexDay := theDay.Date()
- indexMonth := int(indexMonthTime)
- indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
- weekTitle = append(weekTitle, indexWeek)
- days = append(days, theDay.Format("2006-01-02"))
- }
-
- weekStartDay := thisTime.AddDate(0, 0, weekStart)
- weekEndDay := thisTime.AddDate(0, 0, weekEnd)
- weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
- weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
-
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
- theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
- weekStartPoint := theStarTime.Unix()
- weekEndPoint := theEndTime.Unix()
-
- schdules, _ := service.GetWeekScheduleOne(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, partition_id, schedule_type)
- c.ServeSuccessJSON(map[string]interface{}{
- "days": days,
- "weekTitle": weekTitle,
- "schdules": schdules,
- "today": today,
- })
- return
- }
-
- func (c *ScheduleApiController) GetPatients() {
- keywords := c.GetString("keywords", "")
- schedule, _ := c.GetInt64("schedule", 0) //1已2未
- contagion, _ := c.GetInt64("contagion", 0)
-
- adminInfo := c.GetAdminUserInfo()
-
- thisTime := time.Now()
- weekDay := int(thisTime.Weekday())
- if weekDay == 0 {
- weekDay = 7
- }
- thisWeekEnd := 7 - weekDay
- weekStartPoint := thisWeekEnd - 6
- weekStartDay := thisTime.AddDate(0, 0, weekStartPoint)
- weekEndPoint := thisWeekEnd + 7
- weekEndDay := thisTime.AddDate(0, 0, weekEndPoint)
- fmt.Println(weekStartPoint, weekStartDay, weekEndPoint, weekEndDay)
-
- weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
- weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
- fmt.Println(weekStartTime, weekEndTime)
-
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
- theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
- weekStart := theStarTime.Unix()
- weekEnd := theEndTime.Unix()
-
- patients, _ := service.GetPatientWithScheduleAndSolution(adminInfo.CurrentOrgId, keywords, weekStart, weekEnd, schedule, contagion)
- fmt.Println("patinets23233232323232232322323wode", patients)
- c.ServeSuccessJSON(map[string]interface{}{
- "patients": patients,
- })
- return
- }
-
- func (c *ScheduleApiController) CreateSchedule() {
- patientID, _ := c.GetInt64("patient_id", 0)
- if patientID <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patientID)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- var schedule models.Schedule
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if dataBody["schedule_date"] == nil || reflect.TypeOf(dataBody["schedule_date"]).String() != "string" {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- scheduleDate, _ := dataBody["schedule_date"].(string)
- if len(scheduleDate) == 0 {
- utils.ErrorLog("len(schedule_date) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.ScheduleDate = theTime.Unix()
-
- timeNow := time.Now().Format("2006-01-02")
- if timeNow > scheduleDate {
- utils.ErrorLog(timeNow)
- utils.ErrorLog(scheduleDate)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
- return
- }
-
- if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
- utils.ErrorLog("schedule_type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- scheduleType := int64(dataBody["schedule_type"].(float64))
- if scheduleType < 1 || scheduleType > 3 {
- utils.ErrorLog("scheduleType < 3")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.ScheduleType = scheduleType
-
- if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
- utils.ErrorLog("bed_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- bedId := int64(dataBody["bed_id"].(float64))
- if bedId < 1 {
- utils.ErrorLog("bedId < 1")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.BedId = bedId
-
- if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
- utils.ErrorLog("partition_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- partitionId := int64(dataBody["partition_id"].(float64))
- if partitionId < 1 {
- utils.ErrorLog("partitionId < 1")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.PartitionId = partitionId
-
- if dataBody["schedule_week"] == nil || reflect.TypeOf(dataBody["schedule_week"]).String() != "float64" {
- utils.ErrorLog("schedule_week")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- scheduleWeek := int64(dataBody["schedule_week"].(float64))
- if scheduleWeek < 1 || scheduleWeek > 7 {
- utils.ErrorLog("scheduleWeek < 1")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.ScheduleWeek = scheduleWeek
-
- if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
- utils.ErrorLog("mode_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- modeId := int64(dataBody["mode_id"].(float64))
- if modeId < 1 && modeId > 14 {
- utils.ErrorLog("modeId < 1")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.ModeId = modeId
-
- schedule.PatientId = patientID
- schedule.CreatedTime = time.Now().Unix()
- schedule.UpdatedTime = time.Now().Unix()
- schedule.Status = 1
- schedule.UserOrgId = adminUserInfo.CurrentOrgId
- schedule.IsExport = 5
-
- var DialysisMachineName string
- so, _ := service.GetDialysisSolutionTwo(adminUserInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
- filedRecordOne, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器")
- filedRecordTwo, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "灌流器")
- filedRecordThree, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器/灌流器")
-
- if filedRecordOne.IsShow == 1 {
- DialysisMachineName = so.DialysisDialyszers
- }
- if filedRecordThree.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
-
- } else {
- DialysisMachineName = so.DialyzerPerfusionApparatus
-
- }
- }
- if filedRecordTwo.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
-
- } else {
- DialysisMachineName = so.DialysisIrrigation
-
- }
- }
- schedule.DialysisMachineName = DialysisMachineName
-
- bed, _ := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, schedule.BedId)
- if bed == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
- return
- }
- if bed.ZoneID != schedule.PartitionId {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
- return
- }
-
- scheduleDateStart := scheduleDate + " 00:00:00"
- scheduleDateEnd := scheduleDate + " 23:59:59"
- timeLayout = "2006-01-02 15:04:05"
- theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
- theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
- startTime := theStartTime.Unix()
- endTime := theEndTime.Unix()
-
- //一天只有排班一次
- daySchedule, err := service.GetDaySchedule(adminUserInfo.CurrentOrgId, startTime, endTime, patientID)
- if daySchedule.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
- return
- }
-
- //同天同位置只能排一个
- pointSchedule, err := service.GetPointSchedule(adminUserInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- if pointSchedule.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
- return
- }
-
- redis := service.RedisClient()
- schedule.IsExport = 1000
- err = service.CreateSchedule(&schedule)
-
- key := "scheduals_" + scheduleDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
-
- redis.Set(key, "", time.Second)
- //处方
- keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
- redis.Set(keyOne, "", time.Second)
-
- //医嘱
- keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
-
- keySix := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
- redis.Set(keySix, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
- redis.Set(keyThree, "", time.Second)
-
- keyFour := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
- redis.Set(keyFour, "", time.Second)
-
- keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
- redis.Set(keyFive, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
- redis.Set(keySeven, "", time.Second)
- fmt.Println(err)
- defer redis.Close()
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateScheduleFail)
- return
- }
- schedule.Patient = patientInfo.Name
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "schedule": schedule,
- })
- return
- }
-
- func (c *ScheduleApiController) DeleteSchedule() {
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminINfo := c.GetAdminUserInfo()
-
- schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
- timeNow := time.Now().Format("2006-01-02")
- timeTemplate := "2006-01-02"
-
- tm := time.Unix(int64(schedule.ScheduleDate), 0)
- timeStr := tm.Format(timeTemplate)
- if timeNow > timeStr {
- utils.ErrorLog(timeNow)
- utils.ErrorLog(timeStr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
- return
- }
- if schedule == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
- return
- }
-
- order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- if order != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysis)
- return
- }
-
- schedule.Status = 0
- schedule.UpdatedTime = time.Now().Unix()
- err = service.UpdateSchedule(schedule)
- redis := service.RedisClient()
-
- //处方
- keyOne := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
- redis.Set(keyOne, "", time.Second)
-
- //医嘱
- keyTwo := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
-
- keySix := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
- redis.Set(keySix, "", time.Second)
- keyThree := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
- redis.Set(keyThree, "", time.Second)
-
- keyFour := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
- redis.Set(keyFour, "", time.Second)
-
- keyFive := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
- redis.Set(keyFive, "", time.Second)
-
- keySeven := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
- redis.Set(keySeven, "", time.Second)
- fmt.Println(err)
- defer redis.Close()
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteScheduleFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "schedule": &schedule,
- })
- }
-
- func (c *ScheduleApiController) ChangeSchedule() {
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminINfo := c.GetAdminUserInfo()
-
- schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
- if schedule == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
- return
- }
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if dataBody["change_action"] == nil || reflect.TypeOf(dataBody["change_action"]).String() != "string" {
- utils.ErrorLog("change_action")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- changeAction := dataBody["change_action"].(string)
-
- if changeAction == "change_mode" {
- if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
- utils.ErrorLog("mode_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrongForSchMode)
- return
- }
- modeId := int64(dataBody["mode_id"].(float64))
- if modeId < 1 {
- utils.ErrorLog("modeId < 1")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrongForSchMode)
- return
- }
- schedule.ModeId = modeId
-
- so, _ := service.GetDialysisSolutionTwo(adminINfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
- filedRecordOne, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "透析器")
- filedRecordTwo, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "灌流器")
- filedRecordThree, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "透析器/灌流器")
- var DialysisMachineName string
- if filedRecordOne.IsShow == 1 {
- DialysisMachineName = so.DialysisDialyszers
- fmt.Println("1111")
- fmt.Println(DialysisMachineName)
-
- }
- if filedRecordThree.IsShow == 1 {
- if len(schedule.DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
- fmt.Println("22222")
- fmt.Println(DialysisMachineName)
- } else {
- DialysisMachineName = so.DialyzerPerfusionApparatus
- fmt.Println("333333")
- fmt.Println(DialysisMachineName)
- }
- }
- if filedRecordTwo.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
- fmt.Println("55555555")
- fmt.Println(DialysisMachineName)
- } else {
- DialysisMachineName = so.DialysisIrrigation
- fmt.Println("66666666")
- fmt.Println(DialysisMachineName)
- }
- }
- schedule.DialysisMachineName = DialysisMachineName
-
- order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- if order != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeMode)
- return
- }
-
- } else if changeAction == "change_device" {
- order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- if order != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeDeviceNumber)
- return
- }
-
- if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
- utils.ErrorLog("schedule_type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- scheduleType := int64(dataBody["schedule_type"].(float64))
- if scheduleType < 1 || scheduleType > 3 {
- utils.ErrorLog("scheduleType < 3")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.ScheduleType = scheduleType
-
- if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
- utils.ErrorLog("bed_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- bedId := int64(dataBody["bed_id"].(float64))
- if bedId < 1 {
- utils.ErrorLog("bedId < 1")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.BedId = bedId
-
- if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
- utils.ErrorLog("partition_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- partitionId := int64(dataBody["partition_id"].(float64))
- if partitionId < 1 {
- utils.ErrorLog("partitionId < 1")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.PartitionId = partitionId
-
- bed, _ := service.GetDeviceNumberByID(adminINfo.CurrentOrgId, schedule.BedId)
- if bed == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
- return
- }
- if bed.ZoneID != schedule.PartitionId {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
- return
- }
-
- startTime := schedule.ScheduleDate
- endTime := startTime + 86399
-
- //一天只有排班一次
- daySchedule, err := service.GetDaySchedule(adminINfo.CurrentOrgId, startTime, endTime, schedule.PatientId)
- if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
- return
- }
-
- //同天同位置只能排一个
- pointSchedule, err := service.GetPointSchedule(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- if pointSchedule.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
- return
- }
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- schedule.UpdatedTime = time.Now().Unix()
- err = service.UpdateSchedule(schedule)
-
- prescription := models.DialysisPrescription{
- ModeId: schedule.ModeId,
- }
- _, errcode := service.GetDialysisPrescribe(schedule.UserOrgId, schedule.PatientId, schedule.ScheduleDate)
- if errcode == gorm.ErrRecordNotFound {
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "schedule": &schedule,
- })
- } else if errcode == nil {
- err = service.UpdatedDialysisPrescription(&prescription, schedule.ScheduleDate, schedule.PatientId, schedule.UserOrgId)
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "schedule": &schedule,
- })
- }
- }
-
- // /api/schedule/print/initdata [get]
- // @param date:string yyyy-MM-dd 要打印的那一周中的任一天
- func (this *ScheduleApiController) PrintInitData() {
- dateStr := this.GetString("date")
- //week_type, _ := this.GetInt64("type", 0)
- var date *time.Time
- if len(dateStr) == 0 {
- now := time.Now()
- date = &now
- } else {
- var parseErr error
- date, parseErr = utils.ParseTimeStringToTime("2006-01-02", dateStr)
- if parseErr != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- }
-
- adminUserInfo := this.GetAdminUserInfo()
- // 获取本周的排班
- var monday time.Time
- var sunday time.Time
- //switch week_type {
- //case 1:
- monday, sunday = utils.GetMondayAndSundayOfWeekDate(date)
-
- // break
- //case 2:
- // monday, sunday = utils.GetMondayAndSundayOfNextWeekDate(date)
- //
- // break
- //case 3:
- // monday, sunday = utils.GetMondayAndSundayOfNextNextWeekDate(date)
- // break
- //}
- schedules, getScheduleErr := service.GetPrinitWeekSchedules(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
- total, getScheduleErr := service.GetPrinitWeekTotal(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
- if getScheduleErr != nil {
- this.ErrorLog("获取周排班失败:%v", getScheduleErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- thisTime := date
-
- weekDay := int(thisTime.Weekday())
- if weekDay == 0 {
- weekDay = 7
- }
- weekEnd := 7 - weekDay
- weekStart := weekEnd - 6
- days := make([]string, 0)
- for index := weekStart; index <= weekEnd; index++ {
- theDay := thisTime.AddDate(0, 0, index)
- days = append(days, theDay.Format("2006-01-02"))
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "schedules": schedules,
- "monday": monday.Unix(),
- "days": days,
- })
- }
-
- func (this *ScheduleApiController) UrgentScheduleData() {
- schedule_type, _ := this.GetInt("type", 0)
- schedule_date := this.GetString("date")
- var date *time.Time
- if len(schedule_date) == 0 {
- now := time.Now()
- date = &now
- } else {
- var parseErr error
- date, parseErr = utils.ParseTimeStringToTime("2006-01-02", schedule_date)
- if parseErr != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- }
-
- adminUserInfo := this.GetAdminUserInfo()
- deviceNumbers, getDeviceNumbersErr := service.MobileGetAllDeviceNumbersForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
- if getDeviceNumbersErr != nil {
- this.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- // today := utils.ZeroHourTimeOfDay(time.Now())
- schedules, getSchedulesErr := service.MobileGetOtherSchedulesForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
- if getSchedulesErr != nil {
- this.ErrorLog("获取所有排班失败:%v", getSchedulesErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "device_numbers": deviceNumbers,
- "schedules": schedules,
- })
- }
-
- func (this *ScheduleApiController) SearchSchedulePatients() {
- keywords := this.GetString("keywords")
- week_type, _ := this.GetInt64("week_type", 0)
- start_sch := this.GetString("start_sch")
- end_sch := this.GetString("end_sch")
-
- thisTime1 := time.Now()
- thisTime2 := time.Now()
-
- thisTime1 = thisTime1.AddDate(0, 0, 7)
- thisTime2 = thisTime2.AddDate(0, 0, 14)
-
- var start_time string
- var end_time string
-
- switch week_type {
- case 1:
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var startSchTime int64
- if len(start_sch) > 0 {
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_sch+" 00:00:00", loc)
- startSchTime = theTime.Unix()
- }
- var endSchTime int64
- if len(end_sch) > 0 {
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_sch+" 00:00:00", loc)
- endSchTime = theTime.Unix()
- }
-
- adminUserInfo := this.GetAdminUserInfo()
- list, _ := service.GetSchedualPatientsByKeywords(keywords, adminUserInfo.CurrentOrgId, startSchTime, endSchTime)
- this.ServeSuccessJSON(map[string]interface{}{
- "schdules": list,
- })
-
- break
- case 2:
- days := make([]string, 0)
-
- weekDay1 := int(thisTime1.Weekday())
- if weekDay1 == 0 {
- weekDay1 = 7
- }
- weekEnd1 := 7 - weekDay1
- weekStart1 := weekEnd1 - 6
- for index := weekStart1; index <= weekEnd1; index++ {
- fmt.Println(index)
- theDay := thisTime1.AddDate(0, 0, index)
- days = append(days, theDay.Format("2006-01-02"))
-
- }
-
- fmt.Println(days)
-
- start_time = days[0]
- end_time = days[len(days)-1]
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var theStartTime int64
- if len(start_time) > 0 {
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- theStartTime = theTime.Unix()
- }
- var theEndtTime int64
- if len(end_time) > 0 {
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- theEndtTime = theTime.Unix()
- }
-
- adminUserInfo := this.GetAdminUserInfo()
- list, _ := service.GetSchedualPatientsByKeywordsAndWeek(keywords, adminUserInfo.CurrentOrgId, theStartTime, theEndtTime)
- this.ServeSuccessJSON(map[string]interface{}{
- "schdules": list,
- })
-
- break
- case 3:
- days := make([]string, 0)
-
- weekDay2 := int(thisTime2.Weekday())
- if weekDay2 == 0 {
- weekDay2 = 7
- }
- weekEnd2 := 7 - weekDay2
- weekStart2 := weekEnd2 - 6
- for index := weekStart2; index <= weekEnd2; index++ {
- theDay := thisTime2.AddDate(0, 0, index)
- days = append(days, theDay.Format("2006-01-02"))
-
- }
-
- start_time = days[0]
- end_time = days[len(days)-1]
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var theStartTime int64
- if len(start_time) > 0 {
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- theStartTime = theTime.Unix()
- }
- var theEndtTime int64
- if len(end_time) > 0 {
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- theEndtTime = theTime.Unix()
- }
-
- adminUserInfo := this.GetAdminUserInfo()
- list, _ := service.GetSchedualPatientsByKeywordsAndWeek(keywords, adminUserInfo.CurrentOrgId, theStartTime, theEndtTime)
- this.ServeSuccessJSON(map[string]interface{}{
- "schdules": list,
- })
-
- break
- }
-
- }
-
- func (this *ScheduleApiController) GetWeekDaySchedule() {
- week_type, _ := this.GetInt64("week_type", -1)
- week_time, _ := this.GetInt64("week_time")
-
- thisTime := time.Now()
- weekDay := int(thisTime.Weekday())
- if weekDay == 0 {
- weekDay = 7
- }
- weekEnd := 7 - weekDay
- weekStart := weekEnd - 6
- weekTitle := make([]string, 0)
- days := make([]string, 0)
- for index := weekStart; index <= weekEnd; index++ {
- theDay := thisTime.AddDate(0, 0, index)
- indexYear, indexMonthTime, indexDay := theDay.Date()
- indexMonth := int(indexMonthTime)
- indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
- weekTitle = append(weekTitle, indexWeek)
- days = append(days, theDay.Format("2006-01-02"))
- }
- fmt.Println(days)
-
- var targetDayStr string
- var startTime string
- var endTime string
- switch week_type {
- case 0:
- {
- startTime = days[0]
- endTime = days[6]
- }
- case 1:
- targetDayStr = days[0]
- break
- case 2:
- targetDayStr = days[1]
-
- break
- case 3:
- targetDayStr = days[2]
-
- break
- case 4:
- targetDayStr = days[3]
-
- break
- case 5:
- targetDayStr = days[4]
-
- break
- case 6:
- targetDayStr = days[5]
-
- break
- case 7:
- targetDayStr = days[6]
-
- break
- }
- targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
- startDay, _ := utils.ParseTimeStringToTime("2006-01-02", startTime)
- endDay, _ := utils.ParseTimeStringToTime("2006-01-02", endTime)
- fmt.Println(startDay, endDay)
- if parseErr != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- list, _ := service.GetWeekDayScheduleTwo(orgId, targetDay.Unix(), targetDay, week_time)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "schdules": list,
- "day": targetDayStr,
- })
-
- }
-
- func Struct2Map(obj interface{}) map[string]interface{} {
- t := reflect.TypeOf(obj)
- v := reflect.ValueOf(obj)
-
- var data = make(map[string]interface{})
- for i := 0; i < t.NumField(); i++ {
- data[t.Field(i).Name] = v.Field(i).Interface()
- }
- return data
- }
-
- func (this *ScheduleApiController) ExportSchedule() {
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- return
- }
- utils.ErrorLog("%v", dataBody)
- export_time := time.Now().Unix()
- var schedules []*models.Schedule
- var failed_total int
- var total_schedule []interface{}
- var patients []*models.Patients
-
- patients, _, _ = service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
-
- start_time := dataBody["start_time"].(string)
-
- end_time := dataBody["end_time"].(string)
-
- delete_type := int64(dataBody["delete_type"].(float64))
- fmt.Println("delete_type", delete_type)
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
-
- fmt.Println("theTimeStart23232322332322323", theTimeStart.Unix())
- fmt.Println("theTimeStart23232322332322323", theTimeEnd.Unix())
-
- if dataBody["failed_schedule"] != nil || reflect.TypeOf(dataBody["failed_schedule"]).String() == "[]interface {}" {
- tempSchedule := dataBody["failed_schedule"].([]interface{})
- failed_total = len(tempSchedule)
-
- }
-
- if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
- tempSchedule := dataBody["schedule"].([]interface{})
- total_schedule = tempSchedule
- for _, schMap := range tempSchedule {
- schMapM := schMap.(map[string]interface{})
- var sch models.Schedule
-
- if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
- utils.ErrorLog("name")
- return
- }
-
- name, _ := schMapM["name"].(string)
- fmt.Println(name)
- if len(name) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
-
- } else {
- var patient []*models.Patients
- for _, item := range patients {
- if strings.Replace(item.Name, " ", "", -1) == name {
- patient = append(patient, item)
- }
- }
- if len(patient) == 0 { //错误日志
- err_log := models.ExportErrLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
-
- } else if len(patient) == 1 { //
- sch.PatientId = patient[0].ID
-
- } else if len(patient) > 1 { //出现同名的情况
-
- err_log := models.ExportErrLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
-
- ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在在当前机构中存在重名,无法确定到具体患者",
-
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
-
- }
- }
-
- if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
- utils.ErrorLog("schedule_type")
- return
- }
- schedule_type := int64(schMapM["schedule_type"].(float64))
- if schedule_type <= 0 { //班次格式有误,插入日志
-
- log := models.ExportLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_schedule) + failed_total),
- FailNum: 1 + int64(failed_total),
- SuccessNum: int64(len(schedules)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- err_log := models.ExportErrLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
- return
-
- } else {
- sch.ScheduleType = schedule_type
- }
-
- if schMapM["partition_name"] == nil || reflect.TypeOf(schMapM["partition_name"]).String() != "string" {
- utils.ErrorLog("partition_name")
- return
- }
-
- partition_name, _ := schMapM["partition_name"].(string)
- if len(partition_name) == 0 { //分区为空
- log := models.ExportLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_schedule) + failed_total),
- FailNum: 1 + int64(failed_total),
- SuccessNum: int64(len(schedules)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- err_log := models.ExportErrLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
- ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
- return
-
- } else {
- zone, err := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
- if err == nil {
- sch.PartitionId = zone.ID
- } else if err == gorm.ErrRecordNotFound { //查不到数据,插入错误日志
-
- log := models.ExportLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_schedule) + failed_total),
- FailNum: 1 + int64(failed_total),
- SuccessNum: int64(len(schedules)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- err_log := models.ExportErrLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
- ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
- return
-
- }
-
- }
-
- if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
- utils.ErrorLog("device_number_name")
- return
- }
-
- device_number_name, _ := schMapM["device_number_name"].(string)
- if len(device_number_name) == 0 { //分区为空
-
- log := models.ExportLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_schedule) + failed_total),
- FailNum: 1 + int64(failed_total),
- SuccessNum: int64(len(schedules)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- err_log := models.ExportErrLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
- ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
-
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
- return
-
- } else {
- device, err := service.FindDeviceByName(device_number_name, this.GetAdminUserInfo().CurrentOrgId, sch.PartitionId)
- if err == nil {
- if len(device) == 0 { //没查到数据,插入错误日志
-
- log := models.ExportLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_schedule) + failed_total),
- FailNum: 1 + int64(failed_total),
- SuccessNum: int64(len(schedules)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- err_log := models.ExportErrLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
- return
-
- } else if len(device) == 1 {
- sch.BedId = device[0].ID
-
- } else if len(device) > 1 { //出现重名,插入错误日志
-
- log := models.ExportLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_schedule) + failed_total),
- FailNum: 1 + int64(failed_total),
- SuccessNum: int64(len(schedules)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- err_log := models.ExportErrLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "出现两个床位号相同的床位",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
- return
-
- }
- }
- }
-
- if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
- utils.ErrorLog("schedule_week")
- return
- }
- schedule_week, _ := schMapM["schedule_week"].(string)
- if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
-
- log := models.ExportLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_schedule) + failed_total),
- FailNum: 1 + int64(failed_total),
- SuccessNum: int64(len(schedules)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- err_log := models.ExportErrLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
- ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
-
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
- return
-
- } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
-
- log := models.ExportLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_schedule) + failed_total),
- FailNum: 1 + int64(failed_total),
- SuccessNum: int64(len(schedules)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- err_log := models.ExportErrLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
- return
-
- } else {
- schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
- sch.ScheduleWeek = schedule_week
-
- }
-
- if schMapM["schedule_date"] == nil || reflect.TypeOf(schMapM["schedule_date"]).String() != "string" {
- utils.ErrorLog("schedule_date")
- return
- }
- schedule_date, _ := schMapM["schedule_date"].(string)
-
- if len(schedule_date) == 0 { //周几为空则生成一条导入错误日志
-
- log := models.ExportLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_schedule) + failed_total),
- FailNum: 1 + int64(failed_total),
- SuccessNum: int64(len(schedules)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- err_log := models.ExportErrLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
- return
-
- } else if schedule_date == "0" { //周几不符合格式则生成一条导入错误日志
-
- log := models.ExportLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_schedule) + failed_total),
- FailNum: 1 + int64(failed_total),
- SuccessNum: int64(len(schedules)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- err_log := models.ExportErrLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
- return
-
- } else {
- date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
- sch.ScheduleDate = date.Unix()
- }
-
- sch.CreatedTime = time.Now().Unix()
- sch.UpdatedTime = time.Now().Unix()
- sch.ModeId = 1
- sch.Status = 1
- sch.UserOrgId = this.GetAdminUserInfo().CurrentOrgId
- sch.IsExport = 1
-
- var DialysisMachineName string
- so, _ := service.GetDialysisSolutionTwo(sch.UserOrgId, sch.PatientId, sch.ModeId)
- filedRecordOne, _ := service.FindFiledBy(sch.UserOrgId, "透析器")
- filedRecordTwo, _ := service.FindFiledBy(sch.UserOrgId, "灌流器")
- filedRecordThree, _ := service.FindFiledBy(sch.UserOrgId, "透析器/灌流器")
-
- if filedRecordOne.IsShow == 1 {
- DialysisMachineName = so.DialysisDialyszers
- }
- if filedRecordThree.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
-
- } else {
- DialysisMachineName = so.DialyzerPerfusionApparatus
-
- }
- }
- if filedRecordTwo.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
-
- } else {
- DialysisMachineName = so.DialysisIrrigation
-
- }
- }
- sch.DialysisMachineName = DialysisMachineName
-
- schedules = append(schedules, &sch)
- }
-
- errLogs, _ := service.FindSchedualExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
-
- if len(schedules) > 0 {
- schedule_date := time.Now().Format("2006-01-02")
- date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
- clear_schedule_date := date.Unix() //根据日期去清除,该日期未来的排班数据
-
- service.UpdateScheduleByExport(this.GetAdminUserInfo().CurrentOrgId, clear_schedule_date)
-
- if err == nil {
- for _, item := range schedules {
- if item.ScheduleDate > clear_schedule_date {
- //查询该患者是否转出获取死亡
- fmt.Println("11111323242423")
-
- //查找当天日期是否存在
- _, errcode := service.GetTodayScheduleIsExistOne(item.PatientId, item.ScheduleDate, item.UserOrgId)
- if errcode == gorm.ErrRecordNotFound {
- //查询该床位是否有患者
- fmt.Println("errcodes")
- sch, errcodes := service.GetPatientByBed(item.ScheduleDate, item.BedId, item.ScheduleType, item.UserOrgId)
- fmt.Println("errcodes")
- fmt.Println(errcodes)
- fmt.Println(sch)
-
- if errcodes == gorm.ErrRecordNotFound {
- fmt.Println("1111111")
- service.CreateSchedule(item)
- } else if errcodes == nil {
- fmt.Println("1111222222222")
- //清除当天该床位已有的患者
- service.ModeFyScheduleById(sch.ScheduleDate, sch.BedId, sch.ScheduleType, sch.UserOrgId)
- service.CreateSchedule(item)
- }
-
- } else if errcode == nil {
- schedule := models.XtSchedule{
- PartitionId: item.PartitionId,
- BedId: item.BedId,
- PatientId: item.PatientId,
- ScheduleDate: item.ScheduleDate,
- ScheduleType: item.ScheduleType,
- ScheduleWeek: item.ScheduleWeek,
- ModeId: 1,
- Status: 1,
- DialysisMachineName: item.DialysisMachineName,
- }
- fmt.Println("1111222222223333333333333333332")
-
- service.UpdateScheduleByOrgIdOne(item.PatientId, item.ScheduleDate, item.UserOrgId, &schedule)
- }
- }
- }
-
- log := models.ExportLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_schedule) + failed_total),
- FailNum: int64(len(errLogs) + failed_total),
- SuccessNum: int64(len(schedules)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- if failed_total > 0 {
- err_log := models.ExportErrLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
- ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_schedule) + failed_total,
- "success_num": len(schedules),
- "fail_num": int64(len(errLogs)),
- })
- } else {
- log := models.ExportLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_schedule) + failed_total),
- FailNum: int64(len(errLogs) + failed_total),
- SuccessNum: int64(len(schedules)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- if failed_total > 0 {
- err_log := models.ExportErrLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
- ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_schedule),
- "success_num": len(schedules),
- "fail_num": int64(len(errLogs)),
- })
- }
- } else {
- log := models.ExportLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_schedule) + failed_total),
- FailNum: int64(len(errLogs) + failed_total),
- SuccessNum: int64(len(schedules)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- if failed_total > 0 {
- err_log := models.ExportErrLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
- ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_schedule),
- "success_num": len(schedules),
- "fail_num": int64(len(errLogs)),
- })
- }
- }
-
- }
-
- func (this *ScheduleApiController) ExportScheduleTemplate() {
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- return
- }
- utils.ErrorLog("%v", dataBody)
- export_time := time.Now().Unix()
- var schedules []*models.PatientScheduleTemplateItem
- var total_schedule []interface{}
-
- patients, _, _ := service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
-
- if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
- tempSchedule := dataBody["schedule"].([]interface{})
- total_schedule = tempSchedule
- for _, schMap := range tempSchedule {
- schMapM := schMap.(map[string]interface{})
- var sch models.PatientScheduleTemplateItem
-
- if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
- utils.ErrorLog("name")
- return
- }
-
- name, _ := schMapM["name"].(string)
- fmt.Println(name)
- if len(name) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 3,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
-
- } else {
- var patient []*models.Patients
- for _, item := range patients {
- if strings.Replace(item.Name, " ", "", -1) == name {
- patient = append(patient, item)
- }
- }
- if len(patient) == 0 { //错误日志
- err_log := models.ExportErrLog{
- LogType: 3,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名在系统中不存在,请在系统中添加该病人",
- ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
-
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
-
- } else if len(patient) == 1 { //
- sch.PatientID = patient[0].ID
-
- } else if len(patient) > 1 { //出现同名的情况
-
- err_log := models.ExportErrLog{
- LogType: 3,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
- ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在当前机构中存在重名,无法确定到具体患者",
-
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
-
- }
- }
-
- if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
- utils.ErrorLog("schedule_type")
- return
- }
- schedule_type := int64(schMapM["schedule_type"].(float64))
- if schedule_type <= 0 { //班次格式有误,插入日志
- log := models.ExportLog{
- LogType: 3,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_schedule)),
- FailNum: 1,
- SuccessNum: int64(len(schedules)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- err_log := models.ExportErrLog{
- LogType: 3,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
- return
-
- } else {
- sch.TimeType = int8(schedule_type)
- }
-
- if schMapM["template_id"] == nil && reflect.TypeOf(schMapM["template_id"]).String() != "float64" {
- utils.ErrorLog("template_id")
- return
- }
-
- template_id := int64(schMapM["template_id"].(float64))
- sch.TemplateID = template_id
-
- if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
- utils.ErrorLog("device_number_name")
- return
- }
-
- partition_name, _ := schMapM["partition_name"].(string)
- zone, _ := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
-
- device_number_name, _ := schMapM["device_number_name"].(string)
- if len(device_number_name) == 0 { //分区为空
- log := models.ExportLog{
- LogType: 3,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_schedule)),
- FailNum: 1,
- SuccessNum: int64(len(schedules)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- err_log := models.ExportErrLog{
- LogType: 3,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
- ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
-
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
- return
-
- } else {
- device, err := service.FindDeviceByNameTwo(device_number_name, this.GetAdminUserInfo().CurrentOrgId, zone.ID)
- if err == nil {
- if len(device) == 0 { //没查到数据,插入错误日志
- log := models.ExportLog{
- LogType: 3,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_schedule)),
- FailNum: 1,
- SuccessNum: int64(len(schedules)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- err_log := models.ExportErrLog{
- LogType: 3,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
- return
-
- } else if len(device) == 1 {
- sch.DeviceNumberID = device[0].ID
-
- } else if len(device) > 1 { //出现重名,插入错误日志
- log := models.ExportLog{
- LogType: 3,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_schedule)),
- FailNum: 1,
- SuccessNum: int64(len(schedules)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- err_log := models.ExportErrLog{
- LogType: 3,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "出现两个床位号相同的床位",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
- return
-
- }
- }
- }
-
- if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
- utils.ErrorLog("schedule_week")
- return
- }
- schedule_week, _ := schMapM["schedule_week"].(string)
- if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
-
- log := models.ExportLog{
- LogType: 3,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_schedule)),
- FailNum: 1,
- SuccessNum: int64(len(schedules)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- err_log := models.ExportErrLog{
- LogType: 3,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
- ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
-
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
- return
-
- } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
-
- log := models.ExportLog{
- LogType: 3,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_schedule)),
- FailNum: 1,
- SuccessNum: int64(len(schedules)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- err_log := models.ExportErrLog{
- LogType: 3,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
- return
-
- } else {
- schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
- sch.Weekday = int8(schedule_week)
-
- }
- treat_mode, _ := schMapM["treat_mode"].(string)
- treat_mode_int, _ := strconv.ParseInt(treat_mode, 10, 64)
- sch.CreateTime = time.Now().Unix()
- sch.ModifyTime = time.Now().Unix()
- sch.TreatMode = treat_mode_int
- sch.Status = 1
- sch.OrgID = this.GetAdminUserInfo().CurrentOrgId
- sch.IsExport = 1
- schedules = append(schedules, &sch)
- }
-
- errLogs, _ := service.FindSchedualTemplateExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
-
- //for _, item := range schedules {
- //
- //}
-
- if len(schedules) > 0 {
- err := service.UpdateScheduleTemplateStatus(this.GetAdminUserInfo().CurrentOrgId)
- if err == nil {
- for _, item := range schedules {
- //判斷某個模板下,當天是否有排版,沒有的話就新增
- total := service.ExportScheduleTemplate(item)
- if total == 0 {
- service.CreateScheduleTemplate(item)
- }
- }
- ////查询已经转出或者死亡的患者
- //patientList, _ := service.GetDeathPatient(this.GetAdminUserInfo().CurrentOrgId)
- //for _, it := range patientList {
- // timeStr := time.Now().Format("2006-01-02")
- // timeLayout := "2006-01-02 15:04:05"
- // timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
- // timenow := timeStringToTime.Unix()
- // service.UpdateScheduleByDeathTime(it.ID, timenow)
- // service.UpdateScheduleItemByPatientId(it.ID)
- //}
- log := models.ExportLog{
- LogType: 3,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_schedule)),
- FailNum: int64(len(errLogs)),
- SuccessNum: int64(len(schedules)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_schedule),
- "success_num": len(schedules),
- "fail_num": int64(len(errLogs)),
- })
- } else {
- log := models.ExportLog{
- LogType: 3,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_schedule)),
- FailNum: int64(len(errLogs)),
- SuccessNum: int64(len(schedules)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_schedule),
- "success_num": len(schedules),
- "fail_num": int64(len(errLogs)),
- })
- }
- } else {
- log := models.ExportLog{
- LogType: 3,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_schedule)),
- FailNum: int64(len(errLogs)),
- SuccessNum: int64(len(schedules)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_schedule),
- "success_num": len(schedules),
- "fail_num": int64(len(errLogs)),
- })
- }
- }
-
- }
-
- func (c *ScheduleApiController) GetInitExcelInitDate() {
-
- thisTime := time.Now()
- thisTime1 := time.Now()
- thisTime2 := time.Now()
- thisTime3 := time.Now()
- thisTime4 := time.Now()
-
- thisTime1 = thisTime1.AddDate(0, 0, 7)
- thisTime2 = thisTime2.AddDate(0, 0, 14)
- thisTime3 = thisTime3.AddDate(0, 0, 21)
- thisTime4 = thisTime4.AddDate(0, 0, 28)
-
- weekDay := int(thisTime.Weekday())
- if weekDay == 0 {
- weekDay = 7
- }
- weekEnd := 7 - weekDay
- weekStart := weekEnd - 6
- days := make([]string, 0)
- for index := weekStart; index <= weekEnd; index++ {
- theDay := thisTime.AddDate(0, 0, index)
- days = append(days, theDay.Format("2006-01-02"))
- }
-
- weekDay1 := int(thisTime1.Weekday())
- if weekDay1 == 0 {
- weekDay1 = 7
- }
- weekEnd1 := 7 - weekDay1
- weekStart1 := weekEnd1 - 6
- for index := weekStart1; index <= weekEnd1; index++ {
- theDay := thisTime1.AddDate(0, 0, index)
- days = append(days, theDay.Format("2006-01-02"))
- }
-
- weekDay2 := int(thisTime2.Weekday())
- if weekDay2 == 0 {
- weekDay2 = 7
- }
- weekEnd2 := 7 - weekDay2
- weekStart2 := weekEnd2 - 6
- for index := weekStart2; index <= weekEnd2; index++ {
- theDay := thisTime2.AddDate(0, 0, index)
- days = append(days, theDay.Format("2006-01-02"))
- }
-
- weekDay3 := int(thisTime3.Weekday())
- if weekDay3 == 0 {
- weekDay3 = 7
- }
- weekEnd3 := 7 - weekDay3
- weekStart3 := weekEnd3 - 6
- for index := weekStart3; index <= weekEnd3; index++ {
- theDay := thisTime3.AddDate(0, 0, index)
- days = append(days, theDay.Format("2006-01-02"))
- }
-
- weekDay4 := int(thisTime4.Weekday())
- if weekDay4 == 0 {
- weekDay4 = 7
- }
- weekEnd4 := 7 - weekDay4
- weekStart4 := weekEnd4 - 6
- for index := weekStart4; index <= weekEnd4; index++ {
- theDay := thisTime4.AddDate(0, 0, index)
- days = append(days, theDay.Format("2006-01-02"))
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "days": days,
- })
- return
- }
-
- func GetWeekString(week string) string {
- var weekStr string
- switch week {
- case "Sunday":
- weekStr = "周日"
- break
- case "Monday":
- weekStr = "周一"
- break
- case "Tuesday":
- weekStr = "周二"
- break
- case "Wednesday":
- weekStr = "周三"
- break
- case "Thursday":
- weekStr = "周四"
-
- break
- case "Friday":
- weekStr = "周五"
-
- break
- case "Saturday":
- weekStr = "周六"
- break
- default:
- weekStr = ""
- break
-
- }
- return weekStr
- }
-
- func (c *ScheduleApiController) SearchTemplateSchedulePatients() {
- template_id, _ := c.GetInt64("template_id", 0)
- keywords := c.GetString("keywords")
- adminInfo := c.GetAdminUserInfo()
- scheduleItems, _ := service.GetTemplateSchedualPatientsByKeywords(keywords, adminInfo.CurrentOrgId, template_id)
- c.ServeSuccessJSON(map[string]interface{}{
- "schdules": scheduleItems,
- })
- }
-
- func (c *ScheduleApiController) CancelScheduleTemplate() {
- item_id, _ := c.GetInt64("id")
- adminInfo := c.GetAdminUserInfo()
- err := service.UpdateNewScheduleTemplateStatus(item_id, adminInfo.CurrentOrgId)
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "取消成功",
- })
- return
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
- return
- }
- }
- func (this *ScheduleApiController) GetNextWeekDayScheduleOne() {
- week_type, _ := this.GetInt64("week_type", -1)
- week_time, _ := this.GetInt64("week_time")
- record_date := this.GetString("record_date")
-
- zons := this.GetString("zone")
- zone := strings.Split(zons, ",")
-
- start_time, _ := this.GetInt64("start_time")
- end_time, _ := this.GetInt64("end_time")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- //theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- //theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
-
- adminUserInfo := this.GetAdminUserInfo()
- var theStartTIme int64
- if len(record_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- }
- theStartTIme = theTime.Unix()
- }
-
- schedule, err := service.GetNextWeekDayScheduleSix(week_type, week_time, start_time, end_time, adminUserInfo.CurrentOrgId, zone, theStartTIme)
- for _, item := range schedule {
- order, _ := service.GetLastDialysisOrder(adminUserInfo.CurrentOrgId, item.PatientId, theStartTIme)
- item.XtDialysisOrderSix = order
- solutionLastWeek, _ := service.GetDialysisSolutionLastWeek(adminUserInfo.CurrentOrgId, item.PatientId, item.ModeId)
- item.DialysisSolution = solutionLastWeek
- if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
-
- dialysisprescription, _ := service.GetLastDialysisSolution(adminUserInfo.CurrentOrgId, item.PatientId, item.ModeId, item.ScheduleDate)
- item.DialysisPrescription = dialysisprescription
-
- }
-
- }
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "schedule": schedule,
- })
- }
-
- func (this *ScheduleApiController) GetNextWeekDaySchedule() {
-
- week_type, _ := this.GetInt64("week_type", -1)
- week_time, _ := this.GetInt64("week_time")
- record_date := this.GetString("record_date")
-
- zons := this.GetString("zone")
- zone := strings.Split(zons, ",")
-
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
-
- adminUserInfo := this.GetAdminUserInfo()
- var theStartTIme int64
- if len(record_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- }
- theStartTIme = theTime.Unix()
- }
-
- schedule, err := service.GetNextWeekDaySchedule(week_type, week_time, theTimeStart.Unix(), theTimeEnd.Unix(), adminUserInfo.CurrentOrgId, zone, theStartTIme)
-
- for _, item := range schedule {
- AssessmentBefor, _ := service.GetAssessmentBeforListLastWeek(item.ScheduleDate, item.PatientId, item.UserOrgId)
- item.XtAssessmentBeforeDislysis = AssessmentBefor
- doctorAdvices, _ := service.GetDoctorAdviceLastWeek(item.UserOrgId, item.PatientId, item.ScheduleDate)
- item.DoctorAdvice = doctorAdvices
-
- hisDoctorAdvice, _ := service.GetHisDoctorAdviceListLastWeek(item.UserOrgId, item.PatientId, item.ScheduleDate)
-
- item.HisDoctorAdviceInfo = hisDoctorAdvice
-
- solutionLastWeek, _ := service.GetDialysisSolutionLastWeek(item.UserOrgId, item.PatientId, item.ModeId)
- item.DialysisSolution = solutionLastWeek
- }
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "schedule": schedule,
- })
- }
-
- func (this *ScheduleApiController) GetThreeWeekList() {
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- partition_id, _ := this.GetInt64("partition_id")
- schedule_type, _ := this.GetInt64("schedule_type")
- fmt.Println(partition_id, schedule_type)
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var theStartTIme int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- }
- theStartTIme = theTime.Unix()
- }
- var theEndtTIme int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- }
- theEndtTIme = theTime.Unix()
- }
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- partitions, _ := service.GetSchedulePartitionPanel(orgId)
- list, err := service.GetThreeWeekList(theStartTIme, theEndtTIme, orgId, schedule_type, partition_id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "partitions": partitions,
- })
- }
-
- func (this *ScheduleApiController) GetAllZones() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- zones, err := service.GetAllZoneOne(orgId)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "zones": zones,
- })
- }
-
- func (this *ScheduleApiController) GetCopyPatientSchedules() {
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- start_time, _ := this.GetInt64("start_time")
- fmt.Println("start_time", start_time)
- end_time, _ := this.GetInt64("end_time")
- fmt.Println("end_time", end_time)
- copy_startime, _ := this.GetInt64("copy_startime")
- fmt.Println("copy_startime", copy_startime)
- copy_endtime, _ := this.GetInt64("copy_endtime")
-
- //获取本周患者排班
- schedules, _ := service.GetWeekSchedules(orgId, start_time, end_time)
-
- //先清除复制周的排班
- errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
- fmt.Println(errcode)
- var err error
- for _, item := range schedules {
- //fmt.Println(item.StartTime+604800)
- //礼拜1
- if item.ScheduleWeek == 1 {
- item.ScheduleDate = copy_startime
- }
- if item.ScheduleWeek == 2 {
- item.ScheduleDate = copy_startime + 86400
- }
- if item.ScheduleWeek == 3 {
- item.ScheduleDate = copy_startime + 172800
- }
- if item.ScheduleWeek == 4 {
- item.ScheduleDate = copy_startime + 259200
- }
- if item.ScheduleWeek == 5 {
- item.ScheduleDate = copy_startime + 345600
- }
-
- if item.ScheduleWeek == 6 {
- item.ScheduleDate = copy_startime + 432000
- }
- //礼拜天
- if item.ScheduleWeek == 7 {
- item.ScheduleDate = copy_endtime
- }
- schedule := models.XtSchedule{
- UserOrgId: item.UserOrgId,
- PartitionId: item.PartitionId,
- BedId: item.BedId,
- PatientId: item.PatientId,
- ScheduleDate: item.ScheduleDate,
- ScheduleType: item.ScheduleType,
- ScheduleWeek: item.ScheduleWeek,
- ModeId: item.ModeId,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- }
-
- var DialysisMachineName string
-
- so, _ := service.GetDialysisSolutionTwo(adminUserInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
- filedRecordOne, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器")
- filedRecordTwo, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "灌流器")
- filedRecordThree, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器/灌流器")
-
- if filedRecordOne.IsShow == 1 {
- DialysisMachineName = so.DialysisDialyszers
- }
- if filedRecordThree.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
-
- } else {
- DialysisMachineName = so.DialyzerPerfusionApparatus
-
- }
- }
- if filedRecordTwo.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
-
- } else {
- DialysisMachineName = so.DialysisIrrigation
-
- }
- }
- schedule.DialysisMachineName = DialysisMachineName
- schedule.IsExport = 4000
- err = service.AddPatientSchedule(&schedule)
-
- }
- patientList, _ := service.GetDeathPatient(this.GetAdminUserInfo().CurrentOrgId)
- timeStr := time.Now().Format("2006-01-02")
- timeLayout := "2006-01-02 15:04:05"
- timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
- timenow := timeStringToTime.Unix()
- for _, it := range patientList {
- service.UpdateScheduleByDeathTime(it.ID, timenow)
- service.UpdateScheduleItemByPatientId(it.ID)
- }
-
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "msg",
- })
- return
- //查询复制中的排班日期是否存在
- //_, errcode := service.GetLastWeekSchedule(orgId, copy_startime, copy_endtime)
- //
- //if errcode == gorm.ErrRecordNotFound {
- // //如果没有直接新增
- //
- // for _, item := range schedules {
- // //fmt.Println(item.StartTime+604800)
- // //礼拜1
- // if item.ScheduleWeek == 1 {
- // item.ScheduleDate = copy_startime
- // }
- // if item.ScheduleWeek == 2 {
- // item.ScheduleDate = copy_startime + 86400
- // }
- // if item.ScheduleWeek == 3 {
- // item.ScheduleDate = copy_startime + 172800
- // }
- // if item.ScheduleWeek == 4 {
- // item.ScheduleDate = copy_startime + 259200
- // }
- // if item.ScheduleWeek == 5 {
- // item.ScheduleDate = copy_startime + 345600
- // }
- //
- // if item.ScheduleWeek == 6 {
- // item.ScheduleDate = copy_startime + 432000
- // }
- // //礼拜天
- // if item.ScheduleWeek == 0 {
- // item.ScheduleDate = copy_endtime
- // }
- // schedule := models.XtSchedule{
- // UserOrgId: item.UserOrgId,
- // PartitionId: item.PartitionId,
- // BedId: item.BedId,
- // PatientId: item.PatientId,
- // ScheduleDate: item.ScheduleDate,
- // ScheduleType: item.ScheduleType,
- // ScheduleWeek: item.ScheduleWeek,
- // ModeId: item.ModeId,
- // Status: 1,
- // CreatedTime: time.Now().Unix(),
- // }
- //
- // err := service.AddPatientSchedule(&schedule)
- // if err != nil {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // }
- // this.ServeSuccessJSON(map[string]interface{}{
- // "schedule": schedule,
- // })
- // }
- //} else if errcode == nil {
- //
- // //先清除复制周的排班
- // errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
- // fmt.Println(errcode)
- // for _, item := range schedules {
- // //fmt.Println(item.StartTime+604800)
- // //礼拜1
- // if item.ScheduleWeek == 1 {
- // item.ScheduleDate = copy_startime
- // }
- // if item.ScheduleWeek == 2 {
- // item.ScheduleDate = copy_startime + 86400
- // }
- // if item.ScheduleWeek == 3 {
- // item.ScheduleDate = copy_startime + 172800
- // }
- // if item.ScheduleWeek == 4 {
- // item.ScheduleDate = copy_startime + 259200
- // }
- // if item.ScheduleWeek == 5 {
- // item.ScheduleDate = copy_startime + 345600
- // }
- //
- // if item.ScheduleWeek == 6 {
- // item.ScheduleDate = copy_startime + 432000
- // }
- // //礼拜天
- // if item.ScheduleWeek == 0 {
- // item.ScheduleDate = copy_endtime
- // }
- // schedule := models.XtSchedule{
- // UserOrgId: item.UserOrgId,
- // PartitionId: item.PartitionId,
- // BedId: item.BedId,
- // PatientId: item.PatientId,
- // ScheduleDate: item.ScheduleDate,
- // ScheduleType: item.ScheduleType,
- // ScheduleWeek: item.ScheduleWeek,
- // ModeId: item.ModeId,
- // Status: 1,
- // CreatedTime: time.Now().Unix(),
- // }
- //
- // err := service.AddPatientSchedule(&schedule)
- // if err != nil {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // }
- // this.ServeSuccessJSON(map[string]interface{}{
- // "schedule": schedule,
- // })
- // }
- //}
- }
-
- func (this *ScheduleApiController) SaveRemindPrint() {
-
- id, _ := this.GetInt64("id")
- anticoagulants, _ := this.GetInt64("anticoagulant")
- anticoagulant_zongliang, _ := this.GetInt64("anticoagulant_zongliang")
- classes, _ := this.GetInt64("classes")
- dialyzers, _ := this.GetInt64("dialyzers")
- doctor_advice, _ := this.GetInt64("doctor_advice")
- mode, _ := this.GetInt64("mode")
- name, _ := this.GetInt64("name")
- number, _ := this.GetInt64("number")
- perfusion_apparatus, _ := this.GetInt64("perfusion_apparatus")
- prescription_status, _ := this.GetInt64("prescription_status")
- week, _ := this.GetInt64("week")
- zone, _ := this.GetInt64("zone")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- setting := models.XtRemindPrintSetting{
- Anticoagulant: anticoagulants,
- Classes: classes,
- AnticoagulantZongliang: anticoagulant_zongliang,
- Dialyzers: dialyzers,
- DoctorAdvice: doctor_advice,
- Mode: mode,
- Name: name,
- Number: number,
- PerfusionApparatus: perfusion_apparatus,
- PrescriptionStatus: prescription_status,
- Week: week,
- Zone: zone,
- UserOrgId: orgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- }
- _, errcode := service.GetSettingById(id)
- if errcode == gorm.ErrRecordNotFound {
- err := service.CreateSetting(&setting)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "setting": setting,
- })
- } else if errcode == nil {
- err := service.UpdatedRemindPrint(&setting, id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "setting": setting,
- })
- }
-
- }
- func (this *ScheduleApiController) GetRemindPrintList() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- list, err := service.GetRemindPrintList(orgId)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *ScheduleApiController) GetBloodScheduleList() {
-
- week_type, _ := this.GetInt64("week_type", -1)
- week_time, _ := this.GetInt64("week_time")
- zones := this.GetString("zone")
- zone := strings.Split(zones, ",")
- thisTime := time.Now()
- weekDay := int(thisTime.Weekday())
- if weekDay == 0 {
- weekDay = 7
- }
- weekEnd := 7 - weekDay
- weekStart := weekEnd - 6
- weekTitle := make([]string, 0)
- days := make([]string, 0)
- for index := weekStart; index <= weekEnd; index++ {
- theDay := thisTime.AddDate(0, 0, index)
- indexYear, indexMonthTime, indexDay := theDay.Date()
- indexMonth := int(indexMonthTime)
- indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
- weekTitle = append(weekTitle, indexWeek)
- days = append(days, theDay.Format("2006-01-02"))
- }
- fmt.Println(days)
-
- var targetDayStr string
- var startTime string
- switch week_type {
- case 0:
- startTime = days[0]
- targetDayStr = days[6]
- break
- case 1:
- targetDayStr = days[0]
- break
- case 2:
- targetDayStr = days[1]
-
- break
- case 3:
- targetDayStr = days[2]
-
- break
- case 4:
- targetDayStr = days[3]
-
- break
- case 5:
- targetDayStr = days[4]
-
- break
- case 6:
- targetDayStr = days[5]
-
- break
- case 7:
- targetDayStr = days[6]
-
- break
- }
- targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
-
- if parseErr != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- if week_type > 0 {
- list, err := service.GetWeekDayScheduleByIdThee(orgId, targetDay.Unix(), week_time, zone)
- for _, item := range list {
- order, _ := service.GetLastDialysisOrder(orgId, item.PatientId, targetDay.Unix())
- item.XtDialysisOrderSix = order
- if orgId == 9671 || orgId == 9675 || orgId == 10340 {
-
- solution, _ := service.GetLastDialysisSolution(orgId, item.PatientId, item.ModeId, item.ScheduleDate)
- item.DialysisPrescription = solution
- }
-
- }
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "day": targetDayStr,
- })
- }
-
- if week_type == 0 {
- startDate, _ := utils.ParseTimeStringToTime("2006-01-02", startTime)
- list, err := service.GetWeekDayScheduleByIdTwo(orgId, targetDay.Unix(), week_time, startDate.Unix(), zone)
- for _, item := range list {
-
- order, _ := service.GetLastDialysisOrder(orgId, item.PatientId, targetDay.Unix())
- item.XtDialysisOrderSix = order
- if orgId == 9671 || orgId == 9675 || orgId == 10340 {
-
- solution, _ := service.GetLastDialysisSolution(orgId, item.PatientId, item.ModeId, item.ScheduleDate)
- item.DialysisPrescription = solution
- }
-
- }
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "day": targetDayStr,
- })
- }
-
- }
-
- func (this *ScheduleApiController) GetPrintList() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
-
- list, err := service.GetRemindPrintList(orgId)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *ScheduleApiController) GetAllZoneList() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- zoneList, err := service.GetAllZoneOne(orgId)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "zoneList": zoneList,
- })
- }
-
- func (this *ScheduleApiController) GetPatientScheduleCount() {
- patitionIdStr := this.GetString("partition_id")
- week, _ := this.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
- ids := strings.Split(patitionIdStr, ",")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- thisTime := time.Now()
- weekDay := int(thisTime.Weekday())
- if week < 1 || week > 4 {
- week = 2
- }
- if week == 1 {
- thisTime = thisTime.AddDate(0, 0, -7)
- } else if week == 3 {
- thisTime = thisTime.AddDate(0, 0, 7)
- } else if week == 4 {
- thisTime = thisTime.AddDate(0, 0, 14)
- }
- if weekDay == 0 {
- weekDay = 7
- }
- weekEnd := 7 - weekDay
- weekStart := weekEnd - 6
- weekTitle := make([]string, 0)
- days := make([]string, 0)
- for index := weekStart; index <= weekEnd; index++ {
- theDay := thisTime.AddDate(0, 0, index)
- indexYear, indexMonthTime, indexDay := theDay.Date()
- indexMonth := int(indexMonthTime)
- indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
- weekTitle = append(weekTitle, indexWeek)
- days = append(days, theDay.Format("2006-01-02"))
- }
-
- weekStartDay := thisTime.AddDate(0, 0, weekStart)
- weekEndDay := thisTime.AddDate(0, 0, weekEnd)
- weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
- weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
-
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
- theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
- weekStartPoint := theStarTime.Unix()
- weekEndPoint := theEndTime.Unix()
-
- list, err := service.GetPatientScheduleCount(orgId, weekStartPoint, weekEndPoint, ids)
- _, total, _ := service.GetTotalBedNumber(orgId, ids)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- })
- }
-
- func (c *ScheduleApiController) GetWeekPanelsOne() {
-
- data, _ := c.GetInt64("data", 1)
- patitionIdStr := c.GetString("patitionid")
-
- ids := strings.Split(patitionIdStr, ",")
-
- adminInfo := c.GetAdminUserInfo()
- thisTime := time.Now()
- year, monthTime, day := thisTime.Date()
- month := int(monthTime)
- _, theWeek := thisTime.ISOWeek()
- weekDay := int(thisTime.Weekday())
- if weekDay == 0 {
- weekDay = 7
- }
- weekEnd := 7 - weekDay
- weekStart := weekEnd - 6
- weekDays := make([]string, 0)
- for index := weekStart; index <= weekEnd; index++ {
- theDay := thisTime.AddDate(0, 0, index)
- indexYear, indexMonthTime, indexDay := theDay.Date()
- indexMonth := int(indexMonthTime)
- indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
- weekDays = append(weekDays, indexWeek)
- }
-
- returnData := map[string]interface{}{
- "year": year,
- "month": month,
- "day": day,
- "theWeek": theWeek,
- "weekDay": weekDay,
- "weekDays": weekDays,
- }
-
- if data == 1 {
- partitions, _ := service.GetSchedulePartitionPanelTwo(adminInfo.CurrentOrgId, ids)
- returnData["partitions"] = partitions
- }
-
- c.ServeSuccessJSON(returnData)
- return
- }
-
- func (c *ScheduleApiController) GetScheduleOne() {
-
- week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
- patitionIdStr := c.GetString("patitionid")
-
- ids := strings.Split(patitionIdStr, ",")
- fmt.Println("patitonStr", ids)
- schedule_type, _ := c.GetInt64("schedule_type")
-
- adminInfo := c.GetAdminUserInfo()
-
- thisTime := time.Now()
- today := thisTime.Format("2006-01-02")
- if week < 1 || week > 4 {
- week = 2
- }
- if week == 1 {
- thisTime = thisTime.AddDate(0, 0, -7)
- } else if week == 3 {
- thisTime = thisTime.AddDate(0, 0, 7)
- } else if week == 4 {
- thisTime = thisTime.AddDate(0, 0, 14)
- }
-
- weekDay := int(thisTime.Weekday())
- if weekDay == 0 {
- weekDay = 7
- }
- weekEnd := 7 - weekDay
- weekStart := weekEnd - 6
- weekTitle := make([]string, 0)
- days := make([]string, 0)
- for index := weekStart; index <= weekEnd; index++ {
- theDay := thisTime.AddDate(0, 0, index)
- indexYear, indexMonthTime, indexDay := theDay.Date()
- indexMonth := int(indexMonthTime)
- indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
- weekTitle = append(weekTitle, indexWeek)
- days = append(days, theDay.Format("2006-01-02"))
- }
-
- weekStartDay := thisTime.AddDate(0, 0, weekStart)
- weekEndDay := thisTime.AddDate(0, 0, weekEnd)
- weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
- weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
-
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
- theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
- weekStartPoint := theStarTime.Unix()
- weekEndPoint := theEndTime.Unix()
-
- schdules, _ := service.GetWeekScheduleTwo(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "days": days,
- "weekTitle": weekTitle,
- "schdules": schdules,
- "today": today,
- })
- return
- }
-
- func (c *ScheduleApiController) GetScheduleTwo() {
-
- week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
- patitionIdStr := c.GetString("patitionid")
-
- ids := strings.Split(patitionIdStr, ",")
-
- schedule_type, _ := c.GetInt64("schedule_type")
-
- adminInfo := c.GetAdminUserInfo()
- weekDateStr := c.GetString("week_date")
- WeekDayIds := strings.Split(weekDateStr, ",")
-
- thisTime := time.Now()
- today := thisTime.Format("2006-01-02")
- if week < 1 || week > 4 {
- week = 2
- }
- if week == 1 {
- thisTime = thisTime.AddDate(0, 0, -7)
- } else if week == 3 {
- thisTime = thisTime.AddDate(0, 0, 7)
- } else if week == 4 {
- thisTime = thisTime.AddDate(0, 0, 14)
- }
-
- weekDay := int(thisTime.Weekday())
- if weekDay == 0 {
- weekDay = 7
- }
- weekEnd := 7 - weekDay
- weekStart := weekEnd - 6
- weekTitle := make([]string, 0)
- days := make([]string, 0)
- for index := weekStart; index <= weekEnd; index++ {
- theDay := thisTime.AddDate(0, 0, index)
- indexYear, indexMonthTime, indexDay := theDay.Date()
- indexMonth := int(indexMonthTime)
- indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
- weekTitle = append(weekTitle, indexWeek)
- days = append(days, theDay.Format("2006-01-02"))
- }
-
- weekStartDay := thisTime.AddDate(0, 0, weekStart)
- weekEndDay := thisTime.AddDate(0, 0, weekEnd)
- weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
- weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
-
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
- theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
- weekStartPoint := theStarTime.Unix()
- weekEndPoint := theEndTime.Unix()
-
- schdules, _ := service.GetWeekScheduleThree(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type, WeekDayIds)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "days": days,
- "weekTitle": weekTitle,
- "schdules": schdules,
- "today": today,
- })
- return
- }
-
- func (c *ScheduleApiController) SaveScheduleTemplate() {
-
- template_id, _ := c.GetInt64("template_id")
- orgId := c.GetAdminUserInfo().CurrentOrgId
- template := models.ScheduleTemplate{
- TemplateId: template_id,
- UserOrgId: orgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- }
-
- _, errcodes := service.GetScheudleTemplateById(orgId)
- if errcodes == gorm.ErrRecordNotFound {
- service.CreateXtscheduleTemplate(&template)
- } else if errcodes == nil {
- service.UpdateXtScheduleTemplate(&template, orgId)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "template": template,
- })
- return
-
- }
-
- func (c *ScheduleApiController) GetScheduleTemplate() {
-
- adminUserInfo := c.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- template, _ := service.GetScheduleTemplate(orgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "template": template,
- })
- return
- }
-
- func (c *ScheduleApiController) ChangeFuncPrint() {
-
- adminUserInfo := c.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- is_open, _ := c.GetInt64("is_open")
- dataPrint := models.XtDataPrint{
- UserOrgId: orgId,
- IsOpen: is_open,
- Status: 1,
- Ctime: time.Now().Unix(),
- }
-
- _, errcode := service.GetDataPrintByOrgId(orgId)
- if errcode == gorm.ErrRecordNotFound {
- service.CreateDataPrint(&dataPrint)
- c.ServeSuccessJSON(map[string]interface{}{
- "dataPrint": dataPrint,
- })
- return
- } else if errcode == nil {
- service.UpdteDataPrint(orgId, &dataPrint)
- c.ServeSuccessJSON(map[string]interface{}{
- "dataPrint": dataPrint,
- })
- return
- }
-
- }
-
- func (c *ScheduleApiController) GetDataPrint() {
-
- adminUserInfo := c.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
-
- dataPrint, _ := service.GetDataPrint(orgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "dataPrint": dataPrint,
- })
- return
- }
-
- func (c *ScheduleApiController) GetNextWeekPanels() {
- start_time, _ := c.GetInt64("start_time")
- fmt.Println("start_time", start_time)
- end_time, _ := c.GetInt64("end_time")
- fmt.Println("end_time", end_time)
- orgId := c.GetAdminUserInfo().CurrentOrgId
- schedule, _ := service.GetNextWeekPanels(start_time, end_time, orgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "schedule": schedule,
- })
- }
-
- func (c *ScheduleApiController) SynchroSchedule() {
-
- template_id, _ := c.GetInt64("template_id")
- copy_startime, _ := c.GetInt64("copy_startime")
- copy_endtime, _ := c.GetInt64("copy_endtime")
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- //根据模板ID获取模板数据
- list, _ := service.GetTemplateListByTemplateId(template_id, orgId)
- fmt.Println(len(list))
-
- //数据去重操作
- list = RemoveRepeatedScheduleTemplate(list)
-
- recordDateStr := time.Now().Format("2006-01-02")
- recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- nowtime := recordDate.Unix()
- fmt.Println("今日时间", nowtime)
- fmt.Println("后期日期", copy_startime)
- var tuesday int64
- var wednesday int64
- var thursday int64
- var friday int64
- var saturday int64
- //
- //如果选择的开始日期大于当前日期
- if copy_startime > nowtime {
- //清空该时间段的所有排班数据
- service.DeletePatientSchedule(copy_startime, copy_endtime, orgId)
- tuesday = copy_startime + 86400
- wednesday = copy_startime + 172800
- thursday = copy_startime + 259200
- friday = copy_startime + 345600
- saturday = copy_startime + 432000
- for _, item := range list {
- if item.Weekday == 1 {
- item.ScheduleDate = copy_startime
- }
- if item.Weekday == 2 {
- item.ScheduleDate = tuesday
- }
- if item.Weekday == 3 {
- item.ScheduleDate = wednesday
- }
- if item.Weekday == 4 {
- item.ScheduleDate = thursday
- }
- if item.Weekday == 5 {
- item.ScheduleDate = friday
- }
- if item.Weekday == 6 {
- item.ScheduleDate = saturday
- }
- if item.Weekday == 7 {
- item.ScheduleDate = copy_endtime
- }
-
- //根据床位号获取区号
- number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
- item.ZoneId = number.ZoneID
- }
- for _, item := range list {
- schedule := models.XtSchedule{
- UserOrgId: orgId,
- PartitionId: item.ZoneId,
- BedId: item.DeviceNumberID,
- PatientId: item.PatientID,
- ScheduleDate: item.ScheduleDate,
- ScheduleType: item.TimeType,
- ScheduleWeek: item.Weekday,
- ModeId: item.TreatMode,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: 0,
- IsExport: 2000,
- }
-
- var DialysisMachineName string
- so, _ := service.GetDialysisSolutionTwo(c.GetAdminUserInfo().CurrentOrgId, schedule.PatientId, schedule.ModeId)
- filedRecordOne, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器")
- filedRecordTwo, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "灌流器")
- filedRecordThree, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器/灌流器")
-
- if filedRecordOne.IsShow == 1 {
- DialysisMachineName = so.DialysisDialyszers
- }
- if filedRecordThree.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
-
- } else {
- DialysisMachineName = so.DialyzerPerfusionApparatus
-
- }
- }
- if filedRecordTwo.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
-
- } else {
- DialysisMachineName = so.DialysisIrrigation
-
- }
- }
- schedule.DialysisMachineName = DialysisMachineName
-
- service.CreatePatientSchedule(&schedule)
- }
- }
- //如果选择的日期小于当前日期,只同步今日以后的数据
- if copy_startime <= nowtime {
- //清空今日以后的数据
- service.DeletePatientScheduleToday(nowtime, copy_endtime, orgId)
- var tuesday int64
- var wednesday int64
- var thursday int64
- var friday int64
- var saturday int64
-
- tuesday = copy_startime + 86400
- wednesday = copy_startime + 172800
- thursday = copy_startime + 259200
- friday = copy_startime + 345600
- saturday = copy_startime + 432000
-
- for _, item := range list {
- if item.Weekday == 1 {
- item.ScheduleDate = copy_startime
- }
- if item.Weekday == 2 {
- item.ScheduleDate = tuesday
- }
- if item.Weekday == 3 {
- item.ScheduleDate = wednesday
- }
- if item.Weekday == 4 {
- item.ScheduleDate = thursday
- }
- if item.Weekday == 5 {
- item.ScheduleDate = friday
- }
- if item.Weekday == 6 {
- item.ScheduleDate = saturday
- }
- if item.Weekday == 7 {
- item.ScheduleDate = copy_endtime
- }
-
- //根据床位号获取区号
- number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
- item.ZoneId = number.ZoneID
- }
- for _, item := range list {
- // 同步今日以后的数据
- if item.ScheduleDate > nowtime {
- schedule := models.XtSchedule{
- UserOrgId: orgId,
- PartitionId: item.ZoneId,
- BedId: item.DeviceNumberID,
- PatientId: item.PatientID,
- ScheduleDate: item.ScheduleDate,
- ScheduleType: item.TimeType,
- ScheduleWeek: item.Weekday,
- ModeId: item.TreatMode,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: 0,
- }
-
- var DialysisMachineName string
- so, _ := service.GetDialysisSolutionTwo(c.GetAdminUserInfo().CurrentOrgId, schedule.PatientId, schedule.ModeId)
- filedRecordOne, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器")
- filedRecordTwo, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "灌流器")
- filedRecordThree, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器/灌流器")
-
- if filedRecordOne.IsShow == 1 {
- DialysisMachineName = so.DialysisDialyszers
- }
- if filedRecordThree.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
-
- } else {
- DialysisMachineName = so.DialyzerPerfusionApparatus
-
- }
- }
- if filedRecordTwo.IsShow == 1 {
- if len(schedule.DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
-
- } else {
- DialysisMachineName = so.DialysisIrrigation
-
- }
- }
- schedule.DialysisMachineName = DialysisMachineName
- service.CreatePatientSchedule(&schedule)
- }
- }
- }
-
- returnData := make(map[string]interface{}, 0)
- returnData["list"] = list
- c.ServeSuccessJSON(returnData)
- return
- }
-
- func (c *ScheduleApiController) GetPatientScheduleTempalate() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- tempalate, _ := service.GetPatientScheduleTempalate(orgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "schedule": tempalate,
- })
- }
-
- func (c *ScheduleApiController) GetSolutionSchedule() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- solution, _ := service.GetSolutionSchedule(orgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "solution": solution,
- })
- return
- }
-
- func RemoveRepeatedScheduleTemplate(arr []*models.VmPatientScheduleTemplateItem) (newArr []*models.VmPatientScheduleTemplateItem) {
- newArr = make([]*models.VmPatientScheduleTemplateItem, 0)
- for i := 0; i < len(arr); i++ {
- repeat := false
- for j := i + 1; j < len(arr); j++ {
- if arr[i].TemplateID == arr[j].TemplateID && arr[i].PatientID == arr[j].PatientID && arr[i].Weekday == arr[j].Weekday {
- repeat = true
- break
- }
- }
- if !repeat {
- newArr = append(newArr, arr[i])
- }
- }
- return
- }
-
- func (c *ScheduleApiController) DeleteScheduleTwo() {
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminINfo := c.GetAdminUserInfo()
-
- schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
- timeNow := time.Now().Format("2006-01-02")
- timeTemplate := "2006-01-02"
-
- tm := time.Unix(int64(schedule.ScheduleDate), 0)
- timeStr := tm.Format(timeTemplate)
- if timeNow > timeStr {
- utils.ErrorLog(timeNow)
- utils.ErrorLog(timeStr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
- return
- }
- if schedule == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
- return
- }
-
- order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- if order != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysisTwo)
- return
- }
-
- schedule.Status = 0
- schedule.UpdatedTime = time.Now().Unix()
- err = service.UpdateSchedule(schedule)
- redis := service.RedisClient()
-
- //处方
- keyOne := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
- redis.Set(keyOne, "", time.Second)
-
- //医嘱
- keyTwo := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
-
- keySix := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
- redis.Set(keySix, "", time.Second)
- keyThree := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
- redis.Set(keyThree, "", time.Second)
-
- keyFour := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
- redis.Set(keyFour, "", time.Second)
-
- keyFive := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
- redis.Set(keyFive, "", time.Second)
-
- keySeven := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
- redis.Set(keySeven, "", time.Second)
- fmt.Println(err)
- defer redis.Close()
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteScheduleFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "schedule": &schedule,
- })
- }
|