dialysis_api_controller.go 278KB

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