dialysis_api_controller.go 276KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/astaxie/beego"
  6. "github.com/jinzhu/gorm"
  7. "reflect"
  8. "strconv"
  9. "strings"
  10. "time"
  11. "XT_New/enums"
  12. "XT_New/models"
  13. "XT_New/service"
  14. "XT_New/utils"
  15. "math"
  16. )
  17. // type DialysisTestAPIController struct {
  18. // MobileBaseAPIController
  19. // }
  20. // [get]/m/api/test
  21. // func (this *DialysisTestAPIController) Test() {
  22. // orgID := int64(3907)
  23. // now := time.Now()
  24. // nextWeek := now.AddDate(0, 0, 7)
  25. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  26. // nextTwoWeek := now.AddDate(0, 0, 14)
  27. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  28. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  29. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  30. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  31. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  32. // return
  33. // }
  34. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  35. // if exchangeErr != nil {
  36. // this.ErrorLog("%v", exchangeErr)
  37. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  38. // return
  39. // }
  40. // this.ServeSuccessJSON(map[string]interface{}{
  41. // // "now": now,
  42. // // "next_week": nextWeek,f
  43. // // "next_week_mon": nextWeekMon,
  44. // // "next_week_sun": nextWeekSun,
  45. // // "next_two_week_mon": nextTwoWeekMon,
  46. // // "next_two_week_sun": nextTwoWeekSun,
  47. // "next_week_schs": nextWeekSchs,
  48. // "next_two_week_schs": nextTwoWeekSchs,
  49. // })
  50. // }
  51. type DialysisAPIController struct {
  52. MobileBaseAPIAuthController
  53. }
  54. // /m/api/scheduals [get]
  55. // @param type:int
  56. // @param date:string
  57. func (this *DialysisAPIController) Scheduals() {
  58. schedualType, _ := this.GetInt64("type")
  59. schedualDate := this.GetString("date")
  60. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  61. schedualType = 0
  62. }
  63. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  64. if parseDateErr != nil {
  65. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  66. return
  67. }
  68. adminInfo := this.GetMobileAdminUserInfo()
  69. orgID := adminInfo.Org.Id
  70. redis := service.RedisClient()
  71. defer redis.Close()
  72. // cur_date := time.Now().Format("2006-01-02")
  73. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  74. scheduals_json_str, _ := redis.Get(key).Result()
  75. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  76. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  77. if err != nil {
  78. this.ErrorLog("获取排班信息失败:%v", err)
  79. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  80. } else {
  81. if len(scheduals) > 0 {
  82. //缓存数据
  83. scheduals_json, err := json.Marshal(scheduals)
  84. if err == nil {
  85. redis.Set(key, scheduals_json, time.Minute*1)
  86. }
  87. }
  88. this.ServeSuccessJSON(map[string]interface{}{
  89. "scheduals": scheduals,
  90. })
  91. }
  92. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  93. var dat []map[string]interface{}
  94. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  95. } else {
  96. }
  97. this.ServeSuccessJSON(map[string]interface{}{
  98. "scheduals": dat,
  99. "redis": "true",
  100. "date": schedualDate,
  101. })
  102. }
  103. }
  104. // /m/api/waiting_scheduals [get]
  105. // @param date:string
  106. func (this *DialysisAPIController) WaitingScheduals() {
  107. schedualDate := this.GetString("date")
  108. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  109. if parseDateErr != nil && len(schedualDate) != 0 {
  110. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  111. return
  112. }
  113. adminInfo := this.GetMobileAdminUserInfo()
  114. orgID := adminInfo.Org.Id
  115. redis := service.RedisClient()
  116. defer redis.Close()
  117. // cur_date := time.Now().Format("2006-01-02")
  118. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  119. wait_scheduals, _ := redis.Get(key).Result()
  120. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  121. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  122. if err != nil {
  123. this.ErrorLog("获取排班信息失败:%v", err)
  124. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  125. } else {
  126. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  127. for _, s := range scheduals {
  128. returnScheduals = append(returnScheduals, s)
  129. }
  130. if len(returnScheduals) > 0 {
  131. //缓存数据
  132. wait_scheduals_json, err := json.Marshal(scheduals)
  133. if err == nil {
  134. redis.Set(key, wait_scheduals_json, time.Minute*2)
  135. }
  136. }
  137. this.ServeSuccessJSON(map[string]interface{}{
  138. "scheduals": scheduals,
  139. })
  140. }
  141. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  142. var dat []map[string]interface{}
  143. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  144. } else {
  145. }
  146. this.ServeSuccessJSON(map[string]interface{}{
  147. "scheduals": dat,
  148. "redis": "true",
  149. "date": schedualDate,
  150. })
  151. }
  152. }
  153. //else{
  154. // fmt.Println("33333333")
  155. //
  156. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  157. // if err != nil {
  158. // this.ErrorLog("获取排班信息失败:%v", err)
  159. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  160. // } else {
  161. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  162. // for _, s := range scheduals {
  163. //
  164. // returnScheduals = append(returnScheduals, s)
  165. // }
  166. //
  167. // this.ServeSuccessJSON(map[string]interface{}{
  168. // "scheduals": returnScheduals,
  169. // })
  170. // }
  171. //
  172. // }
  173. //if err == nil{
  174. //
  175. //
  176. //
  177. //
  178. //
  179. //}else{
  180. //}
  181. // /m/api/dialysis/record [get]
  182. // @param patient_id:int
  183. // @param date:string (yyyy-MM-dd)
  184. func (this *DialysisAPIController) DialysisRecord() {
  185. patientID, _ := this.GetInt64("patient_id")
  186. recordDateStr := this.GetString("date")
  187. if patientID <= 0 {
  188. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  189. return
  190. }
  191. if len(recordDateStr) == 0 {
  192. recordDateStr = time.Now().Format("2006-01-02")
  193. }
  194. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  195. if parseDateErr != nil {
  196. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  197. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  198. return
  199. }
  200. adminInfo := this.GetMobileAdminUserInfo()
  201. patient, getPatientErr := service.MobileGetPatientDetail(adminInfo.Org.Id, patientID)
  202. if getPatientErr != nil {
  203. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  204. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  205. return
  206. } else if patient == nil {
  207. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  208. return
  209. }
  210. schedual, getSchedualErr := service.MobileGetSchedualDetail(adminInfo.Org.Id, patientID, date.Unix())
  211. // this.TraceLog("==================================%+v", schedual)
  212. if getSchedualErr != nil {
  213. this.ErrorLog("获取患者排班信息失败:%v", getSchedualErr)
  214. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  215. return
  216. }
  217. receiverTreatmentAccess, getRTARErr := service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  218. if getRTARErr != nil {
  219. this.ErrorLog("获取接诊评估失败:%v", getRTARErr)
  220. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  221. return
  222. }
  223. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  224. if getPEErr != nil {
  225. this.ErrorLog("获取透前评估失败:%v", getPEErr)
  226. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  227. return
  228. }
  229. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  230. if getLPEErr != nil {
  231. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  232. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  233. return
  234. }
  235. doctorAdvices, getDoctorAdvicesErr := service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  236. if getDoctorAdvicesErr != nil {
  237. this.ErrorLog("获取临时医嘱失败:%v", getDoctorAdvicesErr)
  238. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  239. return
  240. }
  241. dialysisOrder, getDialysisOrderErr := service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  242. fmt.Println("----------------------------", getDialysisOrderErr)
  243. if getDialysisOrderErr != nil {
  244. this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
  245. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  246. return
  247. }
  248. doubleCheck, getDoubleCheckErr := service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  249. if getDoubleCheckErr != nil {
  250. this.ErrorLog("获取双人核对记录失败:%v", getDoubleCheckErr)
  251. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  252. return
  253. }
  254. monitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  255. if getMonitorRecordsErr != nil {
  256. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  257. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  258. return
  259. }
  260. var lastMonitorRecord *models.MonitoringRecord
  261. lastMonitorRecord, getLastErr := service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  262. if getLastErr != nil {
  263. this.ErrorLog("获取上一次透析的监测记录失败:%v", getLastErr)
  264. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  265. return
  266. }
  267. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  268. if getAADErr != nil {
  269. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  270. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  271. return
  272. }
  273. lastAssessmentAfterDislysis, getLAADErr := service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  274. if getLAADErr != nil {
  275. this.ErrorLog("获取上一次透后评估失败:%v", getLAADErr)
  276. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  277. return
  278. }
  279. treatmentSummary, getTreatmentSummaryErr := service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  280. if getTreatmentSummaryErr != nil {
  281. this.ErrorLog("获取治疗小结失败:%v", getTreatmentSummaryErr)
  282. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  283. return
  284. }
  285. dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  286. //if getDialysisPrescribeErr != nil {
  287. // this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  288. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  289. // return
  290. //}
  291. dialysisSolution, _ := service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  292. //if getDialysisSolutionErr != nil {
  293. // this.ErrorLog("获取透析方案失败:%v", getDialysisSolutionErr)
  294. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  295. // return
  296. //}
  297. lastDialysisPrescribe, _ := service.MobileGetLastDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  298. //fmt.Println("上次透析处方",lastDialysisPrescribe.DialyzerPerfusionApparatus)
  299. //if getDialysisPrescribeErr != nil {
  300. // this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  301. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  302. // return
  303. //}
  304. //获取系统透析处方模版
  305. systemDialysisPrescribe, _ := service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  306. //if getSystemDialysisPrescribeErr != nil {
  307. // this.ErrorLog("获取系统透析处方失败:%v", getSystemDialysisPrescribeErr)
  308. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  309. // return
  310. //}
  311. //dialysisSolution, getDialysisSolutionErr := service.MobileGetDialysisSolution(adminInfo.Org.Id, patientID)
  312. //operators, _ := service.GetAllAdminUserES(adminInfo.Org.Id, adminInfo.App.Id)
  313. if getLPEErr != nil {
  314. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  315. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  316. return
  317. }
  318. lastDryWeightDislysis, getDryErr := service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  319. if getDryErr != nil {
  320. this.ErrorLog("获取最后一条干体重失败:%v", getDryErr)
  321. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  322. return
  323. }
  324. headNurses, _ := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminInfo.Org.Id, adminInfo.App.Id, models.SpecialPermissionTypeHeadNurse)
  325. _, gobalConfig := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  326. goodTypes, _ := service.FindAllGoodTypeByType(1) //查出所有库存配置的系统类型
  327. goodInfos, _ := service.FindAllGoodInfo(adminInfo.Org.Id) //查出所有库存配置的系统类型
  328. operators, err := service.GetAllStarfEs(adminInfo.Org.Id)
  329. fmt.Println("报错", err)
  330. returnData := map[string]interface{}{
  331. "patient": patient,
  332. "schedual": schedual,
  333. "prescription": dialysisPrescribe,
  334. "solution": dialysisSolution,
  335. "last_prescription": lastDialysisPrescribe,
  336. "receiver_treatment_access": receiverTreatmentAccess,
  337. "predialysis_evaluation": predialysisEvaluation,
  338. "doctor_advices": doctorAdvices,
  339. "double_check": doubleCheck,
  340. "assessment_after_dislysis": assessmentAfterDislysis,
  341. "treatment_summary": treatmentSummary,
  342. "monitor_records": monitorRecords,
  343. "dialysis_order": dialysisOrder,
  344. "operators": operators,
  345. "last_predialysis_evaluation": lastPredialysisEvaluation,
  346. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  347. "last_monitor_record": lastMonitorRecord,
  348. "special_premission": headNurses,
  349. "config": gobalConfig,
  350. "types": goodTypes,
  351. "goodInfos": goodInfos,
  352. "dry_weight": lastDryWeightDislysis,
  353. "system_prescription": systemDialysisPrescribe,
  354. }
  355. this.ServeSuccessJSON(returnData)
  356. }
  357. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  358. adminInfo := c.GetMobileAdminUserInfo()
  359. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  360. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  361. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  362. returnData := map[string]interface{}{
  363. "admin_users": adminUsers,
  364. "devices": devices,
  365. "device_numbers": device_numbers,
  366. }
  367. c.ServeSuccessJSON(returnData)
  368. }
  369. func (c *DialysisAPIController) PostAtreatmentInfo() {
  370. id, _ := c.GetInt64("patient", 0)
  371. recordDateStr := c.GetString("record_date")
  372. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  373. summaryContent := c.GetString("summaryContent")
  374. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  375. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  376. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  377. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  378. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  379. nursingRecord := c.GetString("nursing_record")
  380. fmt.Println("护理记录", nursingRecord)
  381. specialRecord := c.GetString("special_record")
  382. fmt.Println("特殊记录", specialRecord)
  383. adminUserInfo := c.GetMobileAdminUserInfo()
  384. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  385. checkStaffId = adminUserInfo.AdminUser.Id
  386. deboardNurseId = adminUserInfo.AdminUser.Id
  387. treatDoctor = adminUserInfo.AdminUser.Id
  388. if id <= 0 {
  389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  390. return
  391. }
  392. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  393. if patient.ID == 0 {
  394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  395. return
  396. }
  397. if len(recordDateStr) == 0 {
  398. recordDateStr = time.Now().Format("2006-01-02")
  399. }
  400. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  401. if parseDateErr != nil {
  402. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  404. return
  405. }
  406. //now := time.Now()
  407. //year, month, day := now.Date()
  408. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  409. //todayTimeStamp := today_time.Unix()
  410. summary := models.TreatmentSummary{
  411. UserOrgId: adminUserInfo.Org.Id,
  412. PatientId: id,
  413. AssessmentDate: recordDate.Unix(),
  414. Mission: propagandaAndEducationContent,
  415. DialysisSummary: summaryContent,
  416. SjNurse: changeMedicalNurseId,
  417. ZlNurse: treatNurseId,
  418. HdNurse: checkStaffId,
  419. XjNurse: deboardNurseId,
  420. ZlDoctor: treatDoctor,
  421. CreatedTime: time.Now().Unix(),
  422. Status: 1,
  423. NursingRecord: nursingRecord,
  424. SpecialRecord: specialRecord,
  425. }
  426. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  427. if treatmentSummary.ID == 0 { //新增
  428. summary.Creater = adminUserInfo.AdminUser.Id
  429. service.AddSigleSummaryRecord(&summary)
  430. c.ServeSuccessJSON(map[string]interface{}{
  431. "summary": summary,
  432. })
  433. } else { //修改
  434. //if treatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  435. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  436. // if getPermissionErr != nil {
  437. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  438. // return
  439. // } else if headNursePermission == nil {
  440. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  441. // return
  442. // }
  443. //}
  444. summary.Creater = treatmentSummary.Creater
  445. summary.CreatedTime = treatmentSummary.CreatedTime
  446. summary.Modifier = adminUserInfo.AdminUser.Id
  447. summary.ID = treatmentSummary.ID
  448. service.UpdateSummeRecord(&summary)
  449. c.ServeSuccessJSON(map[string]interface{}{
  450. "summary": summary,
  451. })
  452. }
  453. }
  454. func (c *DialysisAPIController) PostDoubleCheck() {
  455. id, _ := c.GetInt64("patient", 0)
  456. recordDateStr := c.GetString("record_date")
  457. checkTimeStr := c.GetString("check_time")
  458. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  459. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  460. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  461. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  462. dialysis_item_desc := c.GetString("dialysis_item_desc")
  463. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  464. vascular_access_desc := c.GetString("vascular_access_desc")
  465. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  466. collator, _ := c.GetInt64("collator", 0)
  467. if id <= 0 {
  468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  469. return
  470. }
  471. adminUserInfo := c.GetMobileAdminUserInfo()
  472. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  473. if patient.ID == 0 {
  474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  475. return
  476. }
  477. if len(recordDateStr) == 0 {
  478. recordDateStr = time.Now().Format("2006-01-02")
  479. }
  480. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  481. if parseDateErr != nil {
  482. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  484. return
  485. }
  486. if len(checkTimeStr) == 0 {
  487. checkTimeStr = time.Now().Format("2006-01-02 15:04:05")
  488. }
  489. checkDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  490. //now := time.Now()
  491. //year, month, day := now.Date()
  492. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  493. //todayTimeStamp := today_time.Unix()
  494. doubleCheck := models.DoubleCheck{
  495. UserOrgId: adminUserInfo.Org.Id,
  496. PatientId: id,
  497. DialysisItemCheck: dialysis_item_check,
  498. DialysisParameterCheck: dialysis_parameter_check,
  499. VascularAccessVerification: vascular_access_verification,
  500. PipelineConnectionCheck: pipeline_connection_check,
  501. DialysisItemDesc: dialysis_item_desc,
  502. DialysisParameterDesc: dialysis_parameter_desc,
  503. VascularAccessDesc: vascular_access_desc,
  504. PipelineConnectionDesc: pipeline_connection_desc,
  505. Collator: collator,
  506. Status: 1,
  507. CreatedTime: time.Now().Unix(),
  508. UpdatedTime: time.Now().Unix(),
  509. CheckDate: recordDate.Unix(),
  510. }
  511. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  512. if check.ID == 0 { //新增
  513. doubleCheck.FirstCheckTime = checkDate.Unix()
  514. doubleCheck.Creater = adminUserInfo.AdminUser.Id
  515. err := service.AddSigleDoubleCheck(&doubleCheck)
  516. if err == nil {
  517. c.ServeSuccessJSON(map[string]interface{}{
  518. "doubleCheck": &doubleCheck,
  519. })
  520. }
  521. } else { //修改
  522. if check.Modifier != 0 {
  523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoubleCheckWrong)
  524. } else {
  525. if adminUserInfo.AdminUser.Id == check.Creater {
  526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoubleCheckUserWrong)
  527. return
  528. }
  529. doubleCheck.FirstCheckTime = check.FirstCheckTime
  530. doubleCheck.CheckTime = checkDate.Unix()
  531. doubleCheck.Creater = check.Creater
  532. doubleCheck.CreatedTime = check.CreatedTime
  533. doubleCheck.Modifier = adminUserInfo.AdminUser.Id
  534. doubleCheck.ID = check.ID
  535. err := service.UpdateDoubleCheck(&doubleCheck)
  536. if err == nil {
  537. c.ServeSuccessJSON(map[string]interface{}{
  538. "doubleCheck": &doubleCheck,
  539. })
  540. }
  541. }
  542. }
  543. }
  544. func (c *DialysisAPIController) PostAcceptsAssessment() {
  545. id, _ := c.GetInt64("patient", 0)
  546. recordDateStr := c.GetString("record_date")
  547. way, _ := c.GetInt64("way", 0)
  548. consciousness, _ := c.GetInt64("consciousness", 0)
  549. appetite, _ := c.GetInt64("appetite", 0)
  550. condition, _ := c.GetInt64("condition", 0)
  551. posture, _ := c.GetInt64("posture")
  552. sick_condition, _ := c.GetInt64("sick_condition", 0)
  553. danger_level, _ := c.GetInt64("danger_level", 0)
  554. intake, _ := c.GetInt64("intake", 0)
  555. nutrition, _ := c.GetInt64("nutrition", 0)
  556. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  557. psychological_assessment_other := c.GetString("psychological_assessment_other")
  558. score := c.GetString("score")
  559. sick_condition_other := c.GetString("sick_condition_other")
  560. //precaution, _ := c.GetInt64("precaution", 0)
  561. precaution := c.GetString("precaution")
  562. precaution_other := c.GetString("precaution_other")
  563. psychological_other := c.GetString("psychological_other")
  564. admission_number := c.GetString("admission_number")
  565. if id <= 0 {
  566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  567. return
  568. }
  569. adminUserInfo := c.GetMobileAdminUserInfo()
  570. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  571. if patient.ID == 0 {
  572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  573. return
  574. }
  575. //now := time.Now()
  576. //year, month, day := now.Date()
  577. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  578. //todayTimeStamp := today_time.Unix()
  579. if len(recordDateStr) == 0 {
  580. recordDateStr = time.Now().Format("2006-01-02")
  581. }
  582. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  583. if parseDateErr != nil {
  584. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  586. return
  587. }
  588. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  589. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  590. UserOrgId: adminUserInfo.Org.Id,
  591. PatientId: id,
  592. RecordDate: recordDate.Unix(),
  593. Way: way,
  594. Consciousness: consciousness,
  595. Appetite: appetite,
  596. Condition: condition,
  597. SickCondition: sick_condition,
  598. DangerLevel: danger_level,
  599. Intake: intake,
  600. Nutrition: nutrition,
  601. PsychologicalAssessment: psychological_assessment,
  602. PsychologicalAssessmentOther: psychological_assessment_other,
  603. SickConditionOther: sick_condition_other,
  604. Posture: posture,
  605. CreatedTime: time.Now().Unix(),
  606. UpdateTime: time.Now().Unix(),
  607. Status: 1,
  608. Score: score,
  609. Precaution: precaution,
  610. PrecautionOther: precaution_other,
  611. PsychologicalOther: psychological_other,
  612. AdmissionNumber: admission_number,
  613. }
  614. if receiveTreatment.ID == 0 { //新增
  615. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  616. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  617. if err == nil {
  618. c.ServeSuccessJSON(map[string]interface{}{
  619. "receiveTreatmentAsses": receiveTreatmentAsses,
  620. })
  621. }
  622. } else { //修改
  623. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  624. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  625. // if getPermissionErr != nil {
  626. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  627. // return
  628. // } else if headNursePermission == nil {
  629. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  630. // return
  631. // }
  632. //}
  633. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  634. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  635. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  636. receiveTreatmentAsses.ID = receiveTreatment.ID
  637. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  638. if err == nil {
  639. c.ServeSuccessJSON(map[string]interface{}{
  640. "receiveTreatmentAsses": receiveTreatmentAsses,
  641. })
  642. }
  643. }
  644. }
  645. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  646. id, _ := c.GetInt64("patient", 0)
  647. recordDateStr := c.GetString("record_date")
  648. weightAfter, _ := c.GetFloat("weight_after", 0)
  649. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  650. weightReduce, _ := c.GetFloat("weight_loss", 0)
  651. temperature, _ := c.GetFloat("temperature", 0)
  652. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  653. breathing_rate, _ := c.GetFloat("breathing_rate", 0)
  654. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  655. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  656. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  657. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  658. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  659. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  660. cruor := c.GetString("cruor")
  661. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  662. internalFistula := c.GetString("internal_fistula")
  663. catheter := c.GetString("catheter")
  664. complications := c.GetString("complication")
  665. remark := c.GetString("remark")
  666. dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  667. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  668. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  669. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  670. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  671. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  672. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  673. patientGose, _ := c.GetInt64("patient_gose", 0)
  674. inpatientDepartment := c.GetString("inpatient_department")
  675. observationContent := c.GetString("observation_content")
  676. observationContentOther := c.GetString("observation_content_other")
  677. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  678. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  679. in_advance_reason := c.GetString("in_advance_reason")
  680. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  681. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  682. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  683. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  684. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  685. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  686. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  687. dialyzer, _ := c.GetInt64("dialyzer", 0)
  688. in_advance_reason_other := c.GetString("in_advance_reason_other")
  689. is_eat, _ := c.GetInt64("is_eat", 0)
  690. cvc_a, _ := c.GetFloat("cvc_a", 0)
  691. cvc_v, _ := c.GetFloat("cvc_v", 0)
  692. channels, _ := c.GetInt64("channel", 0)
  693. return_blood, _ := c.GetInt64("return_blood", 0)
  694. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  695. dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  696. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  697. blood_flow, _ := c.GetInt64("blood_flow", 0)
  698. sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  699. sealing_fluid_special := c.GetString("sealing_fluid_special")
  700. if id <= 0 {
  701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  702. return
  703. }
  704. adminUserInfo := c.GetMobileAdminUserInfo()
  705. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  706. if patient.ID == 0 {
  707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  708. return
  709. }
  710. if len(recordDateStr) == 0 {
  711. recordDateStr = time.Now().Format("2006-01-02")
  712. }
  713. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  714. if parseDateErr != nil {
  715. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  717. return
  718. }
  719. //now := time.Now()
  720. //year, month, day := now.Date()
  721. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  722. //todayTimeStamp := today_time.Unix()
  723. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  724. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  725. UserOrgId: adminUserInfo.Org.Id,
  726. PatientId: id,
  727. AssessmentDate: recordDate.Unix(),
  728. Temperature: temperature,
  729. PulseFrequency: pulse_frequency,
  730. BreathingRate: breathing_rate,
  731. SystolicBloodPressure: systolic_blood_pressure,
  732. DiastolicBloodPressure: diastolic_blood_pressure,
  733. ActualUltrafiltration: actual_ultrafiltration,
  734. ActualDisplacement: actual_displacement,
  735. ActualTreatmentHour: actualtreatHour,
  736. ActualTreatmentMinute: actualtreatmin,
  737. WeightAfter: weightAfter,
  738. AdditionalWeight: additionalWeight,
  739. WeightLoss: weightReduce,
  740. Cruor: cruor,
  741. SymptomAfterDialysis: symptomsAfterDialysi,
  742. InternalFistula: internalFistula,
  743. Catheter: catheter,
  744. Complication: complications,
  745. DialysisIntakes: dialysateVolume,
  746. CreatedTime: time.Now().Unix(),
  747. Status: 1,
  748. Remark: remark,
  749. BloodAccessPartId: blood_access_part_id,
  750. BloodAccessPartOperaId: blood_access_part_opera_id,
  751. DialysisIntakesUnit: dialysis_intakes_unit,
  752. PuncturePointOozingBlood: puncturePointOozingBlood,
  753. PuncturePointHaematoma: puncturePointHaematoma,
  754. InternalFistulaTremorAc: internalFistulaTremorAc,
  755. PatientGose: patientGose,
  756. InpatientDepartment: inpatientDepartment,
  757. ObservationContent: observationContent,
  758. ObservationContentOther: observationContentOther,
  759. DialysisProcess: dialysis_process,
  760. InAdvanceMinute: in_advance_minute,
  761. InAdvanceReason: in_advance_reason,
  762. HemostasisMinute: hemostasis_minute,
  763. HemostasisOpera: hemostasis_opera,
  764. TremorNoise: tremor_noise,
  765. DisequilibriumSyndrome: disequilibrium_syndrome,
  766. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  767. ArterialTube: arterial_tube,
  768. IntravenousTube: intravenous_tube,
  769. Dialyzer: dialyzer,
  770. InAdvanceReasonOther: in_advance_reason_other,
  771. IsEat: is_eat,
  772. CvcA: cvc_a,
  773. CvcV: cvc_v,
  774. Channel: channels,
  775. ReturnBlood: return_blood,
  776. RehydrationVolume: rehydration_volume,
  777. DialysisDuring: dialysis_during,
  778. StrokeVolume: stroke_volume,
  779. BloodFlow: blood_flow,
  780. SealingFluidDispose: sealing_fluid_dispose,
  781. SealingFluidSpecial: sealing_fluid_special,
  782. }
  783. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  784. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  785. if assessmentAfter.ID == 0 { //新增
  786. if appRole.UserType == 2 || appRole.UserType == 1 {
  787. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  788. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  789. } else {
  790. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  791. }
  792. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  793. if err == nil {
  794. c.ServeSuccessJSON(map[string]interface{}{
  795. "assessmentAfterDislysis": assessmentAfterDislysis,
  796. })
  797. }
  798. } else { //修改
  799. if appRole.UserType == 2 || appRole.UserType == 1 {
  800. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  801. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  802. } else {
  803. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  804. if assessmentAfterDislysis.Creater == 0 {
  805. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  806. }
  807. }
  808. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  809. assessmentAfterDislysis.ID = assessmentAfter.ID
  810. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  811. if err == nil {
  812. c.ServeSuccessJSON(map[string]interface{}{
  813. "assessmentAfterDislysis": assessmentAfterDislysis,
  814. })
  815. }
  816. }
  817. }
  818. func (c *DialysisAPIController) PostDialysisPrescription() {
  819. id, _ := c.GetInt64("patient", 0)
  820. recordDateStr := c.GetString("record_date")
  821. if id <= 0 {
  822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  823. return
  824. }
  825. adminUserInfo := c.GetMobileAdminUserInfo()
  826. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  827. if patient.ID == 0 {
  828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  829. return
  830. }
  831. if len(recordDateStr) == 0 {
  832. recordDateStr = time.Now().Format("2006-01-02")
  833. }
  834. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  835. if parseDateErr != nil {
  836. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  838. return
  839. }
  840. mode_id, _ := c.GetInt64("mode_id", 0)
  841. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  842. dialyzer, _ := c.GetInt64("dialyzer", 0)
  843. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  844. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  845. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  846. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  847. replacement_total, _ := c.GetFloat("replacement_total", 0)
  848. replacement_way, _ := c.GetInt64("replacement_way", 0)
  849. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  850. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  851. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  852. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  853. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  854. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  855. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  856. kalium, _ := c.GetFloat("kalium", 0)
  857. sodium, _ := c.GetFloat("sodium", 0)
  858. calcium, _ := c.GetFloat("calcium", 0)
  859. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  860. glucose, _ := c.GetFloat("glucose", 0)
  861. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  862. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  863. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  864. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  865. conductivity, _ := c.GetFloat("conductivity", 0)
  866. remark := c.GetString("remark")
  867. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  868. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  869. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  870. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  871. body_fluid, _ := c.GetInt64("body_fluid", 0)
  872. special_medicine, _ := c.GetInt64("special_medicine", 0)
  873. special_medicine_other := c.GetString("special_medicine_other")
  874. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  875. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  876. blood_access, _ := c.GetInt64("blood_access", 0)
  877. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  878. body_fluid_other := c.GetString("body_fluid_other")
  879. niprocart, _ := c.GetInt64("niprocart", 0)
  880. jms, _ := c.GetInt64("jms", 0)
  881. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  882. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  883. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  884. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  885. filtryzer, _ := c.GetInt64("filtryzer", 0)
  886. target_ktv, _ := c.GetFloat("target_ktv", 0)
  887. dialyzers, _ := c.GetInt64("dialyzers", 0)
  888. injector, _ := c.GetInt64("injector", 0)
  889. bloodlines, _ := c.GetInt64("bloodlines", 0)
  890. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  891. safe_package, _ := c.GetInt64("package", 0)
  892. a_liquid, _ := c.GetInt64("a_liquid", 0)
  893. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  894. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  895. //
  896. //if template.TemplateId == 2 || template.TemplateId == 6 {
  897. // if appRole.UserType == 3 {
  898. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  899. // if getPermissionErr != nil {
  900. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  901. // return
  902. // } else if headNursePermission == nil {
  903. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  904. // return
  905. // }
  906. // }
  907. //}
  908. //TODO 需要根据角色去判断
  909. prescription := models.DialysisPrescription{
  910. UserOrgId: adminUserInfo.Org.Id,
  911. PatientId: id,
  912. RecordDate: recordDate.Unix(),
  913. ModeId: mode_id,
  914. DialysisDuration: dialysis_duration,
  915. Dialyzer: dialyzer,
  916. PerfusionApparatus: perfusion_apparatus,
  917. BloodFlowVolume: blood_flow_volume,
  918. DewaterAmount: dewater_amount,
  919. DisplaceLiqui: displace_liqui,
  920. ReplacementWay: replacement_way,
  921. Anticoagulant: anticoagulant,
  922. AnticoagulantShouji: anticoagulant_shouji,
  923. AnticoagulantWeichi: anticoagulant_weichi,
  924. AnticoagulantZongliang: anticoagulant_zongliang,
  925. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  926. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  927. Kalium: kalium,
  928. Sodium: sodium,
  929. Calcium: calcium,
  930. Bicarbonate: bicarbonate,
  931. Glucose: glucose,
  932. // DryWeight: dry_weight,
  933. DialysateFlow: dialysate_flow,
  934. DialysateTemperature: dialysate_temperature,
  935. // PrescriptionDoctor: prescription_doctor,
  936. ReplacementTotal: replacement_total,
  937. Conductivity: conductivity,
  938. Remark: remark,
  939. Status: 1,
  940. CreatedTime: time.Now().Unix(),
  941. UpdatedTime: time.Now().Unix(),
  942. DialysisDurationMinute: dialysisDurationMinute,
  943. DialysisDurationHour: dialysisDurationHour,
  944. TargetUltrafiltration: targetUltrafiltration,
  945. DialysateFormulation: dialysateFormulation,
  946. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  947. BodyFluid: body_fluid,
  948. SpecialMedicine: special_medicine,
  949. SpecialMedicineOther: special_medicine_other,
  950. DisplaceLiquiPart: displace_liqui_part,
  951. DisplaceLiquiValue: displace_liqui_value,
  952. BloodAccess: blood_access,
  953. Ultrafiltration: ultrafiltration,
  954. BodyFluidOther: body_fluid_other,
  955. Niprocart: niprocart,
  956. Jms: jms,
  957. FistulaNeedleSet: fistula_needle_set,
  958. FistulaNeedleSet16: fistula_needle_set_16,
  959. Hemoperfusion: hemoperfusion,
  960. DialyserSterilised: dialyser_sterilised,
  961. Filtryzer: filtryzer,
  962. Dialyzers: dialyzers,
  963. Injector: injector,
  964. Bloodlines: bloodlines,
  965. TubingHemodialysis: tubing_hemodialysis,
  966. Package: safe_package,
  967. ALiquid: a_liquid,
  968. TargetKtv: target_ktv,
  969. }
  970. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  971. if dialysisPrescription.ID == 0 { //新增
  972. //if mode_id > 0 {
  973. // //service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  974. //}
  975. if appRole.UserType == 2 || appRole.UserType == 1 {
  976. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  977. }
  978. prescription.Creater = adminUserInfo.AdminUser.Id
  979. err := service.AddSigleRecord(&prescription)
  980. if err == nil {
  981. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  982. if updateErr != nil {
  983. utils.ErrorLog("%v", updateErr)
  984. }
  985. c.ServeSuccessJSON(map[string]interface{}{
  986. "prescription": prescription,
  987. })
  988. }
  989. } else { //修改
  990. //if mode_id > 0 {
  991. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  992. //}
  993. //if template.TemplateId == 1 {
  994. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  995. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  996. // if getPermissionErr != nil {
  997. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  998. // return
  999. // } else if headNursePermission == nil {
  1000. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1001. // return
  1002. // }
  1003. // }
  1004. //}
  1005. _, record := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  1006. if record.IsOpen == 1 {
  1007. niprocart_good_type_id, _ := beego.AppConfig.Int64("niprocart")
  1008. jms_good_type_id, _ := beego.AppConfig.Int64("jms")
  1009. fistula_needle_set_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set")
  1010. fistula_needle_set_16_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set_16")
  1011. hemoperfusion_good_type_id, _ := beego.AppConfig.Int64("hemoperfusion")
  1012. dialyser_sterilised_good_type_id, _ := beego.AppConfig.Int64("dialyser_sterilised")
  1013. filtryzer_good_type_id, _ := beego.AppConfig.Int64("filtryzer")
  1014. dialyzers_good_type_id, _ := beego.AppConfig.Int64("dialyzers")
  1015. injector_good_type_id, _ := beego.AppConfig.Int64("injector")
  1016. bloodlines_good_type_id, _ := beego.AppConfig.Int64("bloodlines")
  1017. tubingHemodialysis_good_type_id, _ := beego.AppConfig.Int64("tubingHemodialysis")
  1018. safe_package_good_type_id, _ := beego.AppConfig.Int64("package")
  1019. aliquid_good_type_id, _ := beego.AppConfig.Int64("aliquid")
  1020. err, order := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  1021. if err == nil {
  1022. if order.ID > 0 {
  1023. if dialysisPrescription.Niprocart != niprocart {
  1024. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1025. //1.用上机透析日期查出当天的订单
  1026. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1027. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1028. service.UpdateOrderCount(niprocart_good_type_id, dialysisPrescription.Niprocart, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1029. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1030. err, newOut := service.FindOrderInfoByGoodId(niprocart_good_type_id, niprocart, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1031. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1032. warehouseOutInfo := &models.WarehouseOutInfo{
  1033. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1034. WarehouseOutId: out.ID,
  1035. Count: 1,
  1036. Status: 1,
  1037. Ctime: time.Now().Unix(),
  1038. Remark: "",
  1039. OrgId: adminUserInfo.Org.Id,
  1040. Type: 1,
  1041. Manufacturer: 0,
  1042. Dealer: 0,
  1043. IsSys: 1,
  1044. SysRecordTime: order.StartTime,
  1045. }
  1046. stockInInfo, _ := service.FindLastStockInInfoRecord(niprocart, adminUserInfo.Org.Id)
  1047. warehouseOutInfo.Price = stockInInfo.Price
  1048. warehouseOutInfo.GoodId = niprocart
  1049. warehouseOutInfo.GoodTypeId = niprocart_good_type_id
  1050. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1051. if err == nil {
  1052. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1053. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1054. if err == gorm.ErrRecordNotFound {
  1055. details := &models.AutomaticReduceDetail{
  1056. WarehouseOutId: warehouseOutInfo.ID,
  1057. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1058. PatientId: id,
  1059. Ctime: time.Now().Unix(),
  1060. Mtime: time.Now().Unix(),
  1061. Status: 1,
  1062. RecordTime: order.StartTime,
  1063. OrgId: adminUserInfo.Org.Id,
  1064. GoodId: niprocart,
  1065. GoodTypeId: niprocart_good_type_id,
  1066. }
  1067. service.AddSigleAutoReduceRecordInfo(details)
  1068. } else if err == nil {
  1069. if user.ID > 0 {
  1070. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.Org.Id, id, niprocart, warehouseOutInfo)
  1071. }
  1072. }
  1073. }
  1074. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1075. if newOut.ID > 0 {
  1076. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1077. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1078. if err == gorm.ErrRecordNotFound {
  1079. details := &models.AutomaticReduceDetail{
  1080. WarehouseOutId: newOut.ID,
  1081. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1082. PatientId: id,
  1083. Ctime: time.Now().Unix(),
  1084. Mtime: time.Now().Unix(),
  1085. Status: 1,
  1086. RecordTime: order.StartTime,
  1087. OrgId: adminUserInfo.Org.Id,
  1088. GoodId: niprocart,
  1089. GoodTypeId: niprocart_good_type_id,
  1090. }
  1091. service.AddSigleAutoReduceRecordInfo(details)
  1092. } else if err == nil {
  1093. if user.ID > 0 {
  1094. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.Org.Id, id, niprocart, &newOut)
  1095. }
  1096. }
  1097. }
  1098. }
  1099. }
  1100. if dialysisPrescription.Jms != jms {
  1101. //不一致,先将原有的商品出库单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1102. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1103. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1104. service.UpdateOrderCount(jms_good_type_id, dialysisPrescription.Jms, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1105. //_, out := service.FindOrderInfoByGoodId(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id)
  1106. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1107. err, newOut := service.FindOrderInfoByGoodId(jms_good_type_id, jms, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1108. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1109. warehouseOutInfo := &models.WarehouseOutInfo{
  1110. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1111. WarehouseOutId: out.ID,
  1112. Count: 1,
  1113. Status: 1,
  1114. Ctime: time.Now().Unix(),
  1115. Remark: "",
  1116. OrgId: adminUserInfo.Org.Id,
  1117. Type: 1,
  1118. Manufacturer: 0,
  1119. Dealer: 0,
  1120. IsSys: 1,
  1121. SysRecordTime: order.StartTime,
  1122. }
  1123. stockInInfo, _ := service.FindLastStockInInfoRecord(jms, adminUserInfo.Org.Id)
  1124. warehouseOutInfo.Price = stockInInfo.Price
  1125. warehouseOutInfo.GoodId = jms
  1126. warehouseOutInfo.GoodTypeId = jms_good_type_id
  1127. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1128. if err == nil {
  1129. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1130. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1131. if err == gorm.ErrRecordNotFound {
  1132. details := &models.AutomaticReduceDetail{
  1133. WarehouseOutId: warehouseOutInfo.ID,
  1134. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1135. PatientId: id,
  1136. Ctime: time.Now().Unix(),
  1137. Mtime: time.Now().Unix(),
  1138. Status: 1,
  1139. RecordTime: order.StartTime,
  1140. OrgId: adminUserInfo.Org.Id,
  1141. GoodId: jms,
  1142. GoodTypeId: jms_good_type_id,
  1143. }
  1144. service.AddSigleAutoReduceRecordInfo(details)
  1145. } else if err == nil {
  1146. if user.ID > 0 {
  1147. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1148. }
  1149. }
  1150. }
  1151. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1152. if newOut.ID > 0 {
  1153. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1154. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1155. if err == gorm.ErrRecordNotFound {
  1156. details := &models.AutomaticReduceDetail{
  1157. WarehouseOutId: newOut.ID,
  1158. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1159. PatientId: id,
  1160. Ctime: time.Now().Unix(),
  1161. Mtime: time.Now().Unix(),
  1162. Status: 1,
  1163. RecordTime: order.StartTime,
  1164. OrgId: adminUserInfo.Org.Id,
  1165. GoodId: jms,
  1166. GoodTypeId: jms_good_type_id,
  1167. }
  1168. service.AddSigleAutoReduceRecordInfo(details)
  1169. } else if err == nil {
  1170. if user.ID > 0 {
  1171. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, &newOut)
  1172. }
  1173. }
  1174. }
  1175. }
  1176. }
  1177. if dialysisPrescription.FistulaNeedleSet != fistula_needle_set {
  1178. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1179. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1180. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1181. service.UpdateOrderCount(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1182. //_, out := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id)
  1183. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1184. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, fistula_needle_set, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1185. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1186. warehouseOutInfo := &models.WarehouseOutInfo{
  1187. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1188. WarehouseOutId: out.ID,
  1189. Count: 1,
  1190. Status: 1,
  1191. Ctime: time.Now().Unix(),
  1192. Remark: "",
  1193. OrgId: adminUserInfo.Org.Id,
  1194. Type: 1,
  1195. Manufacturer: 0,
  1196. Dealer: 0,
  1197. IsSys: 1,
  1198. SysRecordTime: order.StartTime,
  1199. }
  1200. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set, adminUserInfo.Org.Id)
  1201. warehouseOutInfo.Price = stockInInfo.Price
  1202. warehouseOutInfo.GoodId = fistula_needle_set
  1203. warehouseOutInfo.GoodTypeId = fistula_needle_set_good_type_id
  1204. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1205. if err == nil {
  1206. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1207. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1208. if err == gorm.ErrRecordNotFound {
  1209. details := &models.AutomaticReduceDetail{
  1210. WarehouseOutId: warehouseOutInfo.ID,
  1211. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1212. PatientId: id,
  1213. Ctime: time.Now().Unix(),
  1214. Mtime: time.Now().Unix(),
  1215. Status: 1,
  1216. RecordTime: order.StartTime,
  1217. OrgId: adminUserInfo.Org.Id,
  1218. GoodId: fistula_needle_set,
  1219. GoodTypeId: fistula_needle_set_good_type_id,
  1220. }
  1221. service.AddSigleAutoReduceRecordInfo(details)
  1222. } else if err == nil {
  1223. if user.ID > 0 {
  1224. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1225. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, warehouseOutInfo)
  1226. }
  1227. }
  1228. }
  1229. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1230. if newOut.ID > 0 {
  1231. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1232. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1233. if err == gorm.ErrRecordNotFound {
  1234. details := &models.AutomaticReduceDetail{
  1235. WarehouseOutId: newOut.ID,
  1236. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1237. PatientId: id,
  1238. Ctime: time.Now().Unix(),
  1239. Mtime: time.Now().Unix(),
  1240. Status: 1,
  1241. RecordTime: order.StartTime,
  1242. OrgId: adminUserInfo.Org.Id,
  1243. GoodId: fistula_needle_set,
  1244. GoodTypeId: fistula_needle_set_good_type_id,
  1245. }
  1246. service.AddSigleAutoReduceRecordInfo(details)
  1247. } else if err == nil {
  1248. if user.ID > 0 {
  1249. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1250. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, &newOut)
  1251. }
  1252. }
  1253. }
  1254. }
  1255. }
  1256. if dialysisPrescription.FistulaNeedleSet16 != fistula_needle_set_16 {
  1257. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1258. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1259. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1260. service.UpdateOrderCount(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1261. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1262. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1263. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_16_good_type_id, fistula_needle_set_16, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1264. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1265. warehouseOutInfo := &models.WarehouseOutInfo{
  1266. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1267. WarehouseOutId: out.ID,
  1268. Count: 1,
  1269. Status: 1,
  1270. Ctime: time.Now().Unix(),
  1271. Remark: "",
  1272. OrgId: adminUserInfo.Org.Id,
  1273. Type: 1,
  1274. Manufacturer: 0,
  1275. Dealer: 0,
  1276. IsSys: 1,
  1277. SysRecordTime: order.StartTime,
  1278. }
  1279. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set_16, adminUserInfo.Org.Id)
  1280. warehouseOutInfo.Price = stockInInfo.Price
  1281. warehouseOutInfo.GoodId = fistula_needle_set_16
  1282. warehouseOutInfo.GoodTypeId = fistula_needle_set_16_good_type_id
  1283. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1284. if err == nil {
  1285. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1286. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1287. if err == gorm.ErrRecordNotFound {
  1288. details := &models.AutomaticReduceDetail{
  1289. WarehouseOutId: warehouseOutInfo.ID,
  1290. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1291. PatientId: id,
  1292. Ctime: time.Now().Unix(),
  1293. Mtime: time.Now().Unix(),
  1294. Status: 1,
  1295. RecordTime: order.StartTime,
  1296. OrgId: adminUserInfo.Org.Id,
  1297. GoodId: fistula_needle_set_16,
  1298. GoodTypeId: fistula_needle_set_16_good_type_id,
  1299. }
  1300. service.AddSigleAutoReduceRecordInfo(details)
  1301. } else if err == nil {
  1302. if user.ID > 0 {
  1303. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1304. //service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, warehouseOutInfo)
  1305. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set_16, warehouseOutInfo)
  1306. }
  1307. }
  1308. }
  1309. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1310. if newOut.ID > 0 {
  1311. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1312. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1313. if err == gorm.ErrRecordNotFound {
  1314. details := &models.AutomaticReduceDetail{
  1315. WarehouseOutId: newOut.ID,
  1316. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1317. PatientId: id,
  1318. Ctime: time.Now().Unix(),
  1319. Mtime: time.Now().Unix(),
  1320. Status: 1,
  1321. RecordTime: order.StartTime,
  1322. OrgId: adminUserInfo.Org.Id,
  1323. GoodId: fistula_needle_set_good_type_id,
  1324. GoodTypeId: fistula_needle_set_16_good_type_id,
  1325. }
  1326. service.AddSigleAutoReduceRecordInfo(details)
  1327. } else if err == nil {
  1328. if user.ID > 0 {
  1329. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set_16, &newOut)
  1330. }
  1331. }
  1332. }
  1333. }
  1334. }
  1335. if dialysisPrescription.Hemoperfusion != hemoperfusion {
  1336. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1337. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1338. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1339. service.UpdateOrderCount(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1340. //_, out := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id)
  1341. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1342. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1343. err, newOut := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1344. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1345. warehouseOutInfo := &models.WarehouseOutInfo{
  1346. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1347. WarehouseOutId: out.ID,
  1348. Count: 1,
  1349. Status: 1,
  1350. Ctime: time.Now().Unix(),
  1351. Remark: "",
  1352. OrgId: adminUserInfo.Org.Id,
  1353. Type: 1,
  1354. Manufacturer: 0,
  1355. Dealer: 0,
  1356. IsSys: 1,
  1357. SysRecordTime: order.StartTime,
  1358. }
  1359. stockInInfo, _ := service.FindLastStockInInfoRecord(hemoperfusion, adminUserInfo.Org.Id)
  1360. warehouseOutInfo.Price = stockInInfo.Price
  1361. warehouseOutInfo.GoodId = hemoperfusion
  1362. warehouseOutInfo.GoodTypeId = hemoperfusion_good_type_id
  1363. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1364. if err == nil {
  1365. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1366. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1367. if err == gorm.ErrRecordNotFound {
  1368. details := &models.AutomaticReduceDetail{
  1369. WarehouseOutId: warehouseOutInfo.ID,
  1370. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1371. PatientId: id,
  1372. Ctime: time.Now().Unix(),
  1373. Mtime: time.Now().Unix(),
  1374. Status: 1,
  1375. RecordTime: order.StartTime,
  1376. OrgId: adminUserInfo.Org.Id,
  1377. GoodId: hemoperfusion,
  1378. GoodTypeId: hemoperfusion_good_type_id,
  1379. }
  1380. service.AddSigleAutoReduceRecordInfo(details)
  1381. } else if err == nil {
  1382. if user.ID > 0 {
  1383. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  1384. }
  1385. }
  1386. }
  1387. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1388. if newOut.ID > 0 {
  1389. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1390. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1391. if err == gorm.ErrRecordNotFound {
  1392. details := &models.AutomaticReduceDetail{
  1393. WarehouseOutId: newOut.ID,
  1394. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1395. PatientId: id,
  1396. Ctime: time.Now().Unix(),
  1397. Mtime: time.Now().Unix(),
  1398. Status: 1,
  1399. RecordTime: order.StartTime,
  1400. OrgId: adminUserInfo.Org.Id,
  1401. GoodId: hemoperfusion,
  1402. GoodTypeId: hemoperfusion_good_type_id,
  1403. }
  1404. service.AddSigleAutoReduceRecordInfo(details)
  1405. } else if err == nil {
  1406. if user.ID > 0 {
  1407. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, &newOut)
  1408. }
  1409. }
  1410. }
  1411. }
  1412. }
  1413. if dialysisPrescription.DialyserSterilised != dialyser_sterilised {
  1414. _, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1415. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1416. service.UpdateOrderCount(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1417. //_, out := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id)
  1418. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1419. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1420. err, newOut := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialyser_sterilised, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1421. if err == gorm.ErrRecordNotFound { //����存在,则新增出库记录,并更改使用人商品信息
  1422. warehouseOutInfo := &models.WarehouseOutInfo{
  1423. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1424. WarehouseOutId: out.WarehouseOutId,
  1425. Count: 1,
  1426. Status: 1,
  1427. Ctime: time.Now().Unix(),
  1428. Remark: "",
  1429. OrgId: adminUserInfo.Org.Id,
  1430. Type: 1,
  1431. Manufacturer: 0,
  1432. Dealer: 0,
  1433. IsSys: 1,
  1434. SysRecordTime: order.StartTime,
  1435. }
  1436. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyser_sterilised, adminUserInfo.Org.Id)
  1437. warehouseOutInfo.Price = stockInInfo.Price
  1438. warehouseOutInfo.GoodId = dialyser_sterilised
  1439. warehouseOutInfo.GoodTypeId = dialyser_sterilised_good_type_id
  1440. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1441. if err == nil {
  1442. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1443. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1444. if err == gorm.ErrRecordNotFound {
  1445. details := &models.AutomaticReduceDetail{
  1446. WarehouseOutId: warehouseOutInfo.ID,
  1447. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1448. PatientId: id,
  1449. Ctime: time.Now().Unix(),
  1450. Mtime: time.Now().Unix(),
  1451. Status: 1,
  1452. RecordTime: order.StartTime,
  1453. OrgId: adminUserInfo.Org.Id,
  1454. GoodId: dialyser_sterilised,
  1455. GoodTypeId: dialyser_sterilised_good_type_id,
  1456. }
  1457. service.AddSigleAutoReduceRecordInfo(details)
  1458. } else if err == nil {
  1459. if user.ID > 0 {
  1460. //service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  1461. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id, id, dialyser_sterilised, warehouseOutInfo)
  1462. }
  1463. }
  1464. }
  1465. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1466. if newOut.ID > 0 {
  1467. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1468. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1469. if err == gorm.ErrRecordNotFound {
  1470. details := &models.AutomaticReduceDetail{
  1471. WarehouseOutId: newOut.ID,
  1472. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1473. PatientId: id,
  1474. Ctime: time.Now().Unix(),
  1475. Mtime: time.Now().Unix(),
  1476. Status: 1,
  1477. RecordTime: order.StartTime,
  1478. OrgId: adminUserInfo.Org.Id,
  1479. GoodId: dialyser_sterilised,
  1480. GoodTypeId: dialyser_sterilised_good_type_id,
  1481. }
  1482. service.AddSigleAutoReduceRecordInfo(details)
  1483. } else if err == nil {
  1484. if user.ID > 0 {
  1485. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id, id, dialyser_sterilised, &newOut)
  1486. }
  1487. }
  1488. }
  1489. }
  1490. }
  1491. if dialysisPrescription.Filtryzer != filtryzer {
  1492. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1493. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1494. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1495. service.UpdateOrderCount(filtryzer_good_type_id, dialysisPrescription.Filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1496. //_, out := service.FindOrderInfoByGoodId(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id)
  1497. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1498. err, newOut := service.FindOrderInfoByGoodId(filtryzer_good_type_id, filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1499. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1500. warehouseOutInfo := &models.WarehouseOutInfo{
  1501. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1502. WarehouseOutId: out.ID,
  1503. Count: 1,
  1504. Status: 1,
  1505. Ctime: time.Now().Unix(),
  1506. Remark: "",
  1507. OrgId: adminUserInfo.Org.Id,
  1508. Type: 1,
  1509. Manufacturer: 0,
  1510. Dealer: 0,
  1511. IsSys: 1,
  1512. SysRecordTime: order.StartTime,
  1513. }
  1514. stockInInfo, _ := service.FindLastStockInInfoRecord(filtryzer, adminUserInfo.Org.Id)
  1515. warehouseOutInfo.Price = stockInInfo.Price
  1516. warehouseOutInfo.GoodId = filtryzer
  1517. warehouseOutInfo.GoodTypeId = filtryzer_good_type_id
  1518. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1519. if err == nil {
  1520. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1521. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1522. if err == gorm.ErrRecordNotFound {
  1523. details := &models.AutomaticReduceDetail{
  1524. WarehouseOutId: warehouseOutInfo.ID,
  1525. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1526. PatientId: id,
  1527. Ctime: time.Now().Unix(),
  1528. Mtime: time.Now().Unix(),
  1529. Status: 1,
  1530. RecordTime: order.StartTime,
  1531. OrgId: adminUserInfo.Org.Id,
  1532. GoodId: filtryzer,
  1533. GoodTypeId: filtryzer_good_type_id,
  1534. }
  1535. service.AddSigleAutoReduceRecordInfo(details)
  1536. } else if err == nil {
  1537. if user.ID > 0 {
  1538. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id, id, filtryzer, warehouseOutInfo)
  1539. }
  1540. }
  1541. }
  1542. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1543. if newOut.ID > 0 {
  1544. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1545. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1546. if err == gorm.ErrRecordNotFound {
  1547. details := &models.AutomaticReduceDetail{
  1548. WarehouseOutId: newOut.ID,
  1549. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1550. PatientId: id,
  1551. Ctime: time.Now().Unix(),
  1552. Mtime: time.Now().Unix(),
  1553. Status: 1,
  1554. RecordTime: order.StartTime,
  1555. OrgId: adminUserInfo.Org.Id,
  1556. GoodId: filtryzer,
  1557. GoodTypeId: filtryzer_good_type_id,
  1558. }
  1559. service.AddSigleAutoReduceRecordInfo(details)
  1560. } else if err == nil {
  1561. if user.ID > 0 {
  1562. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id, id, filtryzer, &newOut)
  1563. }
  1564. }
  1565. }
  1566. }
  1567. }
  1568. if dialysisPrescription.Dialyzers != dialyzers {
  1569. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1570. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1571. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1572. service.UpdateOrderCount(dialyzers_good_type_id, dialysisPrescription.Dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1573. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1574. err, newOut := service.FindOrderInfoByGoodId(dialyzers_good_type_id, dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1575. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1576. warehouseOutInfo := &models.WarehouseOutInfo{
  1577. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1578. WarehouseOutId: out.ID,
  1579. Count: 1,
  1580. Status: 1,
  1581. Ctime: time.Now().Unix(),
  1582. Remark: "",
  1583. OrgId: adminUserInfo.Org.Id,
  1584. Type: 1,
  1585. Manufacturer: 0,
  1586. Dealer: 0,
  1587. IsSys: 1,
  1588. SysRecordTime: order.StartTime,
  1589. }
  1590. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyzers, adminUserInfo.Org.Id)
  1591. warehouseOutInfo.Price = stockInInfo.Price
  1592. warehouseOutInfo.GoodId = dialyzers
  1593. warehouseOutInfo.GoodTypeId = dialyzers_good_type_id
  1594. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1595. if err == nil {
  1596. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1597. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1598. if err == gorm.ErrRecordNotFound {
  1599. details := &models.AutomaticReduceDetail{
  1600. WarehouseOutId: warehouseOutInfo.ID,
  1601. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1602. PatientId: id,
  1603. Ctime: time.Now().Unix(),
  1604. Mtime: time.Now().Unix(),
  1605. Status: 1,
  1606. RecordTime: order.StartTime,
  1607. OrgId: adminUserInfo.Org.Id,
  1608. GoodId: dialyzers,
  1609. GoodTypeId: dialyzers_good_type_id,
  1610. }
  1611. service.AddSigleAutoReduceRecordInfo(details)
  1612. } else if err == nil {
  1613. if user.ID > 0 {
  1614. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.Org.Id, id, dialyzers, warehouseOutInfo)
  1615. }
  1616. }
  1617. }
  1618. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1619. if newOut.ID > 0 {
  1620. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1621. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1622. if err == gorm.ErrRecordNotFound {
  1623. details := &models.AutomaticReduceDetail{
  1624. WarehouseOutId: newOut.ID,
  1625. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1626. PatientId: id,
  1627. Ctime: time.Now().Unix(),
  1628. Mtime: time.Now().Unix(),
  1629. Status: 1,
  1630. RecordTime: order.StartTime,
  1631. OrgId: adminUserInfo.Org.Id,
  1632. GoodId: dialyzers,
  1633. GoodTypeId: dialyzers_good_type_id,
  1634. }
  1635. service.AddSigleAutoReduceRecordInfo(details)
  1636. } else if err == nil {
  1637. if user.ID > 0 {
  1638. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.Org.Id, id, dialyzers, &newOut)
  1639. }
  1640. }
  1641. }
  1642. }
  1643. }
  1644. if dialysisPrescription.Injector != injector {
  1645. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1646. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1647. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1648. service.UpdateOrderCount(injector_good_type_id, dialysisPrescription.Injector, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1649. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1650. err, newOut := service.FindOrderInfoByGoodId(injector_good_type_id, injector, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1651. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1652. warehouseOutInfo := &models.WarehouseOutInfo{
  1653. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1654. WarehouseOutId: out.ID,
  1655. Count: 1,
  1656. Status: 1,
  1657. Ctime: time.Now().Unix(),
  1658. Remark: "",
  1659. OrgId: adminUserInfo.Org.Id,
  1660. Type: 1,
  1661. Manufacturer: 0,
  1662. Dealer: 0,
  1663. IsSys: 1,
  1664. SysRecordTime: order.StartTime,
  1665. }
  1666. stockInInfo, _ := service.FindLastStockInInfoRecord(injector, adminUserInfo.Org.Id)
  1667. warehouseOutInfo.Price = stockInInfo.Price
  1668. warehouseOutInfo.GoodId = injector
  1669. warehouseOutInfo.GoodTypeId = injector_good_type_id
  1670. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1671. if err == nil {
  1672. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1673. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1674. if err == gorm.ErrRecordNotFound {
  1675. details := &models.AutomaticReduceDetail{
  1676. WarehouseOutId: warehouseOutInfo.ID,
  1677. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1678. PatientId: id,
  1679. Ctime: time.Now().Unix(),
  1680. Mtime: time.Now().Unix(),
  1681. Status: 1,
  1682. RecordTime: order.StartTime,
  1683. OrgId: adminUserInfo.Org.Id,
  1684. GoodId: injector,
  1685. GoodTypeId: injector_good_type_id,
  1686. }
  1687. service.AddSigleAutoReduceRecordInfo(details)
  1688. } else if err == nil {
  1689. if user.ID > 0 {
  1690. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.Org.Id, id, injector, warehouseOutInfo)
  1691. }
  1692. }
  1693. }
  1694. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1695. if newOut.ID > 0 {
  1696. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1697. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1698. if err == gorm.ErrRecordNotFound {
  1699. details := &models.AutomaticReduceDetail{
  1700. WarehouseOutId: newOut.ID,
  1701. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1702. PatientId: id,
  1703. Ctime: time.Now().Unix(),
  1704. Mtime: time.Now().Unix(),
  1705. Status: 1,
  1706. RecordTime: order.StartTime,
  1707. OrgId: adminUserInfo.Org.Id,
  1708. GoodId: injector,
  1709. GoodTypeId: injector_good_type_id,
  1710. }
  1711. service.AddSigleAutoReduceRecordInfo(details)
  1712. } else if err == nil {
  1713. if user.ID > 0 {
  1714. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.Org.Id, id, injector, &newOut)
  1715. }
  1716. }
  1717. }
  1718. }
  1719. }
  1720. if dialysisPrescription.Bloodlines != bloodlines {
  1721. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1722. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1723. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1724. service.UpdateOrderCount(bloodlines_good_type_id, dialysisPrescription.Bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1725. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1726. err, newOut := service.FindOrderInfoByGoodId(bloodlines_good_type_id, bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1727. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1728. warehouseOutInfo := &models.WarehouseOutInfo{
  1729. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1730. WarehouseOutId: out.ID,
  1731. Count: 1,
  1732. Status: 1,
  1733. Ctime: time.Now().Unix(),
  1734. Remark: "",
  1735. OrgId: adminUserInfo.Org.Id,
  1736. Type: 1,
  1737. Manufacturer: 0,
  1738. Dealer: 0,
  1739. IsSys: 1,
  1740. SysRecordTime: order.StartTime,
  1741. }
  1742. stockInInfo, _ := service.FindLastStockInInfoRecord(bloodlines, adminUserInfo.Org.Id)
  1743. warehouseOutInfo.Price = stockInInfo.Price
  1744. warehouseOutInfo.GoodId = bloodlines
  1745. warehouseOutInfo.GoodTypeId = bloodlines_good_type_id
  1746. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1747. if err == nil {
  1748. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1749. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1750. if err == gorm.ErrRecordNotFound {
  1751. details := &models.AutomaticReduceDetail{
  1752. WarehouseOutId: warehouseOutInfo.ID,
  1753. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1754. PatientId: id,
  1755. Ctime: time.Now().Unix(),
  1756. Mtime: time.Now().Unix(),
  1757. Status: 1,
  1758. RecordTime: order.StartTime,
  1759. OrgId: adminUserInfo.Org.Id,
  1760. GoodId: bloodlines,
  1761. GoodTypeId: bloodlines_good_type_id,
  1762. }
  1763. service.AddSigleAutoReduceRecordInfo(details)
  1764. } else if err == nil {
  1765. if user.ID > 0 {
  1766. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.Org.Id, id, bloodlines, warehouseOutInfo)
  1767. }
  1768. }
  1769. }
  1770. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1771. if newOut.ID > 0 {
  1772. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1773. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1774. if err == gorm.ErrRecordNotFound {
  1775. details := &models.AutomaticReduceDetail{
  1776. WarehouseOutId: newOut.ID,
  1777. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1778. PatientId: id,
  1779. Ctime: time.Now().Unix(),
  1780. Mtime: time.Now().Unix(),
  1781. Status: 1,
  1782. RecordTime: order.StartTime,
  1783. OrgId: adminUserInfo.Org.Id,
  1784. GoodId: bloodlines,
  1785. GoodTypeId: bloodlines_good_type_id,
  1786. }
  1787. service.AddSigleAutoReduceRecordInfo(details)
  1788. } else if err == nil {
  1789. if user.ID > 0 {
  1790. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.Org.Id, id, bloodlines, &newOut)
  1791. }
  1792. }
  1793. }
  1794. }
  1795. }
  1796. if dialysisPrescription.TubingHemodialysis != tubing_hemodialysis {
  1797. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1798. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1799. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1800. service.UpdateOrderCount(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1801. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1802. err, newOut := service.FindOrderInfoByGoodId(tubingHemodialysis_good_type_id, tubing_hemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1803. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1804. warehouseOutInfo := &models.WarehouseOutInfo{
  1805. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1806. WarehouseOutId: out.ID,
  1807. Count: 1,
  1808. Status: 1,
  1809. Ctime: time.Now().Unix(),
  1810. Remark: "",
  1811. OrgId: adminUserInfo.Org.Id,
  1812. Type: 1,
  1813. Manufacturer: 0,
  1814. Dealer: 0,
  1815. IsSys: 1,
  1816. SysRecordTime: order.StartTime,
  1817. }
  1818. stockInInfo, _ := service.FindLastStockInInfoRecord(tubing_hemodialysis, adminUserInfo.Org.Id)
  1819. warehouseOutInfo.Price = stockInInfo.Price
  1820. warehouseOutInfo.GoodId = tubing_hemodialysis
  1821. warehouseOutInfo.GoodTypeId = tubingHemodialysis_good_type_id
  1822. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1823. if err == nil {
  1824. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1825. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1826. if err == gorm.ErrRecordNotFound {
  1827. details := &models.AutomaticReduceDetail{
  1828. WarehouseOutId: warehouseOutInfo.ID,
  1829. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1830. PatientId: id,
  1831. Ctime: time.Now().Unix(),
  1832. Mtime: time.Now().Unix(),
  1833. Status: 1,
  1834. RecordTime: order.StartTime,
  1835. OrgId: adminUserInfo.Org.Id,
  1836. GoodId: tubing_hemodialysis,
  1837. GoodTypeId: tubingHemodialysis_good_type_id,
  1838. }
  1839. service.AddSigleAutoReduceRecordInfo(details)
  1840. } else if err == nil {
  1841. if user.ID > 0 {
  1842. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.Org.Id, id, tubing_hemodialysis, warehouseOutInfo)
  1843. }
  1844. }
  1845. }
  1846. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1847. if newOut.ID > 0 {
  1848. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1849. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1850. if err == gorm.ErrRecordNotFound {
  1851. details := &models.AutomaticReduceDetail{
  1852. WarehouseOutId: newOut.ID,
  1853. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1854. PatientId: id,
  1855. Ctime: time.Now().Unix(),
  1856. Mtime: time.Now().Unix(),
  1857. Status: 1,
  1858. RecordTime: order.StartTime,
  1859. OrgId: adminUserInfo.Org.Id,
  1860. GoodId: tubing_hemodialysis,
  1861. GoodTypeId: tubingHemodialysis_good_type_id,
  1862. }
  1863. service.AddSigleAutoReduceRecordInfo(details)
  1864. } else if err == nil {
  1865. if user.ID > 0 {
  1866. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.Org.Id, id, tubing_hemodialysis, &newOut)
  1867. }
  1868. }
  1869. }
  1870. }
  1871. }
  1872. if dialysisPrescription.Package != safe_package {
  1873. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1874. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1875. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1876. service.UpdateOrderCount(safe_package_good_type_id, dialysisPrescription.Package, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1877. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1878. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1879. err, newOut := service.FindOrderInfoByGoodId(safe_package_good_type_id, safe_package, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1880. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1881. warehouseOutInfo := &models.WarehouseOutInfo{
  1882. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1883. WarehouseOutId: out.ID,
  1884. Count: 1,
  1885. Status: 1,
  1886. Ctime: time.Now().Unix(),
  1887. Remark: "",
  1888. OrgId: adminUserInfo.Org.Id,
  1889. Type: 1,
  1890. Manufacturer: 0,
  1891. Dealer: 0,
  1892. IsSys: 1,
  1893. SysRecordTime: order.StartTime,
  1894. }
  1895. stockInInfo, _ := service.FindLastStockInInfoRecord(safe_package, adminUserInfo.Org.Id)
  1896. warehouseOutInfo.Price = stockInInfo.Price
  1897. warehouseOutInfo.GoodId = safe_package
  1898. warehouseOutInfo.GoodTypeId = safe_package_good_type_id
  1899. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1900. if err == nil {
  1901. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1902. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1903. if err == gorm.ErrRecordNotFound {
  1904. details := &models.AutomaticReduceDetail{
  1905. WarehouseOutId: warehouseOutInfo.ID,
  1906. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1907. PatientId: id,
  1908. Ctime: time.Now().Unix(),
  1909. Mtime: time.Now().Unix(),
  1910. Status: 1,
  1911. RecordTime: order.StartTime,
  1912. OrgId: adminUserInfo.Org.Id,
  1913. GoodId: safe_package,
  1914. GoodTypeId: safe_package_good_type_id,
  1915. }
  1916. service.AddSigleAutoReduceRecordInfo(details)
  1917. } else if err == nil {
  1918. if user.ID > 0 {
  1919. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.Org.Id, id, safe_package, warehouseOutInfo)
  1920. }
  1921. }
  1922. }
  1923. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1924. if newOut.ID > 0 {
  1925. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1926. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1927. if err == gorm.ErrRecordNotFound {
  1928. details := &models.AutomaticReduceDetail{
  1929. WarehouseOutId: newOut.ID,
  1930. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1931. PatientId: id,
  1932. Ctime: time.Now().Unix(),
  1933. Mtime: time.Now().Unix(),
  1934. Status: 1,
  1935. RecordTime: order.StartTime,
  1936. OrgId: adminUserInfo.Org.Id,
  1937. GoodId: safe_package,
  1938. GoodTypeId: safe_package_good_type_id,
  1939. }
  1940. service.AddSigleAutoReduceRecordInfo(details)
  1941. } else if err == nil {
  1942. if user.ID > 0 {
  1943. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.Org.Id, id, safe_package, &newOut)
  1944. }
  1945. }
  1946. }
  1947. }
  1948. }
  1949. if dialysisPrescription.ALiquid != a_liquid {
  1950. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1951. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1952. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1953. service.UpdateOrderCount(aliquid_good_type_id, dialysisPrescription.ALiquid, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1954. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1955. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1956. err, newOut := service.FindOrderInfoByGoodId(aliquid_good_type_id, a_liquid, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1957. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1958. warehouseOutInfo := &models.WarehouseOutInfo{
  1959. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1960. WarehouseOutId: out.ID,
  1961. Count: 1,
  1962. Status: 1,
  1963. Ctime: time.Now().Unix(),
  1964. Remark: "",
  1965. OrgId: adminUserInfo.Org.Id,
  1966. Type: 1,
  1967. Manufacturer: 0,
  1968. Dealer: 0,
  1969. IsSys: 1,
  1970. SysRecordTime: order.StartTime,
  1971. }
  1972. stockInInfo, _ := service.FindLastStockInInfoRecord(a_liquid, adminUserInfo.Org.Id)
  1973. warehouseOutInfo.Price = stockInInfo.Price
  1974. warehouseOutInfo.GoodId = a_liquid
  1975. warehouseOutInfo.GoodTypeId = aliquid_good_type_id
  1976. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1977. if err == nil {
  1978. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1979. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1980. if err == gorm.ErrRecordNotFound {
  1981. details := &models.AutomaticReduceDetail{
  1982. WarehouseOutId: warehouseOutInfo.ID,
  1983. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1984. PatientId: id,
  1985. Ctime: time.Now().Unix(),
  1986. Mtime: time.Now().Unix(),
  1987. Status: 1,
  1988. RecordTime: order.StartTime,
  1989. OrgId: adminUserInfo.Org.Id,
  1990. GoodId: a_liquid,
  1991. GoodTypeId: aliquid_good_type_id,
  1992. }
  1993. service.AddSigleAutoReduceRecordInfo(details)
  1994. } else if err == nil {
  1995. if user.ID > 0 {
  1996. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.Org.Id, id, a_liquid, warehouseOutInfo)
  1997. }
  1998. }
  1999. }
  2000. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  2001. if newOut.ID > 0 {
  2002. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  2003. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  2004. if err == gorm.ErrRecordNotFound {
  2005. details := &models.AutomaticReduceDetail{
  2006. WarehouseOutId: newOut.ID,
  2007. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  2008. PatientId: id,
  2009. Ctime: time.Now().Unix(),
  2010. Mtime: time.Now().Unix(),
  2011. Status: 1,
  2012. RecordTime: order.StartTime,
  2013. OrgId: adminUserInfo.Org.Id,
  2014. GoodId: a_liquid,
  2015. GoodTypeId: aliquid_good_type_id,
  2016. }
  2017. service.AddSigleAutoReduceRecordInfo(details)
  2018. } else if err == nil {
  2019. if user.ID > 0 {
  2020. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.Org.Id, id, a_liquid, &newOut)
  2021. }
  2022. }
  2023. }
  2024. }
  2025. }
  2026. }
  2027. }
  2028. }
  2029. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2030. prescription.Modifier = adminUserInfo.AdminUser.Id
  2031. if appRole.UserType == 2 || appRole.UserType == 1 {
  2032. prescription_doctor := adminUserInfo.AdminUser.Id
  2033. prescription.PrescriptionDoctor = prescription_doctor
  2034. }
  2035. if dialysisPrescription.Creater == 0 { //体重称
  2036. prescription.Creater = adminUserInfo.AdminUser.Id
  2037. } else {
  2038. prescription.Creater = dialysisPrescription.Creater
  2039. }
  2040. prescription.ID = dialysisPrescription.ID
  2041. err := service.UpDateDialysisPrescription(&prescription)
  2042. if err == nil {
  2043. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2044. if updateErr != nil {
  2045. utils.ErrorLog("%v", updateErr)
  2046. }
  2047. c.ServeSuccessJSON(map[string]interface{}{
  2048. "prescription": prescription,
  2049. })
  2050. }
  2051. }
  2052. }
  2053. func (c *DialysisAPIController) Finish() {
  2054. id, _ := c.GetInt64("patient", 0)
  2055. recordDateStr := c.GetString("record_date")
  2056. nurseID, _ := c.GetInt64("nurse")
  2057. end_time := c.GetString("end_time")
  2058. if id <= 0 || nurseID <= 0 {
  2059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2060. return
  2061. }
  2062. adminUserInfo := c.GetMobileAdminUserInfo()
  2063. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2064. if patient.ID == 0 {
  2065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2066. return
  2067. }
  2068. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2069. if getNurseErr != nil {
  2070. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2072. return
  2073. } else if nurse == nil {
  2074. c.ErrorLog("护士不存在")
  2075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2076. return
  2077. }
  2078. if len(recordDateStr) == 0 {
  2079. recordDateStr = time.Now().Format("2006-01-02")
  2080. }
  2081. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2082. if parseDateErr != nil {
  2083. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2085. return
  2086. }
  2087. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2088. if parseEndDateErr != nil {
  2089. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2090. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2091. return
  2092. }
  2093. //now := time.Now()
  2094. //year, month, day := now.Date()
  2095. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2096. //todayTimeStamp := today_time.Unix()
  2097. // 获取当天的第一条透析纪录
  2098. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2099. if getMonitorRecordsErr != nil {
  2100. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2102. return
  2103. }
  2104. // 获取当前的最后一条透析纪录
  2105. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecord(adminUserInfo.Org.Id, id, recordDate.Unix())
  2106. if getMonitorRecordsErr != nil {
  2107. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2109. return
  2110. }
  2111. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2112. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.Org.Id, id, recordDate.Unix())
  2113. if getAADErr != nil {
  2114. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2116. return
  2117. }
  2118. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.Org.Id, id, recordDate.Unix())
  2119. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2120. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2121. if assessmentAfterDislysis != nil {
  2122. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2123. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2124. } else {
  2125. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2126. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2127. tempassessmentAfterDislysis.Status = 1
  2128. tempassessmentAfterDislysis.PatientId = id
  2129. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2130. }
  2131. if dialysisOrder.Stage == 1 {
  2132. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2133. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2134. fmt.Println(value)
  2135. a, b := math.Modf(value)
  2136. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2137. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2138. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2139. fmt.Println(hour)
  2140. fmt.Println(minute)
  2141. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2142. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2143. }
  2144. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2145. //var num1 int64
  2146. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2147. //fmt.Println(num1)
  2148. //sub := float64(num1 / 3600)
  2149. //fmt.Println(sub)
  2150. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2151. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2152. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2153. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2154. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2155. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2156. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2157. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2158. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2159. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2160. }
  2161. if lastAssessmentAfterDislysis != nil {
  2162. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2163. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2164. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2165. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2166. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2167. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2168. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2169. tempassessmentAfterDislysis.Remark = lastAssessmentAfterDislysis.Remark
  2170. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2171. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2172. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2173. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2174. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2175. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2176. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2177. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2178. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2179. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2180. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2181. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2182. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2183. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2184. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2185. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2186. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2187. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2188. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2189. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2190. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2191. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2192. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2193. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2194. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2195. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2196. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2197. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2198. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2199. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2200. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2201. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2202. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2203. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2204. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2205. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2206. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2207. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2208. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2209. }
  2210. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2211. if err != nil {
  2212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2213. return
  2214. }
  2215. if dialysisOrder == nil {
  2216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2217. return
  2218. }
  2219. if dialysisOrder.Stage == 2 {
  2220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2221. return
  2222. }
  2223. if dialysisOrder.Stage == 1 {
  2224. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id)
  2225. //结束时候透析次数加1
  2226. service.UpdateSolutionByPatientId(id)
  2227. dialysisOrder.Stage = 2
  2228. dialysisOrder.FinishNurse = nurseID
  2229. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2230. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2231. dialysisOrder.EndTime = endDate.Unix()
  2232. if err == nil {
  2233. c.ServeSuccessJSON(map[string]interface{}{
  2234. "dialysisOrder": dialysisOrder,
  2235. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2236. })
  2237. } else {
  2238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2239. }
  2240. }
  2241. }
  2242. func (c *DialysisAPIController) GetAllZone() {
  2243. adminUserInfo := c.GetMobileAdminUserInfo()
  2244. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2245. if err == nil {
  2246. c.ServeSuccessJSON(map[string]interface{}{
  2247. "zone": zone,
  2248. })
  2249. }
  2250. }
  2251. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2252. adminUserInfo := c.GetMobileAdminUserInfo()
  2253. page, _ := c.GetInt64("page", 1)
  2254. limit, _ := c.GetInt64("limit", 10)
  2255. schedulType, _ := c.GetInt64("schedul_type", 0)
  2256. startTime, _ := c.GetInt64("schedul_time", 0)
  2257. partitionType, _ := c.GetInt64("partition_type", 0)
  2258. keywords := c.GetString("keywords")
  2259. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2260. if err == nil {
  2261. c.ServeSuccessJSON(map[string]interface{}{
  2262. "schedule": dialysisSchedule,
  2263. })
  2264. }
  2265. return
  2266. }
  2267. // /m/api/dialysis/start [post]
  2268. // @param patient_id:int
  2269. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2270. // @param nurse:int 上机护士
  2271. // @param bed:int 床位号
  2272. func (this *DialysisAPIController) StartDialysis() {
  2273. patientID, _ := this.GetInt64("patient_id")
  2274. recordDateStr := this.GetString("record_date")
  2275. nurseID, _ := this.GetInt64("nurse")
  2276. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2277. blood_drawing, _ := this.GetInt64("blood_drawing")
  2278. schedual_type, _ := this.GetInt64("schedual_type")
  2279. bedID, _ := this.GetInt64("bed")
  2280. start_time := this.GetString("start_time")
  2281. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2282. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2283. return
  2284. }
  2285. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2286. if parseStartDateErr != nil {
  2287. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2288. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2289. return
  2290. }
  2291. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2292. if parseErr != nil {
  2293. this.ErrorLog("时间解析失败:%v", parseErr)
  2294. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2295. return
  2296. }
  2297. adminUserInfo := this.GetMobileAdminUserInfo()
  2298. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2299. if getPatientErr != nil {
  2300. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2301. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2302. return
  2303. } else if patient == nil {
  2304. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2305. return
  2306. }
  2307. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2308. if getNurseErr != nil {
  2309. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2310. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2311. return
  2312. } else if nurse == nil {
  2313. this.ErrorLog("护士不存在")
  2314. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2315. return
  2316. }
  2317. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2318. if getNurseErr != nil {
  2319. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2320. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2321. return
  2322. } else if nurse == nil {
  2323. this.ErrorLog("护士不存在")
  2324. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2325. return
  2326. }
  2327. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2328. if getDeviceNumberErr != nil {
  2329. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2330. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2331. return
  2332. } else if deviceNumber == nil {
  2333. this.ErrorLog("床位号不存在")
  2334. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2335. return
  2336. }
  2337. _, configs := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  2338. if configs.IsOpen == 1 {
  2339. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id)
  2340. if prescription.ID == 0 {
  2341. this.ErrorLog("上机失败,还没开处方")
  2342. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionException)
  2343. return
  2344. }
  2345. }
  2346. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2347. if getRecordErr != nil {
  2348. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2349. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2350. return
  2351. } else if dialysisRecord != nil {
  2352. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2353. return
  2354. }
  2355. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2356. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2357. timeLayout := "2006-01-02 15:04:05"
  2358. loc, _ := time.LoadLocation("Local")
  2359. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2360. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2361. schedulestartTime := theStartTime.Unix()
  2362. scheduleendTime := theEndTime.Unix()
  2363. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2364. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2365. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2366. //查询该床位是否有人用了
  2367. order, order_err := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2368. if err == gorm.ErrRecordNotFound { //空床位
  2369. // 修改了床位逻辑
  2370. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2371. if daySchedule.ID > 0 {
  2372. daySchedule.PartitionId = deviceNumber.ZoneID
  2373. daySchedule.BedId = bedID
  2374. daySchedule.ScheduleType = schedual_type
  2375. daySchedule.UpdatedTime = time.Now().Unix()
  2376. err := service.UpdateSchedule(&daySchedule)
  2377. if err != nil {
  2378. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2379. return
  2380. }
  2381. }
  2382. } else if err == nil {
  2383. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2384. if order_err == nil {
  2385. if order.ID > 0 { //该机位被其他人占用了
  2386. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2387. return
  2388. } else {
  2389. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2390. if daySchedule.ID > 0 {
  2391. daySchedule.PartitionId = deviceNumber.ZoneID
  2392. daySchedule.BedId = bedID
  2393. daySchedule.ScheduleType = schedual_type
  2394. daySchedule.UpdatedTime = time.Now().Unix()
  2395. err := service.UpdateSchedule(&daySchedule)
  2396. if err != nil {
  2397. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2398. return
  2399. }
  2400. }
  2401. }
  2402. } else if order_err == gorm.ErrRecordNotFound { //该床位没被占用
  2403. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2404. if daySchedule.ID > 0 {
  2405. daySchedule.PartitionId = deviceNumber.ZoneID
  2406. daySchedule.BedId = bedID
  2407. daySchedule.ScheduleType = schedual_type
  2408. daySchedule.UpdatedTime = time.Now().Unix()
  2409. err := service.UpdateSchedule(&daySchedule)
  2410. if err != nil {
  2411. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2412. return
  2413. }
  2414. }
  2415. }
  2416. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2417. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2418. return
  2419. }
  2420. } else if err != nil {
  2421. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2422. return
  2423. }
  2424. dialysisRecord = &models.DialysisOrder{
  2425. DialysisDate: recordDate.Unix(),
  2426. UserOrgId: adminUserInfo.Org.Id,
  2427. PatientId: patientID,
  2428. Stage: 1,
  2429. BedID: bedID,
  2430. StartNurse: nurseID,
  2431. Status: 1,
  2432. StartTime: startDate.Unix(),
  2433. CreatedTime: time.Now().Unix(),
  2434. UpdatedTime: time.Now().Unix(),
  2435. PunctureNurse: puncture_nurse,
  2436. Creator: adminUserInfo.AdminUser.Id,
  2437. Modifier: adminUserInfo.AdminUser.Id,
  2438. SchedualType: schedual_type,
  2439. }
  2440. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  2441. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2442. var tempdispose string
  2443. // 只针对中能建
  2444. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  2445. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2446. }
  2447. var ultrafiltration_rate float64
  2448. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2449. if prescription.ID > 0 {
  2450. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2451. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2452. if template.TemplateId == 6 || template.TemplateId == 20 { //adminUserInfo.Org.Id == 9538
  2453. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2454. }
  2455. // 只针对方济医院
  2456. if template.TemplateId == 1 {
  2457. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2458. ultrafiltration_rate = value
  2459. }
  2460. }
  2461. }
  2462. record := models.MonitoringRecord{
  2463. UserOrgId: adminUserInfo.Org.Id,
  2464. PatientId: patientID,
  2465. DialysisOrderId: dialysisRecord.ID,
  2466. MonitoringDate: schedulestartTime,
  2467. OperateTime: startDate.Unix(),
  2468. // MonitoringTime: recordTime,
  2469. MonitoringNurse: nurseID,
  2470. Dispose: tempdispose,
  2471. UltrafiltrationRate: ultrafiltration_rate,
  2472. UltrafiltrationVolume: 0,
  2473. Status: 1,
  2474. CreatedTime: time.Now().Unix(),
  2475. UpdatedTime: time.Now().Unix(),
  2476. }
  2477. // 如果当天有插入数据,则不再往透析纪录里插入数据
  2478. if newdialysisRecord.ID > 0 {
  2479. err := service.CreateMonitor(&record)
  2480. if err != nil {
  2481. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  2482. return
  2483. }
  2484. }
  2485. //是否启动自动扣减功能
  2486. _, config := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  2487. //启动的话
  2488. if config.IsOpen == 1 {
  2489. niprocart, _ := beego.AppConfig.Int64("niprocart")
  2490. jms, _ := beego.AppConfig.Int64("jms")
  2491. fistula_needle_set, _ := beego.AppConfig.Int64("fistula_needle_set")
  2492. fistula_needle_set_16, _ := beego.AppConfig.Int64("fistula_needle_set_16")
  2493. hemoperfusion, _ := beego.AppConfig.Int64("hemoperfusion")
  2494. dialyser_sterilised, _ := beego.AppConfig.Int64("dialyser_sterilised")
  2495. filtryzer, _ := beego.AppConfig.Int64("filtryzer")
  2496. dialyzers, _ := beego.AppConfig.Int64("dialyzers")
  2497. injector, _ := beego.AppConfig.Int64("injector")
  2498. bloodlines, _ := beego.AppConfig.Int64("bloodlines")
  2499. tubingHemodialysis, _ := beego.AppConfig.Int64("tubingHemodialysis")
  2500. safe_package, _ := beego.AppConfig.Int64("package")
  2501. aliquid, _ := beego.AppConfig.Int64("aliquid")
  2502. //库存自动扣减功能
  2503. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id)
  2504. if prescription.ID > 0 {
  2505. out, err := service.FindStockOutByIsSys(adminUserInfo.Org.Id, 1, recordDate.Unix())
  2506. if err == gorm.ErrRecordNotFound {
  2507. //没有记录,则创建出库单
  2508. timeStr := time.Now().Format("2006-01-02")
  2509. timeArr := strings.Split(timeStr, "-")
  2510. total, _ := service.FindAllWarehouseOut(adminUserInfo.Org.Id)
  2511. total = total + 1
  2512. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2513. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2514. number = number + total
  2515. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2516. creater := adminUserInfo.AdminUser.Id
  2517. warehouseOut := models.WarehouseOut{
  2518. WarehouseOutOrderNumber: warehousing_out_order,
  2519. OperationTime: time.Now().Unix(),
  2520. OrgId: adminUserInfo.Org.Id,
  2521. Creater: creater,
  2522. Ctime: time.Now().Unix(),
  2523. Status: 1,
  2524. WarehouseOutTime: recordDate.Unix(),
  2525. Dealer: 0,
  2526. Manufacturer: 0,
  2527. Type: 1,
  2528. IsSys: 1,
  2529. }
  2530. err := service.AddSigleWarehouseOut(&warehouseOut)
  2531. if err != nil {
  2532. utils.TraceLog("创建出库单失败 err = %v", err)
  2533. } else {
  2534. if prescription.Niprocart > 0 {
  2535. warehouseOutInfo := &models.WarehouseOutInfo{
  2536. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2537. WarehouseOutId: warehouseOut.ID,
  2538. Count: 1,
  2539. Status: 1,
  2540. Ctime: time.Now().Unix(),
  2541. Remark: "",
  2542. OrgId: adminUserInfo.Org.Id,
  2543. Type: 1,
  2544. Manufacturer: 0,
  2545. Dealer: 0,
  2546. IsSys: 1,
  2547. SysRecordTime: startDate.Unix(),
  2548. }
  2549. //查出入库记录中最后一条记录
  2550. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Niprocart, adminUserInfo.Org.Id)
  2551. warehouseOutInfo.Price = stockInInfo.Price
  2552. warehouseOutInfo.GoodId = prescription.Niprocart
  2553. warehouseOutInfo.GoodTypeId = niprocart
  2554. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2555. if err == nil {
  2556. details := &models.AutomaticReduceDetail{
  2557. WarehouseOutId: warehouseOutInfo.ID,
  2558. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2559. PatientId: patientID,
  2560. Ctime: time.Now().Unix(),
  2561. Mtime: time.Now().Unix(),
  2562. Status: 1,
  2563. RecordTime: startDate.Unix(),
  2564. OrgId: adminUserInfo.Org.Id,
  2565. GoodId: prescription.Niprocart,
  2566. GoodTypeId: niprocart,
  2567. }
  2568. service.AddSigleAutoReduceRecordInfo(details)
  2569. }
  2570. }
  2571. if prescription.Jms > 0 {
  2572. warehouseOutInfo := &models.WarehouseOutInfo{
  2573. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2574. WarehouseOutId: warehouseOut.ID,
  2575. Count: 1,
  2576. Status: 1,
  2577. Ctime: time.Now().Unix(),
  2578. Remark: "",
  2579. OrgId: adminUserInfo.Org.Id,
  2580. Type: 1,
  2581. Manufacturer: 0,
  2582. Dealer: 0,
  2583. IsSys: 1,
  2584. SysRecordTime: startDate.Unix(),
  2585. }
  2586. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Jms, adminUserInfo.Org.Id)
  2587. warehouseOutInfo.Price = stockInInfo.Price
  2588. warehouseOutInfo.GoodId = prescription.Jms
  2589. warehouseOutInfo.GoodTypeId = jms
  2590. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2591. if err == nil {
  2592. details := &models.AutomaticReduceDetail{
  2593. WarehouseOutId: warehouseOutInfo.ID,
  2594. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2595. PatientId: patientID,
  2596. Ctime: time.Now().Unix(),
  2597. Mtime: time.Now().Unix(),
  2598. Status: 1,
  2599. RecordTime: startDate.Unix(),
  2600. OrgId: adminUserInfo.Org.Id,
  2601. GoodId: prescription.Jms,
  2602. GoodTypeId: jms,
  2603. }
  2604. service.AddSigleAutoReduceRecordInfo(details)
  2605. }
  2606. }
  2607. if prescription.FistulaNeedleSet > 0 {
  2608. warehouseOutInfo := &models.WarehouseOutInfo{
  2609. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2610. WarehouseOutId: warehouseOut.ID,
  2611. Count: 1,
  2612. Status: 1,
  2613. Ctime: time.Now().Unix(),
  2614. Remark: "",
  2615. OrgId: adminUserInfo.Org.Id,
  2616. Type: 1,
  2617. Manufacturer: 0,
  2618. Dealer: 0,
  2619. IsSys: 1,
  2620. SysRecordTime: startDate.Unix(),
  2621. }
  2622. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet, adminUserInfo.Org.Id)
  2623. warehouseOutInfo.Price = stockInInfo.Price
  2624. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet
  2625. warehouseOutInfo.GoodTypeId = fistula_needle_set
  2626. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2627. if err == nil {
  2628. details := &models.AutomaticReduceDetail{
  2629. WarehouseOutId: warehouseOutInfo.ID,
  2630. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2631. PatientId: patientID,
  2632. Ctime: time.Now().Unix(),
  2633. Mtime: time.Now().Unix(),
  2634. Status: 1,
  2635. RecordTime: startDate.Unix(),
  2636. OrgId: adminUserInfo.Org.Id,
  2637. GoodId: prescription.FistulaNeedleSet,
  2638. GoodTypeId: fistula_needle_set,
  2639. }
  2640. service.AddSigleAutoReduceRecordInfo(details)
  2641. }
  2642. }
  2643. if prescription.FistulaNeedleSet16 > 0 {
  2644. warehouseOutInfo := &models.WarehouseOutInfo{
  2645. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2646. WarehouseOutId: warehouseOut.ID,
  2647. Count: 1,
  2648. Status: 1,
  2649. Ctime: time.Now().Unix(),
  2650. Remark: "",
  2651. OrgId: adminUserInfo.Org.Id,
  2652. Type: 1,
  2653. Manufacturer: 0,
  2654. Dealer: 0,
  2655. IsSys: 1,
  2656. SysRecordTime: startDate.Unix(),
  2657. }
  2658. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet16, adminUserInfo.Org.Id)
  2659. warehouseOutInfo.Price = stockInInfo.Price
  2660. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet16
  2661. warehouseOutInfo.GoodTypeId = fistula_needle_set_16
  2662. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2663. if err == nil {
  2664. details := &models.AutomaticReduceDetail{
  2665. WarehouseOutId: warehouseOutInfo.ID,
  2666. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2667. PatientId: patientID,
  2668. Ctime: time.Now().Unix(),
  2669. Mtime: time.Now().Unix(),
  2670. Status: 1,
  2671. RecordTime: startDate.Unix(),
  2672. OrgId: adminUserInfo.Org.Id,
  2673. GoodId: prescription.FistulaNeedleSet16,
  2674. GoodTypeId: fistula_needle_set_16,
  2675. }
  2676. service.AddSigleAutoReduceRecordInfo(details)
  2677. }
  2678. }
  2679. if prescription.Hemoperfusion > 0 {
  2680. warehouseOutInfo := &models.WarehouseOutInfo{
  2681. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2682. WarehouseOutId: warehouseOut.ID,
  2683. Count: 1,
  2684. Status: 1,
  2685. Ctime: time.Now().Unix(),
  2686. Remark: "",
  2687. OrgId: adminUserInfo.Org.Id,
  2688. Type: 1,
  2689. Manufacturer: 0,
  2690. Dealer: 0,
  2691. IsSys: 1,
  2692. SysRecordTime: startDate.Unix(),
  2693. }
  2694. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Hemoperfusion, adminUserInfo.Org.Id)
  2695. warehouseOutInfo.Price = stockInInfo.Price
  2696. warehouseOutInfo.GoodId = prescription.Hemoperfusion
  2697. warehouseOutInfo.GoodTypeId = hemoperfusion
  2698. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2699. if err == nil {
  2700. details := &models.AutomaticReduceDetail{
  2701. WarehouseOutId: warehouseOutInfo.ID,
  2702. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2703. PatientId: patientID,
  2704. Ctime: time.Now().Unix(),
  2705. Mtime: time.Now().Unix(),
  2706. Status: 1,
  2707. RecordTime: startDate.Unix(),
  2708. OrgId: adminUserInfo.Org.Id,
  2709. GoodId: prescription.Hemoperfusion,
  2710. GoodTypeId: hemoperfusion,
  2711. }
  2712. service.AddSigleAutoReduceRecordInfo(details)
  2713. }
  2714. }
  2715. if prescription.DialyserSterilised > 0 {
  2716. warehouseOutInfo := &models.WarehouseOutInfo{
  2717. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2718. WarehouseOutId: warehouseOut.ID,
  2719. Count: 1,
  2720. Status: 1,
  2721. Ctime: time.Now().Unix(),
  2722. Remark: "",
  2723. OrgId: adminUserInfo.Org.Id,
  2724. Type: 1,
  2725. Manufacturer: 0,
  2726. Dealer: 0,
  2727. IsSys: 1,
  2728. SysRecordTime: startDate.Unix(),
  2729. }
  2730. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.DialyserSterilised, adminUserInfo.Org.Id)
  2731. warehouseOutInfo.Price = stockInInfo.Price
  2732. warehouseOutInfo.GoodId = prescription.DialyserSterilised
  2733. warehouseOutInfo.GoodTypeId = dialyser_sterilised
  2734. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2735. if err == nil {
  2736. details := &models.AutomaticReduceDetail{
  2737. WarehouseOutId: warehouseOutInfo.ID,
  2738. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2739. PatientId: patientID,
  2740. Ctime: time.Now().Unix(),
  2741. Mtime: time.Now().Unix(),
  2742. Status: 1,
  2743. RecordTime: startDate.Unix(),
  2744. OrgId: adminUserInfo.Org.Id,
  2745. GoodId: prescription.DialyserSterilised,
  2746. GoodTypeId: dialyser_sterilised,
  2747. }
  2748. service.AddSigleAutoReduceRecordInfo(details)
  2749. }
  2750. }
  2751. if prescription.Filtryzer > 0 {
  2752. warehouseOutInfo := &models.WarehouseOutInfo{
  2753. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2754. WarehouseOutId: warehouseOut.ID,
  2755. Count: 1,
  2756. Status: 1,
  2757. Ctime: time.Now().Unix(),
  2758. Remark: "",
  2759. OrgId: adminUserInfo.Org.Id,
  2760. Type: 1,
  2761. Manufacturer: 0,
  2762. Dealer: 0,
  2763. IsSys: 1,
  2764. SysRecordTime: startDate.Unix(),
  2765. }
  2766. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Filtryzer, adminUserInfo.Org.Id)
  2767. warehouseOutInfo.Price = stockInInfo.Price
  2768. warehouseOutInfo.GoodId = prescription.Filtryzer
  2769. warehouseOutInfo.GoodTypeId = filtryzer
  2770. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2771. if err == nil {
  2772. details := &models.AutomaticReduceDetail{
  2773. WarehouseOutId: warehouseOutInfo.ID,
  2774. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2775. PatientId: patientID,
  2776. Ctime: time.Now().Unix(),
  2777. Mtime: time.Now().Unix(),
  2778. Status: 1,
  2779. RecordTime: startDate.Unix(),
  2780. OrgId: adminUserInfo.Org.Id,
  2781. GoodId: prescription.Filtryzer,
  2782. GoodTypeId: filtryzer,
  2783. }
  2784. service.AddSigleAutoReduceRecordInfo(details)
  2785. }
  2786. }
  2787. if prescription.Dialyzers > 0 {
  2788. warehouseOutInfo := &models.WarehouseOutInfo{
  2789. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2790. WarehouseOutId: warehouseOut.ID,
  2791. Count: 1,
  2792. Status: 1,
  2793. Ctime: time.Now().Unix(),
  2794. Remark: "",
  2795. OrgId: adminUserInfo.Org.Id,
  2796. Type: 1,
  2797. Manufacturer: 0,
  2798. Dealer: 0,
  2799. IsSys: 1,
  2800. SysRecordTime: startDate.Unix(),
  2801. }
  2802. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Dialyzers, adminUserInfo.Org.Id)
  2803. warehouseOutInfo.Price = stockInInfo.Price
  2804. warehouseOutInfo.GoodId = prescription.Dialyzers
  2805. warehouseOutInfo.GoodTypeId = dialyzers
  2806. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2807. if err == nil {
  2808. details := &models.AutomaticReduceDetail{
  2809. WarehouseOutId: warehouseOutInfo.ID,
  2810. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2811. PatientId: patientID,
  2812. Ctime: time.Now().Unix(),
  2813. Mtime: time.Now().Unix(),
  2814. Status: 1,
  2815. RecordTime: startDate.Unix(),
  2816. OrgId: adminUserInfo.Org.Id,
  2817. GoodId: prescription.Dialyzers,
  2818. GoodTypeId: dialyzers,
  2819. }
  2820. service.AddSigleAutoReduceRecordInfo(details)
  2821. }
  2822. }
  2823. if prescription.Injector > 0 {
  2824. warehouseOutInfo := &models.WarehouseOutInfo{
  2825. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2826. WarehouseOutId: warehouseOut.ID,
  2827. Count: 1,
  2828. Status: 1,
  2829. Ctime: time.Now().Unix(),
  2830. Remark: "",
  2831. OrgId: adminUserInfo.Org.Id,
  2832. Type: 1,
  2833. Manufacturer: 0,
  2834. Dealer: 0,
  2835. IsSys: 1,
  2836. SysRecordTime: startDate.Unix(),
  2837. }
  2838. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Injector, adminUserInfo.Org.Id)
  2839. warehouseOutInfo.Price = stockInInfo.Price
  2840. warehouseOutInfo.GoodId = prescription.Injector
  2841. warehouseOutInfo.GoodTypeId = injector
  2842. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2843. if err == nil {
  2844. details := &models.AutomaticReduceDetail{
  2845. WarehouseOutId: warehouseOutInfo.ID,
  2846. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2847. PatientId: patientID,
  2848. Ctime: time.Now().Unix(),
  2849. Mtime: time.Now().Unix(),
  2850. Status: 1,
  2851. RecordTime: startDate.Unix(),
  2852. OrgId: adminUserInfo.Org.Id,
  2853. GoodId: prescription.Injector,
  2854. GoodTypeId: injector,
  2855. }
  2856. service.AddSigleAutoReduceRecordInfo(details)
  2857. }
  2858. }
  2859. if prescription.Bloodlines > 0 {
  2860. warehouseOutInfo := &models.WarehouseOutInfo{
  2861. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2862. WarehouseOutId: warehouseOut.ID,
  2863. Count: 1,
  2864. Status: 1,
  2865. Ctime: time.Now().Unix(),
  2866. Remark: "",
  2867. OrgId: adminUserInfo.Org.Id,
  2868. Type: 1,
  2869. Manufacturer: 0,
  2870. Dealer: 0,
  2871. IsSys: 1,
  2872. SysRecordTime: startDate.Unix(),
  2873. }
  2874. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Bloodlines, adminUserInfo.Org.Id)
  2875. warehouseOutInfo.Price = stockInInfo.Price
  2876. warehouseOutInfo.GoodId = prescription.Bloodlines
  2877. warehouseOutInfo.GoodTypeId = bloodlines
  2878. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2879. if err == nil {
  2880. details := &models.AutomaticReduceDetail{
  2881. WarehouseOutId: warehouseOutInfo.ID,
  2882. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2883. PatientId: patientID,
  2884. Ctime: time.Now().Unix(),
  2885. Mtime: time.Now().Unix(),
  2886. Status: 1,
  2887. RecordTime: startDate.Unix(),
  2888. OrgId: adminUserInfo.Org.Id,
  2889. GoodId: prescription.Bloodlines,
  2890. GoodTypeId: bloodlines,
  2891. }
  2892. service.AddSigleAutoReduceRecordInfo(details)
  2893. }
  2894. }
  2895. if prescription.TubingHemodialysis > 0 {
  2896. warehouseOutInfo := &models.WarehouseOutInfo{
  2897. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2898. WarehouseOutId: warehouseOut.ID,
  2899. Count: 1,
  2900. Status: 1,
  2901. Ctime: time.Now().Unix(),
  2902. Remark: "",
  2903. OrgId: adminUserInfo.Org.Id,
  2904. Type: 1,
  2905. Manufacturer: 0,
  2906. Dealer: 0,
  2907. IsSys: 1,
  2908. SysRecordTime: startDate.Unix(),
  2909. }
  2910. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.TubingHemodialysis, adminUserInfo.Org.Id)
  2911. warehouseOutInfo.Price = stockInInfo.Price
  2912. warehouseOutInfo.GoodId = prescription.TubingHemodialysis
  2913. warehouseOutInfo.GoodTypeId = tubingHemodialysis
  2914. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2915. if err == nil {
  2916. details := &models.AutomaticReduceDetail{
  2917. WarehouseOutId: warehouseOutInfo.ID,
  2918. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2919. PatientId: patientID,
  2920. Ctime: time.Now().Unix(),
  2921. Mtime: time.Now().Unix(),
  2922. Status: 1,
  2923. RecordTime: startDate.Unix(),
  2924. OrgId: adminUserInfo.Org.Id,
  2925. GoodId: prescription.TubingHemodialysis,
  2926. GoodTypeId: tubingHemodialysis,
  2927. }
  2928. service.AddSigleAutoReduceRecordInfo(details)
  2929. }
  2930. }
  2931. if prescription.Package > 0 {
  2932. warehouseOutInfo := &models.WarehouseOutInfo{
  2933. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2934. WarehouseOutId: warehouseOut.ID,
  2935. Count: 1,
  2936. Status: 1,
  2937. Ctime: time.Now().Unix(),
  2938. Remark: "",
  2939. OrgId: adminUserInfo.Org.Id,
  2940. Type: 1,
  2941. Manufacturer: 0,
  2942. Dealer: 0,
  2943. IsSys: 1,
  2944. SysRecordTime: startDate.Unix(),
  2945. }
  2946. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Package, adminUserInfo.Org.Id)
  2947. warehouseOutInfo.Price = stockInInfo.Price
  2948. warehouseOutInfo.GoodId = prescription.Package
  2949. warehouseOutInfo.GoodTypeId = safe_package
  2950. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2951. if err == nil {
  2952. details := &models.AutomaticReduceDetail{
  2953. WarehouseOutId: warehouseOutInfo.ID,
  2954. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2955. PatientId: patientID,
  2956. Ctime: time.Now().Unix(),
  2957. Mtime: time.Now().Unix(),
  2958. Status: 1,
  2959. RecordTime: startDate.Unix(),
  2960. OrgId: adminUserInfo.Org.Id,
  2961. GoodId: prescription.Package,
  2962. GoodTypeId: safe_package,
  2963. }
  2964. service.AddSigleAutoReduceRecordInfo(details)
  2965. }
  2966. }
  2967. if prescription.ALiquid > 0 {
  2968. warehouseOutInfo := &models.WarehouseOutInfo{
  2969. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2970. WarehouseOutId: warehouseOut.ID,
  2971. Count: 1,
  2972. Status: 1,
  2973. Ctime: time.Now().Unix(),
  2974. Remark: "",
  2975. OrgId: adminUserInfo.Org.Id,
  2976. Type: 1,
  2977. Manufacturer: 0,
  2978. Dealer: 0,
  2979. IsSys: 1,
  2980. SysRecordTime: startDate.Unix(),
  2981. }
  2982. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.ALiquid, adminUserInfo.Org.Id)
  2983. warehouseOutInfo.Price = stockInInfo.Price
  2984. warehouseOutInfo.GoodId = prescription.ALiquid
  2985. warehouseOutInfo.GoodTypeId = aliquid
  2986. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2987. if err == nil {
  2988. details := &models.AutomaticReduceDetail{
  2989. WarehouseOutId: warehouseOutInfo.ID,
  2990. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2991. PatientId: patientID,
  2992. Ctime: time.Now().Unix(),
  2993. Mtime: time.Now().Unix(),
  2994. Status: 1,
  2995. RecordTime: startDate.Unix(),
  2996. OrgId: adminUserInfo.Org.Id,
  2997. GoodId: prescription.ALiquid,
  2998. GoodTypeId: aliquid,
  2999. }
  3000. service.AddSigleAutoReduceRecordInfo(details)
  3001. }
  3002. }
  3003. }
  3004. } else if err == nil {
  3005. if out.ID > 0 {
  3006. if prescription.Niprocart > 0 {
  3007. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, niprocart, prescription.Niprocart, out.WarehouseOutOrderNumber)
  3008. if err == gorm.ErrRecordNotFound {
  3009. warehouseOutInfo := &models.WarehouseOutInfo{
  3010. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3011. WarehouseOutId: out.ID,
  3012. Status: 1,
  3013. Ctime: time.Now().Unix(),
  3014. Remark: "",
  3015. OrgId: adminUserInfo.Org.Id,
  3016. Type: 1,
  3017. Manufacturer: 0,
  3018. Dealer: 0,
  3019. IsSys: 1,
  3020. SysRecordTime: startDate.Unix(),
  3021. }
  3022. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Niprocart, adminUserInfo.Org.Id)
  3023. warehouseOutInfo.Price = stockInInfo.Price
  3024. warehouseOutInfo.GoodId = prescription.Niprocart
  3025. warehouseOutInfo.GoodTypeId = niprocart
  3026. warehouseOutInfo.Count = 1
  3027. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3028. if err == nil {
  3029. details := &models.AutomaticReduceDetail{
  3030. WarehouseOutId: warehouseOutInfo.ID,
  3031. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3032. PatientId: patientID,
  3033. Ctime: time.Now().Unix(),
  3034. Mtime: time.Now().Unix(),
  3035. Status: 1,
  3036. RecordTime: startDate.Unix(),
  3037. OrgId: adminUserInfo.Org.Id,
  3038. GoodId: prescription.Niprocart,
  3039. GoodTypeId: niprocart,
  3040. }
  3041. service.AddSigleAutoReduceRecordInfo(details)
  3042. }
  3043. } else if err == nil { //记录存在,则将数量加1
  3044. if outInfo.ID > 0 {
  3045. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3046. }
  3047. details := &models.AutomaticReduceDetail{
  3048. WarehouseOutId: outInfo.ID,
  3049. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3050. PatientId: patientID,
  3051. Ctime: time.Now().Unix(),
  3052. Mtime: time.Now().Unix(),
  3053. Status: 1,
  3054. RecordTime: startDate.Unix(),
  3055. OrgId: adminUserInfo.Org.Id,
  3056. GoodId: prescription.Niprocart,
  3057. GoodTypeId: niprocart,
  3058. }
  3059. service.AddSigleAutoReduceRecordInfo(details)
  3060. }
  3061. }
  3062. if prescription.Jms > 0 {
  3063. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, jms, prescription.Jms, out.WarehouseOutOrderNumber)
  3064. if err == gorm.ErrRecordNotFound {
  3065. warehouseOutInfo := &models.WarehouseOutInfo{
  3066. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3067. WarehouseOutId: out.ID,
  3068. Status: 1,
  3069. Ctime: time.Now().Unix(),
  3070. Remark: "",
  3071. OrgId: adminUserInfo.Org.Id,
  3072. Type: 1,
  3073. Manufacturer: 0,
  3074. Dealer: 0,
  3075. IsSys: 1,
  3076. SysRecordTime: startDate.Unix(),
  3077. }
  3078. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Jms, adminUserInfo.Org.Id)
  3079. warehouseOutInfo.Price = stockInInfo.Price
  3080. warehouseOutInfo.GoodId = prescription.Jms
  3081. warehouseOutInfo.GoodTypeId = jms
  3082. warehouseOutInfo.Count = 1
  3083. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3084. if err == nil {
  3085. details := &models.AutomaticReduceDetail{
  3086. WarehouseOutId: warehouseOutInfo.ID,
  3087. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3088. PatientId: patientID,
  3089. Ctime: time.Now().Unix(),
  3090. Mtime: time.Now().Unix(),
  3091. Status: 1,
  3092. RecordTime: startDate.Unix(),
  3093. OrgId: adminUserInfo.Org.Id,
  3094. GoodId: prescription.Jms,
  3095. GoodTypeId: jms,
  3096. }
  3097. service.AddSigleAutoReduceRecordInfo(details)
  3098. }
  3099. } else if err == nil { //记录存在,则将数量加1
  3100. if outInfo.ID > 0 {
  3101. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3102. }
  3103. details := &models.AutomaticReduceDetail{
  3104. WarehouseOutId: outInfo.ID,
  3105. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3106. PatientId: patientID,
  3107. Ctime: time.Now().Unix(),
  3108. Mtime: time.Now().Unix(),
  3109. Status: 1,
  3110. RecordTime: startDate.Unix(),
  3111. OrgId: adminUserInfo.Org.Id,
  3112. GoodId: prescription.Jms,
  3113. GoodTypeId: jms,
  3114. }
  3115. service.AddSigleAutoReduceRecordInfo(details)
  3116. }
  3117. }
  3118. if prescription.FistulaNeedleSet > 0 {
  3119. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, fistula_needle_set, prescription.FistulaNeedleSet, out.WarehouseOutOrderNumber)
  3120. if err == gorm.ErrRecordNotFound {
  3121. warehouseOutInfo := &models.WarehouseOutInfo{
  3122. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3123. WarehouseOutId: out.ID,
  3124. Status: 1,
  3125. Ctime: time.Now().Unix(),
  3126. Remark: "",
  3127. OrgId: adminUserInfo.Org.Id,
  3128. Type: 1,
  3129. Manufacturer: 0,
  3130. Dealer: 0,
  3131. IsSys: 1,
  3132. SysRecordTime: startDate.Unix(),
  3133. }
  3134. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet, adminUserInfo.Org.Id)
  3135. warehouseOutInfo.Price = stockInInfo.Price
  3136. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet
  3137. warehouseOutInfo.GoodTypeId = fistula_needle_set
  3138. warehouseOutInfo.Count = 1
  3139. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3140. if err == nil {
  3141. details := &models.AutomaticReduceDetail{
  3142. WarehouseOutId: warehouseOutInfo.ID,
  3143. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3144. PatientId: patientID,
  3145. Ctime: time.Now().Unix(),
  3146. Mtime: time.Now().Unix(),
  3147. Status: 1,
  3148. RecordTime: startDate.Unix(),
  3149. OrgId: adminUserInfo.Org.Id,
  3150. GoodId: prescription.FistulaNeedleSet,
  3151. GoodTypeId: fistula_needle_set,
  3152. }
  3153. service.AddSigleAutoReduceRecordInfo(details)
  3154. }
  3155. } else if err == nil { //记录存在,则将数量加1
  3156. if outInfo.ID > 0 {
  3157. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3158. }
  3159. details := &models.AutomaticReduceDetail{
  3160. WarehouseOutId: outInfo.ID,
  3161. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3162. PatientId: patientID,
  3163. Ctime: time.Now().Unix(),
  3164. Mtime: time.Now().Unix(),
  3165. Status: 1,
  3166. RecordTime: startDate.Unix(),
  3167. OrgId: adminUserInfo.Org.Id,
  3168. GoodId: prescription.FistulaNeedleSet,
  3169. GoodTypeId: fistula_needle_set,
  3170. }
  3171. service.AddSigleAutoReduceRecordInfo(details)
  3172. }
  3173. }
  3174. if prescription.FistulaNeedleSet16 > 0 {
  3175. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, fistula_needle_set_16, prescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber)
  3176. if err == gorm.ErrRecordNotFound {
  3177. warehouseOutInfo := &models.WarehouseOutInfo{
  3178. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3179. WarehouseOutId: out.ID,
  3180. Status: 1,
  3181. Ctime: time.Now().Unix(),
  3182. Remark: "",
  3183. OrgId: adminUserInfo.Org.Id,
  3184. Type: 1,
  3185. Manufacturer: 0,
  3186. Dealer: 0,
  3187. IsSys: 1,
  3188. SysRecordTime: startDate.Unix(),
  3189. }
  3190. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet16, adminUserInfo.Org.Id)
  3191. warehouseOutInfo.Price = stockInInfo.Price
  3192. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet16
  3193. warehouseOutInfo.GoodTypeId = fistula_needle_set_16
  3194. warehouseOutInfo.Count = 1
  3195. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3196. if err == nil {
  3197. details := &models.AutomaticReduceDetail{
  3198. WarehouseOutId: warehouseOutInfo.ID,
  3199. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3200. PatientId: patientID,
  3201. Ctime: time.Now().Unix(),
  3202. Mtime: time.Now().Unix(),
  3203. Status: 1,
  3204. RecordTime: startDate.Unix(),
  3205. OrgId: adminUserInfo.Org.Id,
  3206. GoodId: prescription.FistulaNeedleSet16,
  3207. GoodTypeId: fistula_needle_set_16,
  3208. }
  3209. service.AddSigleAutoReduceRecordInfo(details)
  3210. }
  3211. } else if err == nil { //记录存在,则将数量加1
  3212. if outInfo.ID > 0 {
  3213. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3214. }
  3215. details := &models.AutomaticReduceDetail{
  3216. WarehouseOutId: outInfo.ID,
  3217. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3218. PatientId: patientID,
  3219. Ctime: time.Now().Unix(),
  3220. Mtime: time.Now().Unix(),
  3221. Status: 1,
  3222. RecordTime: startDate.Unix(),
  3223. OrgId: adminUserInfo.Org.Id,
  3224. GoodId: prescription.FistulaNeedleSet16,
  3225. GoodTypeId: fistula_needle_set_16,
  3226. }
  3227. service.AddSigleAutoReduceRecordInfo(details)
  3228. }
  3229. }
  3230. if prescription.Hemoperfusion > 0 {
  3231. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, hemoperfusion, prescription.Hemoperfusion, out.WarehouseOutOrderNumber)
  3232. if err == gorm.ErrRecordNotFound {
  3233. warehouseOutInfo := &models.WarehouseOutInfo{
  3234. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3235. WarehouseOutId: out.ID,
  3236. Status: 1,
  3237. Ctime: time.Now().Unix(),
  3238. Remark: "",
  3239. OrgId: adminUserInfo.Org.Id,
  3240. Type: 1,
  3241. Manufacturer: 0,
  3242. Dealer: 0,
  3243. IsSys: 1,
  3244. SysRecordTime: startDate.Unix(),
  3245. }
  3246. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Hemoperfusion, adminUserInfo.Org.Id)
  3247. warehouseOutInfo.Price = stockInInfo.Price
  3248. warehouseOutInfo.GoodId = prescription.Hemoperfusion
  3249. warehouseOutInfo.GoodTypeId = hemoperfusion
  3250. warehouseOutInfo.Count = 1
  3251. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3252. if err == nil {
  3253. details := &models.AutomaticReduceDetail{
  3254. WarehouseOutId: warehouseOutInfo.ID,
  3255. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3256. PatientId: patientID,
  3257. Ctime: time.Now().Unix(),
  3258. Mtime: time.Now().Unix(),
  3259. Status: 1,
  3260. RecordTime: startDate.Unix(),
  3261. OrgId: adminUserInfo.Org.Id,
  3262. GoodId: prescription.Hemoperfusion,
  3263. GoodTypeId: hemoperfusion,
  3264. }
  3265. service.AddSigleAutoReduceRecordInfo(details)
  3266. }
  3267. } else if err == nil { //记录存在,则将数量加1
  3268. if outInfo.ID > 0 {
  3269. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3270. }
  3271. details := &models.AutomaticReduceDetail{
  3272. WarehouseOutId: outInfo.ID,
  3273. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3274. PatientId: patientID,
  3275. Ctime: time.Now().Unix(),
  3276. Mtime: time.Now().Unix(),
  3277. Status: 1,
  3278. RecordTime: startDate.Unix(),
  3279. OrgId: adminUserInfo.Org.Id,
  3280. GoodId: prescription.Hemoperfusion,
  3281. GoodTypeId: hemoperfusion,
  3282. }
  3283. service.AddSigleAutoReduceRecordInfo(details)
  3284. }
  3285. }
  3286. if prescription.DialyserSterilised > 0 {
  3287. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, dialyser_sterilised, prescription.DialyserSterilised, out.WarehouseOutOrderNumber)
  3288. if err == gorm.ErrRecordNotFound {
  3289. warehouseOutInfo := &models.WarehouseOutInfo{
  3290. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3291. WarehouseOutId: out.ID,
  3292. Status: 1,
  3293. Ctime: time.Now().Unix(),
  3294. Remark: "",
  3295. OrgId: adminUserInfo.Org.Id,
  3296. Type: 1,
  3297. Manufacturer: 0,
  3298. Dealer: 0,
  3299. IsSys: 1,
  3300. SysRecordTime: startDate.Unix(),
  3301. }
  3302. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.DialyserSterilised, adminUserInfo.Org.Id)
  3303. warehouseOutInfo.Price = stockInInfo.Price
  3304. warehouseOutInfo.GoodId = prescription.DialyserSterilised
  3305. warehouseOutInfo.GoodTypeId = dialyser_sterilised
  3306. warehouseOutInfo.Count = 1
  3307. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3308. if err == nil {
  3309. details := &models.AutomaticReduceDetail{
  3310. WarehouseOutId: warehouseOutInfo.ID,
  3311. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3312. PatientId: patientID,
  3313. Ctime: time.Now().Unix(),
  3314. Mtime: time.Now().Unix(),
  3315. Status: 1,
  3316. RecordTime: startDate.Unix(),
  3317. OrgId: adminUserInfo.Org.Id,
  3318. GoodId: prescription.DialyserSterilised,
  3319. GoodTypeId: dialyser_sterilised,
  3320. }
  3321. service.AddSigleAutoReduceRecordInfo(details)
  3322. }
  3323. } else if err == nil { //记录存在,则将数量加1
  3324. if outInfo.ID > 0 {
  3325. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3326. }
  3327. details := &models.AutomaticReduceDetail{
  3328. WarehouseOutId: outInfo.ID,
  3329. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3330. PatientId: patientID,
  3331. Ctime: time.Now().Unix(),
  3332. Mtime: time.Now().Unix(),
  3333. Status: 1,
  3334. RecordTime: startDate.Unix(),
  3335. OrgId: adminUserInfo.Org.Id,
  3336. GoodId: prescription.DialyserSterilised,
  3337. GoodTypeId: dialyser_sterilised,
  3338. }
  3339. service.AddSigleAutoReduceRecordInfo(details)
  3340. }
  3341. }
  3342. if prescription.Filtryzer > 0 {
  3343. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, filtryzer, prescription.Filtryzer, out.WarehouseOutOrderNumber)
  3344. if err == gorm.ErrRecordNotFound {
  3345. warehouseOutInfo := &models.WarehouseOutInfo{
  3346. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3347. WarehouseOutId: out.ID,
  3348. Status: 1,
  3349. Ctime: time.Now().Unix(),
  3350. Remark: "",
  3351. OrgId: adminUserInfo.Org.Id,
  3352. Type: 1,
  3353. Manufacturer: 0,
  3354. Dealer: 0,
  3355. IsSys: 1,
  3356. SysRecordTime: startDate.Unix(),
  3357. }
  3358. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Filtryzer, adminUserInfo.Org.Id)
  3359. warehouseOutInfo.Price = stockInInfo.Price
  3360. warehouseOutInfo.GoodId = prescription.Filtryzer
  3361. warehouseOutInfo.GoodTypeId = filtryzer
  3362. warehouseOutInfo.Count = 1
  3363. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3364. if err == nil {
  3365. details := &models.AutomaticReduceDetail{
  3366. WarehouseOutId: warehouseOutInfo.ID,
  3367. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3368. PatientId: patientID,
  3369. Ctime: time.Now().Unix(),
  3370. Mtime: time.Now().Unix(),
  3371. Status: 1,
  3372. RecordTime: startDate.Unix(),
  3373. OrgId: adminUserInfo.Org.Id,
  3374. GoodId: prescription.Filtryzer,
  3375. GoodTypeId: filtryzer,
  3376. }
  3377. service.AddSigleAutoReduceRecordInfo(details)
  3378. }
  3379. } else if err == nil { //记录存在,则将耗材使用数量加1
  3380. if outInfo.ID > 0 {
  3381. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3382. }
  3383. //插入病人耗材使用记录
  3384. details := &models.AutomaticReduceDetail{
  3385. WarehouseOutId: outInfo.ID,
  3386. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3387. PatientId: patientID,
  3388. Ctime: time.Now().Unix(),
  3389. Mtime: time.Now().Unix(),
  3390. Status: 1,
  3391. RecordTime: startDate.Unix(),
  3392. OrgId: adminUserInfo.Org.Id,
  3393. GoodId: prescription.Filtryzer,
  3394. GoodTypeId: filtryzer,
  3395. }
  3396. service.AddSigleAutoReduceRecordInfo(details)
  3397. }
  3398. }
  3399. if prescription.Dialyzers > 0 {
  3400. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, dialyzers, prescription.Dialyzers, out.WarehouseOutOrderNumber)
  3401. if err == gorm.ErrRecordNotFound {
  3402. warehouseOutInfo := &models.WarehouseOutInfo{
  3403. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3404. WarehouseOutId: out.ID,
  3405. Status: 1,
  3406. Ctime: time.Now().Unix(),
  3407. Remark: "",
  3408. OrgId: adminUserInfo.Org.Id,
  3409. Type: 1,
  3410. Manufacturer: 0,
  3411. Dealer: 0,
  3412. IsSys: 1,
  3413. SysRecordTime: startDate.Unix(),
  3414. }
  3415. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Dialyzers, adminUserInfo.Org.Id)
  3416. warehouseOutInfo.Price = stockInInfo.Price
  3417. warehouseOutInfo.GoodId = prescription.Dialyzers
  3418. warehouseOutInfo.GoodTypeId = dialyzers
  3419. warehouseOutInfo.Count = 1
  3420. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3421. if err == nil {
  3422. details := &models.AutomaticReduceDetail{
  3423. WarehouseOutId: warehouseOutInfo.ID,
  3424. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3425. PatientId: patientID,
  3426. Ctime: time.Now().Unix(),
  3427. Mtime: time.Now().Unix(),
  3428. Status: 1,
  3429. RecordTime: startDate.Unix(),
  3430. OrgId: adminUserInfo.Org.Id,
  3431. GoodId: prescription.Dialyzers,
  3432. GoodTypeId: dialyzers,
  3433. }
  3434. service.AddSigleAutoReduceRecordInfo(details)
  3435. }
  3436. } else if err == nil { //记录存在,则将耗材使用数量加1
  3437. if outInfo.ID > 0 {
  3438. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3439. }
  3440. //插入病人耗材使用记录
  3441. details := &models.AutomaticReduceDetail{
  3442. WarehouseOutId: outInfo.ID,
  3443. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3444. PatientId: patientID,
  3445. Ctime: time.Now().Unix(),
  3446. Mtime: time.Now().Unix(),
  3447. Status: 1,
  3448. RecordTime: startDate.Unix(),
  3449. OrgId: adminUserInfo.Org.Id,
  3450. GoodId: prescription.Dialyzer,
  3451. GoodTypeId: dialyzers,
  3452. }
  3453. service.AddSigleAutoReduceRecordInfo(details)
  3454. }
  3455. }
  3456. if prescription.Injector > 0 {
  3457. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, injector, prescription.Injector, out.WarehouseOutOrderNumber)
  3458. if err == gorm.ErrRecordNotFound {
  3459. warehouseOutInfo := &models.WarehouseOutInfo{
  3460. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3461. WarehouseOutId: out.ID,
  3462. Status: 1,
  3463. Ctime: time.Now().Unix(),
  3464. Remark: "",
  3465. OrgId: adminUserInfo.Org.Id,
  3466. Type: 1,
  3467. Manufacturer: 0,
  3468. Dealer: 0,
  3469. IsSys: 1,
  3470. SysRecordTime: startDate.Unix(),
  3471. }
  3472. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Injector, adminUserInfo.Org.Id)
  3473. warehouseOutInfo.Price = stockInInfo.Price
  3474. warehouseOutInfo.GoodId = prescription.Injector
  3475. warehouseOutInfo.GoodTypeId = injector
  3476. warehouseOutInfo.Count = 1
  3477. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3478. if err == nil {
  3479. details := &models.AutomaticReduceDetail{
  3480. WarehouseOutId: warehouseOutInfo.ID,
  3481. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3482. PatientId: patientID,
  3483. Ctime: time.Now().Unix(),
  3484. Mtime: time.Now().Unix(),
  3485. Status: 1,
  3486. RecordTime: startDate.Unix(),
  3487. OrgId: adminUserInfo.Org.Id,
  3488. GoodId: prescription.Injector,
  3489. GoodTypeId: injector,
  3490. }
  3491. service.AddSigleAutoReduceRecordInfo(details)
  3492. }
  3493. } else if err == nil { //记录存在,则将耗材使用数量加1
  3494. if outInfo.ID > 0 {
  3495. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3496. }
  3497. //插入病人耗材使用记录
  3498. details := &models.AutomaticReduceDetail{
  3499. WarehouseOutId: outInfo.ID,
  3500. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3501. PatientId: patientID,
  3502. Ctime: time.Now().Unix(),
  3503. Mtime: time.Now().Unix(),
  3504. Status: 1,
  3505. RecordTime: startDate.Unix(),
  3506. OrgId: adminUserInfo.Org.Id,
  3507. GoodId: prescription.Injector,
  3508. GoodTypeId: injector,
  3509. }
  3510. service.AddSigleAutoReduceRecordInfo(details)
  3511. }
  3512. }
  3513. if prescription.Bloodlines > 0 {
  3514. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, bloodlines, prescription.Bloodlines, out.WarehouseOutOrderNumber)
  3515. if err == gorm.ErrRecordNotFound {
  3516. warehouseOutInfo := &models.WarehouseOutInfo{
  3517. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3518. WarehouseOutId: out.ID,
  3519. Status: 1,
  3520. Ctime: time.Now().Unix(),
  3521. Remark: "",
  3522. OrgId: adminUserInfo.Org.Id,
  3523. Type: 1,
  3524. Manufacturer: 0,
  3525. Dealer: 0,
  3526. IsSys: 1,
  3527. SysRecordTime: startDate.Unix(),
  3528. }
  3529. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Bloodlines, adminUserInfo.Org.Id)
  3530. warehouseOutInfo.Price = stockInInfo.Price
  3531. warehouseOutInfo.GoodId = prescription.Bloodlines
  3532. warehouseOutInfo.GoodTypeId = bloodlines
  3533. warehouseOutInfo.Count = 1
  3534. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3535. if err == nil {
  3536. details := &models.AutomaticReduceDetail{
  3537. WarehouseOutId: warehouseOutInfo.ID,
  3538. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3539. PatientId: patientID,
  3540. Ctime: time.Now().Unix(),
  3541. Mtime: time.Now().Unix(),
  3542. Status: 1,
  3543. RecordTime: startDate.Unix(),
  3544. OrgId: adminUserInfo.Org.Id,
  3545. GoodId: prescription.Bloodlines,
  3546. GoodTypeId: bloodlines,
  3547. }
  3548. service.AddSigleAutoReduceRecordInfo(details)
  3549. }
  3550. } else if err == nil { //记录存在,则将耗材使用数量加1
  3551. if outInfo.ID > 0 {
  3552. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3553. }
  3554. //插入病人耗材使用记录
  3555. details := &models.AutomaticReduceDetail{
  3556. WarehouseOutId: outInfo.ID,
  3557. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3558. PatientId: patientID,
  3559. Ctime: time.Now().Unix(),
  3560. Mtime: time.Now().Unix(),
  3561. Status: 1,
  3562. RecordTime: startDate.Unix(),
  3563. OrgId: adminUserInfo.Org.Id,
  3564. GoodId: prescription.Bloodlines,
  3565. GoodTypeId: bloodlines,
  3566. }
  3567. service.AddSigleAutoReduceRecordInfo(details)
  3568. }
  3569. }
  3570. if prescription.TubingHemodialysis > 0 {
  3571. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, tubingHemodialysis, prescription.TubingHemodialysis, out.WarehouseOutOrderNumber)
  3572. if err == gorm.ErrRecordNotFound {
  3573. warehouseOutInfo := &models.WarehouseOutInfo{
  3574. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3575. WarehouseOutId: out.ID,
  3576. Status: 1,
  3577. Ctime: time.Now().Unix(),
  3578. Remark: "",
  3579. OrgId: adminUserInfo.Org.Id,
  3580. Type: 1,
  3581. Manufacturer: 0,
  3582. Dealer: 0,
  3583. IsSys: 1,
  3584. SysRecordTime: startDate.Unix(),
  3585. }
  3586. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.TubingHemodialysis, adminUserInfo.Org.Id)
  3587. warehouseOutInfo.Price = stockInInfo.Price
  3588. warehouseOutInfo.GoodId = prescription.TubingHemodialysis
  3589. warehouseOutInfo.GoodTypeId = tubingHemodialysis
  3590. warehouseOutInfo.Count = 1
  3591. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3592. if err == nil {
  3593. details := &models.AutomaticReduceDetail{
  3594. WarehouseOutId: warehouseOutInfo.ID,
  3595. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3596. PatientId: patientID,
  3597. Ctime: time.Now().Unix(),
  3598. Mtime: time.Now().Unix(),
  3599. Status: 1,
  3600. RecordTime: startDate.Unix(),
  3601. OrgId: adminUserInfo.Org.Id,
  3602. GoodId: prescription.TubingHemodialysis,
  3603. GoodTypeId: tubingHemodialysis,
  3604. }
  3605. service.AddSigleAutoReduceRecordInfo(details)
  3606. }
  3607. } else if err == nil { //记录存在,则将耗材使用数量加1
  3608. if outInfo.ID > 0 {
  3609. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3610. }
  3611. //插入病人耗材使用记录
  3612. details := &models.AutomaticReduceDetail{
  3613. WarehouseOutId: outInfo.ID,
  3614. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3615. PatientId: patientID,
  3616. Ctime: time.Now().Unix(),
  3617. Mtime: time.Now().Unix(),
  3618. Status: 1,
  3619. RecordTime: startDate.Unix(),
  3620. OrgId: adminUserInfo.Org.Id,
  3621. GoodId: prescription.TubingHemodialysis,
  3622. GoodTypeId: tubingHemodialysis,
  3623. }
  3624. service.AddSigleAutoReduceRecordInfo(details)
  3625. }
  3626. }
  3627. if prescription.Package > 0 {
  3628. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, safe_package, prescription.Package, out.WarehouseOutOrderNumber)
  3629. if err == gorm.ErrRecordNotFound {
  3630. warehouseOutInfo := &models.WarehouseOutInfo{
  3631. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3632. WarehouseOutId: out.ID,
  3633. Status: 1,
  3634. Ctime: time.Now().Unix(),
  3635. Remark: "",
  3636. OrgId: adminUserInfo.Org.Id,
  3637. Type: 1,
  3638. Manufacturer: 0,
  3639. Dealer: 0,
  3640. IsSys: 1,
  3641. SysRecordTime: startDate.Unix(),
  3642. }
  3643. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Package, adminUserInfo.Org.Id)
  3644. warehouseOutInfo.Price = stockInInfo.Price
  3645. warehouseOutInfo.GoodId = prescription.Package
  3646. warehouseOutInfo.GoodTypeId = safe_package
  3647. warehouseOutInfo.Count = 1
  3648. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3649. if err == nil {
  3650. details := &models.AutomaticReduceDetail{
  3651. WarehouseOutId: warehouseOutInfo.ID,
  3652. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3653. PatientId: patientID,
  3654. Ctime: time.Now().Unix(),
  3655. Mtime: time.Now().Unix(),
  3656. Status: 1,
  3657. RecordTime: startDate.Unix(),
  3658. OrgId: adminUserInfo.Org.Id,
  3659. GoodId: prescription.Package,
  3660. GoodTypeId: safe_package,
  3661. }
  3662. service.AddSigleAutoReduceRecordInfo(details)
  3663. }
  3664. } else if err == nil { //记录存在,则将耗材使用数量加1
  3665. if outInfo.ID > 0 {
  3666. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3667. }
  3668. //插入病人耗材使用记录
  3669. details := &models.AutomaticReduceDetail{
  3670. WarehouseOutId: outInfo.ID,
  3671. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3672. PatientId: patientID,
  3673. Ctime: time.Now().Unix(),
  3674. Mtime: time.Now().Unix(),
  3675. Status: 1,
  3676. RecordTime: startDate.Unix(),
  3677. OrgId: adminUserInfo.Org.Id,
  3678. GoodId: prescription.Package,
  3679. GoodTypeId: safe_package,
  3680. }
  3681. service.AddSigleAutoReduceRecordInfo(details)
  3682. }
  3683. }
  3684. if prescription.ALiquid > 0 {
  3685. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, aliquid, prescription.ALiquid, out.WarehouseOutOrderNumber)
  3686. if err == gorm.ErrRecordNotFound {
  3687. warehouseOutInfo := &models.WarehouseOutInfo{
  3688. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3689. WarehouseOutId: out.ID,
  3690. Status: 1,
  3691. Ctime: time.Now().Unix(),
  3692. Remark: "",
  3693. OrgId: adminUserInfo.Org.Id,
  3694. Type: 1,
  3695. Manufacturer: 0,
  3696. Dealer: 0,
  3697. IsSys: 1,
  3698. SysRecordTime: startDate.Unix(),
  3699. }
  3700. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.ALiquid, adminUserInfo.Org.Id)
  3701. warehouseOutInfo.Price = stockInInfo.Price
  3702. warehouseOutInfo.GoodId = prescription.ALiquid
  3703. warehouseOutInfo.GoodTypeId = aliquid
  3704. warehouseOutInfo.Count = 1
  3705. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3706. if err == nil {
  3707. details := &models.AutomaticReduceDetail{
  3708. WarehouseOutId: warehouseOutInfo.ID,
  3709. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3710. PatientId: patientID,
  3711. Ctime: time.Now().Unix(),
  3712. Mtime: time.Now().Unix(),
  3713. Status: 1,
  3714. RecordTime: startDate.Unix(),
  3715. OrgId: adminUserInfo.Org.Id,
  3716. GoodId: prescription.ALiquid,
  3717. GoodTypeId: aliquid,
  3718. }
  3719. service.AddSigleAutoReduceRecordInfo(details)
  3720. }
  3721. } else if err == nil { //记录存在,则将耗材使用数量加1
  3722. if outInfo.ID > 0 {
  3723. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3724. }
  3725. //插入病人耗材使用记录
  3726. details := &models.AutomaticReduceDetail{
  3727. WarehouseOutId: outInfo.ID,
  3728. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3729. PatientId: patientID,
  3730. Ctime: time.Now().Unix(),
  3731. Mtime: time.Now().Unix(),
  3732. Status: 1,
  3733. RecordTime: startDate.Unix(),
  3734. OrgId: adminUserInfo.Org.Id,
  3735. GoodId: prescription.ALiquid,
  3736. GoodTypeId: aliquid,
  3737. }
  3738. service.AddSigleAutoReduceRecordInfo(details)
  3739. }
  3740. }
  3741. }
  3742. }
  3743. } else {
  3744. this.ErrorLog("上机失败,还没开处方")
  3745. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionException)
  3746. return
  3747. }
  3748. }
  3749. if createErr != nil {
  3750. this.ErrorLog("上机失败:%v", createErr)
  3751. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3752. return
  3753. }
  3754. this.ServeSuccessJSON(map[string]interface{}{
  3755. "dialysis_order": newdialysisRecord,
  3756. "monitor": record,
  3757. })
  3758. }
  3759. func (c *DialysisAPIController) PostSolution() {
  3760. id, _ := c.GetInt64("patient", 0)
  3761. recordDateStr := c.GetString("record_date")
  3762. if id <= 0 {
  3763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3764. return
  3765. }
  3766. adminUserInfo := c.GetMobileAdminUserInfo()
  3767. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3768. if patient.ID == 0 {
  3769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3770. return
  3771. }
  3772. if len(recordDateStr) == 0 {
  3773. recordDateStr = time.Now().Format("2006-01-02")
  3774. }
  3775. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3776. if parseDateErr != nil {
  3777. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3779. return
  3780. }
  3781. mode_id, _ := c.GetInt64("mode_id", 0)
  3782. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3783. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3784. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3785. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3786. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3787. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3788. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3789. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3790. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3791. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3792. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3793. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3794. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3795. kalium, _ := c.GetFloat("kalium", 0)
  3796. sodium, _ := c.GetFloat("sodium", 0)
  3797. calcium, _ := c.GetFloat("calcium", 0)
  3798. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3799. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3800. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3801. glucose, _ := c.GetFloat("glucose", 0)
  3802. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3803. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3804. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3805. conductivity, _ := c.GetFloat("conductivity", 0)
  3806. remark := c.GetString("remark")
  3807. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3808. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3809. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3810. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3811. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3812. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3813. special_medicine_other := c.GetString("special_medicine_other")
  3814. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3815. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3816. blood_access, _ := c.GetInt64("blood_access", 0)
  3817. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3818. body_fluid_other := c.GetString("body_fluid_other")
  3819. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3820. niprocart, _ := c.GetInt64("niprocart", 0)
  3821. jms, _ := c.GetInt64("jms", 0)
  3822. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3823. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3824. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3825. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3826. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3827. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3828. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3829. injector, _ := c.GetInt64("injector", 0)
  3830. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3831. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3832. safe_package, _ := c.GetInt64("package", 0)
  3833. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3834. if mode_id > 0 {
  3835. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  3836. }
  3837. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3838. //
  3839. //if appRole.UserType == 2 || appRole.UserType == 1 {
  3840. // prescription_doctor = appRole.AdminUserId
  3841. //} else {
  3842. // prescription_doctor = 0
  3843. //}
  3844. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3845. //
  3846. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3847. // if appRole.UserType == 3 {
  3848. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3849. // if getPermissionErr != nil {
  3850. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3851. // return
  3852. // } else if headNursePermission == nil {
  3853. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3854. // return
  3855. // }
  3856. // }
  3857. //}
  3858. prescription := models.DialysisPrescription{
  3859. UserOrgId: adminUserInfo.Org.Id,
  3860. PatientId: id,
  3861. RecordDate: recordDate.Unix(),
  3862. ModeId: mode_id,
  3863. DialysisDuration: dialysis_duration,
  3864. Dialyzer: dialyzer,
  3865. PerfusionApparatus: perfusion_apparatus,
  3866. BloodFlowVolume: blood_flow_volume,
  3867. DewaterAmount: dewater_amount,
  3868. DisplaceLiqui: displace_liqui,
  3869. ReplacementWay: replacement_way,
  3870. Anticoagulant: anticoagulant,
  3871. AnticoagulantShouji: anticoagulant_shouji,
  3872. AnticoagulantWeichi: anticoagulant_weichi,
  3873. AnticoagulantZongliang: anticoagulant_zongliang,
  3874. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3875. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3876. Kalium: kalium,
  3877. Sodium: sodium,
  3878. Calcium: calcium,
  3879. Bicarbonate: bicarbonate,
  3880. Glucose: glucose,
  3881. // DryWeight: dry_weight,
  3882. DialysateFlow: dialysate_flow,
  3883. DialysateTemperature: dialysate_temperature,
  3884. Conductivity: conductivity,
  3885. Remark: remark,
  3886. PrescriptionDoctor: prescription_doctor,
  3887. Status: 1,
  3888. CreatedTime: time.Now().Unix(),
  3889. UpdatedTime: time.Now().Unix(),
  3890. DialysisDurationMinute: dialysisDurationMinute,
  3891. DialysisDurationHour: dialysisDurationHour,
  3892. TargetUltrafiltration: targetUltrafiltration,
  3893. DialysateFormulation: dialysateFormulation,
  3894. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3895. BodyFluid: body_fluid,
  3896. SpecialMedicine: special_medicine,
  3897. SpecialMedicineOther: special_medicine_other,
  3898. DisplaceLiquiPart: displace_liqui_part,
  3899. DisplaceLiquiValue: displace_liqui_value,
  3900. BloodAccess: blood_access,
  3901. Ultrafiltration: ultrafiltration,
  3902. BodyFluidOther: body_fluid_other,
  3903. ReplacementTotal: replacement_total,
  3904. Niprocart: niprocart,
  3905. Jms: jms,
  3906. FistulaNeedleSet: fistula_needle_set,
  3907. FistulaNeedleSet16: fistula_needle_set_16,
  3908. Hemoperfusion: hemoperfusion,
  3909. DialyserSterilised: dialyser_sterilised,
  3910. Filtryzer: filtryzer,
  3911. TargetKtv: target_ktv,
  3912. Dialyzers: dialyzers,
  3913. Injector: injector,
  3914. Bloodlines: bloodlines,
  3915. TubingHemodialysis: tubing_hemodialysis,
  3916. Package: safe_package,
  3917. ALiquid: a_liquid,
  3918. }
  3919. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3920. if dialysisPrescription.ID == 0 { //新增
  3921. prescription.Creater = adminUserInfo.AdminUser.Id
  3922. } else { //修改
  3923. prescription.Creater = adminUserInfo.AdminUser.Id
  3924. //if/**/
  3925. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3926. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3927. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3928. // if getPermissionErr != nil {
  3929. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3930. // return
  3931. // } else if headNursePermission == nil {
  3932. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3933. // return
  3934. // }
  3935. //}
  3936. _, record := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  3937. if record.IsOpen == 1 {
  3938. niprocart_good_type_id, _ := beego.AppConfig.Int64("niprocart")
  3939. jms_good_type_id, _ := beego.AppConfig.Int64("jms")
  3940. fistula_needle_set_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set")
  3941. fistula_needle_set_16_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set_16")
  3942. hemoperfusion_good_type_id, _ := beego.AppConfig.Int64("hemoperfusion")
  3943. dialyser_sterilised_good_type_id, _ := beego.AppConfig.Int64("dialyser_sterilised")
  3944. filtryzer_good_type_id, _ := beego.AppConfig.Int64("filtryzer")
  3945. dialyzers_good_type_id, _ := beego.AppConfig.Int64("dialyzers")
  3946. injector_good_type_id, _ := beego.AppConfig.Int64("injector")
  3947. bloodlines_good_type_id, _ := beego.AppConfig.Int64("bloodlines")
  3948. tubingHemodialysis_good_type_id, _ := beego.AppConfig.Int64("tubingHemodialysis")
  3949. safe_package_good_type_id, _ := beego.AppConfig.Int64("package")
  3950. aliquid_good_type_id, _ := beego.AppConfig.Int64("aliquid")
  3951. err, order := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  3952. if err == nil {
  3953. if order.ID > 0 {
  3954. if dialysisPrescription.Niprocart != niprocart {
  3955. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  3956. //1.用上机透析日期查出当天的订单
  3957. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  3958. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  3959. service.UpdateOrderCount(niprocart_good_type_id, dialysisPrescription.Niprocart, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  3960. //判断前端更改后的商品id的出库记录在数据库中是否存在
  3961. err, newOut := service.FindOrderInfoByGoodId(niprocart_good_type_id, niprocart, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  3962. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  3963. warehouseOutInfo := &models.WarehouseOutInfo{
  3964. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3965. WarehouseOutId: out.ID,
  3966. Count: 1,
  3967. Status: 1,
  3968. Ctime: time.Now().Unix(),
  3969. Remark: "",
  3970. OrgId: adminUserInfo.Org.Id,
  3971. Type: 1,
  3972. Manufacturer: 0,
  3973. Dealer: 0,
  3974. IsSys: 1,
  3975. SysRecordTime: order.StartTime,
  3976. }
  3977. stockInInfo, _ := service.FindLastStockInInfoRecord(niprocart, adminUserInfo.Org.Id)
  3978. warehouseOutInfo.Price = stockInInfo.Price
  3979. warehouseOutInfo.GoodId = niprocart
  3980. warehouseOutInfo.GoodTypeId = niprocart_good_type_id
  3981. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3982. if err == nil {
  3983. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  3984. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  3985. if err == gorm.ErrRecordNotFound {
  3986. details := &models.AutomaticReduceDetail{
  3987. WarehouseOutId: warehouseOutInfo.ID,
  3988. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3989. PatientId: id,
  3990. Ctime: time.Now().Unix(),
  3991. Mtime: time.Now().Unix(),
  3992. Status: 1,
  3993. RecordTime: order.StartTime,
  3994. OrgId: adminUserInfo.Org.Id,
  3995. GoodId: niprocart,
  3996. GoodTypeId: niprocart_good_type_id,
  3997. }
  3998. service.AddSigleAutoReduceRecordInfo(details)
  3999. } else if err == nil {
  4000. if user.ID > 0 {
  4001. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.Org.Id, id, niprocart, warehouseOutInfo)
  4002. }
  4003. }
  4004. }
  4005. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4006. if newOut.ID > 0 {
  4007. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4008. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4009. if err == gorm.ErrRecordNotFound {
  4010. details := &models.AutomaticReduceDetail{
  4011. WarehouseOutId: newOut.ID,
  4012. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4013. PatientId: id,
  4014. Ctime: time.Now().Unix(),
  4015. Mtime: time.Now().Unix(),
  4016. Status: 1,
  4017. RecordTime: order.StartTime,
  4018. OrgId: adminUserInfo.Org.Id,
  4019. GoodId: niprocart,
  4020. GoodTypeId: niprocart_good_type_id,
  4021. }
  4022. service.AddSigleAutoReduceRecordInfo(details)
  4023. } else if err == nil {
  4024. if user.ID > 0 {
  4025. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.Org.Id, id, niprocart, &newOut)
  4026. }
  4027. }
  4028. }
  4029. }
  4030. }
  4031. if dialysisPrescription.Jms != jms {
  4032. //不一致,先将原有的商品出库单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4033. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4034. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4035. service.UpdateOrderCount(jms_good_type_id, dialysisPrescription.Jms, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4036. //_, out := service.FindOrderInfoByGoodId(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id)
  4037. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4038. err, newOut := service.FindOrderInfoByGoodId(jms_good_type_id, jms, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4039. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4040. warehouseOutInfo := &models.WarehouseOutInfo{
  4041. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4042. WarehouseOutId: out.ID,
  4043. Count: 1,
  4044. Status: 1,
  4045. Ctime: time.Now().Unix(),
  4046. Remark: "",
  4047. OrgId: adminUserInfo.Org.Id,
  4048. Type: 1,
  4049. Manufacturer: 0,
  4050. Dealer: 0,
  4051. IsSys: 1,
  4052. SysRecordTime: order.StartTime,
  4053. }
  4054. stockInInfo, _ := service.FindLastStockInInfoRecord(jms, adminUserInfo.Org.Id)
  4055. warehouseOutInfo.Price = stockInInfo.Price
  4056. warehouseOutInfo.GoodId = jms
  4057. warehouseOutInfo.GoodTypeId = jms_good_type_id
  4058. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4059. if err == nil {
  4060. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4061. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4062. if err == gorm.ErrRecordNotFound {
  4063. details := &models.AutomaticReduceDetail{
  4064. WarehouseOutId: warehouseOutInfo.ID,
  4065. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4066. PatientId: id,
  4067. Ctime: time.Now().Unix(),
  4068. Mtime: time.Now().Unix(),
  4069. Status: 1,
  4070. RecordTime: order.StartTime,
  4071. OrgId: adminUserInfo.Org.Id,
  4072. GoodId: jms,
  4073. GoodTypeId: jms_good_type_id,
  4074. }
  4075. service.AddSigleAutoReduceRecordInfo(details)
  4076. } else if err == nil {
  4077. if user.ID > 0 {
  4078. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  4079. }
  4080. }
  4081. }
  4082. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4083. if newOut.ID > 0 {
  4084. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4085. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4086. if err == gorm.ErrRecordNotFound {
  4087. details := &models.AutomaticReduceDetail{
  4088. WarehouseOutId: newOut.ID,
  4089. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4090. PatientId: id,
  4091. Ctime: time.Now().Unix(),
  4092. Mtime: time.Now().Unix(),
  4093. Status: 1,
  4094. RecordTime: order.StartTime,
  4095. OrgId: adminUserInfo.Org.Id,
  4096. GoodId: jms,
  4097. GoodTypeId: jms_good_type_id,
  4098. }
  4099. service.AddSigleAutoReduceRecordInfo(details)
  4100. } else if err == nil {
  4101. if user.ID > 0 {
  4102. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, &newOut)
  4103. }
  4104. }
  4105. }
  4106. }
  4107. }
  4108. if dialysisPrescription.FistulaNeedleSet != fistula_needle_set {
  4109. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4110. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4111. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4112. service.UpdateOrderCount(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4113. //_, out := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id)
  4114. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4115. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, fistula_needle_set, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4116. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4117. warehouseOutInfo := &models.WarehouseOutInfo{
  4118. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4119. WarehouseOutId: out.ID,
  4120. Count: 1,
  4121. Status: 1,
  4122. Ctime: time.Now().Unix(),
  4123. Remark: "",
  4124. OrgId: adminUserInfo.Org.Id,
  4125. Type: 1,
  4126. Manufacturer: 0,
  4127. Dealer: 0,
  4128. IsSys: 1,
  4129. SysRecordTime: order.StartTime,
  4130. }
  4131. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set, adminUserInfo.Org.Id)
  4132. warehouseOutInfo.Price = stockInInfo.Price
  4133. warehouseOutInfo.GoodId = fistula_needle_set
  4134. warehouseOutInfo.GoodTypeId = fistula_needle_set_good_type_id
  4135. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4136. if err == nil {
  4137. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4138. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4139. if err == gorm.ErrRecordNotFound {
  4140. details := &models.AutomaticReduceDetail{
  4141. WarehouseOutId: warehouseOutInfo.ID,
  4142. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4143. PatientId: id,
  4144. Ctime: time.Now().Unix(),
  4145. Mtime: time.Now().Unix(),
  4146. Status: 1,
  4147. RecordTime: order.StartTime,
  4148. OrgId: adminUserInfo.Org.Id,
  4149. GoodId: fistula_needle_set,
  4150. GoodTypeId: fistula_needle_set_good_type_id,
  4151. }
  4152. service.AddSigleAutoReduceRecordInfo(details)
  4153. } else if err == nil {
  4154. if user.ID > 0 {
  4155. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  4156. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, warehouseOutInfo)
  4157. }
  4158. }
  4159. }
  4160. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4161. if newOut.ID > 0 {
  4162. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4163. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4164. if err == gorm.ErrRecordNotFound {
  4165. details := &models.AutomaticReduceDetail{
  4166. WarehouseOutId: newOut.ID,
  4167. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4168. PatientId: id,
  4169. Ctime: time.Now().Unix(),
  4170. Mtime: time.Now().Unix(),
  4171. Status: 1,
  4172. RecordTime: order.StartTime,
  4173. OrgId: adminUserInfo.Org.Id,
  4174. GoodId: fistula_needle_set,
  4175. GoodTypeId: fistula_needle_set_good_type_id,
  4176. }
  4177. service.AddSigleAutoReduceRecordInfo(details)
  4178. } else if err == nil {
  4179. if user.ID > 0 {
  4180. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  4181. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, &newOut)
  4182. }
  4183. }
  4184. }
  4185. }
  4186. }
  4187. if dialysisPrescription.FistulaNeedleSet16 != fistula_needle_set_16 {
  4188. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4189. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4190. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4191. service.UpdateOrderCount(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4192. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4193. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4194. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_16_good_type_id, fistula_needle_set_16, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4195. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4196. warehouseOutInfo := &models.WarehouseOutInfo{
  4197. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4198. WarehouseOutId: out.ID,
  4199. Count: 1,
  4200. Status: 1,
  4201. Ctime: time.Now().Unix(),
  4202. Remark: "",
  4203. OrgId: adminUserInfo.Org.Id,
  4204. Type: 1,
  4205. Manufacturer: 0,
  4206. Dealer: 0,
  4207. IsSys: 1,
  4208. SysRecordTime: order.StartTime,
  4209. }
  4210. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set_16, adminUserInfo.Org.Id)
  4211. warehouseOutInfo.Price = stockInInfo.Price
  4212. warehouseOutInfo.GoodId = fistula_needle_set_16
  4213. warehouseOutInfo.GoodTypeId = fistula_needle_set_16_good_type_id
  4214. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4215. if err == nil {
  4216. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4217. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4218. if err == gorm.ErrRecordNotFound {
  4219. details := &models.AutomaticReduceDetail{
  4220. WarehouseOutId: warehouseOutInfo.ID,
  4221. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4222. PatientId: id,
  4223. Ctime: time.Now().Unix(),
  4224. Mtime: time.Now().Unix(),
  4225. Status: 1,
  4226. RecordTime: order.StartTime,
  4227. OrgId: adminUserInfo.Org.Id,
  4228. GoodId: fistula_needle_set_16,
  4229. GoodTypeId: fistula_needle_set_16_good_type_id,
  4230. }
  4231. service.AddSigleAutoReduceRecordInfo(details)
  4232. } else if err == nil {
  4233. if user.ID > 0 {
  4234. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  4235. //service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, warehouseOutInfo)
  4236. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set_16, warehouseOutInfo)
  4237. }
  4238. }
  4239. }
  4240. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4241. if newOut.ID > 0 {
  4242. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4243. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4244. if err == gorm.ErrRecordNotFound {
  4245. details := &models.AutomaticReduceDetail{
  4246. WarehouseOutId: newOut.ID,
  4247. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4248. PatientId: id,
  4249. Ctime: time.Now().Unix(),
  4250. Mtime: time.Now().Unix(),
  4251. Status: 1,
  4252. RecordTime: order.StartTime,
  4253. OrgId: adminUserInfo.Org.Id,
  4254. GoodId: fistula_needle_set_good_type_id,
  4255. GoodTypeId: fistula_needle_set_16_good_type_id,
  4256. }
  4257. service.AddSigleAutoReduceRecordInfo(details)
  4258. } else if err == nil {
  4259. if user.ID > 0 {
  4260. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set_16, &newOut)
  4261. }
  4262. }
  4263. }
  4264. }
  4265. }
  4266. if dialysisPrescription.Hemoperfusion != hemoperfusion {
  4267. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4268. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4269. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4270. service.UpdateOrderCount(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4271. //_, out := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id)
  4272. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4273. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4274. err, newOut := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4275. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4276. warehouseOutInfo := &models.WarehouseOutInfo{
  4277. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4278. WarehouseOutId: out.ID,
  4279. Count: 1,
  4280. Status: 1,
  4281. Ctime: time.Now().Unix(),
  4282. Remark: "",
  4283. OrgId: adminUserInfo.Org.Id,
  4284. Type: 1,
  4285. Manufacturer: 0,
  4286. Dealer: 0,
  4287. IsSys: 1,
  4288. SysRecordTime: order.StartTime,
  4289. }
  4290. stockInInfo, _ := service.FindLastStockInInfoRecord(hemoperfusion, adminUserInfo.Org.Id)
  4291. warehouseOutInfo.Price = stockInInfo.Price
  4292. warehouseOutInfo.GoodId = hemoperfusion
  4293. warehouseOutInfo.GoodTypeId = hemoperfusion_good_type_id
  4294. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4295. if err == nil {
  4296. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4297. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4298. if err == gorm.ErrRecordNotFound {
  4299. details := &models.AutomaticReduceDetail{
  4300. WarehouseOutId: warehouseOutInfo.ID,
  4301. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4302. PatientId: id,
  4303. Ctime: time.Now().Unix(),
  4304. Mtime: time.Now().Unix(),
  4305. Status: 1,
  4306. RecordTime: order.StartTime,
  4307. OrgId: adminUserInfo.Org.Id,
  4308. GoodId: hemoperfusion,
  4309. GoodTypeId: hemoperfusion_good_type_id,
  4310. }
  4311. service.AddSigleAutoReduceRecordInfo(details)
  4312. } else if err == nil {
  4313. if user.ID > 0 {
  4314. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  4315. }
  4316. }
  4317. }
  4318. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4319. if newOut.ID > 0 {
  4320. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4321. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4322. if err == gorm.ErrRecordNotFound {
  4323. details := &models.AutomaticReduceDetail{
  4324. WarehouseOutId: newOut.ID,
  4325. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4326. PatientId: id,
  4327. Ctime: time.Now().Unix(),
  4328. Mtime: time.Now().Unix(),
  4329. Status: 1,
  4330. RecordTime: order.StartTime,
  4331. OrgId: adminUserInfo.Org.Id,
  4332. GoodId: hemoperfusion,
  4333. GoodTypeId: hemoperfusion_good_type_id,
  4334. }
  4335. service.AddSigleAutoReduceRecordInfo(details)
  4336. } else if err == nil {
  4337. if user.ID > 0 {
  4338. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, &newOut)
  4339. }
  4340. }
  4341. }
  4342. }
  4343. }
  4344. if dialysisPrescription.DialyserSterilised != dialyser_sterilised {
  4345. _, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4346. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4347. service.UpdateOrderCount(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4348. //_, out := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id)
  4349. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4350. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4351. err, newOut := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialyser_sterilised, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4352. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4353. warehouseOutInfo := &models.WarehouseOutInfo{
  4354. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4355. WarehouseOutId: out.WarehouseOutId,
  4356. Count: 1,
  4357. Status: 1,
  4358. Ctime: time.Now().Unix(),
  4359. Remark: "",
  4360. OrgId: adminUserInfo.Org.Id,
  4361. Type: 1,
  4362. Manufacturer: 0,
  4363. Dealer: 0,
  4364. IsSys: 1,
  4365. SysRecordTime: order.StartTime,
  4366. }
  4367. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyser_sterilised, adminUserInfo.Org.Id)
  4368. warehouseOutInfo.Price = stockInInfo.Price
  4369. warehouseOutInfo.GoodId = dialyser_sterilised
  4370. warehouseOutInfo.GoodTypeId = dialyser_sterilised_good_type_id
  4371. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4372. if err == nil {
  4373. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4374. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4375. if err == gorm.ErrRecordNotFound {
  4376. details := &models.AutomaticReduceDetail{
  4377. WarehouseOutId: warehouseOutInfo.ID,
  4378. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4379. PatientId: id,
  4380. Ctime: time.Now().Unix(),
  4381. Mtime: time.Now().Unix(),
  4382. Status: 1,
  4383. RecordTime: order.StartTime,
  4384. OrgId: adminUserInfo.Org.Id,
  4385. GoodId: dialyser_sterilised,
  4386. GoodTypeId: dialyser_sterilised_good_type_id,
  4387. }
  4388. service.AddSigleAutoReduceRecordInfo(details)
  4389. } else if err == nil {
  4390. if user.ID > 0 {
  4391. //service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  4392. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id, id, dialyser_sterilised, warehouseOutInfo)
  4393. }
  4394. }
  4395. }
  4396. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4397. if newOut.ID > 0 {
  4398. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4399. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4400. if err == gorm.ErrRecordNotFound {
  4401. details := &models.AutomaticReduceDetail{
  4402. WarehouseOutId: newOut.ID,
  4403. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4404. PatientId: id,
  4405. Ctime: time.Now().Unix(),
  4406. Mtime: time.Now().Unix(),
  4407. Status: 1,
  4408. RecordTime: order.StartTime,
  4409. OrgId: adminUserInfo.Org.Id,
  4410. GoodId: dialyser_sterilised,
  4411. GoodTypeId: dialyser_sterilised_good_type_id,
  4412. }
  4413. service.AddSigleAutoReduceRecordInfo(details)
  4414. } else if err == nil {
  4415. if user.ID > 0 {
  4416. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id, id, dialyser_sterilised, &newOut)
  4417. }
  4418. }
  4419. }
  4420. }
  4421. }
  4422. if dialysisPrescription.Filtryzer != filtryzer {
  4423. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4424. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4425. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4426. service.UpdateOrderCount(filtryzer_good_type_id, dialysisPrescription.Filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4427. //_, out := service.FindOrderInfoByGoodId(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id)
  4428. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4429. err, newOut := service.FindOrderInfoByGoodId(filtryzer_good_type_id, filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4430. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4431. warehouseOutInfo := &models.WarehouseOutInfo{
  4432. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4433. WarehouseOutId: out.ID,
  4434. Count: 1,
  4435. Status: 1,
  4436. Ctime: time.Now().Unix(),
  4437. Remark: "",
  4438. OrgId: adminUserInfo.Org.Id,
  4439. Type: 1,
  4440. Manufacturer: 0,
  4441. Dealer: 0,
  4442. IsSys: 1,
  4443. SysRecordTime: order.StartTime,
  4444. }
  4445. stockInInfo, _ := service.FindLastStockInInfoRecord(filtryzer, adminUserInfo.Org.Id)
  4446. warehouseOutInfo.Price = stockInInfo.Price
  4447. warehouseOutInfo.GoodId = filtryzer
  4448. warehouseOutInfo.GoodTypeId = filtryzer_good_type_id
  4449. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4450. if err == nil {
  4451. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4452. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4453. if err == gorm.ErrRecordNotFound {
  4454. details := &models.AutomaticReduceDetail{
  4455. WarehouseOutId: warehouseOutInfo.ID,
  4456. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4457. PatientId: id,
  4458. Ctime: time.Now().Unix(),
  4459. Mtime: time.Now().Unix(),
  4460. Status: 1,
  4461. RecordTime: order.StartTime,
  4462. OrgId: adminUserInfo.Org.Id,
  4463. GoodId: filtryzer,
  4464. GoodTypeId: filtryzer_good_type_id,
  4465. }
  4466. service.AddSigleAutoReduceRecordInfo(details)
  4467. } else if err == nil {
  4468. if user.ID > 0 {
  4469. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id, id, filtryzer, warehouseOutInfo)
  4470. }
  4471. }
  4472. }
  4473. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4474. if newOut.ID > 0 {
  4475. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4476. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4477. if err == gorm.ErrRecordNotFound {
  4478. details := &models.AutomaticReduceDetail{
  4479. WarehouseOutId: newOut.ID,
  4480. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4481. PatientId: id,
  4482. Ctime: time.Now().Unix(),
  4483. Mtime: time.Now().Unix(),
  4484. Status: 1,
  4485. RecordTime: order.StartTime,
  4486. OrgId: adminUserInfo.Org.Id,
  4487. GoodId: filtryzer,
  4488. GoodTypeId: filtryzer_good_type_id,
  4489. }
  4490. service.AddSigleAutoReduceRecordInfo(details)
  4491. } else if err == nil {
  4492. if user.ID > 0 {
  4493. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id, id, filtryzer, &newOut)
  4494. }
  4495. }
  4496. }
  4497. }
  4498. }
  4499. if dialysisPrescription.Dialyzers != dialyzers {
  4500. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4501. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4502. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4503. service.UpdateOrderCount(dialyzers_good_type_id, dialysisPrescription.Dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4504. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4505. err, newOut := service.FindOrderInfoByGoodId(dialyzers_good_type_id, dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4506. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4507. warehouseOutInfo := &models.WarehouseOutInfo{
  4508. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4509. WarehouseOutId: out.ID,
  4510. Count: 1,
  4511. Status: 1,
  4512. Ctime: time.Now().Unix(),
  4513. Remark: "",
  4514. OrgId: adminUserInfo.Org.Id,
  4515. Type: 1,
  4516. Manufacturer: 0,
  4517. Dealer: 0,
  4518. IsSys: 1,
  4519. SysRecordTime: order.StartTime,
  4520. }
  4521. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyzers, adminUserInfo.Org.Id)
  4522. warehouseOutInfo.Price = stockInInfo.Price
  4523. warehouseOutInfo.GoodId = dialyzers
  4524. warehouseOutInfo.GoodTypeId = dialyzers_good_type_id
  4525. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4526. if err == nil {
  4527. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4528. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4529. if err == gorm.ErrRecordNotFound {
  4530. details := &models.AutomaticReduceDetail{
  4531. WarehouseOutId: warehouseOutInfo.ID,
  4532. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4533. PatientId: id,
  4534. Ctime: time.Now().Unix(),
  4535. Mtime: time.Now().Unix(),
  4536. Status: 1,
  4537. RecordTime: order.StartTime,
  4538. OrgId: adminUserInfo.Org.Id,
  4539. GoodId: dialyzers,
  4540. GoodTypeId: dialyzers_good_type_id,
  4541. }
  4542. service.AddSigleAutoReduceRecordInfo(details)
  4543. } else if err == nil {
  4544. if user.ID > 0 {
  4545. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.Org.Id, id, dialyzers, warehouseOutInfo)
  4546. }
  4547. }
  4548. }
  4549. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4550. if newOut.ID > 0 {
  4551. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4552. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4553. if err == gorm.ErrRecordNotFound {
  4554. details := &models.AutomaticReduceDetail{
  4555. WarehouseOutId: newOut.ID,
  4556. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4557. PatientId: id,
  4558. Ctime: time.Now().Unix(),
  4559. Mtime: time.Now().Unix(),
  4560. Status: 1,
  4561. RecordTime: order.StartTime,
  4562. OrgId: adminUserInfo.Org.Id,
  4563. GoodId: dialyzers,
  4564. GoodTypeId: dialyzers_good_type_id,
  4565. }
  4566. service.AddSigleAutoReduceRecordInfo(details)
  4567. } else if err == nil {
  4568. if user.ID > 0 {
  4569. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.Org.Id, id, dialyzers, &newOut)
  4570. }
  4571. }
  4572. }
  4573. }
  4574. }
  4575. if dialysisPrescription.Injector != injector {
  4576. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4577. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4578. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4579. service.UpdateOrderCount(injector_good_type_id, dialysisPrescription.Injector, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4580. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4581. err, newOut := service.FindOrderInfoByGoodId(injector_good_type_id, injector, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4582. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4583. warehouseOutInfo := &models.WarehouseOutInfo{
  4584. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4585. WarehouseOutId: out.ID,
  4586. Count: 1,
  4587. Status: 1,
  4588. Ctime: time.Now().Unix(),
  4589. Remark: "",
  4590. OrgId: adminUserInfo.Org.Id,
  4591. Type: 1,
  4592. Manufacturer: 0,
  4593. Dealer: 0,
  4594. IsSys: 1,
  4595. SysRecordTime: order.StartTime,
  4596. }
  4597. stockInInfo, _ := service.FindLastStockInInfoRecord(injector, adminUserInfo.Org.Id)
  4598. warehouseOutInfo.Price = stockInInfo.Price
  4599. warehouseOutInfo.GoodId = injector
  4600. warehouseOutInfo.GoodTypeId = injector_good_type_id
  4601. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4602. if err == nil {
  4603. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4604. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4605. if err == gorm.ErrRecordNotFound {
  4606. details := &models.AutomaticReduceDetail{
  4607. WarehouseOutId: warehouseOutInfo.ID,
  4608. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4609. PatientId: id,
  4610. Ctime: time.Now().Unix(),
  4611. Mtime: time.Now().Unix(),
  4612. Status: 1,
  4613. RecordTime: order.StartTime,
  4614. OrgId: adminUserInfo.Org.Id,
  4615. GoodId: injector,
  4616. GoodTypeId: injector_good_type_id,
  4617. }
  4618. service.AddSigleAutoReduceRecordInfo(details)
  4619. } else if err == nil {
  4620. if user.ID > 0 {
  4621. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.Org.Id, id, injector, warehouseOutInfo)
  4622. }
  4623. }
  4624. }
  4625. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4626. if newOut.ID > 0 {
  4627. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4628. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4629. if err == gorm.ErrRecordNotFound {
  4630. details := &models.AutomaticReduceDetail{
  4631. WarehouseOutId: newOut.ID,
  4632. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4633. PatientId: id,
  4634. Ctime: time.Now().Unix(),
  4635. Mtime: time.Now().Unix(),
  4636. Status: 1,
  4637. RecordTime: order.StartTime,
  4638. OrgId: adminUserInfo.Org.Id,
  4639. GoodId: injector,
  4640. GoodTypeId: injector_good_type_id,
  4641. }
  4642. service.AddSigleAutoReduceRecordInfo(details)
  4643. } else if err == nil {
  4644. if user.ID > 0 {
  4645. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.Org.Id, id, injector, &newOut)
  4646. }
  4647. }
  4648. }
  4649. }
  4650. }
  4651. if dialysisPrescription.Bloodlines != bloodlines {
  4652. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4653. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4654. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4655. service.UpdateOrderCount(bloodlines_good_type_id, dialysisPrescription.Bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4656. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4657. err, newOut := service.FindOrderInfoByGoodId(bloodlines_good_type_id, bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4658. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4659. warehouseOutInfo := &models.WarehouseOutInfo{
  4660. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4661. WarehouseOutId: out.ID,
  4662. Count: 1,
  4663. Status: 1,
  4664. Ctime: time.Now().Unix(),
  4665. Remark: "",
  4666. OrgId: adminUserInfo.Org.Id,
  4667. Type: 1,
  4668. Manufacturer: 0,
  4669. Dealer: 0,
  4670. IsSys: 1,
  4671. SysRecordTime: order.StartTime,
  4672. }
  4673. stockInInfo, _ := service.FindLastStockInInfoRecord(bloodlines, adminUserInfo.Org.Id)
  4674. warehouseOutInfo.Price = stockInInfo.Price
  4675. warehouseOutInfo.GoodId = bloodlines
  4676. warehouseOutInfo.GoodTypeId = bloodlines_good_type_id
  4677. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4678. if err == nil {
  4679. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4680. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4681. if err == gorm.ErrRecordNotFound {
  4682. details := &models.AutomaticReduceDetail{
  4683. WarehouseOutId: warehouseOutInfo.ID,
  4684. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4685. PatientId: id,
  4686. Ctime: time.Now().Unix(),
  4687. Mtime: time.Now().Unix(),
  4688. Status: 1,
  4689. RecordTime: order.StartTime,
  4690. OrgId: adminUserInfo.Org.Id,
  4691. GoodId: bloodlines,
  4692. GoodTypeId: bloodlines_good_type_id,
  4693. }
  4694. service.AddSigleAutoReduceRecordInfo(details)
  4695. } else if err == nil {
  4696. if user.ID > 0 {
  4697. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.Org.Id, id, bloodlines, warehouseOutInfo)
  4698. }
  4699. }
  4700. }
  4701. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4702. if newOut.ID > 0 {
  4703. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4704. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4705. if err == gorm.ErrRecordNotFound {
  4706. details := &models.AutomaticReduceDetail{
  4707. WarehouseOutId: newOut.ID,
  4708. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4709. PatientId: id,
  4710. Ctime: time.Now().Unix(),
  4711. Mtime: time.Now().Unix(),
  4712. Status: 1,
  4713. RecordTime: order.StartTime,
  4714. OrgId: adminUserInfo.Org.Id,
  4715. GoodId: bloodlines,
  4716. GoodTypeId: bloodlines_good_type_id,
  4717. }
  4718. service.AddSigleAutoReduceRecordInfo(details)
  4719. } else if err == nil {
  4720. if user.ID > 0 {
  4721. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.Org.Id, id, bloodlines, &newOut)
  4722. }
  4723. }
  4724. }
  4725. }
  4726. }
  4727. if dialysisPrescription.TubingHemodialysis != tubing_hemodialysis {
  4728. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4729. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4730. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4731. service.UpdateOrderCount(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4732. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4733. err, newOut := service.FindOrderInfoByGoodId(tubingHemodialysis_good_type_id, tubing_hemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4734. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4735. warehouseOutInfo := &models.WarehouseOutInfo{
  4736. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4737. WarehouseOutId: out.ID,
  4738. Count: 1,
  4739. Status: 1,
  4740. Ctime: time.Now().Unix(),
  4741. Remark: "",
  4742. OrgId: adminUserInfo.Org.Id,
  4743. Type: 1,
  4744. Manufacturer: 0,
  4745. Dealer: 0,
  4746. IsSys: 1,
  4747. SysRecordTime: order.StartTime,
  4748. }
  4749. stockInInfo, _ := service.FindLastStockInInfoRecord(tubing_hemodialysis, adminUserInfo.Org.Id)
  4750. warehouseOutInfo.Price = stockInInfo.Price
  4751. warehouseOutInfo.GoodId = tubing_hemodialysis
  4752. warehouseOutInfo.GoodTypeId = tubingHemodialysis_good_type_id
  4753. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4754. if err == nil {
  4755. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4756. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4757. if err == gorm.ErrRecordNotFound {
  4758. details := &models.AutomaticReduceDetail{
  4759. WarehouseOutId: warehouseOutInfo.ID,
  4760. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4761. PatientId: id,
  4762. Ctime: time.Now().Unix(),
  4763. Mtime: time.Now().Unix(),
  4764. Status: 1,
  4765. RecordTime: order.StartTime,
  4766. OrgId: adminUserInfo.Org.Id,
  4767. GoodId: tubing_hemodialysis,
  4768. GoodTypeId: tubingHemodialysis_good_type_id,
  4769. }
  4770. service.AddSigleAutoReduceRecordInfo(details)
  4771. } else if err == nil {
  4772. if user.ID > 0 {
  4773. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.Org.Id, id, tubing_hemodialysis, warehouseOutInfo)
  4774. }
  4775. }
  4776. }
  4777. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4778. if newOut.ID > 0 {
  4779. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4780. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4781. if err == gorm.ErrRecordNotFound {
  4782. details := &models.AutomaticReduceDetail{
  4783. WarehouseOutId: newOut.ID,
  4784. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4785. PatientId: id,
  4786. Ctime: time.Now().Unix(),
  4787. Mtime: time.Now().Unix(),
  4788. Status: 1,
  4789. RecordTime: order.StartTime,
  4790. OrgId: adminUserInfo.Org.Id,
  4791. GoodId: tubing_hemodialysis,
  4792. GoodTypeId: tubingHemodialysis_good_type_id,
  4793. }
  4794. service.AddSigleAutoReduceRecordInfo(details)
  4795. } else if err == nil {
  4796. if user.ID > 0 {
  4797. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.Org.Id, id, tubing_hemodialysis, &newOut)
  4798. }
  4799. }
  4800. }
  4801. }
  4802. }
  4803. if dialysisPrescription.Package != safe_package {
  4804. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4805. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4806. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4807. service.UpdateOrderCount(safe_package_good_type_id, dialysisPrescription.Package, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4808. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4809. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4810. err, newOut := service.FindOrderInfoByGoodId(safe_package_good_type_id, safe_package, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4811. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4812. warehouseOutInfo := &models.WarehouseOutInfo{
  4813. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4814. WarehouseOutId: out.ID,
  4815. Count: 1,
  4816. Status: 1,
  4817. Ctime: time.Now().Unix(),
  4818. Remark: "",
  4819. OrgId: adminUserInfo.Org.Id,
  4820. Type: 1,
  4821. Manufacturer: 0,
  4822. Dealer: 0,
  4823. IsSys: 1,
  4824. SysRecordTime: order.StartTime,
  4825. }
  4826. stockInInfo, _ := service.FindLastStockInInfoRecord(safe_package, adminUserInfo.Org.Id)
  4827. warehouseOutInfo.Price = stockInInfo.Price
  4828. warehouseOutInfo.GoodId = safe_package
  4829. warehouseOutInfo.GoodTypeId = safe_package_good_type_id
  4830. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4831. if err == nil {
  4832. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4833. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4834. if err == gorm.ErrRecordNotFound {
  4835. details := &models.AutomaticReduceDetail{
  4836. WarehouseOutId: warehouseOutInfo.ID,
  4837. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4838. PatientId: id,
  4839. Ctime: time.Now().Unix(),
  4840. Mtime: time.Now().Unix(),
  4841. Status: 1,
  4842. RecordTime: order.StartTime,
  4843. OrgId: adminUserInfo.Org.Id,
  4844. GoodId: safe_package,
  4845. GoodTypeId: safe_package_good_type_id,
  4846. }
  4847. service.AddSigleAutoReduceRecordInfo(details)
  4848. } else if err == nil {
  4849. if user.ID > 0 {
  4850. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.Org.Id, id, safe_package, warehouseOutInfo)
  4851. }
  4852. }
  4853. }
  4854. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4855. if newOut.ID > 0 {
  4856. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4857. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4858. if err == gorm.ErrRecordNotFound {
  4859. details := &models.AutomaticReduceDetail{
  4860. WarehouseOutId: newOut.ID,
  4861. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4862. PatientId: id,
  4863. Ctime: time.Now().Unix(),
  4864. Mtime: time.Now().Unix(),
  4865. Status: 1,
  4866. RecordTime: order.StartTime,
  4867. OrgId: adminUserInfo.Org.Id,
  4868. GoodId: safe_package,
  4869. GoodTypeId: safe_package_good_type_id,
  4870. }
  4871. service.AddSigleAutoReduceRecordInfo(details)
  4872. } else if err == nil {
  4873. if user.ID > 0 {
  4874. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.Org.Id, id, safe_package, &newOut)
  4875. }
  4876. }
  4877. }
  4878. }
  4879. }
  4880. if dialysisPrescription.ALiquid != a_liquid {
  4881. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4882. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4883. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4884. service.UpdateOrderCount(aliquid_good_type_id, dialysisPrescription.ALiquid, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4885. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4886. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4887. err, newOut := service.FindOrderInfoByGoodId(aliquid_good_type_id, a_liquid, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4888. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4889. warehouseOutInfo := &models.WarehouseOutInfo{
  4890. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4891. WarehouseOutId: out.ID,
  4892. Count: 1,
  4893. Status: 1,
  4894. Ctime: time.Now().Unix(),
  4895. Remark: "",
  4896. OrgId: adminUserInfo.Org.Id,
  4897. Type: 1,
  4898. Manufacturer: 0,
  4899. Dealer: 0,
  4900. IsSys: 1,
  4901. SysRecordTime: order.StartTime,
  4902. }
  4903. stockInInfo, _ := service.FindLastStockInInfoRecord(a_liquid, adminUserInfo.Org.Id)
  4904. warehouseOutInfo.Price = stockInInfo.Price
  4905. warehouseOutInfo.GoodId = a_liquid
  4906. warehouseOutInfo.GoodTypeId = aliquid_good_type_id
  4907. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4908. if err == nil {
  4909. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4910. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4911. if err == gorm.ErrRecordNotFound {
  4912. details := &models.AutomaticReduceDetail{
  4913. WarehouseOutId: warehouseOutInfo.ID,
  4914. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4915. PatientId: id,
  4916. Ctime: time.Now().Unix(),
  4917. Mtime: time.Now().Unix(),
  4918. Status: 1,
  4919. RecordTime: order.StartTime,
  4920. OrgId: adminUserInfo.Org.Id,
  4921. GoodId: a_liquid,
  4922. GoodTypeId: aliquid_good_type_id,
  4923. }
  4924. service.AddSigleAutoReduceRecordInfo(details)
  4925. } else if err == nil {
  4926. if user.ID > 0 {
  4927. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.Org.Id, id, a_liquid, warehouseOutInfo)
  4928. }
  4929. }
  4930. }
  4931. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4932. if newOut.ID > 0 {
  4933. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4934. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4935. if err == gorm.ErrRecordNotFound {
  4936. details := &models.AutomaticReduceDetail{
  4937. WarehouseOutId: newOut.ID,
  4938. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4939. PatientId: id,
  4940. Ctime: time.Now().Unix(),
  4941. Mtime: time.Now().Unix(),
  4942. Status: 1,
  4943. RecordTime: order.StartTime,
  4944. OrgId: adminUserInfo.Org.Id,
  4945. GoodId: a_liquid,
  4946. GoodTypeId: aliquid_good_type_id,
  4947. }
  4948. service.AddSigleAutoReduceRecordInfo(details)
  4949. } else if err == nil {
  4950. if user.ID > 0 {
  4951. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.Org.Id, id, a_liquid, &newOut)
  4952. }
  4953. }
  4954. }
  4955. }
  4956. }
  4957. }
  4958. }
  4959. }
  4960. //prescription.Creater = dialysisPrescription.Creater
  4961. prescription.CreatedTime = dialysisPrescription.CreatedTime
  4962. prescription.Modifier = adminUserInfo.AdminUser.Id
  4963. prescription.ID = dialysisPrescription.ID
  4964. }
  4965. solution := models.DialysisSolution{
  4966. RegistrarsId: adminUserInfo.AdminUser.Id,
  4967. UserOrgId: adminUserInfo.Org.Id,
  4968. Doctor: prescription_doctor,
  4969. PatientId: id,
  4970. ModeId: mode_id,
  4971. DialysisDuration: dialysis_duration,
  4972. PerfusionApparatus: perfusion_apparatus,
  4973. BloodFlowVolume: blood_flow_volume,
  4974. Dewater: dewater_amount,
  4975. DisplaceLiqui: displace_liqui,
  4976. ReplacementWay: replacement_way,
  4977. Anticoagulant: anticoagulant,
  4978. AnticoagulantShouji: anticoagulant_shouji,
  4979. AnticoagulantWeichi: anticoagulant_weichi,
  4980. AnticoagulantZongliang: anticoagulant_zongliang,
  4981. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4982. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4983. Kalium: kalium,
  4984. Sodium: sodium,
  4985. Calcium: calcium,
  4986. Bicarbonate: bicarbonate,
  4987. Glucose: glucose,
  4988. // DryWeight: dry_weight,
  4989. DialysateFlow: dialysate_flow,
  4990. DialysateTemperature: dialysate_temperature,
  4991. Conductivity: conductivity,
  4992. Remark: remark,
  4993. Status: 1,
  4994. CreatedTime: time.Now().Unix(),
  4995. UpdatedTime: time.Now().Unix(),
  4996. DialysisDurationMinute: dialysisDurationMinute,
  4997. DialysisDurationHour: dialysisDurationHour,
  4998. TargetUltrafiltration: targetUltrafiltration,
  4999. DialysateFormulation: dialysateFormulation,
  5000. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  5001. BodyFluid: body_fluid,
  5002. SpecialMedicine: special_medicine,
  5003. SpecialMedicineOther: special_medicine_other,
  5004. DisplaceLiquiPart: displace_liqui_part,
  5005. DisplaceLiquiValue: displace_liqui_value,
  5006. BloodAccess: blood_access,
  5007. Ultrafiltration: ultrafiltration,
  5008. BodyFluidOther: body_fluid_other,
  5009. ReplacementTotal: replacement_total,
  5010. TargetKtv: target_ktv,
  5011. }
  5012. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  5013. c.ServeSuccessJSON(map[string]interface{}{
  5014. "solution": &solution,
  5015. "prescription": &prescription,
  5016. })
  5017. }
  5018. func (c *DialysisAPIController) GetAcceptsAssessment() {
  5019. patient, _ := c.GetInt64("patient", 0)
  5020. adminUserInfo := c.GetMobileAdminUserInfo()
  5021. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  5022. c.ServeSuccessJSON(map[string]interface{}{
  5023. "receiveTreatmentAsses": receiveTreatmentAsses,
  5024. })
  5025. }
  5026. func (this *DialysisAPIController) PostSignInfo() {
  5027. patientID, _ := this.GetInt64("patient_id")
  5028. recordDateStr := this.GetString("date")
  5029. if patientID <= 0 {
  5030. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5031. return
  5032. }
  5033. if len(recordDateStr) == 0 {
  5034. recordDateStr = time.Now().Format("2006-01-02")
  5035. }
  5036. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5037. if parseDateErr != nil {
  5038. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  5039. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5040. return
  5041. }
  5042. adminInfo := this.GetMobileAdminUserInfo()
  5043. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  5044. if err != nil {
  5045. this.ErrorLog("签名失败:%v", err)
  5046. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5047. return
  5048. }
  5049. this.ServeSuccessJSON(map[string]interface{}{
  5050. "doctor_id": adminInfo.AdminUser.Id,
  5051. })
  5052. }
  5053. func (this *DialysisAPIController) GetLastMonitorRecord() {
  5054. patientID, _ := this.GetInt64("patient_id")
  5055. adminInfo := this.GetMobileAdminUserInfo()
  5056. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  5057. this.ServeSuccessJSON(map[string]interface{}{
  5058. "monitor": record,
  5059. })
  5060. }
  5061. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  5062. thisTime := time.Now()
  5063. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  5064. timeLayout := "2006-01-02 15:04:05"
  5065. loc, _ := time.LoadLocation("Local")
  5066. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  5067. theAssessmentDateTime := theStartTime.Unix()
  5068. patientID, _ := this.GetInt64("patient_id")
  5069. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  5070. adminInfo := this.GetMobileAdminUserInfo()
  5071. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  5072. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  5073. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  5074. var ultrafiltration_rate float64
  5075. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  5076. if prescription.ID > 0 {
  5077. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  5078. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5079. if template.TemplateId == 6 || template.TemplateId == 20 {
  5080. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  5081. record.UltrafiltrationRate = ultrafiltration_rate
  5082. }
  5083. // 只针对方济医院
  5084. if template.TemplateId == 1 {
  5085. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  5086. ultrafiltration_rate = value
  5087. record.UltrafiltrationRate = ultrafiltration_rate
  5088. }
  5089. }
  5090. }
  5091. // record.UltrafiltrationRate = ultrafiltration_rate
  5092. record.UltrafiltrationVolume = 0
  5093. if template.TemplateId == 1 { //adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535
  5094. if ultrafiltration_rate > 0 {
  5095. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  5096. record.UltrafiltrationVolume = value
  5097. }
  5098. }
  5099. if template.TemplateId == 6 || template.TemplateId == 20 { //adminInfo.Org.Id == 9538
  5100. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  5101. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5102. record.UltrafiltrationVolume = ultrafiltration_volume
  5103. }
  5104. }
  5105. this.ServeSuccessJSON(map[string]interface{}{
  5106. "monitor": record,
  5107. })
  5108. }
  5109. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  5110. record_id, _ := this.GetInt64("id")
  5111. nurseID, _ := this.GetInt64("nurse")
  5112. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  5113. bedID, _ := this.GetInt64("bed")
  5114. start_time := this.GetString("start_time")
  5115. schedual_type, _ := this.GetInt64("schedual_type")
  5116. if record_id == 0 {
  5117. this.ErrorLog("id:%v", record_id)
  5118. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5119. return
  5120. }
  5121. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5122. if parseStartDateErr != nil {
  5123. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  5124. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5125. return
  5126. }
  5127. adminUserInfo := this.GetMobileAdminUserInfo()
  5128. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5129. if getNurseErr != nil {
  5130. this.ErrorLog("获取护士失败:%v", getNurseErr)
  5131. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5132. return
  5133. } else if nurse == nil {
  5134. this.ErrorLog("护士不存在")
  5135. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5136. return
  5137. }
  5138. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  5139. if getNurseErr != nil {
  5140. this.ErrorLog("获取护士失败:%v", getNurseErr)
  5141. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5142. return
  5143. } else if nurse == nil {
  5144. this.ErrorLog("护士不存在")
  5145. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5146. return
  5147. }
  5148. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  5149. if getDeviceNumberErr != nil {
  5150. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  5151. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5152. return
  5153. } else if deviceNumber == nil {
  5154. this.ErrorLog("床位号不存在")
  5155. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5156. return
  5157. }
  5158. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  5159. //
  5160. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  5161. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5162. // if getPermissionErr != nil {
  5163. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5164. // return
  5165. // } else if headNursePermission == nil {
  5166. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5167. // return
  5168. // }
  5169. //}
  5170. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  5171. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  5172. timeLayout := "2006-01-02 15:04:05"
  5173. loc, _ := time.LoadLocation("Local")
  5174. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  5175. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  5176. schedulestartTime := theStartTime.Unix()
  5177. scheduleendTime := theEndTime.Unix()
  5178. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  5179. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  5180. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5181. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  5182. if err == gorm.ErrRecordNotFound { //空床位
  5183. // 修改了床位逻辑
  5184. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5185. if daySchedule.ID > 0 {
  5186. daySchedule.BedId = bedID
  5187. daySchedule.PartitionId = deviceNumber.ZoneID
  5188. daySchedule.ScheduleType = schedual_type
  5189. daySchedule.UpdatedTime = time.Now().Unix()
  5190. err := service.UpdateSchedule(&daySchedule)
  5191. if err != nil {
  5192. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5193. return
  5194. }
  5195. }
  5196. } else if err == nil {
  5197. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  5198. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5199. if daySchedule.ID > 0 {
  5200. daySchedule.BedId = bedID
  5201. daySchedule.PartitionId = deviceNumber.ZoneID
  5202. daySchedule.ScheduleType = schedual_type
  5203. daySchedule.UpdatedTime = time.Now().Unix()
  5204. err := service.UpdateSchedule(&daySchedule)
  5205. if err != nil {
  5206. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5207. return
  5208. }
  5209. }
  5210. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  5211. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  5212. return
  5213. }
  5214. } else if err != nil {
  5215. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5216. return
  5217. }
  5218. }
  5219. dialysisRecord := &models.DialysisOrder{
  5220. ID: record_id,
  5221. UserOrgId: adminUserInfo.Org.Id,
  5222. BedID: bedID,
  5223. StartNurse: nurseID,
  5224. StartTime: startDate.Unix(),
  5225. PunctureNurse: puncture_nurse,
  5226. Creator: adminUserInfo.AdminUser.Id,
  5227. Modifier: adminUserInfo.AdminUser.Id,
  5228. SchedualType: schedual_type,
  5229. }
  5230. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  5231. if updateErr != nil {
  5232. this.ErrorLog("修改上机失败:%v", updateErr)
  5233. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5234. return
  5235. }
  5236. if updateErr == nil {
  5237. if tempDialysisRecord.Stage == 2 {
  5238. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  5239. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5240. fmt.Println(value)
  5241. a, b := math.Modf(value)
  5242. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5243. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5244. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5245. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  5246. if updateAssessmentErr != nil {
  5247. utils.ErrorLog("%v", updateAssessmentErr)
  5248. }
  5249. }
  5250. }
  5251. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5252. this.ServeSuccessJSON(map[string]interface{}{
  5253. "dialysis_order": dialysisRecords,
  5254. })
  5255. }
  5256. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  5257. record_id, _ := c.GetInt64("id")
  5258. nurseID, _ := c.GetInt64("nurse")
  5259. end_time := c.GetString("end_time")
  5260. if record_id <= 0 || nurseID <= 0 {
  5261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5262. return
  5263. }
  5264. adminUserInfo := c.GetMobileAdminUserInfo()
  5265. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5266. if getNurseErr != nil {
  5267. c.ErrorLog("获取护士失败:%v", getNurseErr)
  5268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5269. return
  5270. } else if nurse == nil {
  5271. c.ErrorLog("护士不存在")
  5272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5273. return
  5274. }
  5275. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  5276. if parseEndDateErr != nil {
  5277. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  5278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5279. return
  5280. }
  5281. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  5282. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  5283. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5284. // if getPermissionErr != nil {
  5285. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5286. // return
  5287. // } else if headNursePermission == nil {
  5288. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5289. // return
  5290. // }
  5291. //}
  5292. dialysisRecord := &models.DialysisOrder{
  5293. ID: record_id,
  5294. UserOrgId: adminUserInfo.Org.Id,
  5295. EndTime: endDate.Unix(),
  5296. FinishNurse: nurseID,
  5297. FinishModifier: adminUserInfo.AdminUser.Id,
  5298. }
  5299. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  5300. if updateErr != nil {
  5301. c.ErrorLog("修改下机失败:%v", updateErr)
  5302. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5303. return
  5304. }
  5305. if updateErr == nil {
  5306. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  5307. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5308. a, b := math.Modf(value)
  5309. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5310. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5311. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5312. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  5313. if updateAssessmentErr != nil {
  5314. utils.ErrorLog("%v", updateAssessmentErr)
  5315. }
  5316. }
  5317. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5318. c.ServeSuccessJSON(map[string]interface{}{
  5319. "dialysis_order": dialysisRecords,
  5320. })
  5321. }
  5322. func (c *DialysisAPIController) GetLongAdvice() {
  5323. patient_id, _ := c.GetInt64("id")
  5324. adminUserInfo := c.GetMobileAdminUserInfo()
  5325. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5326. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5327. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5328. c.ServeSuccessJSON(map[string]interface{}{
  5329. "status": "1",
  5330. })
  5331. return
  5332. } else { //开启推送提醒
  5333. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5334. var advice_three []*models.DoctorAdvice
  5335. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  5336. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id)
  5337. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id)
  5338. for _, advice := range advices {
  5339. if advice.FrequencyType == 3 {
  5340. t := time.Now()
  5341. week := int(t.Weekday())
  5342. switch week {
  5343. case 1:
  5344. if strings.Index(advice.WeekDay, "周一") == -1 {
  5345. advice_three = append(advice_three, advice)
  5346. }
  5347. break
  5348. case 2:
  5349. if strings.Index(advice.WeekDay, "周二") == -1 {
  5350. advice_three = append(advice_three, advice)
  5351. }
  5352. break
  5353. case 3:
  5354. if strings.Index(advice.WeekDay, "周三") == -1 {
  5355. advice_three = append(advice_three, advice)
  5356. }
  5357. break
  5358. case 4:
  5359. if strings.Index(advice.WeekDay, "周四") == -1 {
  5360. advice_three = append(advice_three, advice)
  5361. }
  5362. break
  5363. case 5:
  5364. if strings.Index(advice.WeekDay, "周五") == -1 {
  5365. advice_three = append(advice_three, advice)
  5366. }
  5367. break
  5368. case 6:
  5369. if strings.Index(advice.WeekDay, "周六") == -1 {
  5370. advice_three = append(advice_three, advice)
  5371. }
  5372. break
  5373. case 0:
  5374. if strings.Index(advice.WeekDay, "周日") == -1 {
  5375. advice_three = append(advice_three, advice)
  5376. }
  5377. break
  5378. }
  5379. }
  5380. }
  5381. for _, advice := range advices_two {
  5382. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5383. now := p.Unix()
  5384. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5385. dayStr2 := "-" + dayStr
  5386. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5387. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5388. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5389. for _, ad := range advices {
  5390. advice_three = append(advice_three, ad)
  5391. }
  5392. }
  5393. if err == nil {
  5394. c.ServeSuccessJSON(map[string]interface{}{
  5395. "status": "2",
  5396. "advices": advices,
  5397. "advices_two": RemoveRepeatedElement(advice_three),
  5398. "is_open_remind": config.IsOpenRemind,
  5399. })
  5400. }
  5401. }
  5402. }
  5403. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5404. newArr = make([]*models.DoctorAdvice, 0)
  5405. for i := 0; i < len(arr); i++ {
  5406. repeat := false
  5407. for j := i + 1; j < len(arr); j++ {
  5408. if arr[i].ID == arr[j].ID {
  5409. repeat = true
  5410. break
  5411. }
  5412. }
  5413. if !repeat {
  5414. newArr = append(newArr, arr[i])
  5415. }
  5416. }
  5417. return
  5418. }
  5419. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5420. patient, _ := c.GetInt64("id", 0)
  5421. groupNo, _ := c.GetInt64("groupno", 0)
  5422. if patient <= 0 {
  5423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5424. return
  5425. }
  5426. adminUserInfo := c.GetMobileAdminUserInfo()
  5427. dataBody := make(map[string]interface{}, 0)
  5428. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5429. if err != nil {
  5430. utils.ErrorLog(err.Error())
  5431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5432. return
  5433. }
  5434. utils.ErrorLog("%v", dataBody)
  5435. timeLayout := "2006-01-02 15:04"
  5436. loc, _ := time.LoadLocation("Local")
  5437. timeLayout2 := "2006-01-02"
  5438. loc2, _ := time.LoadLocation("Local")
  5439. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5440. utils.ErrorLog("advice_type")
  5441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5442. return
  5443. }
  5444. adviceType := int64(2)
  5445. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5446. utils.ErrorLog("advice_date")
  5447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5448. return
  5449. }
  5450. adviceDate, _ := dataBody["advice_date"].(string)
  5451. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5452. AdviceDate := theTime.Unix()
  5453. RecordDate := theTime.Unix()
  5454. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5455. utils.ErrorLog("start_time")
  5456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5457. return
  5458. }
  5459. startTime, _ := dataBody["start_time"].(string)
  5460. if len(startTime) == 0 {
  5461. utils.ErrorLog("len(start_time) == 0")
  5462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5463. return
  5464. }
  5465. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5466. if err != nil {
  5467. utils.ErrorLog(err.Error())
  5468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5469. return
  5470. }
  5471. StartTime := theTime.Unix()
  5472. Remark := ""
  5473. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5474. remark, _ := dataBody["remark"].(string)
  5475. Remark = remark
  5476. }
  5477. var advices []*models.GroupAdvice
  5478. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5479. utils.ErrorLog("advices")
  5480. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5481. return
  5482. }
  5483. adviceNames := dataBody["advices"].([]interface{})
  5484. for _, adviceNameMap := range adviceNames {
  5485. adviceNameM := adviceNameMap.(map[string]interface{})
  5486. var advice models.GroupAdvice
  5487. advice.Remark = Remark
  5488. advice.AdviceType = adviceType
  5489. advice.StartTime = StartTime
  5490. advice.AdviceDate = AdviceDate
  5491. advice.RecordDate = RecordDate
  5492. advice.Status = 1
  5493. advice.CreatedTime = time.Now().Unix()
  5494. advice.UpdatedTime = time.Now().Unix()
  5495. advice.StopState = 2
  5496. advice.ExecutionState = 2
  5497. advice.UserOrgId = adminUserInfo.Org.Id
  5498. advice.PatientId = patient
  5499. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5500. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5501. utils.ErrorLog("advice_name")
  5502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5503. return
  5504. }
  5505. adviceName, _ := adviceNameM["advice_name"].(string)
  5506. if len(adviceName) == 0 {
  5507. utils.ErrorLog("len(advice_name) == 0")
  5508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5509. return
  5510. }
  5511. advice.AdviceName = adviceName
  5512. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5513. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5514. advice.DrugSpec = drugSpec
  5515. }
  5516. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5517. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5518. advice.AdviceDesc = adviceDesc
  5519. }
  5520. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5521. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5522. advice.DrugSpecUnit = drugSpecUnit
  5523. }
  5524. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5525. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5526. // advice.SingleDose = singleDose
  5527. //}
  5528. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5529. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5530. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5531. }
  5532. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5533. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5534. advice.SingleDoseUnit = singleDoseUnit
  5535. }
  5536. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5537. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5538. // advice.PrescribingNumber = prescribingNumber
  5539. //}
  5540. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5541. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5542. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5543. }
  5544. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5545. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5546. advice.PrescribingNumberUnit = prescribingNumberUnit
  5547. }
  5548. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5549. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5550. advice.DeliveryWay = deliveryWay
  5551. }
  5552. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5553. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5554. advice.ExecutionFrequency = executionFrequency
  5555. }
  5556. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5557. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5558. advice.FrequencyType = frequency_type
  5559. }
  5560. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5561. day_count := int64(adviceNameM["day_count"].(float64))
  5562. advice.DayCount = day_count
  5563. }
  5564. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5565. week_day, _ := adviceNameM["week_day"].(string)
  5566. advice.WeekDay = week_day
  5567. }
  5568. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5569. template_id, _ := adviceNameM["template_id"].(string)
  5570. advice.TemplateId = template_id
  5571. }
  5572. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5573. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5574. advice.ExecutionFrequency = executionFrequency
  5575. }
  5576. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5577. children := adviceNameM["child"].([]interface{})
  5578. if len(children) > 0 {
  5579. for _, childrenMap := range children {
  5580. childMap := childrenMap.(map[string]interface{})
  5581. var child models.GroupAdvice
  5582. child.Remark = Remark
  5583. child.AdviceType = adviceType
  5584. child.StartTime = StartTime
  5585. child.AdviceDate = AdviceDate
  5586. child.RecordDate = RecordDate
  5587. child.Status = 1
  5588. child.CreatedTime = time.Now().Unix()
  5589. child.UpdatedTime = time.Now().Unix()
  5590. child.StopState = 2
  5591. child.ExecutionState = 2
  5592. child.UserOrgId = adminUserInfo.Org.Id
  5593. child.PatientId = patient
  5594. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5595. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5596. utils.ErrorLog("child advice_name")
  5597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5598. return
  5599. }
  5600. childAdviceName, _ := childMap["advice_name"].(string)
  5601. if len(childAdviceName) == 0 {
  5602. utils.ErrorLog("len(child advice_name) == 0")
  5603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5604. return
  5605. }
  5606. child.AdviceName = childAdviceName
  5607. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5608. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5609. child.AdviceDesc = childAdviceDesc
  5610. }
  5611. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5612. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5613. child.DrugSpec = childDrugSpec
  5614. }
  5615. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5616. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5617. child.DrugSpecUnit = childDrugSpecUnit
  5618. }
  5619. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5620. child.SingleDose = childMap["single_dose"].(float64)
  5621. }
  5622. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5623. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5624. child.SingleDoseUnit = childSingleDoseUnit
  5625. }
  5626. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5627. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5628. }
  5629. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5630. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5631. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5632. }
  5633. child.DeliveryWay = advice.DeliveryWay
  5634. child.ExecutionFrequency = advice.ExecutionFrequency
  5635. advice.Children = append(advice.Children, &child)
  5636. }
  5637. }
  5638. }
  5639. advices = append(advices, &advice)
  5640. }
  5641. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5642. if err != nil {
  5643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5644. return
  5645. }
  5646. c.ServeSuccessJSON(map[string]interface{}{
  5647. "msg": "ok",
  5648. "advices": list,
  5649. })
  5650. return
  5651. }
  5652. func (c *DialysisAPIController) UploadDryWeight() {
  5653. patient_id, _ := c.GetInt64("id")
  5654. dry_weight, _ := c.GetFloat("dry_weight")
  5655. doctor_id, _ := c.GetInt64("doctor_id")
  5656. remark := c.GetString("remark")
  5657. adminUserInfo := c.GetMobileAdminUserInfo()
  5658. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5659. if err == gorm.ErrRecordNotFound {
  5660. dryWeight := &models.SgjPatientDryweight{
  5661. PatientId: patient_id,
  5662. DryWeight: dry_weight,
  5663. Remakes: remark,
  5664. Ctime: time.Now().Unix(),
  5665. Mtime: time.Now().Unix(),
  5666. Creator: doctor_id,
  5667. Status: 1,
  5668. UserOrgId: adminUserInfo.Org.Id,
  5669. AdjustedValue: "/",
  5670. UserId: adminUserInfo.AdminUser.Id,
  5671. }
  5672. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5673. if createErr == nil {
  5674. c.ServeSuccessJSON(map[string]interface{}{
  5675. "msg": "提交成功",
  5676. "weight": dryWeight,
  5677. })
  5678. }
  5679. } else {
  5680. dryWeight := &models.SgjPatientDryweight{
  5681. PatientId: patient_id,
  5682. DryWeight: dry_weight,
  5683. Remakes: remark,
  5684. Ctime: time.Now().Unix(),
  5685. Mtime: time.Now().Unix(),
  5686. Creator: doctor_id,
  5687. Status: 1,
  5688. UserOrgId: adminUserInfo.Org.Id,
  5689. AdjustedValue: "/",
  5690. UserId: adminUserInfo.AdminUser.Id,
  5691. }
  5692. var value float64
  5693. value = dry_weight - weightAdjust.DryWeight
  5694. if value < 0 {
  5695. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5696. } else if value == 0 {
  5697. dryWeight.AdjustedValue = "/"
  5698. } else if value > 0 {
  5699. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5700. }
  5701. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5702. if createErr == nil {
  5703. c.ServeSuccessJSON(map[string]interface{}{
  5704. "msg": "提交成功",
  5705. "weight": dryWeight,
  5706. })
  5707. }
  5708. }
  5709. }
  5710. func (c *DialysisAPIController) GetSolution() {
  5711. patient_id, _ := c.GetInt64("patient_id")
  5712. mode_id, _ := c.GetInt64("mode_id")
  5713. adminUserInfo := c.GetMobileAdminUserInfo()
  5714. solution, err := service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
  5715. prescription, err := service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
  5716. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.Org.Id, mode_id)
  5717. if err != nil {
  5718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5719. return
  5720. }
  5721. c.ServeSuccessJSON(map[string]interface{}{
  5722. "solution": solution,
  5723. "prescription": prescription,
  5724. "system_prescription": system_prescription,
  5725. })
  5726. }
  5727. func (c *DialysisAPIController) GetSchedule() {
  5728. schedual_type, _ := c.GetInt64("schedual_type")
  5729. adminUserInfo := c.GetMobileAdminUserInfo()
  5730. timeLayout := "2006-01-02 15:04:05"
  5731. date := time.Now().Format("2006-01-02") + " 00:00:00"
  5732. loc, _ := time.LoadLocation("Local")
  5733. theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  5734. scheduleTime := theStartTime.Unix()
  5735. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5736. c.ServeSuccessJSON(map[string]interface{}{
  5737. "number": deviceNumber,
  5738. })
  5739. }
  5740. func (c *DialysisAPIController) GetPatientId() {
  5741. id, _ := c.GetInt64("id")
  5742. patientId, _ := service.GetPatientId(id)
  5743. c.ServeSuccessJSON(map[string]interface{}{
  5744. "patient": patientId,
  5745. })
  5746. }