schedule_api_controller.go 183KB

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