schedule_api_controller.go 182KB

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