dialysis_api_controller.go 269KB

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