schedule_api_controller.go 156KB

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