dialysis_api_controller.go 349KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680
  1. package mobile_api_controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "errors"
  9. "fmt"
  10. "github.com/astaxie/beego"
  11. "github.com/jinzhu/gorm"
  12. "math"
  13. "net/http"
  14. "net/url"
  15. "reflect"
  16. "strconv"
  17. "strings"
  18. "time"
  19. )
  20. // type DialysisTestAPIController struct {
  21. // MobileBaseAPIController
  22. // }
  23. // [get]/m/api/test
  24. // func (this *DialysisTestAPIController) Test() {
  25. // orgID := int64(3907)
  26. // now := time.Now()
  27. // nextWeek := now.AddDate(0, 0, 7)
  28. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  29. // nextTwoWeek := now.AddDate(0, 0, 14)
  30. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  31. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  32. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  33. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  34. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. // return
  36. // }
  37. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  38. // if exchangeErr != nil {
  39. // this.ErrorLog("%v", exchangeErr)
  40. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. // return
  42. // }
  43. // this.ServeSuccessJSON(map[string]interface{}{
  44. // // "now": now,
  45. // // "next_week": nextWeek,f
  46. // // "next_week_mon": nextWeekMon,
  47. // // "next_week_sun": nextWeekSun,
  48. // // "next_two_week_mon": nextTwoWeekMon,
  49. // // "next_two_week_sun": nextTwoWeekSun,
  50. // "next_week_schs": nextWeekSchs,
  51. // "next_two_week_schs": nextTwoWeekSchs,
  52. // })
  53. // }
  54. type DialysisAPIController struct {
  55. MobileBaseAPIAuthController
  56. }
  57. // /m/api/scheduals [get]
  58. // @param type:int
  59. // @param date:string
  60. func (this *DialysisAPIController) Scheduals() {
  61. schedualType, _ := this.GetInt64("type")
  62. schedualDate := this.GetString("date")
  63. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  64. schedualType = 0
  65. }
  66. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  67. if parseDateErr != nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. adminInfo := this.GetMobileAdminUserInfo()
  72. orgID := adminInfo.Org.Id
  73. redis := service.RedisClient()
  74. defer redis.Close()
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. //redis.Set(key, "", time.Second)
  77. scheduals_json_str, _ := redis.Get(key).Result()
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. for _, item := range scheduals {
  82. order, _ := service.GetMonitDialysisOrder(item.UserOrgId, item.PatientId, date.Unix())
  83. item.DialysisLastOrder = order
  84. solution, _ := service.GetMonitDialysisSolution(item.UserOrgId, item.PatientId, item.ModeId)
  85. item.DialysisSolution = solution
  86. }
  87. if err != nil {
  88. this.ErrorLog("获取排班信息失败:%v", err)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. } else {
  91. if len(scheduals) > 0 {
  92. devices, _ := service.GetAllDevicetByListSix(orgID)
  93. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  94. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  95. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  96. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  97. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  98. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  99. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  100. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  101. inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
  102. //monitor, _ := service.GetMonitorByListSix(orgID, date.Unix())
  103. for key, item := range scheduals {
  104. for _, infor := range inforMation {
  105. if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
  106. scheduals[key].NewDeviceInformation = infor
  107. break
  108. }
  109. }
  110. // 获取患者信息
  111. for _, patient := range patients {
  112. if item.PatientId == patient.ID {
  113. scheduals[key].SchedualPatient = patient
  114. break
  115. }
  116. }
  117. // 床位信息
  118. for _, device := range devices {
  119. if item.BedId == device.ID {
  120. scheduals[key].DeviceNumber = device
  121. break
  122. }
  123. }
  124. // 医嘱信息
  125. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  126. for _, advice := range advices {
  127. if item.PatientId == advice.PatientId {
  128. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  129. }
  130. }
  131. // 医嘱信息
  132. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  133. for _, hisAdvice := range hisAdvices {
  134. if item.PatientId == hisAdvice.PatientId {
  135. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  136. }
  137. }
  138. // 医嘱信息
  139. for _, prescription := range prescriptions {
  140. if item.PatientId == prescription.PatientId {
  141. scheduals[key].Prescription = prescription
  142. break
  143. }
  144. }
  145. // 透前评估
  146. for _, assessmentBefore := range assessmentBefores {
  147. if item.PatientId == assessmentBefore.PatientId {
  148. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  149. break
  150. }
  151. }
  152. // 透析上下机
  153. for _, dialysisOrder := range dialysisOrders {
  154. if item.PatientId == dialysisOrder.PatientId {
  155. scheduals[key].DialysisOrder = dialysisOrder
  156. break
  157. }
  158. }
  159. // 治疗小节
  160. for _, afterDislysis := range AssessmentAfterDislysis {
  161. if item.PatientId == afterDislysis.PatientId {
  162. scheduals[key].AssessmentAfterDislysis = afterDislysis
  163. break
  164. }
  165. }
  166. // 透后评估
  167. for _, treatmentSummary := range treatmentSummarys {
  168. if item.PatientId == treatmentSummary.PatientId {
  169. scheduals[key].TreatmentSummary = treatmentSummary
  170. break
  171. }
  172. }
  173. for _, check := range dobulecheck {
  174. if item.PatientId == check.PatientId {
  175. scheduals[key].DoubleCheck = check
  176. break
  177. }
  178. }
  179. //// 监测
  180. //scheduals[key].VMMonitoringRecord = make([]models.VMMonitoringRecord, 0)
  181. //for _, moni := range monitor {
  182. // if item.PatientId == moni.PatientId {
  183. // scheduals[key].VMMonitoringRecord = append(scheduals[key].VMMonitoringRecord, moni)
  184. // }
  185. //}
  186. }
  187. //缓存数据
  188. scheduals_json, err := json.Marshal(&scheduals)
  189. if err == nil {
  190. redis.Set(key, scheduals_json, time.Second*60)
  191. }
  192. }
  193. //获取今日所有的处方开的耗材
  194. _, configs := service.FindXTHisProjectByOrgId(orgID)
  195. project := make([]*models.HisPrescriptionProjectTwo, 0)
  196. if configs.ID > 0 && configs.IsOpen == 1 {
  197. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  198. }
  199. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  200. this.ServeSuccessJSON(map[string]interface{}{
  201. "scheduals": scheduals,
  202. "project": project,
  203. })
  204. }
  205. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  206. var dat []map[string]interface{}
  207. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  208. } else {
  209. }
  210. //获取今日所有的处方开的耗材
  211. _, configs := service.FindXTHisProjectByOrgId(orgID)
  212. project := make([]*models.HisPrescriptionProjectTwo, 0)
  213. if configs.ID > 0 && configs.IsOpen == 1 {
  214. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  215. }
  216. this.ServeSuccessJSON(map[string]interface{}{
  217. "scheduals": dat,
  218. "redis": "true",
  219. "date": schedualDate,
  220. "project": project,
  221. })
  222. }
  223. }
  224. // /m/api/waiting_scheduals [get]
  225. // @param date:string
  226. func (this *DialysisAPIController) WaitingScheduals() {
  227. schedualDate := this.GetString("date")
  228. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  229. if parseDateErr != nil && len(schedualDate) != 0 {
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. return
  232. }
  233. adminInfo := this.GetMobileAdminUserInfo()
  234. orgID := adminInfo.Org.Id
  235. redis := service.RedisClient()
  236. defer redis.Close()
  237. // cur_date := time.Now().Format("2006-01-02")
  238. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  239. wait_scheduals, _ := redis.Get(key).Result()
  240. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  241. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  242. if err != nil {
  243. this.ErrorLog("获取排班信息失败:%v", err)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. } else {
  246. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  247. for _, s := range scheduals {
  248. returnScheduals = append(returnScheduals, s)
  249. }
  250. if len(returnScheduals) > 0 {
  251. //缓存数据
  252. wait_scheduals_json, err := json.Marshal(scheduals)
  253. if err == nil {
  254. redis.Set(key, wait_scheduals_json, time.Second*30)
  255. }
  256. }
  257. this.ServeSuccessJSON(map[string]interface{}{
  258. "scheduals": scheduals,
  259. })
  260. }
  261. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  262. var dat []map[string]interface{}
  263. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  264. } else {
  265. }
  266. this.ServeSuccessJSON(map[string]interface{}{
  267. "scheduals": dat,
  268. "redis": "true",
  269. "date": schedualDate,
  270. })
  271. }
  272. }
  273. //else{
  274. // fmt.Println("33333333")
  275. //
  276. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  277. // if err != nil {
  278. // this.ErrorLog("获取排班信息失败:%v", err)
  279. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  280. // } else {
  281. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  282. // for _, s := range scheduals {
  283. //
  284. // returnScheduals = append(returnScheduals, s)
  285. // }
  286. //
  287. // this.ServeSuccessJSON(map[string]interface{}{
  288. // "scheduals": returnScheduals,
  289. // })
  290. // }
  291. //
  292. // }
  293. //if err == nil{
  294. //
  295. //
  296. //
  297. //
  298. //
  299. //}else{
  300. //}
  301. // /m/api/dialysis/record [get]
  302. // @param patient_id:int
  303. // @param date:string (yyyy-MM-dd)
  304. func (this *DialysisAPIController) DialysisRecord() {
  305. patientID, _ := this.GetInt64("patient_id")
  306. recordDateStr := this.GetString("date")
  307. if patientID <= 0 {
  308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  309. return
  310. }
  311. if len(recordDateStr) == 0 {
  312. recordDateStr = time.Now().Format("2006-01-02")
  313. }
  314. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  315. if parseDateErr != nil {
  316. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  318. return
  319. }
  320. adminInfo := this.GetMobileAdminUserInfo()
  321. ch := make(chan struct{})
  322. count := 24 // count 表示活动的协程个数
  323. var patient models.Patients
  324. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  325. var predialysisEvaluation *models.PredialysisEvaluation
  326. var lastPredialysisEvaluation *models.PredialysisEvaluation
  327. var doctorAdvices []*models.DoctorAdvice
  328. var dialysisOrder *models.DialysisOrder
  329. var doubleCheck *models.DoubleCheck
  330. var monitorRecords []*models.MonitoringRecord
  331. var lastMonitorRecord *models.MonitoringRecord
  332. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  333. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  334. var treatmentSummary *models.TreatmentSummary
  335. var dialysisPrescribe *models.DialysisPrescription
  336. var dialysisSolution *models.DialysisSolution
  337. var lastDialysisPrescribe *models.DialysisPrescription
  338. var systemDialysisPrescribe *models.SystemPrescription
  339. var is_project_open_config models.XtHisProjectConfig
  340. var projects []*models.HisPrescriptionProject
  341. var stockType []*models.GoodsTypeOne
  342. var prepare []*models.XtDialysisBeforePrepare
  343. var lastAssessment models.XtPatientVascularAccess
  344. var lastDryWeightDislysis *models.SgjPatientDryweight
  345. var gobalConfig models.GobalConfig
  346. var operators []*models.SgjUserAdminRoles
  347. // 先走redis,没有走数据库
  348. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  349. go func() {
  350. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  351. ch <- struct{}{}
  352. }()
  353. go func() {
  354. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  355. ch <- struct{}{}
  356. }()
  357. go func() {
  358. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  359. ch <- struct{}{}
  360. }()
  361. go func() {
  362. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  363. ch <- struct{}{}
  364. }()
  365. go func() {
  366. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  367. ch <- struct{}{}
  368. }()
  369. go func() {
  370. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  371. ch <- struct{}{}
  372. }()
  373. go func() {
  374. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  375. ch <- struct{}{}
  376. }()
  377. go func() {
  378. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  379. ch <- struct{}{}
  380. }()
  381. go func() {
  382. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  383. ch <- struct{}{}
  384. }()
  385. go func() {
  386. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  387. ch <- struct{}{}
  388. }()
  389. go func() {
  390. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  391. ch <- struct{}{}
  392. }()
  393. go func() {
  394. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  395. ch <- struct{}{}
  396. }()
  397. go func() {
  398. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  399. ch <- struct{}{}
  400. }()
  401. go func() {
  402. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  403. ch <- struct{}{}
  404. }()
  405. go func() {
  406. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  407. ch <- struct{}{}
  408. }()
  409. go func() {
  410. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  411. ch <- struct{}{}
  412. }()
  413. go func() {
  414. // 先走redis,没有走数据库
  415. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  416. ch <- struct{}{}
  417. }()
  418. go func() {
  419. // 先走redis,没有走数据库
  420. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  421. ch <- struct{}{}
  422. }()
  423. go func() {
  424. // // 先走redis,没有走数据库
  425. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  426. ch <- struct{}{}
  427. }()
  428. go func() {
  429. // 先走redis,没有走数据库
  430. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  431. ch <- struct{}{}
  432. }()
  433. go func() {
  434. // //获取最后一次血管通路
  435. // 先走redis,没有走数据库
  436. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  437. ch <- struct{}{}
  438. }()
  439. go func() {
  440. // 先走redis,没有走数据库
  441. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  442. ch <- struct{}{}
  443. }()
  444. go func() {
  445. // 先走redis,没有走数据库
  446. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  447. ch <- struct{}{}
  448. }()
  449. go func() {
  450. // 先走redis,没有走数据库
  451. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  452. ch <- struct{}{}
  453. }()
  454. for range ch {
  455. // 每次从ch中接收数据,表明一个活动的协程结束
  456. count--
  457. // 当所有活动的协程都结束时,关闭管道
  458. if count == 0 {
  459. close(ch)
  460. }
  461. }
  462. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  463. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  464. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  465. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  466. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  467. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  468. var team_projects []*models.HisPrescriptionProject
  469. //var index int64 = 0
  470. for _, item := range temp_team_projects {
  471. //组套里面非检验项目的
  472. if item.HisProject.CostClassify != 3 {
  473. projects = append(projects, item)
  474. }
  475. //组套里面检验项目的
  476. if item.HisProject.CostClassify == 3 {
  477. team_projects = append(team_projects, item)
  478. }
  479. }
  480. team_projects = RemoveRepeatedCheckRecod(team_projects)
  481. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  482. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  483. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  484. var his_advices []*models.HisDoctorAdviceInfo
  485. if is_open_config.IsOpen == 1 {
  486. // 先走redis,没有走数据库
  487. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  488. }
  489. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  490. if is_advice_open.IsAdviceOpen == 1 {
  491. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  492. }
  493. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  494. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  495. var remind_lists []models.XtCheckRemind
  496. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  497. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  498. }
  499. returnData := map[string]interface{}{
  500. "patient": patient,
  501. "schedual": schedual,
  502. "prescription": dialysisPrescribe,
  503. "solution": dialysisSolution,
  504. "last_prescription": lastDialysisPrescribe,
  505. "receiver_treatment_access": receiverTreatmentAccess,
  506. "predialysis_evaluation": predialysisEvaluation,
  507. "doctor_advices": doctorAdvices,
  508. "double_check": doubleCheck,
  509. "assessment_after_dislysis": assessmentAfterDislysis,
  510. "treatment_summary": treatmentSummary,
  511. "monitor_records": monitorRecords,
  512. "dialysis_order": dialysisOrder,
  513. "operators": operators,
  514. "last_predialysis_evaluation": lastPredialysisEvaluation,
  515. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  516. "last_monitor_record": lastMonitorRecord,
  517. "config": gobalConfig,
  518. "dry_weight": lastDryWeightDislysis,
  519. "system_prescription": systemDialysisPrescribe,
  520. "his_advices": his_advices,
  521. "is_open_config": is_open_config,
  522. "stockType": stockType,
  523. "prepare": prepare,
  524. "lastAssessment": lastAssessment,
  525. "prescribeOne": prescribeOne,
  526. "is_project_open_config": is_project_open_config,
  527. "project": projects,
  528. "team_projects": team_projects,
  529. "is_advice_open": is_advice_open,
  530. "prescription_open": prescriptionConfig.IsOpen,
  531. "lastOrder": lastOrder,
  532. "remind_lists": remind_lists,
  533. }
  534. this.ServeSuccessJSON(returnData)
  535. }
  536. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  537. adminInfo := c.GetMobileAdminUserInfo()
  538. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  539. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  540. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  541. returnData := map[string]interface{}{
  542. "admin_users": adminUsers,
  543. "devices": devices,
  544. "device_numbers": device_numbers,
  545. }
  546. c.ServeSuccessJSON(returnData)
  547. }
  548. func (c *DialysisAPIController) PostAtreatmentInfo() {
  549. id, _ := c.GetInt64("patient", 0)
  550. recordDateStr := c.GetString("record_date")
  551. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  552. summaryContent := c.GetString("summaryContent")
  553. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  554. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  555. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  556. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  557. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  558. nursingRecord := c.GetString("nursing_record")
  559. fmt.Println("护理记录", nursingRecord)
  560. specialRecord := c.GetString("special_record")
  561. fmt.Println("特殊记录", specialRecord)
  562. adminUserInfo := c.GetMobileAdminUserInfo()
  563. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  564. checkStaffId = adminUserInfo.AdminUser.Id
  565. deboardNurseId = adminUserInfo.AdminUser.Id
  566. treatDoctor = adminUserInfo.AdminUser.Id
  567. if id <= 0 {
  568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  569. return
  570. }
  571. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  572. if patient.ID == 0 {
  573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  574. return
  575. }
  576. if len(recordDateStr) == 0 {
  577. recordDateStr = time.Now().Format("2006-01-02")
  578. }
  579. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  580. if parseDateErr != nil {
  581. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  583. return
  584. }
  585. summary := models.TreatmentSummary{
  586. UserOrgId: adminUserInfo.Org.Id,
  587. PatientId: id,
  588. AssessmentDate: recordDate.Unix(),
  589. Mission: propagandaAndEducationContent,
  590. DialysisSummary: summaryContent,
  591. SjNurse: changeMedicalNurseId,
  592. ZlNurse: treatNurseId,
  593. HdNurse: checkStaffId,
  594. XjNurse: deboardNurseId,
  595. ZlDoctor: treatDoctor,
  596. CreatedTime: time.Now().Unix(),
  597. Status: 1,
  598. NursingRecord: nursingRecord,
  599. SpecialRecord: specialRecord,
  600. }
  601. // 查询信息规挡的设置天数
  602. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  603. if infor.ID > 0 && infor.WeekDay > 0 {
  604. var cha_time int64
  605. timeNowStr := time.Now().Format("2006-01-02")
  606. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  607. //今日的日期减去设置的日期
  608. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  609. if cha_time >= recordDate.Unix() {
  610. //查询审核是否允许
  611. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  612. //申请状态不允许的情况 拒绝修改
  613. if infor.ApplicationStatus != 1 {
  614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  615. return
  616. }
  617. }
  618. }
  619. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  620. if treatmentSummary.ID == 0 { //新增
  621. summary.Creater = adminUserInfo.AdminUser.Id
  622. service.AddSigleSummaryRecord(&summary)
  623. finish := models.XtDialysisFinish{
  624. IsFinish: 1,
  625. UserOrgId: adminUserInfo.Org.Id,
  626. Status: 1,
  627. Ctime: time.Now().Unix(),
  628. Mtime: 0,
  629. Module: 10,
  630. RecordDate: recordDate.Unix(),
  631. Sourse: 1,
  632. PatientId: id,
  633. }
  634. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  635. if dialysisFinish.ID == 0 {
  636. service.CreateDialysisFinish(finish)
  637. }
  638. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  639. redis := service.RedisClient()
  640. //清空key 值
  641. redis.Set(key, "", time.Second)
  642. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  643. redis.Set(keyOne, "", time.Second)
  644. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  645. redis.Set(keyThree, "", time.Second)
  646. defer redis.Close()
  647. c.ServeSuccessJSON(map[string]interface{}{
  648. "summary": summary,
  649. })
  650. } else { //修改
  651. summary.Creater = treatmentSummary.Creater
  652. summary.CreatedTime = treatmentSummary.CreatedTime
  653. summary.Modifier = adminUserInfo.AdminUser.Id
  654. summary.ID = treatmentSummary.ID
  655. service.UpdateSummeRecord(&summary)
  656. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  657. redis := service.RedisClient()
  658. //清空key 值
  659. redis.Set(key, "", time.Second)
  660. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  661. redis.Set(keyOne, "", time.Second)
  662. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  663. redis.Set(keyThree, "", time.Second)
  664. defer redis.Close()
  665. c.ServeSuccessJSON(map[string]interface{}{
  666. "summary": summary,
  667. })
  668. }
  669. }
  670. func (c *DialysisAPIController) PostDoubleCheck() {
  671. id, _ := c.GetInt64("patient", 0)
  672. recordDateStr := c.GetString("record_date")
  673. checkTimeStr := c.GetString("check_time")
  674. firstCheckTimeStr := c.GetString("first_check_time")
  675. creater, _ := c.GetInt64("creater", 0)
  676. modifier, _ := c.GetInt64("modifier", 0)
  677. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  678. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  679. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  680. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  681. dialysis_item_desc := c.GetString("dialysis_item_desc")
  682. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  683. vascular_access_desc := c.GetString("vascular_access_desc")
  684. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  685. collator, _ := c.GetInt64("collator", 0)
  686. employee_number := c.GetString("employee_number")
  687. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  688. needle_batch_number := c.GetString("needle_batch_number")
  689. if id <= 0 {
  690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  691. return
  692. }
  693. adminUserInfo := c.GetMobileAdminUserInfo()
  694. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  695. if patient.ID == 0 {
  696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  697. return
  698. }
  699. if len(recordDateStr) == 0 {
  700. recordDateStr = time.Now().Format("2006-01-02")
  701. }
  702. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  703. if parseDateErr != nil {
  704. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  706. return
  707. }
  708. var checkDate int64
  709. if len(checkTimeStr) == 0 {
  710. checkDate = 0
  711. } else {
  712. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  713. checkDate = checkDateUnix.Unix()
  714. }
  715. var firstCheckDate int64
  716. if len(firstCheckTimeStr) == 0 {
  717. firstCheckDate = 0
  718. } else {
  719. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  720. firstCheckDate = firstCheckDateUnix.Unix()
  721. }
  722. //if adminUserInfo.Org.Id == 10340 {
  723. //
  724. // list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  725. // _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  726. // if check.ID == 0 {
  727. // if employee_number != list.JobNumber {
  728. // c.ServeSuccessJSON(map[string]interface{}{
  729. // "doubleCheck": check,
  730. // "msg": "2",
  731. // })
  732. // return
  733. // }
  734. // }
  735. // if check.ID > 0 {
  736. // if employee_number != list.JobNumber {
  737. // c.ServeSuccessJSON(map[string]interface{}{
  738. // "doubleCheck": check,
  739. // "msg": "2",
  740. // })
  741. // return
  742. // }
  743. // }
  744. //
  745. //}
  746. doubleCheck := models.DoubleCheck{
  747. UserOrgId: adminUserInfo.Org.Id,
  748. PatientId: id,
  749. DialysisItemCheck: dialysis_item_check,
  750. DialysisParameterCheck: dialysis_parameter_check,
  751. VascularAccessVerification: vascular_access_verification,
  752. PipelineConnectionCheck: pipeline_connection_check,
  753. DialysisItemDesc: dialysis_item_desc,
  754. DialysisParameterDesc: dialysis_parameter_desc,
  755. VascularAccessDesc: vascular_access_desc,
  756. PipelineConnectionDesc: pipeline_connection_desc,
  757. Collator: collator,
  758. Status: 1,
  759. CreatedTime: time.Now().Unix(),
  760. CheckDate: recordDate.Unix(),
  761. UpdatedTime: time.Now().Unix(),
  762. EmployeeNumber: employee_number,
  763. DialyzerBatchNumber: dialyzer_batch_number,
  764. NeedleBatchNumber: needle_batch_number,
  765. }
  766. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  767. if check.ID == 0 { //新增
  768. doubleCheck.FirstCheckTime = firstCheckDate
  769. doubleCheck.CheckTime = checkDate
  770. doubleCheck.Creater = creater
  771. doubleCheck.Modifier = modifier
  772. if adminUserInfo.Org.Id == 10340 {
  773. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  774. doubleCheck.Creater = order.StartNurse
  775. }
  776. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  777. //查询未核对的医嘱
  778. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  779. for _, advice := range doctorList {
  780. if advice.ExecutionStaff == modifier {
  781. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  782. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  783. return
  784. }
  785. }
  786. }
  787. // 查询信息规挡的设置天数
  788. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  789. if infor.ID > 0 && infor.WeekDay > 0 {
  790. var cha_time int64
  791. timeNowStr := time.Now().Format("2006-01-02")
  792. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  793. //今日的日期减去设置的日期
  794. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  795. if cha_time >= recordDate.Unix() {
  796. //查询审核是否允许
  797. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  798. //申请状态不允许的情况 拒绝修改
  799. if infor.ApplicationStatus != 1 {
  800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  801. return
  802. }
  803. }
  804. }
  805. err := service.AddSigleDoubleCheck(&doubleCheck)
  806. finish := models.XtDialysisFinish{
  807. IsFinish: 1,
  808. UserOrgId: adminUserInfo.Org.Id,
  809. Status: 1,
  810. Ctime: time.Now().Unix(),
  811. Mtime: 0,
  812. Module: 5,
  813. RecordDate: recordDate.Unix(),
  814. Sourse: 1,
  815. PatientId: id,
  816. }
  817. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  818. if dialysisFinish.ID == 0 {
  819. service.CreateDialysisFinish(finish)
  820. }
  821. //针对长沙南雅
  822. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  823. //查询未核对的医嘱
  824. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  825. if len(doctorList) > 0 && modifier > 0 {
  826. for _, advice := range doctorList {
  827. service.UpdateDoctorAdviceList(advice.ID, modifier)
  828. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  829. redis := service.RedisClient()
  830. //清空key 值
  831. redis.Set(key, "", time.Second)
  832. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  833. redis.Set(keyTwo, "", time.Second)
  834. theTime := time.Now()
  835. recordDate := theTime.Format("2006-01-02")
  836. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  837. redis.Set(keyFour, "", time.Second)
  838. defer redis.Close()
  839. }
  840. }
  841. }
  842. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  843. redis := service.RedisClient()
  844. //清空key 值
  845. redis.Set(key, "", time.Second)
  846. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  847. redis.Set(keyOne, "", time.Second)
  848. defer redis.Close()
  849. if err == nil {
  850. c.ServeSuccessJSON(map[string]interface{}{
  851. "doubleCheck": &doubleCheck,
  852. })
  853. }
  854. } else { //修改
  855. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  856. if infor.ID > 0 {
  857. var cha_time int64
  858. timeNowStr := time.Now().Format("2006-01-02")
  859. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  860. //今日的日期减去设置的日期
  861. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  862. if cha_time >= recordDate.Unix() {
  863. //查询审核是否允许
  864. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  865. //申请状态不允许的情况 拒绝修改
  866. if infor.ApplicationStatus != 1 {
  867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  868. return
  869. }
  870. }
  871. }
  872. doubleCheck.FirstCheckTime = firstCheckDate
  873. doubleCheck.CheckTime = checkDate
  874. doubleCheck.Creater = creater
  875. doubleCheck.Modifier = modifier
  876. doubleCheck.CreatedTime = check.CreatedTime
  877. doubleCheck.ID = check.ID
  878. doubleCheck.EmployeeNumber = employee_number
  879. doubleCheck.NeedleBatchNumber = needle_batch_number
  880. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  881. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  882. //查询未核对的医嘱
  883. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  884. for _, advice := range doctorList {
  885. if advice.ExecutionStaff == modifier {
  886. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  887. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  888. return
  889. }
  890. }
  891. }
  892. err := service.UpdateDoubleCheck(&doubleCheck)
  893. //针对长沙南雅
  894. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  895. //查询未核对的医嘱
  896. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  897. if len(doctorList) > 0 && modifier > 0 {
  898. for _, advice := range doctorList {
  899. service.UpdateDoctorAdviceList(advice.ID, modifier)
  900. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  901. redis := service.RedisClient()
  902. //清空key 值
  903. redis.Set(key, "", time.Second)
  904. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  905. redis.Set(keyTwo, "", time.Second)
  906. theTime := time.Now()
  907. recordDate := theTime.Format("2006-01-02")
  908. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  909. redis.Set(keyFour, "", time.Second)
  910. defer redis.Close()
  911. }
  912. }
  913. }
  914. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  915. redis := service.RedisClient()
  916. //清空key 值
  917. redis.Set(key, "", time.Second)
  918. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  919. redis.Set(keyOne, "", time.Second)
  920. defer redis.Close()
  921. if err == nil {
  922. c.ServeSuccessJSON(map[string]interface{}{
  923. "doubleCheck": &doubleCheck,
  924. "msg": "1",
  925. })
  926. }
  927. }
  928. }
  929. func (c *DialysisAPIController) PostAcceptsAssessment() {
  930. id, _ := c.GetInt64("patient", 0)
  931. recordDateStr := c.GetString("record_date")
  932. way, _ := c.GetInt64("way", 0)
  933. consciousness, _ := c.GetInt64("consciousness", 0)
  934. appetite, _ := c.GetInt64("appetite", 0)
  935. condition, _ := c.GetInt64("condition", 0)
  936. posture, _ := c.GetInt64("posture")
  937. sick_condition, _ := c.GetInt64("sick_condition", 0)
  938. danger_level, _ := c.GetInt64("danger_level", 0)
  939. intake, _ := c.GetInt64("intake", 0)
  940. nutrition, _ := c.GetInt64("nutrition", 0)
  941. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  942. psychological_assessment_other := c.GetString("psychological_assessment_other")
  943. score := c.GetString("score")
  944. sick_condition_other := c.GetString("sick_condition_other")
  945. //precaution, _ := c.GetInt64("precaution", 0)
  946. precaution := c.GetString("precaution")
  947. precaution_other := c.GetString("precaution_other")
  948. psychological_other := c.GetString("psychological_other")
  949. admission_number := c.GetString("admission_number")
  950. tumble, _ := c.GetInt64("tumble")
  951. diacrisis := c.GetString("diacrisis")
  952. his_department := c.GetString("his_department")
  953. his_bed := c.GetString("his_bed")
  954. if id <= 0 {
  955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  956. return
  957. }
  958. adminUserInfo := c.GetMobileAdminUserInfo()
  959. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  960. if patient.ID == 0 {
  961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  962. return
  963. }
  964. //now := time.Now()
  965. //year, month, day := now.Date()
  966. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  967. //todayTimeStamp := today_time.Unix()
  968. if len(recordDateStr) == 0 {
  969. recordDateStr = time.Now().Format("2006-01-02")
  970. }
  971. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  972. if parseDateErr != nil {
  973. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  975. return
  976. }
  977. // 查询信息规挡的设置天数
  978. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  979. if infor.ID > 0 && infor.WeekDay > 0 {
  980. var cha_time int64
  981. timeNowStr := time.Now().Format("2006-01-02")
  982. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  983. //今日的日期减去设置的日期
  984. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  985. if cha_time >= recordDate.Unix() {
  986. //查询审核是否允许
  987. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  988. //申请状态不允许的情况 拒绝修改
  989. if infor.ApplicationStatus != 1 {
  990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  991. return
  992. }
  993. }
  994. }
  995. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  996. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  997. UserOrgId: adminUserInfo.Org.Id,
  998. PatientId: id,
  999. RecordDate: recordDate.Unix(),
  1000. Way: way,
  1001. Consciousness: consciousness,
  1002. Appetite: appetite,
  1003. Condition: condition,
  1004. SickCondition: sick_condition,
  1005. DangerLevel: danger_level,
  1006. Intake: intake,
  1007. Nutrition: nutrition,
  1008. PsychologicalAssessment: psychological_assessment,
  1009. PsychologicalAssessmentOther: psychological_assessment_other,
  1010. SickConditionOther: sick_condition_other,
  1011. Posture: posture,
  1012. CreatedTime: time.Now().Unix(),
  1013. UpdateTime: time.Now().Unix(),
  1014. Status: 1,
  1015. Score: score,
  1016. Precaution: precaution,
  1017. PrecautionOther: precaution_other,
  1018. PsychologicalOther: psychological_other,
  1019. AdmissionNumber: admission_number,
  1020. Tumble: tumble,
  1021. Diacrisis: diacrisis,
  1022. HisBed: his_bed,
  1023. HisDepartment: his_department,
  1024. }
  1025. if receiveTreatment.ID == 0 { //新增
  1026. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1027. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1028. finish := models.XtDialysisFinish{
  1029. IsFinish: 1,
  1030. UserOrgId: adminUserInfo.Org.Id,
  1031. Status: 1,
  1032. Ctime: time.Now().Unix(),
  1033. Mtime: 0,
  1034. Module: 2,
  1035. RecordDate: recordDate.Unix(),
  1036. Sourse: 1,
  1037. PatientId: id,
  1038. }
  1039. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1040. if dialysisFinish.ID == 0 {
  1041. service.CreateDialysisFinish(finish)
  1042. }
  1043. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1044. redis := service.RedisClient()
  1045. defer redis.Close()
  1046. //清空key 值
  1047. redis.Set(key, "", time.Second)
  1048. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1049. redis.Set(keyOne, "", time.Second)
  1050. if err == nil {
  1051. c.ServeSuccessJSON(map[string]interface{}{
  1052. "receiveTreatmentAsses": receiveTreatmentAsses,
  1053. })
  1054. }
  1055. } else { //修改
  1056. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1057. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1058. // if getPermissionErr != nil {
  1059. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1060. // return
  1061. // } else if headNursePermission == nil {
  1062. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1063. // return
  1064. // }
  1065. //}
  1066. // 查询信息规挡的设置天数
  1067. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1068. if infor.ID > 0 && infor.WeekDay > 0 {
  1069. var cha_time int64
  1070. timeNowStr := time.Now().Format("2006-01-02")
  1071. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1072. //今日的日期减去设置的日期
  1073. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1074. if cha_time >= recordDate.Unix() {
  1075. //查询审核是否允许
  1076. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1077. //申请状态不允许的情况 拒绝修改
  1078. if infor.ApplicationStatus != 1 {
  1079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1080. return
  1081. }
  1082. }
  1083. }
  1084. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1085. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1086. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1087. receiveTreatmentAsses.ID = receiveTreatment.ID
  1088. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1089. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1090. redis := service.RedisClient()
  1091. defer redis.Close()
  1092. //清空key 值
  1093. redis.Set(key, "", time.Second)
  1094. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1095. redis.Set(keyOne, "", time.Second)
  1096. if err == nil {
  1097. c.ServeSuccessJSON(map[string]interface{}{
  1098. "receiveTreatmentAsses": receiveTreatmentAsses,
  1099. })
  1100. }
  1101. }
  1102. }
  1103. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1104. id, _ := c.GetInt64("patient", 0)
  1105. recordDateStr := c.GetString("record_date")
  1106. weightAfter, _ := c.GetFloat("weight_after", 0)
  1107. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1108. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1109. fmt.Println("weight_loss", weightReduce)
  1110. temperature, _ := c.GetFloat("temperature", 0)
  1111. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1112. breathing_rate := c.GetString("breathing_rate")
  1113. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1114. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1115. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1116. fmt.Println("actual_ultrafiltration233232322323", actual_ultrafiltration)
  1117. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1118. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1119. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1120. cruor := c.GetString("cruor")
  1121. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1122. internalFistula := c.GetString("internal_fistula")
  1123. catheter := c.GetString("catheter")
  1124. complications := c.GetString("complication")
  1125. remark := c.GetString("remark")
  1126. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1127. dialysis_intakes := c.GetString("dialysis_intakes")
  1128. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1129. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1130. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1131. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1132. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1133. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1134. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1135. patientGose, _ := c.GetInt64("patient_gose", 0)
  1136. inpatientDepartment := c.GetString("inpatient_department")
  1137. observationContent := c.GetString("observation_content")
  1138. observationContentOther := c.GetString("observation_content_other")
  1139. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1140. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1141. in_advance_reason := c.GetString("in_advance_reason")
  1142. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1143. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1144. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1145. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1146. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1147. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1148. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1149. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1150. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1151. is_eat, _ := c.GetInt64("is_eat", 0)
  1152. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1153. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1154. channels, _ := c.GetInt64("channel", 0)
  1155. return_blood, _ := c.GetInt64("return_blood", 0)
  1156. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1157. dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1158. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1159. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1160. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1161. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1162. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1163. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1164. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1165. setting_pressure := c.GetString("setting_pressure")
  1166. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1167. diastolic_pressure := c.GetString("diastolic_pressure")
  1168. other_complication := c.GetString("other_complication")
  1169. ktv := c.GetString("ktv")
  1170. urr := c.GetString("urr")
  1171. hypertenison, _ := c.GetInt64("hypertenison")
  1172. hypopiesia, _ := c.GetInt64("hypopiesia")
  1173. leave_office_method, _ := c.GetInt64("leave_office_method")
  1174. lapse, _ := c.GetInt64("lapse")
  1175. consciousness, _ := c.GetInt64("consciousness")
  1176. fallrisk, _ := c.GetInt64("fallrisk")
  1177. machine_run := c.GetString("machine_run")
  1178. after_urea := c.GetString("after_urea")
  1179. pip_coagulation := c.GetString("pip_coagulation")
  1180. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1181. fmt.Println("accumulated_blood_volume", accumulated_blood_volume)
  1182. if id <= 0 {
  1183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1184. return
  1185. }
  1186. adminUserInfo := c.GetMobileAdminUserInfo()
  1187. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1188. if patient.ID == 0 {
  1189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1190. return
  1191. }
  1192. if len(recordDateStr) == 0 {
  1193. recordDateStr = time.Now().Format("2006-01-02")
  1194. }
  1195. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1196. fmt.Println("parseDateErr", parseDateErr)
  1197. if parseDateErr != nil {
  1198. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1200. return
  1201. }
  1202. //now := time.Now()
  1203. //year, month, day := now.Date()
  1204. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1205. //todayTimeStamp := today_time.Unix()
  1206. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1207. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1208. UserOrgId: adminUserInfo.Org.Id,
  1209. PatientId: id,
  1210. AssessmentDate: recordDate.Unix(),
  1211. Temperature: temperature,
  1212. PulseFrequency: pulse_frequency,
  1213. BreathingRate: breathing_rate,
  1214. SystolicBloodPressure: systolic_blood_pressure,
  1215. DiastolicBloodPressure: diastolic_blood_pressure,
  1216. ActualUltrafiltration: actual_ultrafiltration,
  1217. ActualDisplacement: actual_displacement,
  1218. ActualTreatmentHour: actualtreatHour,
  1219. ActualTreatmentMinute: actualtreatmin,
  1220. WeightAfter: weightAfter,
  1221. AdditionalWeight: additionalWeight,
  1222. WeightLoss: weightReduce,
  1223. Cruor: cruor,
  1224. SymptomAfterDialysis: symptomsAfterDialysi,
  1225. InternalFistula: internalFistula,
  1226. Catheter: catheter,
  1227. Complication: complications,
  1228. DialysisIntakes: dialysateVolume,
  1229. CreatedTime: time.Now().Unix(),
  1230. UpdatedTime: time.Now().Unix(),
  1231. Status: 1,
  1232. Remark: remark,
  1233. BloodAccessPartId: blood_access_part_id,
  1234. BloodAccessPartOperaId: blood_access_part_opera_id,
  1235. DialysisIntakesUnit: dialysis_intakes_unit,
  1236. PuncturePointOozingBlood: puncturePointOozingBlood,
  1237. PuncturePointHaematoma: puncturePointHaematoma,
  1238. InternalFistulaTremorAc: internalFistulaTremorAc,
  1239. PatientGose: patientGose,
  1240. InpatientDepartment: inpatientDepartment,
  1241. ObservationContent: observationContent,
  1242. ObservationContentOther: observationContentOther,
  1243. DialysisProcess: dialysis_process,
  1244. InAdvanceMinute: in_advance_minute,
  1245. InAdvanceReason: in_advance_reason,
  1246. HemostasisMinute: hemostasis_minute,
  1247. HemostasisOpera: hemostasis_opera,
  1248. TremorNoise: tremor_noise,
  1249. DisequilibriumSyndrome: disequilibrium_syndrome,
  1250. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1251. ArterialTube: arterial_tube,
  1252. IntravenousTube: intravenous_tube,
  1253. Dialyzer: dialyzer,
  1254. InAdvanceReasonOther: in_advance_reason_other,
  1255. IsEat: is_eat,
  1256. CvcA: cvc_a,
  1257. CvcV: cvc_v,
  1258. Channel: channels,
  1259. ReturnBlood: return_blood,
  1260. RehydrationVolume: rehydration_volume,
  1261. DialysisDuring: dialysis_during,
  1262. StrokeVolume: stroke_volume,
  1263. BloodFlow: blood_flow,
  1264. SealingFluidDispose: sealing_fluid_dispose,
  1265. SealingFluidSpecial: sealing_fluid_special,
  1266. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1267. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1268. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1269. SettingPressure: setting_pressure,
  1270. DiastolicPressure: diastolic_pressure,
  1271. OtherComplication: other_complication,
  1272. Ktv: ktv,
  1273. Urr: urr,
  1274. Hypopiesia: hypopiesia,
  1275. Hypertenison: hypertenison,
  1276. Lapse: lapse,
  1277. LeaveOfficeMethod: leave_office_method,
  1278. Consciousness: consciousness,
  1279. Fallrisk: fallrisk,
  1280. MachineRun: machine_run,
  1281. AfterUrea: after_urea,
  1282. PipCoagulation: pip_coagulation,
  1283. AccumulatedBloodVolume: accumulated_blood_volume,
  1284. }
  1285. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1286. // 查询信息规挡的设置天数
  1287. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1288. if infor.ID > 0 && infor.WeekDay > 0 {
  1289. var cha_time int64
  1290. timeNowStr := time.Now().Format("2006-01-02")
  1291. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1292. //今日的日期减去设置的日期
  1293. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1294. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1295. if cha_time >= recordDate.Unix() {
  1296. //查询审核是否允许
  1297. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1298. //申请状态不允许的情况 拒绝修改
  1299. if infor.ApplicationStatus != 1 {
  1300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1301. return
  1302. }
  1303. }
  1304. }
  1305. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1306. if assessmentAfter.ID == 0 { //新增
  1307. if appRole.UserType == 2 || appRole.UserType == 1 {
  1308. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1309. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1310. } else {
  1311. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1312. }
  1313. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1314. finish := models.XtDialysisFinish{
  1315. IsFinish: 1,
  1316. UserOrgId: adminUserInfo.Org.Id,
  1317. Status: 1,
  1318. Ctime: time.Now().Unix(),
  1319. Mtime: 0,
  1320. Module: 9,
  1321. RecordDate: recordDate.Unix(),
  1322. Sourse: 1,
  1323. PatientId: id,
  1324. }
  1325. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1326. if dialysisFinish.ID == 0 {
  1327. service.CreateDialysisFinish(finish)
  1328. }
  1329. redis := service.RedisClient()
  1330. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1331. redis.Set(keyTwo, "", time.Second)
  1332. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1333. //清空key 值
  1334. redis.Set(key, "", time.Second)
  1335. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1336. redis.Set(keyOne, "", time.Second)
  1337. defer redis.Close()
  1338. if err == nil {
  1339. c.ServeSuccessJSON(map[string]interface{}{
  1340. "assessmentAfterDislysis": assessmentAfterDislysis,
  1341. })
  1342. }
  1343. return
  1344. } else { //修改
  1345. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1346. if infor.ID > 0 && infor.WeekDay > 0 {
  1347. var cha_time int64
  1348. timeNowStr := time.Now().Format("2006-01-02")
  1349. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1350. //今日的日期减去设置的日期
  1351. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1352. if cha_time >= recordDate.Unix() {
  1353. //查询审核是否允许
  1354. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1355. //申请状态不允许的情况 拒绝修改
  1356. if infor.ApplicationStatus != 1 {
  1357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1358. return
  1359. }
  1360. }
  1361. }
  1362. if appRole.UserType == 2 || appRole.UserType == 1 {
  1363. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1364. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1365. } else {
  1366. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1367. if assessmentAfterDislysis.Creater == 0 {
  1368. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1369. }
  1370. }
  1371. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1372. assessmentAfterDislysis.ID = assessmentAfter.ID
  1373. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1374. fmt.Println("werwewweoweoweoweoewoewoew", err)
  1375. redis := service.RedisClient()
  1376. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1377. redis.Set(keyTwo, "", time.Second)
  1378. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1379. //清空key 值
  1380. redis.Set(key, "", time.Second)
  1381. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1382. redis.Set(keyOne, "", time.Second)
  1383. if err == nil {
  1384. c.ServeSuccessJSON(map[string]interface{}{
  1385. "assessmentAfterDislysis": assessmentAfterDislysis,
  1386. })
  1387. return
  1388. }
  1389. }
  1390. return
  1391. }
  1392. func (c *DialysisAPIController) PostDialysisPrescription() {
  1393. id, _ := c.GetInt64("patient", 0)
  1394. recordDateStr := c.GetString("record_date")
  1395. if id <= 0 {
  1396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1397. return
  1398. }
  1399. adminUserInfo := c.GetMobileAdminUserInfo()
  1400. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1401. if patient.ID == 0 {
  1402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1403. return
  1404. }
  1405. if len(recordDateStr) == 0 {
  1406. recordDateStr = time.Now().Format("2006-01-02")
  1407. }
  1408. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1409. if parseDateErr != nil {
  1410. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1412. return
  1413. }
  1414. mode_id, _ := c.GetInt64("mode_id", 0)
  1415. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1416. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1417. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1418. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1419. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1420. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1421. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1422. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1423. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1424. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1425. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1426. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1427. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1428. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1429. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1430. kalium, _ := c.GetFloat("kalium", 0)
  1431. sodium, _ := c.GetFloat("sodium", 0)
  1432. calcium, _ := c.GetFloat("calcium", 0)
  1433. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1434. glucose, _ := c.GetFloat("glucose", 0)
  1435. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1436. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1437. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1438. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1439. conductivity, _ := c.GetFloat("conductivity", 0)
  1440. remark := c.GetString("remark")
  1441. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1442. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1443. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1444. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1445. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1446. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1447. special_medicine_other := c.GetString("special_medicine_other")
  1448. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1449. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1450. blood_access, _ := c.GetInt64("blood_access", 0)
  1451. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1452. body_fluid_other := c.GetString("body_fluid_other")
  1453. niprocart, _ := c.GetInt64("niprocart", 0)
  1454. jms, _ := c.GetInt64("jms", 0)
  1455. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1456. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1457. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1458. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1459. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1460. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1461. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1462. injector, _ := c.GetInt64("injector", 0)
  1463. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1464. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1465. safe_package, _ := c.GetInt64("package", 0)
  1466. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1467. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1468. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1469. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1470. blood := c.GetString("blood")
  1471. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1472. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1473. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1474. displace_speed := c.GetString("displace_speed")
  1475. illness, _ := c.GetInt64("illness")
  1476. amylaceum := c.GetString("amylaceum")
  1477. single_time := c.GetString("single_time")
  1478. single_water := c.GetString("single_water")
  1479. replacement_flow := c.GetString("replacement_flow")
  1480. plasma_separator := c.GetString("plasma_separator")
  1481. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1482. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1483. oxygen_flow := c.GetString("oxygen_flow")
  1484. oxygen_time := c.GetString("oxygen_time")
  1485. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1486. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1487. puncture_needle := c.GetString("puncture_needle")
  1488. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1489. epo := c.GetString("epo")
  1490. epo_count, _ := c.GetFloat("epo_count", 0)
  1491. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1492. admin_user_id, _ := c.GetInt64("admin_user_id")
  1493. is_water := c.GetString("is_water")
  1494. var is_war int64
  1495. if is_water == "是" {
  1496. is_war = 1
  1497. }
  1498. if is_water == "否" {
  1499. is_war = 2
  1500. }
  1501. if is_water == "请选择" {
  1502. is_war = 0
  1503. }
  1504. drhy_water := c.GetString("drhy_water")
  1505. dry_water_hour := c.GetString("dry_water_hour")
  1506. water_machine := c.GetString("water_machine")
  1507. add_amount, _ := c.GetFloat("add_amount")
  1508. reduce_amount, _ := c.GetFloat("reduce_amount")
  1509. dialysis_remark := c.GetString("dialysis_remark")
  1510. prescribing_number, _ := c.GetFloat("prescribing_number")
  1511. prescription_sodium := c.GetString("prescription_sodium")
  1512. start_sodium := c.GetString("start_sodium")
  1513. sodium_curve := c.GetString("sodium_curve")
  1514. treatment_remark := c.GetString("treatment_remark")
  1515. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1516. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1517. prescription_water, _ := c.GetFloat("prescription_water")
  1518. dialysis_strainer := c.GetString("dialysis_strainer")
  1519. chaptalization := c.GetString("chaptalization")
  1520. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1521. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1522. //
  1523. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1524. // if appRole.UserType == 3 {
  1525. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1526. // if getPermissionErr != nil {
  1527. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1528. // return
  1529. // } else if headNursePermission == nil {
  1530. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1531. // return
  1532. // }
  1533. // }
  1534. //}
  1535. // 查询信息规挡的设置天数
  1536. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1537. if infor.ID > 0 && infor.WeekDay > 0 {
  1538. var cha_time int64
  1539. timeNowStr := time.Now().Format("2006-01-02")
  1540. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1541. //今日的日期减去设置的日期
  1542. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1543. if cha_time >= recordDate.Unix() {
  1544. //查询审核是否允许
  1545. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1546. //申请状态不允许的情况 拒绝修改
  1547. if infor.ApplicationStatus != 1 {
  1548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1549. return
  1550. }
  1551. }
  1552. }
  1553. if mode_id > 0 {
  1554. var str string
  1555. //查找该机构用的是什么透析器
  1556. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1557. if filedConfig.ID > 0 {
  1558. str = dialyzerPerfusionApparatus
  1559. } else {
  1560. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1561. }
  1562. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1563. }
  1564. //TODO 需要根据角色去判断
  1565. prescription := models.DialysisPrescription{
  1566. UserOrgId: adminUserInfo.Org.Id,
  1567. PatientId: id,
  1568. RecordDate: recordDate.Unix(),
  1569. ModeId: mode_id,
  1570. DialysisDuration: dialysis_duration,
  1571. Dialyzer: dialyzer,
  1572. PerfusionApparatus: perfusion_apparatus,
  1573. BloodFlowVolume: blood_flow_volume,
  1574. DewaterAmount: dewater_amount,
  1575. DisplaceLiqui: displace_liqui,
  1576. ReplacementWay: replacement_way,
  1577. Anticoagulant: anticoagulant,
  1578. AnticoagulantShouji: anticoagulant_shouji,
  1579. AnticoagulantWeichi: anticoagulant_weichi,
  1580. AnticoagulantZongliang: anticoagulant_zongliang,
  1581. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1582. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1583. Kalium: kalium,
  1584. Sodium: sodium,
  1585. Calcium: calcium,
  1586. Bicarbonate: bicarbonate,
  1587. Glucose: glucose,
  1588. // DryWeight: dry_weight,
  1589. DialysateFlow: dialysate_flow,
  1590. DialysateTemperature: dialysate_temperature,
  1591. // PrescriptionDoctor: prescription_doctor,
  1592. ReplacementTotal: replacement_total,
  1593. Conductivity: conductivity,
  1594. Remark: remark,
  1595. Status: 1,
  1596. CreatedTime: time.Now().Unix(),
  1597. UpdatedTime: time.Now().Unix(),
  1598. DialysisDurationMinute: dialysisDurationMinute,
  1599. DialysisDurationHour: dialysisDurationHour,
  1600. TargetUltrafiltration: targetUltrafiltration,
  1601. DialysateFormulation: dialysateFormulation,
  1602. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1603. BodyFluid: body_fluid,
  1604. SpecialMedicine: special_medicine,
  1605. SpecialMedicineOther: special_medicine_other,
  1606. DisplaceLiquiPart: displace_liqui_part,
  1607. DisplaceLiquiValue: displace_liqui_value,
  1608. BloodAccess: blood_access,
  1609. Ultrafiltration: ultrafiltration,
  1610. BodyFluidOther: body_fluid_other,
  1611. Niprocart: niprocart,
  1612. Jms: jms,
  1613. FistulaNeedleSet: fistula_needle_set,
  1614. FistulaNeedleSet16: fistula_needle_set_16,
  1615. Hemoperfusion: hemoperfusion,
  1616. DialyserSterilised: dialyser_sterilised,
  1617. Filtryzer: filtryzer,
  1618. Dialyzers: dialyzers,
  1619. Injector: injector,
  1620. Bloodlines: bloodlines,
  1621. TubingHemodialysis: tubing_hemodialysis,
  1622. Package: safe_package,
  1623. ALiquid: a_liquid,
  1624. TargetKtv: target_ktv,
  1625. PreImpulse: pre_impulse,
  1626. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1627. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1628. Blood: blood,
  1629. DialysisDialyszers: dialysis_dialyszers,
  1630. DialysisIrrigation: dialysis_irrigation,
  1631. AntioxidantCommodityName: antioxidant_commodity_name,
  1632. DisplaceSpeed: displace_speed,
  1633. Illness: illness,
  1634. Amylaceum: amylaceum,
  1635. SingleTime: single_time,
  1636. SingleWater: single_water,
  1637. ReplacementFlow: replacement_flow,
  1638. PlasmaSeparator: plasma_separator,
  1639. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1640. OxygenUptake: oxygen_uptake,
  1641. OxygenFlow: oxygen_flow,
  1642. OxygenTime: oxygen_time,
  1643. HemodialysisPipelines: hemodialysis_pipelines,
  1644. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1645. PunctureNeedle: puncture_needle,
  1646. PunctureNeedleCount: puncture_needle_count,
  1647. Epo: epo,
  1648. EpoCount: epo_count,
  1649. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1650. AdminUserId: admin_user_id,
  1651. IsWater: is_war,
  1652. DrhyWater: drhy_water,
  1653. DryWaterHour: dry_water_hour,
  1654. WaterMachine: water_machine,
  1655. AddAmount: add_amount,
  1656. ReduceAmount: reduce_amount,
  1657. DialysisRemark: dialysis_remark,
  1658. PrescribingNumber: prescribing_number,
  1659. StartSodium: start_sodium,
  1660. SodiumCurve: sodium_curve,
  1661. TreatmentRemark: treatment_remark,
  1662. PrescriptionSodium: prescription_sodium,
  1663. DialysisFluidFlow: dialysis_fluid_flow,
  1664. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1665. PrescriptionWater: prescription_water,
  1666. DialysisStrainer: dialysis_strainer,
  1667. Chaptalization: chaptalization,
  1668. }
  1669. //查询最近透析准备表里是否存在 透析器 灌流器
  1670. //
  1671. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1672. //
  1673. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1674. //
  1675. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1676. //if len(mation)>0{
  1677. // for _, item := range splitStr {
  1678. // for _,it := range mation{
  1679. // if(item == it.SpecificationName){
  1680. //
  1681. // //查询最近一次的透析器
  1682. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1683. //
  1684. // if errcode == gorm.ErrRecordNotFound{
  1685. // //插入数据
  1686. // prepare := models.DialysisBeforePrepare{
  1687. // UserOrgId: adminUserInfo.Org.Id,
  1688. // PatientId: id,
  1689. // RecordDate: recordDate.Unix(),
  1690. // GoodTypeId: it.GoodTypeId,
  1691. // GoodId: it.ID,
  1692. // Count: 1,
  1693. // Ctime: time.Now().Unix(),
  1694. // Creater: adminUserInfo.AdminUser.Id,
  1695. // Status:1,
  1696. //
  1697. // }
  1698. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1699. // fmt.Println("",errcode)
  1700. // }
  1701. // }
  1702. // }
  1703. //
  1704. // }
  1705. //
  1706. // for _, item := range splitIrrigation {
  1707. // for _,it := range mation{
  1708. // if(item == it.SpecificationName){
  1709. // //查询最近一次的透析器
  1710. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1711. // if errcode == gorm.ErrRecordNotFound{
  1712. // //插入数据
  1713. // prepare := models.DialysisBeforePrepare{
  1714. // UserOrgId: adminUserInfo.Org.Id,
  1715. // PatientId: id,
  1716. // RecordDate: recordDate.Unix(),
  1717. // GoodTypeId: it.GoodTypeId,
  1718. // GoodId: it.ID,
  1719. // Count: 1,
  1720. // Ctime: time.Now().Unix(),
  1721. // Creater: adminUserInfo.AdminUser.Id,
  1722. // Status:1,
  1723. //
  1724. // }
  1725. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1726. // fmt.Println(errcode)
  1727. // }
  1728. // }
  1729. // }
  1730. // }
  1731. //}
  1732. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1733. if dialysisPrescription.ID == 0 { //新增
  1734. if appRole.UserType == 2 || appRole.UserType == 1 {
  1735. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1736. }
  1737. prescription.Creater = adminUserInfo.AdminUser.Id
  1738. //针对河间咸得
  1739. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1740. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1741. prescription.DisplaceLiquiPart = 0
  1742. prescription.DisplaceLiquiValue = 0
  1743. }
  1744. }
  1745. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  1746. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1747. }
  1748. err := service.AddSigleRecord(&prescription)
  1749. finish := models.XtDialysisFinish{
  1750. IsFinish: 1,
  1751. UserOrgId: adminUserInfo.Org.Id,
  1752. Status: 1,
  1753. Ctime: time.Now().Unix(),
  1754. Mtime: 0,
  1755. Module: 1,
  1756. RecordDate: recordDate.Unix(),
  1757. Sourse: 1,
  1758. PatientId: id,
  1759. }
  1760. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  1761. if dialysisFinish.ID == 0 {
  1762. service.CreateDialysisFinish(finish)
  1763. }
  1764. //长沙南雅医院,自动生成抗凝剂的临时处方
  1765. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  1766. if prescribing_number == 0 {
  1767. prescribing_number = 1
  1768. }
  1769. if prescribing_number == 0 && id == 14682 {
  1770. prescribing_number = 2
  1771. }
  1772. if prescribing_number == 0 && id == 18560 {
  1773. prescribing_number = 2
  1774. }
  1775. advice := models.DoctorAdvice{
  1776. UserOrgId: adminUserInfo.Org.Id,
  1777. PatientId: id,
  1778. GroupNo: 0,
  1779. AdviceType: 2,
  1780. RecordDate: recordDate.Unix(),
  1781. AdviceDate: recordDate.Unix(),
  1782. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1783. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1784. AdviceDesc: "",
  1785. ReminderDate: 0,
  1786. SingleDose: anticoagulant_zongliang,
  1787. SingleDoseUnit: "iu",
  1788. DrugSpec: 0,
  1789. DrugSpecUnit: "",
  1790. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1791. PrescribingNumberUnit: "支",
  1792. DeliveryWay: "静脉注射",
  1793. ExecutionFrequency: "上机前",
  1794. AdviceDoctor: 0,
  1795. Status: 1,
  1796. CreatedTime: time.Now().Unix(),
  1797. UpdatedTime: time.Now().Unix(),
  1798. IsPrescription: 1,
  1799. ExecutionState: 2,
  1800. StopState: 2,
  1801. IsSettle: 2,
  1802. }
  1803. // 查询排班信息
  1804. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1805. if schedulePatient.ID > 0 {
  1806. if schedulePatient.ScheduleType == 1 {
  1807. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1808. }
  1809. if schedulePatient.ScheduleType == 2 {
  1810. advice.StartTime = recordDate.Unix() + 10*60*60
  1811. }
  1812. }
  1813. // 抗凝剂名称
  1814. switch anticoagulant {
  1815. case 1:
  1816. advice.AdviceName = "无肝素"
  1817. break
  1818. case 2:
  1819. advice.AdviceName = "普通肝素"
  1820. break
  1821. case 3:
  1822. advice.AdviceName = "低分子肝素"
  1823. break
  1824. case 4:
  1825. advice.AdviceName = "阿加曲班"
  1826. break
  1827. case 5:
  1828. advice.AdviceName = "枸橼酸钠"
  1829. break
  1830. case 6:
  1831. advice.AdviceName = "低分子肝素钙"
  1832. break
  1833. case 7:
  1834. advice.AdviceName = "低分子肝素钠"
  1835. break
  1836. case 8:
  1837. advice.AdviceName = "依诺肝素"
  1838. break
  1839. case 9:
  1840. advice.AdviceName = "达肝素"
  1841. break
  1842. case 10:
  1843. advice.AdviceName = "体外抗凝"
  1844. break
  1845. case 11:
  1846. advice.AdviceName = "那曲肝素"
  1847. break
  1848. case 12:
  1849. advice.AdviceName = "无抗凝剂"
  1850. break
  1851. }
  1852. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  1853. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  1854. advice.AdviceDoctor = appRole.AdminUserId
  1855. }
  1856. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  1857. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  1858. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  1859. advice.AdviceName = "低分子肝素钠注射液"
  1860. // 修改患者临时医嘱里的抗凝剂医嘱
  1861. advice.ID = advicePrescription.ID
  1862. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  1863. } else {
  1864. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  1865. advice.AdviceName = "低分子肝素钠注射液"
  1866. // 新增患者临时医嘱里的抗凝剂医嘱
  1867. service.CreateDoctorAdvice(&advice)
  1868. }
  1869. }
  1870. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  1871. redis := service.RedisClient()
  1872. defer redis.Close()
  1873. //清空key 值
  1874. redis.Set(key, "", time.Second)
  1875. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  1876. redis.Set(keyOne, "", time.Second)
  1877. }
  1878. //获取key,清空redis
  1879. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1880. redis := service.RedisClient()
  1881. //清空key 值
  1882. redis.Set(key, "", time.Second)
  1883. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1884. //清空key 值
  1885. redis.Set(keyOne, "", time.Second)
  1886. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1887. //清空key 值
  1888. redis.Set(keyTwo, "", time.Second)
  1889. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1890. redis.Set(keySix, "", time.Second)
  1891. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1892. redis.Set(keySeven, "", time.Second)
  1893. if err == nil {
  1894. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1895. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  1896. //清空key 值
  1897. redis.Set(keyThree, "", time.Second)
  1898. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  1899. //清空key 值
  1900. redis.Set(keyFour, "", time.Second)
  1901. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  1902. redis.Set(keyFive, "", time.Second)
  1903. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1904. redis.Set(keySix, "", time.Second)
  1905. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1906. redis.Set(keySeven, "", time.Second)
  1907. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1908. //清空key 值
  1909. redis.Set(keyOne, "", time.Second)
  1910. if updateErr != nil {
  1911. utils.ErrorLog("%v", updateErr)
  1912. }
  1913. defer redis.Close()
  1914. c.ServeSuccessJSON(map[string]interface{}{
  1915. "prescription": prescription,
  1916. })
  1917. }
  1918. } else { //修改
  1919. //if mode_id > 0 {
  1920. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1921. //}
  1922. //if template.TemplateId == 1 {
  1923. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1924. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1925. // if getPermissionErr != nil {
  1926. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1927. // return
  1928. // } else if headNursePermission == nil {
  1929. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1930. // return
  1931. // }
  1932. // }
  1933. //}
  1934. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1935. prescription.Modifier = adminUserInfo.AdminUser.Id
  1936. if appRole.UserType == 2 || appRole.UserType == 1 {
  1937. prescription_doctor := adminUserInfo.AdminUser.Id
  1938. prescription.PrescriptionDoctor = prescription_doctor
  1939. } else {
  1940. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  1941. }
  1942. if dialysisPrescription.Creater == 0 { //体重称
  1943. prescription.Creater = adminUserInfo.AdminUser.Id
  1944. } else {
  1945. prescription.Creater = dialysisPrescription.Creater
  1946. if adminUserInfo.Org.Id == 9882 {
  1947. if appRole.UserType == 2 || appRole.UserType == 1 {
  1948. prescription_doctor := adminUserInfo.AdminUser.Id
  1949. prescription.PrescriptionDoctor = prescription_doctor
  1950. prescription.Creater = prescription_doctor
  1951. }
  1952. }
  1953. }
  1954. prescription.ID = dialysisPrescription.ID
  1955. err := service.UpDateDialysisPrescription(&prescription)
  1956. finish := models.XtDialysisFinish{
  1957. IsFinish: 1,
  1958. UserOrgId: adminUserInfo.Org.Id,
  1959. Status: 1,
  1960. Ctime: time.Now().Unix(),
  1961. Mtime: 0,
  1962. Module: 1,
  1963. RecordDate: recordDate.Unix(),
  1964. Sourse: 1,
  1965. PatientId: id,
  1966. }
  1967. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  1968. if dialysisFinish.ID == 0 {
  1969. service.CreateDialysisFinish(finish)
  1970. }
  1971. //修改处方
  1972. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  1973. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  1974. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  1975. if advicePrescription.ID > 0 {
  1976. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  1977. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  1978. redis := service.RedisClient()
  1979. defer redis.Close()
  1980. //清空key 值
  1981. redis.Set(key, "", time.Second)
  1982. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  1983. redis.Set(keyOne, "", time.Second)
  1984. }
  1985. }
  1986. //获取key,清空redis
  1987. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1988. redis := service.RedisClient()
  1989. //清空key 值
  1990. redis.Set(key, "", time.Second)
  1991. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1992. //清空key 值
  1993. redis.Set(keyOne, "", time.Second)
  1994. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1995. redis.Set(keySix, "", time.Second)
  1996. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1997. redis.Set(keySeven, "", time.Second)
  1998. if err == nil {
  1999. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2000. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2001. //清空key 值
  2002. redis.Set(keyOne, "", time.Second)
  2003. defer redis.Close()
  2004. if updateErr != nil {
  2005. utils.ErrorLog("%v", updateErr)
  2006. }
  2007. c.ServeSuccessJSON(map[string]interface{}{
  2008. "prescription": prescription,
  2009. })
  2010. }
  2011. }
  2012. }
  2013. func (c *DialysisAPIController) Finish() {
  2014. id, _ := c.GetInt64("patient", 0)
  2015. recordDateStr := c.GetString("record_date")
  2016. nurseID, _ := c.GetInt64("nurse")
  2017. end_time := c.GetString("end_time")
  2018. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2019. internal_fistula := c.GetString("blood_access_internal_fistula")
  2020. catheter := c.GetString("catheter")
  2021. cruor := c.GetString("cruor")
  2022. mission := c.GetString("mission")
  2023. if id <= 0 || nurseID <= 0 {
  2024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2025. return
  2026. }
  2027. adminUserInfo := c.GetMobileAdminUserInfo()
  2028. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2029. if patient.ID == 0 {
  2030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2031. return
  2032. }
  2033. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2034. if getNurseErr != nil {
  2035. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2036. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2037. return
  2038. } else if nurse == nil {
  2039. c.ErrorLog("护士不存在")
  2040. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2041. return
  2042. }
  2043. if len(recordDateStr) == 0 {
  2044. recordDateStr = time.Now().Format("2006-01-02")
  2045. }
  2046. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2047. if parseDateErr != nil {
  2048. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2049. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2050. return
  2051. }
  2052. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2053. if parseEndDateErr != nil {
  2054. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2056. return
  2057. }
  2058. // 查询信息规挡的设置天数
  2059. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2060. if infor.ID > 0 && infor.WeekDay > 0 {
  2061. var cha_time int64
  2062. timeNowStr := time.Now().Format("2006-01-02")
  2063. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2064. //今日的日期减去设置的日期
  2065. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2066. if cha_time >= recordDate.Unix() {
  2067. //查询审核是否允许
  2068. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2069. //申请状态不允许的情况 拒绝修改
  2070. if infor.ApplicationStatus != 1 {
  2071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2072. return
  2073. }
  2074. }
  2075. }
  2076. //now := time.Now()
  2077. //year, month, day := now.Date()
  2078. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2079. //todayTimeStamp := today_time.Unix()
  2080. // 获取当天的第一条透析纪录
  2081. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2082. if getMonitorRecordsErr != nil {
  2083. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2085. return
  2086. }
  2087. // 获取当前的最后一条透析纪录
  2088. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2089. if getMonitorRecordsErr != nil {
  2090. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2092. return
  2093. }
  2094. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2095. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2096. if getAADErr != nil {
  2097. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2099. return
  2100. }
  2101. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2102. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2103. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2104. if assessmentAfterDislysis != nil {
  2105. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2106. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2107. } else {
  2108. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2109. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2110. tempassessmentAfterDislysis.Status = 1
  2111. tempassessmentAfterDislysis.PatientId = id
  2112. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2113. }
  2114. //长沙南雅
  2115. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2116. //获取最后一条透析处方数据
  2117. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2118. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2119. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2120. }
  2121. if dialysisOrder.Stage == 1 {
  2122. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2123. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2124. fmt.Println(value)
  2125. a, b := math.Modf(value)
  2126. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2127. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2128. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2129. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2130. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2131. }
  2132. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2133. //var num1 int64
  2134. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2135. //fmt.Println(num1)
  2136. //sub := float64(num1 / 3600)
  2137. //fmt.Println(sub)
  2138. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2139. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2140. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2141. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2142. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2143. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2144. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2145. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2146. if adminUserInfo.Org.Id != 10445 {
  2147. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2148. }
  2149. //北方营口医院
  2150. if adminUserInfo.Org.Id == 10445 {
  2151. //获取最后一条透析处方数据
  2152. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2153. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2154. } else {
  2155. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2156. }
  2157. //新化博翔
  2158. if adminUserInfo.Org.Id == 10447 {
  2159. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2160. }
  2161. //阳春
  2162. if adminUserInfo.Org.Id == 10485 {
  2163. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2164. }
  2165. }
  2166. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 10243 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10414 || adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 {
  2167. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2168. if evaluation.SystolicBloodPressure == 0 {
  2169. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2170. pre := models.PredialysisEvaluation{
  2171. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2172. }
  2173. fmt.Println("prew", pre)
  2174. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2175. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2176. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2177. redis := service.RedisClient()
  2178. redis.Set(key, "", time.Second)
  2179. redis.Set(keyOne, "", time.Second)
  2180. defer redis.Close()
  2181. fmt.Println(getNurseErr)
  2182. }
  2183. if evaluation.DiastolicBloodPressure == 0 {
  2184. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2185. pres := models.PredialysisEvaluation{
  2186. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2187. }
  2188. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2189. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2190. redis := service.RedisClient()
  2191. redis.Set(key, "", time.Second)
  2192. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2193. redis.Set(keyOne, "", time.Second)
  2194. defer redis.Close()
  2195. fmt.Println(getNurseErr)
  2196. }
  2197. if evaluation.PulseFrequency == 0 {
  2198. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2199. press := models.PredialysisEvaluation{
  2200. PulseFrequency: evaluation.PulseFrequency,
  2201. }
  2202. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2203. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2204. redis := service.RedisClient()
  2205. redis.Set(key, "", time.Second)
  2206. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2207. redis.Set(keyOne, "", time.Second)
  2208. defer redis.Close()
  2209. fmt.Println(getNurseErr)
  2210. }
  2211. if evaluation.Temperature == 0 {
  2212. evaluation.Temperature = fmonitorRecords.Temperature
  2213. press := models.PredialysisEvaluation{
  2214. Temperature: evaluation.Temperature,
  2215. }
  2216. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2217. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2218. redis := service.RedisClient()
  2219. redis.Set(key, "", time.Second)
  2220. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2221. redis.Set(keyOne, "", time.Second)
  2222. defer redis.Close()
  2223. fmt.Println(getNurseErr)
  2224. }
  2225. }
  2226. if adminUserInfo.Org.Id == 9583 {
  2227. //获取透析处方的最后一条数据
  2228. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2229. if diaerr != nil {
  2230. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2232. return
  2233. }
  2234. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2235. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2236. }
  2237. }
  2238. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2239. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2240. }
  2241. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2242. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2243. }
  2244. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2245. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2246. }
  2247. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2248. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2249. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2250. }
  2251. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2252. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2253. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2254. }
  2255. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2256. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2257. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2258. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2259. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2260. }
  2261. if lastAssessmentAfterDislysis != nil {
  2262. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2263. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2264. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2265. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2266. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2267. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2268. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2269. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2270. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2271. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2272. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2273. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2274. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2275. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2276. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2277. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2278. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2279. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2280. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2281. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2282. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2283. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2284. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2285. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2286. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2287. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2288. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2289. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2290. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2291. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2292. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2293. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2294. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2295. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2296. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2297. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2298. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2299. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2300. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2301. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2302. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2303. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2304. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2305. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2306. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2307. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2308. if tempassessmentAfterDislysis.PatientId == 18695 {
  2309. tempassessmentAfterDislysis.ActualDisplacement = 0
  2310. }
  2311. }
  2312. finish := models.XtDialysisFinish{
  2313. IsFinish: 1,
  2314. UserOrgId: adminUserInfo.Org.Id,
  2315. Status: 1,
  2316. Ctime: time.Now().Unix(),
  2317. Mtime: 0,
  2318. Module: 9,
  2319. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2320. Sourse: 1,
  2321. PatientId: tempassessmentAfterDislysis.PatientId,
  2322. }
  2323. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2324. if dialysisFinish.ID == 0 {
  2325. service.CreateDialysisFinish(finish)
  2326. }
  2327. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2328. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2329. redis := service.RedisClient()
  2330. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2331. redis.Set(keyOne, "", time.Second)
  2332. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2333. redis.Set(keyTwo, "", time.Second)
  2334. defer redis.Close()
  2335. //清空key 值
  2336. redis.Set(key, "", time.Second)
  2337. if err != nil {
  2338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2339. return
  2340. }
  2341. if dialysisOrder == nil {
  2342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2343. return
  2344. }
  2345. if dialysisOrder.Stage == 2 {
  2346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2347. return
  2348. }
  2349. if dialysisOrder.Stage == 1 {
  2350. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission)
  2351. finish := models.XtDialysisFinish{
  2352. IsFinish: 1,
  2353. UserOrgId: adminUserInfo.Org.Id,
  2354. Status: 1,
  2355. Ctime: time.Now().Unix(),
  2356. Mtime: 0,
  2357. Module: 8,
  2358. RecordDate: recordDate.Unix(),
  2359. Sourse: 1,
  2360. PatientId: id,
  2361. }
  2362. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2363. if dialysisFinish.ID == 0 {
  2364. service.CreateDialysisFinish(finish)
  2365. }
  2366. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2367. redis := service.RedisClient()
  2368. defer redis.Close()
  2369. //清空key 值
  2370. redis.Set(key, "", time.Second)
  2371. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2372. redis.Set(keyOne, "", time.Second)
  2373. //结束时候透析次数加1
  2374. service.UpdateSolutionByPatientId(id)
  2375. //下机完自动消毒,针对长沙南雅
  2376. if dialysisOrder.Stage == 1 {
  2377. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9538 || adminUserInfo.Org.Id == 10121 {
  2378. //根据床位号获取设备型号
  2379. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2380. //查询使用消毒最后一条消毒记录
  2381. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2382. fmt.Println("err", err)
  2383. if err == gorm.ErrRecordNotFound {
  2384. //查找排班
  2385. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2386. //查询改设备是否有消毒计划
  2387. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2388. //根据床位号获取设备id
  2389. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2390. //查询病人信息
  2391. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2392. var con = ""
  2393. if patients.IsInfectious == 0 {
  2394. con = ""
  2395. }
  2396. if patients.IsInfectious == 1 {
  2397. con = "无"
  2398. }
  2399. if patients.IsInfectious == 2 {
  2400. con = "有"
  2401. }
  2402. if errcode == nil {
  2403. var end_time int64
  2404. end_time = endDate.Unix() + plan.DisinfecTime*60
  2405. //新增消毒
  2406. information := models.DeviceInformation{
  2407. Date: dialysisOrder.DialysisDate,
  2408. Zone: dialysisOrder.ZoneId,
  2409. Class: dialysisOrder.SchedualType,
  2410. BedNumber: dialysisOrder.BedID,
  2411. PatientId: dialysisOrder.PatientId,
  2412. DialysisMode: scheduleByPatient.ModeId,
  2413. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2414. Disinfection: 1,
  2415. DialysisConcentration: 1,
  2416. DisinfectionStatus: 1,
  2417. Move: 1,
  2418. UserOrgId: dialysisOrder.UserOrgId,
  2419. DisinfectType: plan.Way,
  2420. DisinfectantType: plan.MachineDisinfectant,
  2421. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2422. Disinfectant: plan.Disinfectant,
  2423. Ctime: time.Now().Unix(),
  2424. Status: 1,
  2425. SignName: nurseID,
  2426. EquimentId: addmacher.ID,
  2427. DisinfectionResidue: 2,
  2428. Bed: addmacher.BedNumber,
  2429. StartTime: dialysisOrder.StartTime,
  2430. EndTime: dialysisOrder.EndTime,
  2431. Contagion: con,
  2432. WeightLoss: 0,
  2433. Hyperfiltratio: 0,
  2434. DialysisHour: "",
  2435. MachineRun: 1,
  2436. DisinfecStartime: endDate.Unix(),
  2437. DisinfecEndtime: end_time,
  2438. }
  2439. err := service.CreateInformationTwo(&information)
  2440. fmt.Println("报错", err)
  2441. }
  2442. }
  2443. }
  2444. }
  2445. dialysisOrder.Stage = 2
  2446. dialysisOrder.FinishNurse = nurseID
  2447. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2448. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2449. dialysisOrder.EndTime = endDate.Unix()
  2450. fmt.Println("ADMINWOOWOWOWOWO", adminUserInfo.Org.Id)
  2451. // 长沙南雅需求
  2452. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2453. //获取最后1条监测的数据
  2454. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2455. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2456. var accumulatedBloodVolume float64
  2457. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2458. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2459. fmt.Println(err)
  2460. // 查询未执行的医嘱
  2461. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2462. fmt.Println("doctorAdviceWOWOOWOWOWOWOWOW", doctorAdvice)
  2463. for _, item := range doctorAdvice {
  2464. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2465. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2466. redis := service.RedisClient()
  2467. //清空key 值
  2468. redis.Set(key, "", time.Second)
  2469. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2470. redis.Set(keyTwo, "", time.Second)
  2471. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2472. redis.Set(keyThree, "", time.Second)
  2473. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2474. theTime := toTime.Format("2006-01-02")
  2475. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2476. redis.Set(keyFour, "", time.Second)
  2477. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2478. redis.Set(keyFive, "", time.Second)
  2479. defer redis.Close()
  2480. }
  2481. }
  2482. go func() {
  2483. ssoDomain := beego.AppConfig.String("call_domain")
  2484. api := ssoDomain + "/index/downpatient"
  2485. values := make(url.Values)
  2486. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2487. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2488. values.Set("patient_id", strconv.FormatInt(id, 10))
  2489. http.PostForm(api, values)
  2490. }()
  2491. if err == nil {
  2492. c.ServeSuccessJSON(map[string]interface{}{
  2493. "dialysisOrder": dialysisOrder,
  2494. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2495. })
  2496. } else {
  2497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2498. }
  2499. }
  2500. }
  2501. func (c *DialysisAPIController) GetAllZone() {
  2502. adminUserInfo := c.GetMobileAdminUserInfo()
  2503. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2504. if err == nil {
  2505. c.ServeSuccessJSON(map[string]interface{}{
  2506. "zone": zone,
  2507. })
  2508. }
  2509. }
  2510. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2511. adminUserInfo := c.GetMobileAdminUserInfo()
  2512. page, _ := c.GetInt64("page", 1)
  2513. limit, _ := c.GetInt64("limit", 10)
  2514. schedulType, _ := c.GetInt64("schedul_type", 0)
  2515. startTime, _ := c.GetInt64("schedul_time", 0)
  2516. partitionType, _ := c.GetInt64("partition_type", 0)
  2517. keywords := c.GetString("keywords")
  2518. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2519. if err == nil {
  2520. c.ServeSuccessJSON(map[string]interface{}{
  2521. "schedule": dialysisSchedule,
  2522. })
  2523. }
  2524. return
  2525. }
  2526. // /m/api/dialysis/start [post]
  2527. // @param patient_id:int
  2528. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2529. // @param nurse:int 上机护士
  2530. // @param bed:int 床位号
  2531. func (this *DialysisAPIController) StartDialysis() {
  2532. patientID, _ := this.GetInt64("patient_id")
  2533. recordDateStr := this.GetString("record_date")
  2534. nurseID, _ := this.GetInt64("start_nurse")
  2535. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2536. blood_drawing, _ := this.GetInt64("blood_drawing")
  2537. schedual_type, _ := this.GetInt64("schedual_type")
  2538. bedID, _ := this.GetInt64("bed")
  2539. start_time := this.GetString("start_time")
  2540. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2541. change_nurse, _ := this.GetInt64("change_nurse")
  2542. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2543. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2544. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2545. puncture_needle := this.GetString("puncture_needle")
  2546. puncture_way := this.GetString("puncture_way")
  2547. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2548. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2549. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  2550. zone_id, _ := this.GetInt64("zone_id")
  2551. elecsign := this.GetString("url")
  2552. nuclein_date_str := this.GetString("nuclein_date_str")
  2553. schedule_remark := this.GetString("schedule_remark")
  2554. order_remark := this.GetString("order_remark")
  2555. catheter_operation := this.GetString("catheter_operation")
  2556. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2557. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2558. return
  2559. }
  2560. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2561. if parseStartDateErr != nil {
  2562. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2563. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2564. return
  2565. }
  2566. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2567. if parseErr != nil {
  2568. this.ErrorLog("时间解析失败:%v", parseErr)
  2569. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2570. return
  2571. }
  2572. adminUserInfo := this.GetMobileAdminUserInfo()
  2573. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2574. if getPatientErr != nil {
  2575. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2576. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2577. return
  2578. } else if patient == nil {
  2579. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2580. return
  2581. }
  2582. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2583. if getNurseErr != nil {
  2584. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2585. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2586. return
  2587. } else if nurse == nil {
  2588. this.ErrorLog("护士不存在")
  2589. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2590. return
  2591. }
  2592. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2593. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2594. if getDeviceNumberErr != nil {
  2595. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2596. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2597. return
  2598. } else if deviceNumber == nil {
  2599. this.ErrorLog("床位号不存在")
  2600. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2601. return
  2602. }
  2603. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2604. if getRecordErr != nil {
  2605. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2606. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2607. return
  2608. } else if dialysisRecord != nil {
  2609. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2610. return
  2611. }
  2612. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2613. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2614. timeLayout := "2006-01-02 15:04:05"
  2615. loc, _ := time.LoadLocation("Local")
  2616. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2617. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2618. schedulestartTime := theStartTime.Unix()
  2619. scheduleendTime := theEndTime.Unix()
  2620. var theNucleinDate int64
  2621. timeLayoutOne := "2006-01-02"
  2622. if len(nuclein_date_str) > 0 {
  2623. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2624. if err != nil {
  2625. utils.ErrorLog(err.Error())
  2626. }
  2627. theNucleinDate = theTime.Unix()
  2628. }
  2629. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2630. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2631. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  2632. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2633. //查询该床位是否有人用了
  2634. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2635. if err == gorm.ErrRecordNotFound { //空床位
  2636. // 修改了床位逻辑
  2637. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2638. if daySchedule.ID > 0 {
  2639. daySchedule.PartitionId = deviceNumber.ZoneID
  2640. daySchedule.BedId = bedID
  2641. daySchedule.ScheduleType = schedual_type
  2642. daySchedule.UpdatedTime = time.Now().Unix()
  2643. xtSchedule := models.Schedule{
  2644. PartitionId: deviceNumber.ZoneID,
  2645. BedId: bedID,
  2646. ScheduleType: schedual_type,
  2647. UpdatedTime: time.Now().Unix(),
  2648. }
  2649. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2650. if err != nil {
  2651. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2652. return
  2653. }
  2654. }
  2655. } else if err == nil {
  2656. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2657. if order.ID > 0 { //该机位被其他人占用了
  2658. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2659. return
  2660. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  2661. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2662. if daySchedule.ID > 0 {
  2663. err := service.UpdateScheduleTwo(daySchedule, schedule)
  2664. if err != nil {
  2665. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2666. return
  2667. }
  2668. }
  2669. }
  2670. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2671. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2672. return
  2673. }
  2674. //else if order.ID == 0 { //该床位没被占用
  2675. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2676. // if daySchedule.ID > 0 {
  2677. // //daySchedule.PartitionId = deviceNumber.ZoneID
  2678. // //daySchedule.BedId = bedID
  2679. // //daySchedule.ScheduleType = schedual_type
  2680. // //daySchedule.UpdatedTime = time.Now().Unix()
  2681. // //err := service.UpdateSchedule(&daySchedule)
  2682. // xtSchedule := models.Schedule{
  2683. // PartitionId: deviceNumber.ZoneID,
  2684. // BedId: bedID,
  2685. // ScheduleType: schedual_type,
  2686. // UpdatedTime: time.Now().Unix(),
  2687. // }
  2688. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2689. // if err != nil {
  2690. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2691. // return
  2692. // }
  2693. // }
  2694. //}
  2695. //}
  2696. } else if err != nil {
  2697. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2698. return
  2699. }
  2700. // 查询信息规挡的设置天数
  2701. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2702. if infor.ID > 0 && infor.WeekDay > 0 {
  2703. var cha_time int64
  2704. timeNowStr := time.Now().Format("2006-01-02")
  2705. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2706. //今日的日期减去设置的日期
  2707. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2708. if cha_time >= recordDate.Unix() {
  2709. //查询审核是否允许
  2710. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id)
  2711. //申请状态不允许的情况 拒绝修改
  2712. if infor.ApplicationStatus != 1 {
  2713. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2714. return
  2715. }
  2716. }
  2717. }
  2718. dialysisRecord = &models.DialysisOrder{
  2719. DialysisDate: recordDate.Unix(),
  2720. UserOrgId: adminUserInfo.Org.Id,
  2721. PatientId: patientID,
  2722. Stage: 1,
  2723. BedID: bedID,
  2724. StartNurse: nurseID,
  2725. Status: 1,
  2726. StartTime: startDate.Unix(),
  2727. CreatedTime: time.Now().Unix(),
  2728. UpdatedTime: time.Now().Unix(),
  2729. PunctureNurse: puncture_nurse,
  2730. Creator: adminUserInfo.AdminUser.Id,
  2731. Modifier: adminUserInfo.AdminUser.Id,
  2732. SchedualType: schedual_type,
  2733. WashpipeNurse: washpipe_nurse,
  2734. ChangeNurse: change_nurse,
  2735. DifficultPunctureNurse: difficult_puncture_nurse,
  2736. NewFistulaNurse: new_fistula_nurse,
  2737. ZoneId: zone_id,
  2738. QualityNurseId: quality_nurse_id,
  2739. PunctureNeedle: puncture_needle,
  2740. PunctureWay: puncture_way,
  2741. DialysisIrrigation: dialysis_irrigation,
  2742. DialysisDialyszers: dialysis_dialyszers,
  2743. BloodAccessId: blood_access_id,
  2744. Url: elecsign,
  2745. NucleinDate: theNucleinDate,
  2746. ScheduleRemark: schedule_remark,
  2747. OrderRemark: order_remark,
  2748. CatheterOperation: catheter_operation,
  2749. }
  2750. //查询该床位是否有人用了
  2751. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2752. if errorscode == gorm.ErrRecordNotFound {
  2753. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  2754. finish := models.XtDialysisFinish{
  2755. IsFinish: 1,
  2756. UserOrgId: adminUserInfo.Org.Id,
  2757. Status: 1,
  2758. Ctime: time.Now().Unix(),
  2759. Mtime: 0,
  2760. Module: 6,
  2761. RecordDate: schedulestartTime,
  2762. Sourse: 1,
  2763. PatientId: patientID,
  2764. }
  2765. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  2766. if dialysisFinish.ID == 0 {
  2767. service.CreateDialysisFinish(finish)
  2768. }
  2769. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  2770. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  2771. //统计该患者总次数
  2772. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  2773. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2774. }
  2775. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  2776. //统计该患者总次数
  2777. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  2778. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2779. }
  2780. redis := service.RedisClient()
  2781. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2782. redis.Set(key, "", time.Second)
  2783. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2784. //清空key 值
  2785. redis.Set(keyOne, "", time.Second)
  2786. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2787. //清空key 值
  2788. redis.Set(keyTwo, "", time.Second)
  2789. if createErr != nil {
  2790. this.ErrorLog("上机失败:%v", createErr)
  2791. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2792. return
  2793. }
  2794. }
  2795. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2796. var tempdispose string
  2797. // 只针对中能建
  2798. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  2799. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2800. }
  2801. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  2802. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2803. }
  2804. var ultrafiltration_rate float64
  2805. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2806. //后期预增脱水量
  2807. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2808. if prescription.ID > 0 {
  2809. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2810. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2811. if (template.TemplateId == 6 || template.TemplateId == 32 || template.TemplateId == 65 || adminUserInfo.Org.Id == 10375) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  2812. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2813. }
  2814. //针对医师汇
  2815. if adminUserInfo.Org.Id == 10121 {
  2816. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  2817. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  2818. }
  2819. //针对通道
  2820. if adminUserInfo.Org.Id == 10234 {
  2821. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  2822. }
  2823. //针对监利大垸医院
  2824. if template.TemplateId == 41 {
  2825. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  2826. }
  2827. //针对肇庆三鹤血液透析中心
  2828. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  2829. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2830. }
  2831. if adminUserInfo.Org.Id == 10469 {
  2832. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  2833. }
  2834. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  2835. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2836. }
  2837. // 只针对方济医院
  2838. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  2839. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2840. ultrafiltration_rate = value
  2841. }
  2842. //针对
  2843. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  2844. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2845. ultrafiltration_rate = ultrafiltration_rate / 1000
  2846. }
  2847. }
  2848. }
  2849. record := models.MonitoringRecord{
  2850. UserOrgId: adminUserInfo.Org.Id,
  2851. PatientId: patientID,
  2852. DialysisOrderId: dialysisRecord.ID,
  2853. MonitoringDate: schedulestartTime,
  2854. OperateTime: startDate.Unix(),
  2855. // MonitoringTime: recordTime,
  2856. MonitoringNurse: nurseID,
  2857. Dispose: tempdispose,
  2858. UltrafiltrationRate: ultrafiltration_rate,
  2859. UltrafiltrationVolume: 0,
  2860. Status: 1,
  2861. CreatedTime: time.Now().Unix(),
  2862. UpdatedTime: time.Now().Unix(),
  2863. }
  2864. //只针对广慈医院
  2865. if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.Org.Id == 9987 || adminUserInfo.Org.Id == 9526 || template.TemplateId == 32 || adminUserInfo.Org.Id == 9918 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 4 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10517 {
  2866. // 查询病人是否有透前评估数据
  2867. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2868. //如果有数据就插入
  2869. if errcode == nil {
  2870. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2871. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2872. record.BreathingRate = befor.BreathingRate
  2873. record.PulseFrequency = befor.PulseFrequency
  2874. record.Temperature = befor.Temperature
  2875. }
  2876. }
  2877. // 如果当天有插入数据,则不再往透析纪录里插入数据
  2878. if newdialysisRecord.ID > 0 {
  2879. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  2880. record.Temperature = 36.5
  2881. record.ArterialPressure = -100
  2882. record.DialysateTemperature = 36.5
  2883. record.Conductivity = 14
  2884. record.BreathingRate = "20"
  2885. record.VenousPressure = 80
  2886. record.TransmembranePressure = 60
  2887. record.Dispose = catheter_operation
  2888. }
  2889. //针对新化博翔
  2890. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  2891. record.BloodOxygenSaturation = "99"
  2892. record.Conductivity = 14
  2893. record.DialysateTemperature = 36.5
  2894. record.BreathingRate = "20"
  2895. }
  2896. //针对兰溪人民医院的需求
  2897. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 {
  2898. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2899. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2900. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2901. record.Temperature = befor.Temperature
  2902. record.PulseFrequency = befor.PulseFrequency
  2903. record.BreathingRate = befor.BreathingRate
  2904. }
  2905. //新化博翔
  2906. if adminUserInfo.Org.Id == 10447 {
  2907. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2908. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2909. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2910. record.BreathingRate = befor.BreathingRate
  2911. }
  2912. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  2913. record.PulseFrequency = 80
  2914. record.Temperature = 36.5
  2915. }
  2916. //诊断灵山圣康
  2917. if adminUserInfo.Org.Id == 10375 {
  2918. record.Conductivity = 13.8
  2919. record.DialysateTemperature = 37
  2920. record.DialysateFlow = 500
  2921. record.BloodFlowVolume = 200
  2922. record.BreathingRate = "18"
  2923. record.SodiumConcentration = 140
  2924. }
  2925. err := service.CreateMonitor(&record)
  2926. finish := models.XtDialysisFinish{
  2927. IsFinish: 1,
  2928. UserOrgId: adminUserInfo.Org.Id,
  2929. Status: 1,
  2930. Ctime: time.Now().Unix(),
  2931. Mtime: 0,
  2932. Module: 7,
  2933. RecordDate: schedulestartTime,
  2934. Sourse: 1,
  2935. PatientId: patientID,
  2936. }
  2937. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  2938. if dialysisFinish.ID == 0 {
  2939. service.CreateDialysisFinish(finish)
  2940. }
  2941. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  2942. redis := service.RedisClient()
  2943. //清空key 值
  2944. redis.Set(key, "", time.Second)
  2945. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  2946. redis.Set(keyOne, "", time.Second)
  2947. defer redis.Close()
  2948. if err != nil {
  2949. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  2950. return
  2951. }
  2952. }
  2953. go func() {
  2954. ssoDomain := beego.AppConfig.String("call_domain")
  2955. api := ssoDomain + "/index/uppatient"
  2956. values := make(url.Values)
  2957. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  2958. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2959. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  2960. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  2961. http.PostForm(api, values)
  2962. }()
  2963. this.ServeSuccessJSON(map[string]interface{}{
  2964. "dialysis_order": newdialysisRecord,
  2965. "monitor": record,
  2966. })
  2967. return
  2968. }
  2969. func (c *DialysisAPIController) PostSolution() {
  2970. id, _ := c.GetInt64("patient", 0)
  2971. recordDateStr := c.GetString("record_date")
  2972. if id <= 0 {
  2973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2974. return
  2975. }
  2976. adminUserInfo := c.GetMobileAdminUserInfo()
  2977. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2978. if patient.ID == 0 {
  2979. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2980. return
  2981. }
  2982. if len(recordDateStr) == 0 {
  2983. recordDateStr = time.Now().Format("2006-01-02")
  2984. }
  2985. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2986. if parseDateErr != nil {
  2987. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2989. return
  2990. }
  2991. mode_id, _ := c.GetInt64("mode_id", 0)
  2992. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  2993. dialyzer, _ := c.GetInt64("dialyzer", 0)
  2994. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  2995. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  2996. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  2997. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  2998. replacement_way, _ := c.GetInt64("replacement_way", 0)
  2999. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3000. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3001. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3002. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3003. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3004. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3005. kalium, _ := c.GetFloat("kalium", 0)
  3006. sodium, _ := c.GetFloat("sodium", 0)
  3007. calcium, _ := c.GetFloat("calcium", 0)
  3008. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3009. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3010. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3011. glucose, _ := c.GetFloat("glucose", 0)
  3012. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3013. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3014. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3015. conductivity, _ := c.GetFloat("conductivity", 0)
  3016. remark := c.GetString("remark")
  3017. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3018. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3019. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3020. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3021. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3022. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3023. special_medicine_other := c.GetString("special_medicine_other")
  3024. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3025. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3026. blood_access, _ := c.GetInt64("blood_access", 0)
  3027. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3028. body_fluid_other := c.GetString("body_fluid_other")
  3029. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3030. niprocart, _ := c.GetInt64("niprocart", 0)
  3031. jms, _ := c.GetInt64("jms", 0)
  3032. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3033. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3034. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3035. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3036. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3037. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3038. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3039. injector, _ := c.GetInt64("injector", 0)
  3040. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3041. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3042. safe_package, _ := c.GetInt64("package", 0)
  3043. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3044. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3045. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3046. blood := c.GetString("blood")
  3047. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3048. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3049. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3050. displace_speed := c.GetString("displace_speed")
  3051. illness, _ := c.GetInt64("illness")
  3052. amylaceum := c.GetString("amylaceum")
  3053. single_time := c.GetString("single_time")
  3054. single_water := c.GetString("single_water")
  3055. replacement_flow := c.GetString("replacement_flow")
  3056. plasma_separator := c.GetString("plasma_separator")
  3057. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3058. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3059. oxygen_flow := c.GetString("oxygen_flow")
  3060. oxygen_time := c.GetString("oxygen_time")
  3061. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3062. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3063. puncture_needle := c.GetString("puncture_needle")
  3064. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3065. epo := c.GetString("epo")
  3066. epo_count, _ := c.GetFloat("epo_count", 0)
  3067. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3068. pre_impulse := c.GetString("pre_impulse")
  3069. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3070. admin_user_id, _ := c.GetInt64("admin_user_id")
  3071. is_water := c.GetString("is_water")
  3072. add_amount, _ := c.GetFloat("add_amount")
  3073. reduce_amount, _ := c.GetFloat("reduce_amount")
  3074. prescribing_number, _ := c.GetFloat("prescribing_number")
  3075. treatment_remark := c.GetString("treatment_remark")
  3076. prescription_sodium := c.GetString("prescription_sodium")
  3077. start_sodium := c.GetString("start_sodium")
  3078. sodium_curve := c.GetString("sodium_curve")
  3079. var is_war int64
  3080. if is_water == "是" {
  3081. is_war = 1
  3082. }
  3083. if is_water == "否" {
  3084. is_war = 2
  3085. }
  3086. if is_water == "请选择" {
  3087. is_war = 0
  3088. }
  3089. drhy_water := c.GetString("drhy_water")
  3090. dry_water_hour := c.GetString("dry_water_hour")
  3091. water_machine := c.GetString("water_machine")
  3092. dialysis_remark := c.GetString("dialysis_remark")
  3093. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3094. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3095. prescription_water, _ := c.GetFloat("prescription_water")
  3096. dialysis_strainer := c.GetString("dialysis_strainer")
  3097. chaptalization := c.GetString("chaptalization")
  3098. if mode_id > 0 {
  3099. var str string
  3100. //查找该机构用的是什么透析器
  3101. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3102. if filedConfig.ID > 0 {
  3103. str = dialyzerPerfusionApparatus
  3104. } else {
  3105. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3106. }
  3107. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3108. }
  3109. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3110. //
  3111. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3112. // if appRole.UserType == 3 {
  3113. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3114. // if getPermissionErr != nil {
  3115. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3116. // return
  3117. // } else if headNursePermission == nil {
  3118. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3119. // return
  3120. // }
  3121. // }
  3122. //}
  3123. // 查询信息规挡的设置天数
  3124. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3125. if infor.ID > 0 && infor.WeekDay > 0 {
  3126. var cha_time int64
  3127. timeNowStr := time.Now().Format("2006-01-02")
  3128. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3129. //今日的日期减去设置的日期
  3130. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3131. if cha_time >= recordDate.Unix() {
  3132. //查询审核是否允许
  3133. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3134. //申请状态不允许的情况 拒绝修改
  3135. if infor.ApplicationStatus != 1 {
  3136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3137. return
  3138. }
  3139. }
  3140. }
  3141. prescription := models.DialysisPrescription{
  3142. UserOrgId: adminUserInfo.Org.Id,
  3143. PatientId: id,
  3144. RecordDate: recordDate.Unix(),
  3145. ModeId: mode_id,
  3146. DialysisDuration: dialysis_duration,
  3147. Dialyzer: dialyzer,
  3148. PerfusionApparatus: perfusion_apparatus,
  3149. BloodFlowVolume: blood_flow_volume,
  3150. DewaterAmount: dewater_amount,
  3151. DisplaceLiqui: displace_liqui,
  3152. ReplacementWay: replacement_way,
  3153. Anticoagulant: anticoagulant,
  3154. AnticoagulantShouji: anticoagulant_shouji,
  3155. AnticoagulantWeichi: anticoagulant_weichi,
  3156. AnticoagulantZongliang: anticoagulant_zongliang,
  3157. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3158. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3159. Kalium: kalium,
  3160. Sodium: sodium,
  3161. Calcium: calcium,
  3162. Bicarbonate: bicarbonate,
  3163. Glucose: glucose,
  3164. // DryWeight: dry_weight,
  3165. DialysateFlow: dialysate_flow,
  3166. DialysateTemperature: dialysate_temperature,
  3167. Conductivity: conductivity,
  3168. Remark: remark,
  3169. Status: 1,
  3170. CreatedTime: time.Now().Unix(),
  3171. UpdatedTime: time.Now().Unix(),
  3172. DialysisDurationMinute: dialysisDurationMinute,
  3173. DialysisDurationHour: dialysisDurationHour,
  3174. TargetUltrafiltration: targetUltrafiltration,
  3175. DialysateFormulation: dialysateFormulation,
  3176. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3177. BodyFluid: body_fluid,
  3178. SpecialMedicine: special_medicine,
  3179. SpecialMedicineOther: special_medicine_other,
  3180. DisplaceLiquiPart: displace_liqui_part,
  3181. DisplaceLiquiValue: displace_liqui_value,
  3182. BloodAccess: blood_access,
  3183. Ultrafiltration: ultrafiltration,
  3184. BodyFluidOther: body_fluid_other,
  3185. ReplacementTotal: replacement_total,
  3186. Niprocart: niprocart,
  3187. Jms: jms,
  3188. FistulaNeedleSet: fistula_needle_set,
  3189. FistulaNeedleSet16: fistula_needle_set_16,
  3190. Hemoperfusion: hemoperfusion,
  3191. DialyserSterilised: dialyser_sterilised,
  3192. Filtryzer: filtryzer,
  3193. TargetKtv: target_ktv,
  3194. Dialyzers: dialyzers,
  3195. Injector: injector,
  3196. Bloodlines: bloodlines,
  3197. TubingHemodialysis: tubing_hemodialysis,
  3198. Package: safe_package,
  3199. ALiquid: a_liquid,
  3200. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3201. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3202. Blood: blood,
  3203. DialysisDialyszers: dialysis_dialyszers,
  3204. DialysisIrrigation: dialysis_irrigation,
  3205. AntioxidantCommodityName: antioxidant_commodity_name,
  3206. DisplaceSpeed: displace_speed,
  3207. Illness: illness,
  3208. Amylaceum: amylaceum,
  3209. SingleWater: single_water,
  3210. SingleTime: single_time,
  3211. ReplacementFlow: replacement_flow,
  3212. PlasmaSeparator: plasma_separator,
  3213. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3214. OxygenUptake: oxygen_uptake,
  3215. OxygenTime: oxygen_time,
  3216. OxygenFlow: oxygen_flow,
  3217. HemodialysisPipelines: hemodialysis_pipelines,
  3218. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3219. PunctureNeedle: puncture_needle,
  3220. PunctureNeedleCount: puncture_needle_count,
  3221. Epo: epo,
  3222. EpoCount: epo_count,
  3223. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3224. PreImpulse: impulse,
  3225. AdminUserId: admin_user_id,
  3226. IsWater: is_war,
  3227. DrhyWater: drhy_water,
  3228. DryWaterHour: dry_water_hour,
  3229. WaterMachine: water_machine,
  3230. AddAmount: add_amount,
  3231. ReduceAmount: reduce_amount,
  3232. DialysisRemark: dialysis_remark,
  3233. PrescribingNumber: prescribing_number,
  3234. PrescriptionSodium: prescription_sodium,
  3235. StartSodium: start_sodium,
  3236. SodiumCurve: sodium_curve,
  3237. TreatmentRemark: treatment_remark,
  3238. DialysisFluidFlow: dialysis_fluid_flow,
  3239. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3240. PrescriptionWater: prescription_water,
  3241. DialysisStrainer: dialysis_strainer,
  3242. Chaptalization: chaptalization,
  3243. }
  3244. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3245. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3246. fmt.Println("appRole0000000000000", appRole.UserType)
  3247. //
  3248. if appRole.UserType == 2 || appRole.UserType == 1 {
  3249. prescription_doctor = adminUserInfo.AdminUser.Id
  3250. prescription.PrescriptionDoctor = prescription_doctor
  3251. }
  3252. if dialysisPrescription.ID == 0 { //新增
  3253. prescription.Creater = adminUserInfo.AdminUser.Id
  3254. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3255. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3256. }
  3257. } else { //修改
  3258. if dialysisPrescription.Creater == 0 {
  3259. prescription.Creater = adminUserInfo.AdminUser.Id
  3260. } else {
  3261. prescription.Creater = dialysisPrescription.Creater
  3262. if adminUserInfo.Org.Id == 9882 {
  3263. if appRole.UserType == 2 || appRole.UserType == 1 {
  3264. prescription.Creater = adminUserInfo.AdminUser.Id
  3265. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3266. }
  3267. }
  3268. }
  3269. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3270. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3271. }
  3272. //if/**/
  3273. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3274. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3275. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3276. // if getPermissionErr != nil {
  3277. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3278. // return
  3279. // } else if headNursePermission == nil {
  3280. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3281. // return
  3282. // }
  3283. //}
  3284. //prescription.Creater = dialysisPrescription.Creater
  3285. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3286. prescription.Modifier = adminUserInfo.AdminUser.Id
  3287. prescription.ID = dialysisPrescription.ID
  3288. }
  3289. solution := models.DialysisSolution{
  3290. RegistrarsId: adminUserInfo.AdminUser.Id,
  3291. UserOrgId: adminUserInfo.Org.Id,
  3292. Doctor: prescription_doctor,
  3293. PatientId: id,
  3294. ModeId: mode_id,
  3295. DialysisDuration: dialysis_duration,
  3296. PerfusionApparatus: perfusion_apparatus,
  3297. BloodFlowVolume: blood_flow_volume,
  3298. Dewater: dewater_amount,
  3299. DisplaceLiqui: displace_liqui,
  3300. ReplacementWay: replacement_way,
  3301. Anticoagulant: anticoagulant,
  3302. AnticoagulantShouji: anticoagulant_shouji,
  3303. AnticoagulantWeichi: anticoagulant_weichi,
  3304. AnticoagulantZongliang: anticoagulant_zongliang,
  3305. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3306. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3307. Kalium: kalium,
  3308. Sodium: sodium,
  3309. Calcium: calcium,
  3310. Bicarbonate: bicarbonate,
  3311. Glucose: glucose,
  3312. // DryWeight: dry_weight,
  3313. DialysateFlow: dialysate_flow,
  3314. DialysateTemperature: dialysate_temperature,
  3315. Conductivity: conductivity,
  3316. Remark: remark,
  3317. Status: 1,
  3318. CreatedTime: time.Now().Unix(),
  3319. UpdatedTime: time.Now().Unix(),
  3320. DialysisDurationMinute: dialysisDurationMinute,
  3321. DialysisDurationHour: dialysisDurationHour,
  3322. TargetUltrafiltration: targetUltrafiltration,
  3323. DialysateFormulation: dialysateFormulation,
  3324. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3325. BodyFluid: body_fluid,
  3326. SpecialMedicine: special_medicine,
  3327. SpecialMedicineOther: special_medicine_other,
  3328. DisplaceLiquiPart: displace_liqui_part,
  3329. DisplaceLiquiValue: displace_liqui_value,
  3330. BloodAccess: blood_access,
  3331. Ultrafiltration: ultrafiltration,
  3332. BodyFluidOther: body_fluid_other,
  3333. ReplacementTotal: replacement_total,
  3334. TargetKtv: target_ktv,
  3335. DialysisDialyszers: dialysis_dialyszers,
  3336. DialysisIrrigation: dialysis_irrigation,
  3337. HemodialysisPipelines: hemodialysis_pipelines,
  3338. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3339. PunctureNeedle: puncture_needle,
  3340. PunctureNeedleCount: puncture_needle_count,
  3341. Epo: epo,
  3342. EpoCount: epo_count,
  3343. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3344. PreImpulse: impulse,
  3345. SolutionStatus: 1,
  3346. DialysisRemark: dialysis_remark,
  3347. PrescribingNumber: prescribing_number,
  3348. PrescriptionSodium: prescription_sodium,
  3349. StartSodium: start_sodium,
  3350. SodiumCurve: sodium_curve,
  3351. TreatmentRemark: treatment_remark,
  3352. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3353. DialysisFluidFlow: dialysis_fluid_flow,
  3354. PrescriptionWater: prescription_water,
  3355. DialysisStrainer: dialysis_strainer,
  3356. Chaptalization: chaptalization,
  3357. }
  3358. //针对河间咸的
  3359. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  3360. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  3361. solution.DisplaceLiquiPart = 0
  3362. solution.DisplaceLiquiValue = 0
  3363. }
  3364. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  3365. prescription.DisplaceLiquiPart = 0
  3366. prescription.DisplaceLiquiValue = 0
  3367. }
  3368. }
  3369. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  3370. if solution.PrescribingNumber == 0 {
  3371. solution.PrescribingNumber = 1
  3372. }
  3373. if prescription.PrescribingNumber == 0 {
  3374. prescription.PrescribingNumber = 1
  3375. }
  3376. if solution.PrescribingNumber == 0 && id == 14682 {
  3377. solution.PrescribingNumber = 2
  3378. }
  3379. if solution.PrescribingNumber == 0 && id == 18560 {
  3380. solution.PrescribingNumber = 2
  3381. }
  3382. if prescription.PrescribingNumber == 0 && id == 14682 {
  3383. prescription.PrescribingNumber = 2
  3384. }
  3385. if prescription.PrescribingNumber == 0 && id == 18560 {
  3386. prescription.PrescribingNumber = 2
  3387. }
  3388. }
  3389. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  3390. finish := models.XtDialysisFinish{
  3391. IsFinish: 1,
  3392. UserOrgId: adminUserInfo.Org.Id,
  3393. Status: 1,
  3394. Ctime: time.Now().Unix(),
  3395. Mtime: 0,
  3396. Module: 1,
  3397. RecordDate: recordDate.Unix(),
  3398. Sourse: 1,
  3399. PatientId: id,
  3400. }
  3401. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  3402. if dialysisFinish.ID == 0 {
  3403. service.CreateDialysisFinish(finish)
  3404. }
  3405. //获取最新1条
  3406. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  3407. //更新状态
  3408. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  3409. //长沙南雅医院,自动生成抗凝剂的临时处方
  3410. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  3411. if prescribing_number == 0 {
  3412. prescribing_number = 1
  3413. }
  3414. advice := models.DoctorAdvice{
  3415. UserOrgId: adminUserInfo.Org.Id,
  3416. PatientId: id,
  3417. GroupNo: 0,
  3418. AdviceType: 2,
  3419. RecordDate: recordDate.Unix(),
  3420. AdviceDate: recordDate.Unix(),
  3421. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  3422. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  3423. AdviceDesc: "",
  3424. ReminderDate: 0,
  3425. SingleDose: prescription.AnticoagulantZongliang,
  3426. SingleDoseUnit: "iu",
  3427. DrugSpec: 0,
  3428. DrugSpecUnit: "",
  3429. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  3430. PrescribingNumberUnit: "支",
  3431. DeliveryWay: "静脉注射",
  3432. ExecutionFrequency: "上机前",
  3433. AdviceDoctor: 0,
  3434. Status: 1,
  3435. CreatedTime: time.Now().Unix(),
  3436. UpdatedTime: time.Now().Unix(),
  3437. IsPrescription: 1,
  3438. ExecutionState: 2,
  3439. StopState: 2,
  3440. IsSettle: 2,
  3441. }
  3442. // 查询排班信息
  3443. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3444. if schedulePatient.ID > 0 {
  3445. if schedulePatient.ScheduleType == 1 {
  3446. advice.StartTime = recordDate.Unix() + 6.5*60*60
  3447. }
  3448. if schedulePatient.ScheduleType == 2 {
  3449. advice.StartTime = recordDate.Unix() + 10*60*60
  3450. }
  3451. }
  3452. // 抗凝剂名称
  3453. switch anticoagulant {
  3454. case 1:
  3455. advice.AdviceName = "无肝素"
  3456. break
  3457. case 2:
  3458. advice.AdviceName = "普通肝素"
  3459. break
  3460. case 3:
  3461. advice.AdviceName = "低分子肝素"
  3462. break
  3463. case 4:
  3464. advice.AdviceName = "阿加曲班"
  3465. break
  3466. case 5:
  3467. advice.AdviceName = "枸橼酸钠"
  3468. break
  3469. case 6:
  3470. advice.AdviceName = "低分子肝素钙"
  3471. break
  3472. case 7:
  3473. advice.AdviceName = "低分子肝素钠"
  3474. break
  3475. case 8:
  3476. advice.AdviceName = "依诺肝素"
  3477. break
  3478. case 9:
  3479. advice.AdviceName = "达肝素"
  3480. break
  3481. case 10:
  3482. advice.AdviceName = "体外抗凝"
  3483. break
  3484. case 11:
  3485. advice.AdviceName = "那曲肝素"
  3486. break
  3487. case 12:
  3488. advice.AdviceName = "无抗凝剂"
  3489. break
  3490. }
  3491. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  3492. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  3493. advice.AdviceDoctor = appRole.AdminUserId
  3494. }
  3495. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  3496. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  3497. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  3498. advice.AdviceName = "低分子肝素钠注射液"
  3499. // 修改患者临时医嘱里的抗凝剂医嘱
  3500. advice.ID = advicePrescription.ID
  3501. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  3502. } else {
  3503. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  3504. advice.AdviceName = "低分子肝素钠注射液"
  3505. service.CreateDoctorAdvice(&advice)
  3506. }
  3507. }
  3508. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  3509. redis := service.RedisClient()
  3510. defer redis.Close()
  3511. //清空key 值
  3512. redis.Set(key, "", time.Second)
  3513. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  3514. redis.Set(keyOne, "", time.Second)
  3515. }
  3516. //获取key,清空redis
  3517. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3518. redis := service.RedisClient()
  3519. defer redis.Close()
  3520. //清空key 值
  3521. redis.Set(key, "", time.Second)
  3522. //清空长期医嘱的key
  3523. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3524. redis.Set(soulution_key, "", time.Second)
  3525. //查询最近透析准备表里是否存在 透析器 灌流器
  3526. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3527. redis.Set(keyOne, "", time.Second)
  3528. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  3529. redis.Set(keyTwo, "", time.Second)
  3530. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3531. redis.Set(keyThree, "", time.Second)
  3532. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  3533. redis.Set(keyFour, "", time.Second)
  3534. //splitStr := strings.Split(dialysis_dialyszers, ",")
  3535. //
  3536. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  3537. //
  3538. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  3539. //if len(mation)>0{
  3540. // for _, item := range splitStr {
  3541. // for _,it := range mation{
  3542. // if(item == it.SpecificationName){
  3543. //
  3544. // //查询最近一次的透析器
  3545. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3546. //
  3547. // if errcode == gorm.ErrRecordNotFound{
  3548. // //插入数据
  3549. // prepare := models.DialysisBeforePrepare{
  3550. // UserOrgId: adminUserInfo.Org.Id,
  3551. // PatientId: id,
  3552. // RecordDate: recordDate.Unix(),
  3553. // GoodTypeId: it.GoodTypeId,
  3554. // GoodId: it.ID,
  3555. // Count: 1,
  3556. // Ctime: time.Now().Unix(),
  3557. // Creater: adminUserInfo.AdminUser.Id,
  3558. // Status:1,
  3559. //
  3560. // }
  3561. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3562. // fmt.Println("",errcode)
  3563. // }
  3564. // }
  3565. // }
  3566. //
  3567. // }
  3568. //
  3569. // for _, item := range splitIrrigation {
  3570. // for _,it := range mation{
  3571. // if(item == it.SpecificationName){
  3572. // //查询最近一次的透析器
  3573. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3574. // if errcode == gorm.ErrRecordNotFound{
  3575. // //插入数据
  3576. // prepare := models.DialysisBeforePrepare{
  3577. // UserOrgId: adminUserInfo.Org.Id,
  3578. // PatientId: id,
  3579. // RecordDate: recordDate.Unix(),
  3580. // GoodTypeId: it.GoodTypeId,
  3581. // GoodId: it.ID,
  3582. // Count: 1,
  3583. // Ctime: time.Now().Unix(),
  3584. // Creater: adminUserInfo.AdminUser.Id,
  3585. // Status:1,
  3586. //
  3587. // }
  3588. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3589. // fmt.Println(errcode)
  3590. // }
  3591. // }
  3592. // }
  3593. // }
  3594. //}
  3595. c.ServeSuccessJSON(map[string]interface{}{
  3596. "solution": &solution,
  3597. "prescription": &prescription,
  3598. })
  3599. }
  3600. func (c *DialysisAPIController) GetAcceptsAssessment() {
  3601. patient, _ := c.GetInt64("patient", 0)
  3602. adminUserInfo := c.GetMobileAdminUserInfo()
  3603. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  3604. c.ServeSuccessJSON(map[string]interface{}{
  3605. "receiveTreatmentAsses": receiveTreatmentAsses,
  3606. })
  3607. }
  3608. func (this *DialysisAPIController) PostSignInfo() {
  3609. patientID, _ := this.GetInt64("patient_id")
  3610. recordDateStr := this.GetString("date")
  3611. if patientID <= 0 {
  3612. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3613. return
  3614. }
  3615. if len(recordDateStr) == 0 {
  3616. recordDateStr = time.Now().Format("2006-01-02")
  3617. }
  3618. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3619. if parseDateErr != nil {
  3620. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3621. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3622. return
  3623. }
  3624. adminInfo := this.GetMobileAdminUserInfo()
  3625. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  3626. if err != nil {
  3627. this.ErrorLog("签名失败:%v", err)
  3628. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3629. return
  3630. }
  3631. this.ServeSuccessJSON(map[string]interface{}{
  3632. "doctor_id": adminInfo.AdminUser.Id,
  3633. })
  3634. }
  3635. func (this *DialysisAPIController) GetLastMonitorRecord() {
  3636. patientID, _ := this.GetInt64("patient_id")
  3637. adminInfo := this.GetMobileAdminUserInfo()
  3638. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  3639. this.ServeSuccessJSON(map[string]interface{}{
  3640. "monitor": record,
  3641. })
  3642. }
  3643. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  3644. thisTime := time.Now()
  3645. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  3646. timeLayout := "2006-01-02 15:04:05"
  3647. loc, _ := time.LoadLocation("Local")
  3648. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3649. theAssessmentDateTime := theStartTime.Unix()
  3650. patientID, _ := this.GetInt64("patient_id")
  3651. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  3652. adminInfo := this.GetMobileAdminUserInfo()
  3653. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3654. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3655. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  3656. var ultrafiltration_rate float64
  3657. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3658. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3659. fmt.Println(evaluation)
  3660. fmt.Println("prescription.ID", prescription.ID)
  3661. if prescription.ID > 0 {
  3662. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3663. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3664. fmt.Println("hahhdahahah", template.TemplateId)
  3665. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375) && adminInfo.Org.Id != 9538 {
  3666. fmt.Println("hahhdahahah")
  3667. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3668. record.UltrafiltrationRate = ultrafiltration_rate
  3669. }
  3670. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  3671. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  3672. record.UltrafiltrationRate = ultrafiltration_rate
  3673. }
  3674. if template.TemplateId == 20 || template.TemplateId == 22 {
  3675. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3676. record.UltrafiltrationRate = ultrafiltration_rate
  3677. }
  3678. // 只针对方济医院
  3679. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  3680. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3681. ultrafiltration_rate = value
  3682. record.UltrafiltrationRate = ultrafiltration_rate
  3683. }
  3684. if template.TemplateId == 41 || template.TemplateId == 47 {
  3685. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3686. record.UltrafiltrationRate = ultrafiltration_rate
  3687. }
  3688. if template.TemplateId == 43 {
  3689. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3690. record.UltrafiltrationRate = ultrafiltration_rate
  3691. }
  3692. if template.TemplateId == 46 || template.TemplateId == 54 {
  3693. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3694. record.UltrafiltrationRate = ultrafiltration_rate
  3695. }
  3696. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 9829 || adminInfo.Org.Id == 10440 {
  3697. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  3698. record.UltrafiltrationRate = ultrafiltration_rate
  3699. }
  3700. if adminInfo.Org.Id == 10469 {
  3701. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  3702. record.UltrafiltrationRate = ultrafiltration_rate
  3703. }
  3704. if adminInfo.Org.Id == 10471 {
  3705. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3706. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3707. }
  3708. if adminInfo.Org.Id == 10460 {
  3709. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3710. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3711. }
  3712. //if template.TemplateId == 47 {
  3713. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3714. // record.UltrafiltrationRate = ultrafiltration_rate
  3715. //}
  3716. }
  3717. }
  3718. // record.UltrafiltrationRate = ultrafiltration_rate
  3719. record.UltrafiltrationVolume = 0
  3720. 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
  3721. if ultrafiltration_rate > 0 {
  3722. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  3723. record.UltrafiltrationVolume = value
  3724. }
  3725. }
  3726. if template.TemplateId == 6 || template.TemplateId == 65 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 || template.TemplateId == 41 || template.TemplateId == 43 || template.TemplateId == 47 || template.TemplateId == 54 { //adminInfo.Org.Id == 9538
  3727. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  3728. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3729. record.UltrafiltrationVolume = ultrafiltration_volume
  3730. }
  3731. }
  3732. //长沙南雅
  3733. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 10469 || adminInfo.Org.Id == 10375 {
  3734. if ultrafiltration_rate > 0 {
  3735. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3736. record.UltrafiltrationVolume = ultrafiltration_volume
  3737. }
  3738. }
  3739. if adminInfo.Org.Id == 10471 {
  3740. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3741. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3742. }
  3743. if adminInfo.Org.Id == 10460 {
  3744. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3745. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3746. }
  3747. //长沙南雅累计血容量自动计算
  3748. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  3749. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  3750. //}
  3751. if template.TemplateId == 47 || template.TemplateId == 54 {
  3752. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  3753. }
  3754. this.ServeSuccessJSON(map[string]interface{}{
  3755. "monitor": record,
  3756. })
  3757. }
  3758. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  3759. record_id, _ := this.GetInt64("id")
  3760. nurseID, _ := this.GetInt64("start_nurse")
  3761. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3762. bedID, _ := this.GetInt64("bed")
  3763. start_time := this.GetString("start_time")
  3764. schedual_type, _ := this.GetInt64("schedual_type")
  3765. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3766. change_nurse, _ := this.GetInt64("change_nurse")
  3767. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3768. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3769. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3770. fmt.Println("quality_nurse_id", quality_nurse_id)
  3771. patient_id, _ := this.GetInt64("patient_id")
  3772. record_date, _ := this.GetInt64("record_date")
  3773. puncture_needle := this.GetString("puncture_needle")
  3774. puncture_way := this.GetString("puncture_way")
  3775. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3776. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3777. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3778. nuclein_date_str := this.GetString("nuclein_date_str")
  3779. order_remark := this.GetString("order_remark")
  3780. schedule_remark := this.GetString("schedule_remark")
  3781. catheter_operation := this.GetString("catheter_operation")
  3782. if record_id == 0 {
  3783. this.ErrorLog("id:%v", record_id)
  3784. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3785. return
  3786. }
  3787. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3788. if parseStartDateErr != nil {
  3789. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3790. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3791. return
  3792. }
  3793. adminUserInfo := this.GetMobileAdminUserInfo()
  3794. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3795. if getNurseErr != nil {
  3796. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3797. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3798. return
  3799. } else if nurse == nil {
  3800. this.ErrorLog("护士不存在")
  3801. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3802. return
  3803. }
  3804. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3805. //if getNurseErr != nil {
  3806. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  3807. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3808. // return
  3809. //} else if nurse == nil {
  3810. // this.ErrorLog("护士不存在")
  3811. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3812. // return
  3813. //}
  3814. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3815. if getDeviceNumberErr != nil {
  3816. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3817. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3818. return
  3819. } else if deviceNumber == nil {
  3820. this.ErrorLog("床位号不存在")
  3821. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3822. return
  3823. }
  3824. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  3825. //
  3826. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  3827. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3828. // if getPermissionErr != nil {
  3829. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3830. // return
  3831. // } else if headNursePermission == nil {
  3832. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3833. // return
  3834. // }
  3835. //}
  3836. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  3837. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  3838. timeLayout := "2006-01-02 15:04:05"
  3839. loc, _ := time.LoadLocation("Local")
  3840. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3841. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  3842. schedulestartTime := theStartTime.Unix()
  3843. scheduleendTime := theEndTime.Unix()
  3844. var theNucleinDate int64
  3845. timeLayoutOne := "2006-01-02"
  3846. if len(nuclein_date_str) > 0 {
  3847. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  3848. if err != nil {
  3849. utils.ErrorLog(err.Error())
  3850. }
  3851. theNucleinDate = theTime.Unix()
  3852. }
  3853. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  3854. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3855. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  3856. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  3857. if err == gorm.ErrRecordNotFound { //空床位
  3858. // 修改了床位逻辑
  3859. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  3860. if daySchedule.ID > 0 {
  3861. //daySchedule.BedId = bedID
  3862. //daySchedule.PartitionId = deviceNumber.ZoneID
  3863. //daySchedule.ScheduleType = schedual_type
  3864. //daySchedule.UpdatedTime = time.Now().Unix()
  3865. //err := service.UpdateSchedule(&daySchedule)
  3866. xtSchedule := models.Schedule{
  3867. PartitionId: deviceNumber.ZoneID,
  3868. BedId: bedID,
  3869. ScheduleType: schedual_type,
  3870. UpdatedTime: time.Now().Unix(),
  3871. }
  3872. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3873. if err != nil {
  3874. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3875. return
  3876. }
  3877. }
  3878. } else if err == nil {
  3879. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  3880. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  3881. if daySchedule.ID > 0 {
  3882. //daySchedule.BedId = bedID
  3883. //daySchedule.PartitionId = deviceNumber.ZoneID
  3884. //
  3885. //daySchedule.ScheduleType = schedual_type
  3886. //daySchedule.UpdatedTime = time.Now().Unix()
  3887. //err := service.UpdateSchedule(&daySchedule)
  3888. xtSchedule := models.Schedule{
  3889. PartitionId: deviceNumber.ZoneID,
  3890. BedId: bedID,
  3891. ScheduleType: schedual_type,
  3892. UpdatedTime: time.Now().Unix(),
  3893. }
  3894. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3895. if err != nil {
  3896. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3897. return
  3898. }
  3899. }
  3900. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  3901. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3902. return
  3903. }
  3904. } else if err != nil {
  3905. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3906. return
  3907. }
  3908. }
  3909. dialysisRecord := &models.DialysisOrder{
  3910. ID: record_id,
  3911. UserOrgId: adminUserInfo.Org.Id,
  3912. BedID: bedID,
  3913. StartNurse: nurseID,
  3914. StartTime: startDate.Unix(),
  3915. PunctureNurse: puncture_nurse,
  3916. Creator: adminUserInfo.AdminUser.Id,
  3917. Modifier: adminUserInfo.AdminUser.Id,
  3918. WashpipeNurse: washpipe_nurse,
  3919. SchedualType: schedual_type,
  3920. ChangeNurse: change_nurse,
  3921. DifficultPunctureNurse: difficult_puncture_nurse,
  3922. NewFistulaNurse: new_fistula_nurse,
  3923. QualityNurseId: quality_nurse_id,
  3924. PunctureNeedle: puncture_needle,
  3925. PunctureWay: puncture_way,
  3926. DialysisDialyszers: dialysis_dialyszers,
  3927. DialysisIrrigation: dialysis_irrigation,
  3928. BloodAccessId: blood_access_id,
  3929. NucleinDate: theNucleinDate,
  3930. OrderRemark: order_remark,
  3931. ScheduleRemark: schedule_remark,
  3932. CatheterOperation: catheter_operation,
  3933. }
  3934. //修改床位号需要重新消毒
  3935. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  3936. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  3937. //查询第一条监测
  3938. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  3939. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  3940. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  3941. redis := service.RedisClient()
  3942. //清空key 值
  3943. redis.Set(key, "", time.Second)
  3944. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  3945. redis.Set(keyOne, "", time.Second)
  3946. defer redis.Close()
  3947. }
  3948. // 查询信息规挡的设置天数
  3949. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3950. if infor.ID > 0 && infor.WeekDay > 0 {
  3951. var cha_time int64
  3952. timeNowStr := time.Now().Format("2006-01-02")
  3953. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3954. //今日的日期减去设置的日期
  3955. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3956. if cha_time >= record_date {
  3957. //查询审核是否允许
  3958. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id)
  3959. //申请状态不允许的情况 拒绝修改
  3960. if infor.ApplicationStatus != 1 {
  3961. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3962. return
  3963. }
  3964. }
  3965. }
  3966. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  3967. order, _ := service.GetLastPatientOrder(record_id)
  3968. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  3969. redis := service.RedisClient()
  3970. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  3971. redis.Set(key, "", time.Second)
  3972. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  3973. //清空key 值
  3974. redis.Set(keyOne, "", time.Second)
  3975. scheduleDateStartOne := startDate.Format("2006-01-02")
  3976. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3977. redis.Set(keyTwo, "", time.Second)
  3978. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  3979. redis.Set(keyThree, "", time.Second)
  3980. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  3981. redis.Set(keyFour, "", time.Second)
  3982. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  3983. redis.Set(keyFive, "", time.Second)
  3984. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  3985. redis.Set(keySix, "", time.Second)
  3986. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  3987. redis.Set(keySeven, "", time.Second)
  3988. if updateErr != nil {
  3989. this.ErrorLog("修改上机失败:%v", updateErr)
  3990. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3991. return
  3992. }
  3993. if updateErr == nil {
  3994. if tempDialysisRecord.Stage == 2 {
  3995. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  3996. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  3997. fmt.Println(value)
  3998. a, b := math.Modf(value)
  3999. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4000. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4001. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4002. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4003. redis := service.RedisClient()
  4004. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4005. redis.Set(key, "", time.Second)
  4006. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4007. redis.Set(keyOne, "", time.Second)
  4008. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4009. //清空key 值
  4010. redis.Set(keySix, "", time.Second)
  4011. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4012. redis.Set(keySeven, "", time.Second)
  4013. redis.Close()
  4014. if updateAssessmentErr != nil {
  4015. utils.ErrorLog("%v", updateAssessmentErr)
  4016. }
  4017. }
  4018. }
  4019. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4020. this.ServeSuccessJSON(map[string]interface{}{
  4021. "dialysis_order": dialysisRecords,
  4022. })
  4023. }
  4024. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4025. record_id, _ := c.GetInt64("id")
  4026. nurseID, _ := c.GetInt64("nurse")
  4027. end_time := c.GetString("end_time")
  4028. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4029. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4030. catheter := c.GetString("catheter")
  4031. cruor := c.GetString("cruor")
  4032. mission := c.GetString("mission")
  4033. if record_id <= 0 || nurseID <= 0 {
  4034. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4035. return
  4036. }
  4037. adminUserInfo := c.GetMobileAdminUserInfo()
  4038. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4039. if getNurseErr != nil {
  4040. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4041. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4042. return
  4043. } else if nurse == nil {
  4044. c.ErrorLog("护士不存在")
  4045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4046. return
  4047. }
  4048. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4049. if parseEndDateErr != nil {
  4050. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4052. return
  4053. }
  4054. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4055. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4056. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4057. // if getPermissionErr != nil {
  4058. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4059. // return
  4060. // } else if headNursePermission == nil {
  4061. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4062. // return
  4063. // }
  4064. //}
  4065. // 查询信息规挡的设置天数
  4066. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4067. if infor.ID > 0 {
  4068. var cha_time int64
  4069. timeNowStr := time.Now().Format("2006-01-02")
  4070. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4071. //今日的日期减去设置的日期
  4072. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4073. if cha_time >= tempDialysisRecords.DialysisDate {
  4074. //查询审核是否允许
  4075. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id)
  4076. //申请状态不允许的情况 拒绝修改
  4077. if infor.ApplicationStatus != 1 {
  4078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4079. return
  4080. }
  4081. }
  4082. }
  4083. dialysisRecord := &models.DialysisOrder{
  4084. ID: record_id,
  4085. UserOrgId: adminUserInfo.Org.Id,
  4086. EndTime: endDate.Unix(),
  4087. FinishNurse: nurseID,
  4088. FinishModifier: adminUserInfo.AdminUser.Id,
  4089. PuncturePointHaematoma: puncture_point_haematoma,
  4090. BloodAccessInternalFistula: blood_access_internal_fistula,
  4091. Catheter: catheter,
  4092. Cruor: cruor,
  4093. Mission: mission,
  4094. }
  4095. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4096. redis := service.RedisClient()
  4097. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4098. //清空key 值
  4099. redis.Set(key, "", time.Second)
  4100. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4101. //清空key 值
  4102. redis.Set(keyOne, "", time.Second)
  4103. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4104. redis.Set(keySeven, "", time.Second)
  4105. redis.Close()
  4106. if updateErr != nil {
  4107. c.ErrorLog("修改下机失败:%v", updateErr)
  4108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4109. return
  4110. }
  4111. if updateErr == nil {
  4112. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4113. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4114. a, b := math.Modf(value)
  4115. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4116. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4117. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4118. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4119. redis := service.RedisClient()
  4120. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4121. redis.Set(keyTen, "", time.Second)
  4122. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4123. redis.Set(keyTwo, "", time.Second)
  4124. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4125. redis.Set(key, "", time.Second)
  4126. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4127. redis.Set(keyThree, "", time.Second)
  4128. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4129. redis.Set(keySeven, "", time.Second)
  4130. defer redis.Close()
  4131. if updateAssessmentErr != nil {
  4132. utils.ErrorLog("%v", updateAssessmentErr)
  4133. }
  4134. }
  4135. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4136. c.ServeSuccessJSON(map[string]interface{}{
  4137. "dialysis_order": dialysisRecords,
  4138. })
  4139. }
  4140. func (c *DialysisAPIController) GetLongAdvice() {
  4141. patient_id, _ := c.GetInt64("id")
  4142. adminUserInfo := c.GetMobileAdminUserInfo()
  4143. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4144. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4145. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4146. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4147. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4148. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4149. c.ServeSuccessJSON(map[string]interface{}{
  4150. "status": "1",
  4151. })
  4152. return
  4153. } else { //开启推送提醒
  4154. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4155. var advice_three []*models.DoctorAdvice
  4156. recordDateStr := time.Now().Format("2006-01-02")
  4157. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4158. nowtime := recordDate.Unix()
  4159. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4160. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4161. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4162. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4163. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4164. for _, advice := range advices {
  4165. if advice.FrequencyType == 3 {
  4166. t := time.Now()
  4167. week := int(t.Weekday())
  4168. fmt.Println(t.Weekday())
  4169. fmt.Println(week)
  4170. switch week {
  4171. case 1:
  4172. if strings.Index(advice.WeekDay, "周一") == -1 {
  4173. advice_three = append(advice_three, advice)
  4174. }
  4175. break
  4176. case 2:
  4177. if strings.Index(advice.WeekDay, "周二") == -1 {
  4178. advice_three = append(advice_three, advice)
  4179. }
  4180. break
  4181. case 3:
  4182. if strings.Index(advice.WeekDay, "周三") == -1 {
  4183. advice_three = append(advice_three, advice)
  4184. }
  4185. break
  4186. case 4:
  4187. if strings.Index(advice.WeekDay, "周四") == -1 {
  4188. advice_three = append(advice_three, advice)
  4189. }
  4190. break
  4191. case 5:
  4192. if strings.Index(advice.WeekDay, "周五") == -1 {
  4193. advice_three = append(advice_three, advice)
  4194. }
  4195. break
  4196. case 6:
  4197. if strings.Index(advice.WeekDay, "周六") == -1 {
  4198. advice_three = append(advice_three, advice)
  4199. }
  4200. break
  4201. case 0:
  4202. if strings.Index(advice.WeekDay, "周日") == -1 {
  4203. advice_three = append(advice_three, advice)
  4204. }
  4205. break
  4206. }
  4207. }
  4208. }
  4209. for _, advice := range advices_two {
  4210. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4211. now := p.Unix()
  4212. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4213. dayStr2 := "-" + dayStr
  4214. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4215. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4216. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4217. for _, ad := range advices {
  4218. advice_three = append(advice_three, ad)
  4219. }
  4220. }
  4221. if err == nil {
  4222. c.ServeSuccessJSON(map[string]interface{}{
  4223. "status": "2",
  4224. "advices": advices,
  4225. "advices_two": RemoveRepeatedElement(advice_three),
  4226. "is_open_remind": config.IsOpenRemind,
  4227. "his_config_open": hisConfig.IsOpen,
  4228. "is_advice_open": is_advice_open.IsAdviceOpen,
  4229. "prescription_open": prescription_open.IsOpen,
  4230. })
  4231. }
  4232. }
  4233. }
  4234. func (c *DialysisAPIController) GetLongAdviceOne() {
  4235. patient_id, _ := c.GetInt64("id")
  4236. startTime := c.GetString("schedule_date")
  4237. timeLayout := "2006-01-02"
  4238. loc, _ := time.LoadLocation("Local")
  4239. var theStartTime int64
  4240. if len(startTime) > 0 {
  4241. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4242. if err != nil {
  4243. utils.ErrorLog(err.Error())
  4244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4245. return
  4246. }
  4247. theStartTime = theTime.Unix()
  4248. }
  4249. adminUserInfo := c.GetMobileAdminUserInfo()
  4250. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4251. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4252. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4253. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4254. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4255. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4256. c.ServeSuccessJSON(map[string]interface{}{
  4257. "status": "1",
  4258. })
  4259. return
  4260. } else { //开启推送提醒
  4261. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4262. var advice_three []*models.DoctorAdvice
  4263. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  4264. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  4265. for _, advice := range advices {
  4266. if advice.FrequencyType == 3 {
  4267. t := time.Now()
  4268. week := int(t.Weekday())
  4269. fmt.Println(t.Weekday())
  4270. fmt.Println(week)
  4271. switch week {
  4272. case 1:
  4273. if strings.Index(advice.WeekDay, "周一") == -1 {
  4274. advice_three = append(advice_three, advice)
  4275. }
  4276. break
  4277. case 2:
  4278. if strings.Index(advice.WeekDay, "周二") == -1 {
  4279. advice_three = append(advice_three, advice)
  4280. }
  4281. break
  4282. case 3:
  4283. if strings.Index(advice.WeekDay, "周三") == -1 {
  4284. advice_three = append(advice_three, advice)
  4285. }
  4286. break
  4287. case 4:
  4288. if strings.Index(advice.WeekDay, "周四") == -1 {
  4289. advice_three = append(advice_three, advice)
  4290. }
  4291. break
  4292. case 5:
  4293. if strings.Index(advice.WeekDay, "周五") == -1 {
  4294. advice_three = append(advice_three, advice)
  4295. }
  4296. break
  4297. case 6:
  4298. if strings.Index(advice.WeekDay, "周六") == -1 {
  4299. advice_three = append(advice_three, advice)
  4300. }
  4301. break
  4302. case 0:
  4303. if strings.Index(advice.WeekDay, "周日") == -1 {
  4304. advice_three = append(advice_three, advice)
  4305. }
  4306. break
  4307. }
  4308. }
  4309. }
  4310. for _, advice := range advices_two {
  4311. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4312. now := p.Unix()
  4313. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4314. dayStr2 := "-" + dayStr
  4315. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4316. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4317. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4318. for _, ad := range advices {
  4319. advice_three = append(advice_three, ad)
  4320. }
  4321. }
  4322. if err == nil {
  4323. c.ServeSuccessJSON(map[string]interface{}{
  4324. "status": "2",
  4325. "advices": advices,
  4326. "advices_two": RemoveRepeatedElement(advice_three),
  4327. "is_open_remind": config.IsOpenRemind,
  4328. "his_config_open": hisConfig.IsOpen,
  4329. "is_advice_open": is_advice_open.IsAdviceOpen,
  4330. "prescription_open": prescription_open.IsOpen,
  4331. })
  4332. }
  4333. }
  4334. }
  4335. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4336. newArr = make([]*models.DoctorAdvice, 0)
  4337. for i := 0; i < len(arr); i++ {
  4338. repeat := false
  4339. for j := i + 1; j < len(arr); j++ {
  4340. if arr[i].ID == arr[j].ID {
  4341. repeat = true
  4342. break
  4343. }
  4344. }
  4345. if !repeat {
  4346. newArr = append(newArr, arr[i])
  4347. }
  4348. }
  4349. return
  4350. }
  4351. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  4352. patient, _ := c.GetInt64("id", 0)
  4353. groupNo, _ := c.GetInt64("groupno", 0)
  4354. if patient <= 0 {
  4355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4356. return
  4357. }
  4358. adminUserInfo := c.GetMobileAdminUserInfo()
  4359. dataBody := make(map[string]interface{}, 0)
  4360. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4361. if err != nil {
  4362. utils.ErrorLog(err.Error())
  4363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4364. return
  4365. }
  4366. utils.ErrorLog("%v", dataBody)
  4367. timeLayout := "2006-01-02 15:04"
  4368. loc, _ := time.LoadLocation("Local")
  4369. timeLayout2 := "2006-01-02"
  4370. loc2, _ := time.LoadLocation("Local")
  4371. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4372. utils.ErrorLog("advice_type")
  4373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4374. return
  4375. }
  4376. adviceType := int64(2)
  4377. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4378. utils.ErrorLog("advice_date")
  4379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4380. return
  4381. }
  4382. adviceDate, _ := dataBody["advice_date"].(string)
  4383. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4384. AdviceDate := theTime.Unix()
  4385. RecordDate := theTime.Unix()
  4386. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4387. utils.ErrorLog("start_time")
  4388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4389. return
  4390. }
  4391. startTime, _ := dataBody["start_time"].(string)
  4392. if len(startTime) == 0 {
  4393. utils.ErrorLog("len(start_time) == 0")
  4394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4395. return
  4396. }
  4397. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4398. if err != nil {
  4399. utils.ErrorLog(err.Error())
  4400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4401. return
  4402. }
  4403. StartTime := theTime.Unix()
  4404. Remark := ""
  4405. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4406. remark, _ := dataBody["remark"].(string)
  4407. Remark = remark
  4408. }
  4409. var advices []*models.GroupAdvice
  4410. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4411. utils.ErrorLog("advices")
  4412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4413. return
  4414. }
  4415. adviceNames := dataBody["advices"].([]interface{})
  4416. for _, adviceNameMap := range adviceNames {
  4417. adviceNameM := adviceNameMap.(map[string]interface{})
  4418. var advice models.GroupAdvice
  4419. advice.Remark = Remark
  4420. advice.AdviceType = adviceType
  4421. advice.StartTime = StartTime
  4422. advice.AdviceDate = AdviceDate
  4423. advice.RecordDate = RecordDate
  4424. advice.Status = 1
  4425. advice.CreatedTime = time.Now().Unix()
  4426. advice.UpdatedTime = time.Now().Unix()
  4427. advice.StopState = 2
  4428. advice.ExecutionState = 2
  4429. advice.UserOrgId = adminUserInfo.Org.Id
  4430. advice.PatientId = patient
  4431. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4432. advice.IsSettle = 2
  4433. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4434. utils.ErrorLog("advice_name")
  4435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4436. return
  4437. }
  4438. adviceName, _ := adviceNameM["advice_name"].(string)
  4439. if len(adviceName) == 0 {
  4440. utils.ErrorLog("len(advice_name) == 0")
  4441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4442. return
  4443. }
  4444. advice.AdviceName = adviceName
  4445. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4446. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4447. advice.DrugSpec = drugSpec
  4448. }
  4449. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4450. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4451. advice.AdviceDesc = adviceDesc
  4452. }
  4453. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4454. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4455. advice.DrugSpecUnit = drugSpecUnit
  4456. }
  4457. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4458. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4459. // advice.SingleDose = singleDose
  4460. //}
  4461. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4462. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4463. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4464. }
  4465. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4466. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4467. advice.SingleDoseUnit = singleDoseUnit
  4468. }
  4469. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4470. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4471. // advice.PrescribingNumber = prescribingNumber
  4472. //}
  4473. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4474. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4475. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4476. }
  4477. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4478. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4479. advice.PrescribingNumberUnit = prescribingNumberUnit
  4480. }
  4481. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4482. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4483. advice.DeliveryWay = deliveryWay
  4484. }
  4485. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4486. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4487. advice.ExecutionFrequency = executionFrequency
  4488. }
  4489. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  4490. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  4491. advice.FrequencyType = frequency_type
  4492. }
  4493. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  4494. day_count := int64(adviceNameM["day_count"].(float64))
  4495. advice.DayCount = day_count
  4496. }
  4497. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  4498. week_day, _ := adviceNameM["week_day"].(string)
  4499. advice.WeekDay = week_day
  4500. }
  4501. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  4502. way := int64(adviceNameM["way"].(float64))
  4503. advice.Way = way
  4504. }
  4505. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  4506. drug_id := int64(adviceNameM["drug_id"].(float64))
  4507. advice.DrugId = drug_id
  4508. }
  4509. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  4510. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  4511. advice.DrugNameId = drug_name_id
  4512. }
  4513. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  4514. template_id, _ := adviceNameM["template_id"].(string)
  4515. advice.TemplateId = template_id
  4516. }
  4517. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  4518. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4519. advice.ExecutionFrequency = executionFrequency
  4520. }
  4521. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  4522. children := adviceNameM["child"].([]interface{})
  4523. if len(children) > 0 {
  4524. for _, childrenMap := range children {
  4525. childMap := childrenMap.(map[string]interface{})
  4526. var child models.GroupAdvice
  4527. child.Remark = Remark
  4528. child.AdviceType = adviceType
  4529. child.StartTime = StartTime
  4530. child.AdviceDate = AdviceDate
  4531. child.RecordDate = RecordDate
  4532. child.Status = 1
  4533. child.CreatedTime = time.Now().Unix()
  4534. child.UpdatedTime = time.Now().Unix()
  4535. child.StopState = 2
  4536. child.ExecutionState = 2
  4537. child.UserOrgId = adminUserInfo.Org.Id
  4538. child.PatientId = patient
  4539. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  4540. child.IsSettle = 1
  4541. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  4542. utils.ErrorLog("child advice_name")
  4543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4544. return
  4545. }
  4546. childAdviceName, _ := childMap["advice_name"].(string)
  4547. if len(childAdviceName) == 0 {
  4548. utils.ErrorLog("len(child advice_name) == 0")
  4549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4550. return
  4551. }
  4552. child.AdviceName = childAdviceName
  4553. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  4554. childAdviceDesc, _ := childMap["advice_desc"].(string)
  4555. child.AdviceDesc = childAdviceDesc
  4556. }
  4557. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  4558. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  4559. child.DrugSpec = childDrugSpec
  4560. }
  4561. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  4562. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  4563. child.DrugSpecUnit = childDrugSpecUnit
  4564. }
  4565. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  4566. child.SingleDose = childMap["single_dose"].(float64)
  4567. }
  4568. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  4569. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  4570. child.SingleDoseUnit = childSingleDoseUnit
  4571. }
  4572. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  4573. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  4574. }
  4575. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  4576. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  4577. child.PrescribingNumberUnit = childPrescribingNumberUnit
  4578. }
  4579. child.DeliveryWay = advice.DeliveryWay
  4580. child.ExecutionFrequency = advice.ExecutionFrequency
  4581. advice.Children = append(advice.Children, &child)
  4582. }
  4583. }
  4584. }
  4585. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  4586. if temp_advice.ID == 0 {
  4587. advices = append(advices, &advice)
  4588. }
  4589. }
  4590. if len(advices) > 0 {
  4591. finish := models.XtDialysisFinish{
  4592. IsFinish: 1,
  4593. UserOrgId: adminUserInfo.Org.Id,
  4594. Status: 1,
  4595. Ctime: time.Now().Unix(),
  4596. Mtime: 0,
  4597. Module: 4,
  4598. RecordDate: AdviceDate,
  4599. Sourse: 1,
  4600. PatientId: patient,
  4601. }
  4602. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  4603. if dialysisFinish.ID == 0 {
  4604. service.CreateDialysisFinish(finish)
  4605. }
  4606. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  4607. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  4608. redis := service.RedisClient()
  4609. //清空key 值
  4610. redis.Set(key, "", time.Second)
  4611. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4612. redis.Set(keyOne, "", time.Second)
  4613. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4614. defer redis.Close()
  4615. redis.Set(keyThree, "", time.Second)
  4616. if err != nil {
  4617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4618. return
  4619. }
  4620. c.ServeSuccessJSON(map[string]interface{}{
  4621. "msg": "ok",
  4622. "advices": list,
  4623. })
  4624. } else {
  4625. c.ServeSuccessJSON(map[string]interface{}{
  4626. "msg": "ok",
  4627. })
  4628. }
  4629. return
  4630. }
  4631. func (c *DialysisAPIController) UploadDryWeight() {
  4632. patient_id, _ := c.GetInt64("id")
  4633. dry_weight, _ := c.GetFloat("dry_weight")
  4634. doctor_id, _ := c.GetInt64("doctor_id")
  4635. remark := c.GetString("remark")
  4636. adminUserInfo := c.GetMobileAdminUserInfo()
  4637. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  4638. if err == gorm.ErrRecordNotFound {
  4639. dryWeight := &models.SgjPatientDryweight{
  4640. PatientId: patient_id,
  4641. DryWeight: dry_weight,
  4642. Remakes: remark,
  4643. Ctime: time.Now().Unix(),
  4644. Mtime: time.Now().Unix(),
  4645. Creator: doctor_id,
  4646. Status: 1,
  4647. UserOrgId: adminUserInfo.Org.Id,
  4648. AdjustedValue: "/",
  4649. UserId: adminUserInfo.AdminUser.Id,
  4650. }
  4651. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4652. redis := service.RedisClient()
  4653. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  4654. redis.Set(keyOne, "", time.Second)
  4655. loc, _ := time.LoadLocation("Local")
  4656. nowTime := time.Now()
  4657. nowDay := nowTime.Format("2006-01-02")
  4658. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4659. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4660. redis.Set(key, "", time.Second)
  4661. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4662. redis.Set(keyTwo, "", time.Second)
  4663. redis.Close()
  4664. if createErr == nil {
  4665. c.ServeSuccessJSON(map[string]interface{}{
  4666. "msg": "提交成功",
  4667. "weight": dryWeight,
  4668. })
  4669. }
  4670. } else {
  4671. dryWeight := &models.SgjPatientDryweight{
  4672. PatientId: patient_id,
  4673. DryWeight: dry_weight,
  4674. Remakes: remark,
  4675. Ctime: time.Now().Unix(),
  4676. Mtime: time.Now().Unix(),
  4677. Creator: doctor_id,
  4678. Status: 1,
  4679. UserOrgId: adminUserInfo.Org.Id,
  4680. AdjustedValue: "/",
  4681. UserId: adminUserInfo.AdminUser.Id,
  4682. }
  4683. var value float64
  4684. value = dry_weight - weightAdjust.DryWeight
  4685. if value < 0 {
  4686. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  4687. } else if value == 0 {
  4688. dryWeight.AdjustedValue = "/"
  4689. } else if value > 0 {
  4690. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  4691. }
  4692. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4693. redis := service.RedisClient()
  4694. loc, _ := time.LoadLocation("Local")
  4695. nowTime := time.Now()
  4696. nowDay := nowTime.Format("2006-01-02")
  4697. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4698. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4699. redis.Set(keyOne, "", time.Second)
  4700. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4701. redis.Set(key, "", time.Second)
  4702. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4703. redis.Set(keyTwo, "", time.Second)
  4704. redis.Close()
  4705. if createErr == nil {
  4706. c.ServeSuccessJSON(map[string]interface{}{
  4707. "msg": "提交成功",
  4708. "weight": dryWeight,
  4709. })
  4710. }
  4711. }
  4712. }
  4713. func (c *DialysisAPIController) GetSolution() {
  4714. patient_id, _ := c.GetInt64("patient_id")
  4715. mode_id, _ := c.GetInt64("mode_id")
  4716. adminUserInfo := c.GetMobileAdminUserInfo()
  4717. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  4718. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  4719. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  4720. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  4721. if err != nil {
  4722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4723. return
  4724. }
  4725. c.ServeSuccessJSON(map[string]interface{}{
  4726. "solution": solution,
  4727. "prescription": prescription,
  4728. "system_prescription": system_prescription,
  4729. "dialysisPrescription": dialysisPrescription,
  4730. })
  4731. }
  4732. func (c *DialysisAPIController) GetSchedule() {
  4733. schedual_type, _ := c.GetInt64("schedual_type")
  4734. adminUserInfo := c.GetMobileAdminUserInfo()
  4735. scheduleTime, _ := c.GetInt64("record_date")
  4736. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  4737. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  4738. c.ServeSuccessJSON(map[string]interface{}{
  4739. "number": deviceNumber,
  4740. "list": list,
  4741. })
  4742. }
  4743. func (c *DialysisAPIController) GetPatientId() {
  4744. id, _ := c.GetInt64("id")
  4745. //orgid := c.GetMobileAdminUserInfo().Org.Id
  4746. patientId, _ := service.GetPatientId(id)
  4747. //获取该患者的所有传染病
  4748. list, _ := service.GetPatientInfectious(id)
  4749. c.ServeSuccessJSON(map[string]interface{}{
  4750. "patient": patientId,
  4751. "infectioulist": list,
  4752. })
  4753. }
  4754. func (this *DialysisAPIController) GetDialysisSchedule() {
  4755. schedualDate := this.GetString("date")
  4756. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  4757. if parseDateErr != nil {
  4758. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4759. return
  4760. }
  4761. adminInfo := this.GetMobileAdminUserInfo()
  4762. orgID := adminInfo.Org.Id
  4763. redis := service.RedisClient()
  4764. defer redis.Close()
  4765. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  4766. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  4767. if len(scheduals) > 0 {
  4768. //缓存数据
  4769. scheduals_json, err := json.Marshal(scheduals)
  4770. if err == nil {
  4771. redis.Set(key, scheduals_json, time.Second*30)
  4772. }
  4773. }
  4774. this.ServeSuccessJSON(map[string]interface{}{
  4775. "scheduals": scheduals,
  4776. })
  4777. }
  4778. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  4779. change_type, _ := this.GetInt64("type", 0)
  4780. record_date := this.GetString("record_time")
  4781. patient_id, _ := this.GetInt64("patient_id", 0)
  4782. timeLayout := "2006-01-02"
  4783. loc, _ := time.LoadLocation("Local")
  4784. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4785. record_time := theAdviceRecordTime.Unix()
  4786. adminUserInfo := this.GetMobileAdminUserInfo()
  4787. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  4788. if err == nil {
  4789. if len(advices) == 0 {
  4790. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4791. return
  4792. } else {
  4793. this.ServeSuccessJSON(map[string]interface{}{
  4794. "advices": advices,
  4795. "schedule": sch,
  4796. })
  4797. return
  4798. }
  4799. } else {
  4800. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4801. return
  4802. }
  4803. }
  4804. func (c *DialysisAPIController) CreateConsumables() {
  4805. record_date := c.GetString("record_time")
  4806. patient_id, _ := c.GetInt64("patient_id", 0)
  4807. active, _ := c.GetInt64("active")
  4808. adminUser := c.GetMobileAdminUserInfo()
  4809. timeLayout := "2006-01-02"
  4810. loc, _ := time.LoadLocation("Local")
  4811. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4812. record_time := theRecordTime.Unix()
  4813. // 查询信息规挡的设置天数
  4814. orgid := c.GetMobileAdminUserInfo().Org.Id
  4815. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  4816. if infor.ID > 0 {
  4817. var cha_time int64
  4818. timeNowStr := time.Now().Format("2006-01-02")
  4819. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4820. //今日的日期减去设置的日期
  4821. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4822. if cha_time >= record_time {
  4823. //查询审核是否允许
  4824. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid)
  4825. //申请状态不允许的情况 拒绝修改
  4826. if infor.ApplicationStatus != 1 {
  4827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4828. return
  4829. }
  4830. }
  4831. }
  4832. dataBody := make(map[string]interface{}, 0)
  4833. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4834. if err != nil {
  4835. utils.ErrorLog(err.Error())
  4836. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4837. return
  4838. }
  4839. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  4840. var beforePrepares []*models.DialysisBeforePrepareGoods
  4841. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  4842. var dialysisBefor []*models.DialysisBeforePrepare
  4843. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  4844. goods, _ := dataBody["goods"].([]interface{})
  4845. if len(goods) > 0 {
  4846. for _, item := range goods {
  4847. items := item.(map[string]interface{})
  4848. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4849. utils.ErrorLog("good_id")
  4850. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4851. return
  4852. }
  4853. good_id := int64(items["good_id"].(float64))
  4854. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  4855. utils.ErrorLog("good_type_id")
  4856. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4857. return
  4858. }
  4859. good_type_id := int64(items["good_type_id"].(float64))
  4860. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  4861. utils.ErrorLog("count")
  4862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4863. return
  4864. }
  4865. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  4866. commdity_code := items["commdity_code"].(string)
  4867. fmt.Println("commdity", commdity_code)
  4868. prepareGoods := &models.DialysisBeforePrepareGoods{
  4869. GoodTypeId: good_type_id,
  4870. GoodId: good_id,
  4871. Count: count,
  4872. StorehouseId: houseConfig.StorehouseOutInfo,
  4873. }
  4874. beforePrepares = append(beforePrepares, prepareGoods)
  4875. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  4876. GoodTypeId: good_type_id,
  4877. GoodId: good_id,
  4878. Count: count,
  4879. StorehouseId: houseConfig.StorehouseOutInfo,
  4880. }
  4881. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  4882. prepare := &models.DialysisBeforePrepare{
  4883. GoodTypeId: good_type_id,
  4884. GoodId: good_id,
  4885. Count: count,
  4886. PatientId: patient_id,
  4887. RecordDate: record_time,
  4888. UserOrgId: adminUser.Org.Id,
  4889. Status: 1,
  4890. Ctime: time.Now().Unix(),
  4891. Creater: adminUser.AdminUser.Id,
  4892. CommdityCode: commdity_code,
  4893. StorehouseId: houseConfig.StorehouseOutInfo,
  4894. }
  4895. dialysisBefor = append(dialysisBefor, prepare)
  4896. }
  4897. }
  4898. //查询是否有库存
  4899. for _, item := range dialysisBefor {
  4900. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  4901. if err == gorm.ErrRecordNotFound {
  4902. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4903. c.ServeSuccessJSON(map[string]interface{}{
  4904. "message": "1",
  4905. "good_name": goodObj.GoodName,
  4906. "specification_name": goodObj.SpecificationName,
  4907. })
  4908. return
  4909. }
  4910. if err != nil {
  4911. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4912. c.ServeSuccessJSON(map[string]interface{}{
  4913. "message": "1",
  4914. "good_name": goodObj.GoodName,
  4915. "specification_name": goodObj.SpecificationName,
  4916. })
  4917. return
  4918. }
  4919. }
  4920. //新增
  4921. if active == 1 && len(goods) > 0 {
  4922. for _, item := range dialysisBefor {
  4923. dialyPrepareOne := models.DialysisBeforePrepare{
  4924. GoodTypeId: item.GoodTypeId,
  4925. GoodId: item.GoodId,
  4926. PatientId: item.PatientId,
  4927. RecordDate: item.RecordDate,
  4928. UserOrgId: item.UserOrgId,
  4929. Count: item.Count,
  4930. Ctime: time.Now().Unix(),
  4931. Creater: item.Creater,
  4932. CommdityCode: item.CommdityCode,
  4933. Status: 1,
  4934. StorehouseId: houseConfig.StorehouseOutInfo,
  4935. }
  4936. //先清除再插入
  4937. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4938. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  4939. //查询默认仓库
  4940. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  4941. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  4942. var total_count int64
  4943. for _, it := range stockList {
  4944. total_count += it.StockCount
  4945. }
  4946. //基础库插入数据
  4947. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  4948. //更新库存
  4949. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  4950. var flush_count int64
  4951. for _, it := range goodList {
  4952. flush_count += it.StockCount
  4953. }
  4954. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  4955. }
  4956. if err == nil {
  4957. c.ServeSuccessJSON(map[string]interface{}{
  4958. "msg": "保存成功",
  4959. "message": "2",
  4960. })
  4961. return
  4962. } else {
  4963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4964. return
  4965. }
  4966. }
  4967. if len(beforePrepares) > 0 && active == 2 {
  4968. for _, item := range beforePrepares {
  4969. //1.查看该患者该耗材型号最后一次出库数量
  4970. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  4971. //判断当前出库数量和最后一次出库数量的大小
  4972. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  4973. if item.Count <= goodInfo.Count {
  4974. //退库
  4975. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  4976. //查询今日出库数据
  4977. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  4978. for _, it := range list {
  4979. prepare := models.DialysisBeforePrepare{
  4980. UserOrgId: it.OrgId,
  4981. PatientId: patient_id,
  4982. RecordDate: it.RecordTime,
  4983. GoodId: it.GoodId,
  4984. GoodTypeId: it.GoodTypeId,
  4985. Count: it.Count,
  4986. Ctime: time.Now().Unix(),
  4987. Creater: adminUser.AdminUser.Id,
  4988. Status: 1,
  4989. StorehouseId: houseConfig.StorehouseOutInfo,
  4990. }
  4991. //删除准备表数据
  4992. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4993. service.CreateDialysisBeforePrepareOne(&prepare)
  4994. }
  4995. }
  4996. var last_total int64
  4997. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  4998. if item.Count >= goodInfo.Count {
  4999. //查询当前批次当前耗材最后一条出库数据
  5000. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5001. //计算当前出库和最后一次出库数据相差数据
  5002. last_total = item.Count - lastOutInfo.Count
  5003. //查询该批次剩余库存
  5004. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  5005. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  5006. if lastInfo.StockCount >= last_total {
  5007. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5008. //查询今日出库数据
  5009. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5010. for _, it := range list {
  5011. prepare := models.DialysisBeforePrepare{
  5012. UserOrgId: it.OrgId,
  5013. PatientId: patient_id,
  5014. RecordDate: it.RecordTime,
  5015. GoodId: it.GoodId,
  5016. GoodTypeId: it.GoodTypeId,
  5017. Count: it.Count,
  5018. Ctime: time.Now().Unix(),
  5019. Creater: adminUser.AdminUser.Id,
  5020. Status: 1,
  5021. StorehouseId: houseConfig.StorehouseOutInfo,
  5022. }
  5023. //删除准备表数据
  5024. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5025. service.CreateDialysisBeforePrepareOne(&prepare)
  5026. //查询默认仓库
  5027. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5028. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5029. var total_count int64
  5030. for _, it := range stockList {
  5031. total_count += it.StockCount
  5032. }
  5033. //基础库插入数据
  5034. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5035. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5036. var flush_count int64
  5037. for _, it := range goodList {
  5038. flush_count += it.StockCount
  5039. }
  5040. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5041. }
  5042. }
  5043. //如果库存不够,则出库到下一个批次
  5044. if lastInfo.StockCount < last_total {
  5045. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5046. //查询今日出库数据
  5047. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5048. for _, it := range list {
  5049. prepare := models.DialysisBeforePrepare{
  5050. UserOrgId: it.OrgId,
  5051. PatientId: patient_id,
  5052. RecordDate: it.RecordTime,
  5053. GoodId: it.GoodId,
  5054. GoodTypeId: it.GoodTypeId,
  5055. Count: it.Count,
  5056. Ctime: time.Now().Unix(),
  5057. Creater: adminUser.AdminUser.Id,
  5058. Status: 1,
  5059. StorehouseId: houseConfig.StorehouseOutInfo,
  5060. }
  5061. //删除准备表数据
  5062. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5063. service.CreateDialysisBeforePrepareOne(&prepare)
  5064. //查询默认仓库
  5065. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5066. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5067. var total_count int64
  5068. for _, it := range stockList {
  5069. total_count += it.StockCount
  5070. }
  5071. //基础库插入数据
  5072. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5073. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5074. var flush_count int64
  5075. for _, it := range goodList {
  5076. flush_count += it.StockCount
  5077. }
  5078. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5079. }
  5080. if err != nil {
  5081. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5082. c.ServeSuccessJSON(map[string]interface{}{
  5083. "message": "1",
  5084. "good_name": goodObj.GoodName,
  5085. "specification_name": goodObj.SpecificationName,
  5086. })
  5087. return
  5088. }
  5089. }
  5090. }
  5091. if err != nil {
  5092. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5093. c.ServeSuccessJSON(map[string]interface{}{
  5094. "message": "1",
  5095. "good_name": goodObj.GoodName,
  5096. "specification_name": goodObj.SpecificationName,
  5097. })
  5098. return
  5099. }
  5100. }
  5101. }
  5102. }
  5103. var errs error
  5104. if errs == nil {
  5105. c.ServeSuccessJSON(map[string]interface{}{
  5106. "msg": "提交成功",
  5107. "message": "2",
  5108. "good_name": "",
  5109. "specification_name": "",
  5110. })
  5111. return
  5112. } else {
  5113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5114. return
  5115. }
  5116. }
  5117. func (c *DialysisAPIController) CreateStockOutInfo() {
  5118. patient_id, _ := c.GetInt64("patient_id", 0)
  5119. record_date := c.GetString("record_time")
  5120. if patient_id <= 0 {
  5121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5122. return
  5123. }
  5124. adminInfo := c.GetMobileAdminUserInfo()
  5125. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5126. timeLayout := "2006-01-02"
  5127. loc, _ := time.LoadLocation("Local")
  5128. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5129. record_time := theRecordTime.Unix()
  5130. // 查询信息规挡的设置天数
  5131. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5132. if infor.ID > 0 && infor.WeekDay > 0 {
  5133. var cha_time int64
  5134. timeNowStr := time.Now().Format("2006-01-02")
  5135. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5136. //今日的日期减去设置的日期
  5137. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5138. if cha_time >= record_time {
  5139. //查询审核是否允许
  5140. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id)
  5141. //申请状态不允许的情况 拒绝修改
  5142. if infor.ApplicationStatus != 1 {
  5143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5144. return
  5145. }
  5146. }
  5147. }
  5148. //创建步骤表
  5149. finish := models.XtDialysisFinish{
  5150. IsFinish: 1,
  5151. UserOrgId: adminInfo.Org.Id,
  5152. Status: 1,
  5153. Ctime: time.Now().Unix(),
  5154. Mtime: 0,
  5155. Module: 11,
  5156. RecordDate: record_time,
  5157. Sourse: 1,
  5158. PatientId: patient_id,
  5159. }
  5160. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  5161. if dialysisFinish.ID == 0 {
  5162. service.CreateDialysisFinish(finish)
  5163. }
  5164. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  5165. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5166. //去重
  5167. consumables = RemoveRepeatedGood(consumables)
  5168. if record.IsOpen == 1 {
  5169. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5170. //查询是否有库存
  5171. for _, item := range consumables {
  5172. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5173. if item.Count > warehouse.Count {
  5174. goodErrcode := models.XtGoodErrcode{
  5175. UserOrgId: item.UserOrgId,
  5176. Errcode: "自动出库库存不足",
  5177. GoodId: item.GoodId,
  5178. Status: 1,
  5179. Ctime: time.Now().Unix(),
  5180. Mtime: 0,
  5181. Count: 0,
  5182. StockCount: 0,
  5183. Creater: creator,
  5184. BatchNumberId: warehouse.ID,
  5185. WarehouseOutId: 0,
  5186. }
  5187. service.CreateGoodErrcode(goodErrcode)
  5188. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5189. c.ServeSuccessJSON(map[string]interface{}{
  5190. "message": "1",
  5191. "good_name": goodObj.GoodName,
  5192. "specification_name": goodObj.SpecificationName,
  5193. })
  5194. return
  5195. }
  5196. }
  5197. //查询是否有出库单
  5198. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5199. if err == gorm.ErrRecordNotFound {
  5200. //没有记录,则创建出库单
  5201. timeStr := time.Now().Format("2006-01-02")
  5202. timeArr := strings.Split(timeStr, "-")
  5203. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5204. total = total + 1
  5205. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5206. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5207. number = number + total
  5208. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5209. creater := adminInfo.AdminUser.Id
  5210. warehouseOut := models.WarehouseOut{
  5211. WarehouseOutOrderNumber: warehousing_out_order,
  5212. OperationTime: time.Now().Unix(),
  5213. OrgId: adminInfo.Org.Id,
  5214. Creater: creater,
  5215. Ctime: time.Now().Unix(),
  5216. Status: 1,
  5217. WarehouseOutTime: record_time,
  5218. Dealer: 0,
  5219. Manufacturer: 0,
  5220. Type: 1,
  5221. IsSys: 1,
  5222. StorehouseId: houseConfig.StorehouseOutInfo,
  5223. IsCheck: 1,
  5224. }
  5225. err := service.AddSigleWarehouseOut(&warehouseOut)
  5226. if err != nil {
  5227. goodErrcode := models.XtGoodErrcode{
  5228. UserOrgId: adminInfo.Org.Id,
  5229. Errcode: "创建出库单失败",
  5230. GoodId: 0,
  5231. Status: 1,
  5232. Ctime: time.Now().Unix(),
  5233. Mtime: 0,
  5234. Count: 0,
  5235. StockCount: 0,
  5236. Creater: creator,
  5237. BatchNumberId: 0,
  5238. WarehouseOutId: 0,
  5239. }
  5240. service.CreateGoodErrcode(goodErrcode)
  5241. utils.TraceLog("创建出库单失败 err = %v", err)
  5242. } else {
  5243. for _, item := range consumables {
  5244. //出库
  5245. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5246. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5247. if err == nil {
  5248. goodErrcode := models.XtGoodErrcode{
  5249. UserOrgId: adminInfo.Org.Id,
  5250. Errcode: "自动出库接口报错",
  5251. GoodId: 0,
  5252. Status: 1,
  5253. Ctime: time.Now().Unix(),
  5254. Mtime: 0,
  5255. Count: 0,
  5256. StockCount: 0,
  5257. Creater: creator,
  5258. BatchNumberId: 0,
  5259. WarehouseOutId: 0,
  5260. }
  5261. service.CreateGoodErrcode(goodErrcode)
  5262. utils.TraceLog("创建出库单失败 err = %v", err)
  5263. }
  5264. //查询
  5265. //出库数量相加
  5266. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5267. if errs != nil {
  5268. goodErrcode := models.XtGoodErrcode{
  5269. UserOrgId: item.UserOrgId,
  5270. Errcode: "创建剩余库存字段报错",
  5271. GoodId: item.GoodId,
  5272. Status: 1,
  5273. Ctime: time.Now().Unix(),
  5274. Mtime: 0,
  5275. Count: 0,
  5276. StockCount: 0,
  5277. Creater: creater,
  5278. BatchNumberId: 0,
  5279. WarehouseOutId: 0,
  5280. }
  5281. service.CreateGoodErrcode(goodErrcode)
  5282. }
  5283. }
  5284. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5285. if len(list) == 0 {
  5286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5287. return
  5288. }
  5289. for _, item := range list {
  5290. prepare := models.DialysisBeforePrepare{
  5291. UserOrgId: adminInfo.Org.Id,
  5292. PatientId: patient_id,
  5293. RecordDate: record_time,
  5294. GoodId: item.GoodId,
  5295. GoodTypeId: item.GoodTypeId,
  5296. Count: item.Count,
  5297. Creater: adminInfo.AdminUser.Id,
  5298. Status: 1,
  5299. Ctime: time.Now().Unix(),
  5300. StorehouseId: houseConfig.StorehouseOutInfo,
  5301. }
  5302. //清空准备表数据
  5303. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5304. if err != nil {
  5305. goodErrcode := models.XtGoodErrcode{
  5306. UserOrgId: item.OrgId,
  5307. Errcode: "自动出库清空准备表数据报错",
  5308. GoodId: item.GoodId,
  5309. Status: 1,
  5310. Ctime: time.Now().Unix(),
  5311. Mtime: 0,
  5312. Count: 0,
  5313. StockCount: 0,
  5314. Creater: creater,
  5315. BatchNumberId: 0,
  5316. WarehouseOutId: 0,
  5317. }
  5318. service.CreateGoodErrcode(goodErrcode)
  5319. }
  5320. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5321. if errs != nil {
  5322. goodErrcode := models.XtGoodErrcode{
  5323. UserOrgId: item.OrgId,
  5324. Errcode: "自动出库创建准备表数据报错",
  5325. GoodId: item.GoodId,
  5326. Status: 1,
  5327. Ctime: time.Now().Unix(),
  5328. Mtime: 0,
  5329. Count: 0,
  5330. StockCount: 0,
  5331. Creater: creater,
  5332. BatchNumberId: 0,
  5333. WarehouseOutId: 0,
  5334. }
  5335. service.CreateGoodErrcode(goodErrcode)
  5336. }
  5337. //查询默认仓库
  5338. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5339. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5340. var total_count int64
  5341. for _, it := range stockList {
  5342. total_count += it.StockCount
  5343. }
  5344. //基础库插入数据
  5345. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5346. if errcodes != nil {
  5347. goodErrcode := models.XtGoodErrcode{
  5348. UserOrgId: item.OrgId,
  5349. Errcode: "自动出库基础库插入数据",
  5350. GoodId: item.GoodId,
  5351. Status: 1,
  5352. Ctime: time.Now().Unix(),
  5353. Mtime: 0,
  5354. Count: 0,
  5355. StockCount: 0,
  5356. Creater: creater,
  5357. BatchNumberId: 0,
  5358. WarehouseOutId: 0,
  5359. }
  5360. service.CreateGoodErrcode(goodErrcode)
  5361. }
  5362. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5363. var flush_count int64
  5364. for _, it := range goodList {
  5365. flush_count += it.StockCount
  5366. }
  5367. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5368. if errsss != nil {
  5369. goodErrcode := models.XtGoodErrcode{
  5370. UserOrgId: item.OrgId,
  5371. Errcode: "自动出库剩余库存更新数据",
  5372. GoodId: item.GoodId,
  5373. Status: 1,
  5374. Ctime: time.Now().Unix(),
  5375. Mtime: 0,
  5376. Count: 0,
  5377. StockCount: 0,
  5378. Creater: creater,
  5379. BatchNumberId: 0,
  5380. WarehouseOutId: 0,
  5381. }
  5382. service.CreateGoodErrcode(goodErrcode)
  5383. }
  5384. }
  5385. }
  5386. //
  5387. } else if err == nil {
  5388. for _, item := range consumables {
  5389. //出库
  5390. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  5391. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  5392. if err != nil {
  5393. goodErrcode := models.XtGoodErrcode{
  5394. UserOrgId: adminInfo.Org.Id,
  5395. Errcode: "自动出库接口报错",
  5396. GoodId: 0,
  5397. Status: 1,
  5398. Ctime: time.Now().Unix(),
  5399. Mtime: 0,
  5400. Count: 0,
  5401. StockCount: 0,
  5402. Creater: creator,
  5403. BatchNumberId: 0,
  5404. WarehouseOutId: 0,
  5405. }
  5406. service.CreateGoodErrcode(goodErrcode)
  5407. }
  5408. //出库数量相加
  5409. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5410. if errss != nil {
  5411. goodErrcode := models.XtGoodErrcode{
  5412. UserOrgId: item.UserOrgId,
  5413. Errcode: "创建剩余库存字段报错",
  5414. GoodId: item.GoodId,
  5415. Status: 1,
  5416. Ctime: time.Now().Unix(),
  5417. Mtime: time.Now().Unix(),
  5418. Count: 0,
  5419. StockCount: 0,
  5420. Creater: item.Creater,
  5421. BatchNumberId: 0,
  5422. WarehouseOutId: 0,
  5423. }
  5424. service.CreateGoodErrcode(goodErrcode)
  5425. }
  5426. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5427. if len(list) == 0 {
  5428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5429. return
  5430. }
  5431. for _, item := range list {
  5432. prepare := models.DialysisBeforePrepare{
  5433. UserOrgId: adminInfo.Org.Id,
  5434. PatientId: patient_id,
  5435. RecordDate: record_time,
  5436. GoodId: item.GoodId,
  5437. GoodTypeId: item.GoodTypeId,
  5438. Count: item.Count,
  5439. Creater: adminInfo.AdminUser.Id,
  5440. Status: 1,
  5441. Ctime: time.Now().Unix(),
  5442. StorehouseId: houseConfig.StorehouseOutInfo,
  5443. }
  5444. //清空准备表数据
  5445. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5446. if errs != nil {
  5447. goodErrcode := models.XtGoodErrcode{
  5448. UserOrgId: adminInfo.Org.Id,
  5449. Errcode: "自动出库清空准备表数据报错",
  5450. GoodId: 0,
  5451. Status: 1,
  5452. Ctime: time.Now().Unix(),
  5453. Mtime: 0,
  5454. Count: 0,
  5455. StockCount: 0,
  5456. Creater: creator,
  5457. BatchNumberId: 0,
  5458. WarehouseOutId: 0,
  5459. }
  5460. service.CreateGoodErrcode(goodErrcode)
  5461. }
  5462. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  5463. if errcodes != nil {
  5464. goodErrcode := models.XtGoodErrcode{
  5465. UserOrgId: adminInfo.Org.Id,
  5466. Errcode: "自动出库创建准备表数据报错",
  5467. GoodId: 0,
  5468. Status: 1,
  5469. Ctime: time.Now().Unix(),
  5470. Mtime: 0,
  5471. Count: 0,
  5472. StockCount: 0,
  5473. Creater: creator,
  5474. BatchNumberId: 0,
  5475. WarehouseOutId: 0,
  5476. }
  5477. service.CreateGoodErrcode(goodErrcode)
  5478. }
  5479. //查询默认仓库
  5480. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5481. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5482. var total_count int64
  5483. for _, it := range stockList {
  5484. total_count += it.StockCount
  5485. }
  5486. //基础库插入数据
  5487. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5488. if errcodes != nil {
  5489. goodErrcode := models.XtGoodErrcode{
  5490. UserOrgId: adminInfo.Org.Id,
  5491. Errcode: "自动出库基础库插入数据报错",
  5492. GoodId: 0,
  5493. Status: 1,
  5494. Ctime: time.Now().Unix(),
  5495. Mtime: 0,
  5496. Count: 0,
  5497. StockCount: 0,
  5498. Creater: creator,
  5499. BatchNumberId: 0,
  5500. WarehouseOutId: 0,
  5501. }
  5502. service.CreateGoodErrcode(goodErrcode)
  5503. }
  5504. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5505. var flush_count int64
  5506. for _, it := range goodList {
  5507. flush_count += it.StockCount
  5508. }
  5509. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5510. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5511. if errss != nil {
  5512. goodErrcode := models.XtGoodErrcode{
  5513. UserOrgId: item.OrgId,
  5514. Errcode: "自动出库剩余库存更新数据",
  5515. GoodId: item.GoodId,
  5516. Status: 1,
  5517. Ctime: time.Now().Unix(),
  5518. Mtime: 0,
  5519. Count: 0,
  5520. StockCount: 0,
  5521. Creater: creater,
  5522. BatchNumberId: 0,
  5523. WarehouseOutId: 0,
  5524. }
  5525. service.CreateGoodErrcode(goodErrcode)
  5526. }
  5527. }
  5528. }
  5529. }
  5530. c.ServeSuccessJSON(map[string]interface{}{
  5531. "msg": "提交成功",
  5532. "message": "2",
  5533. "good_name": "",
  5534. "specification_name": "",
  5535. })
  5536. return
  5537. } else {
  5538. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  5539. return
  5540. }
  5541. }
  5542. func (c *DialysisAPIController) EditConsumables() {
  5543. patient_id, _ := c.GetInt64("patient_id", 0)
  5544. record_date := c.GetString("record_time")
  5545. if patient_id <= 0 {
  5546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5547. return
  5548. }
  5549. adminInfo := c.GetMobileAdminUserInfo()
  5550. timeLayout := "2006-01-02"
  5551. loc, _ := time.LoadLocation("Local")
  5552. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5553. record_time := theRecordTime.Unix()
  5554. // 查询信息规挡的设置天数
  5555. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5556. if infor.ID > 0 && infor.WeekDay > 0 {
  5557. var cha_time int64
  5558. timeNowStr := time.Now().Format("2006-01-02")
  5559. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5560. //今日的日期减去设置的日期
  5561. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5562. if cha_time >= record_time {
  5563. //查询审核是否允许
  5564. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id)
  5565. //申请状态不允许的情况 拒绝修改
  5566. if infor.ApplicationStatus != 1 {
  5567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5568. return
  5569. }
  5570. }
  5571. }
  5572. dataBody := make(map[string]interface{}, 0)
  5573. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5574. if err != nil {
  5575. utils.ErrorLog(err.Error())
  5576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5577. return
  5578. }
  5579. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5580. var beforePrepares []*models.DialysisBeforePrepareGoods
  5581. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5582. var cancelbefor []*models.DialysisBeforePrepareGoods
  5583. var outbefor []*models.DialysisBeforePrepareGoods
  5584. //判断是否开启自动出库
  5585. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5586. if record.IsOpen == 1 {
  5587. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5588. goods, _ := dataBody["goods"].([]interface{})
  5589. if len(goods) > 0 {
  5590. for _, item := range goods {
  5591. items := item.(map[string]interface{})
  5592. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5593. utils.ErrorLog("good_id")
  5594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5595. return
  5596. }
  5597. good_id := int64(items["good_id"].(float64))
  5598. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5599. utils.ErrorLog("good_type_id")
  5600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5601. return
  5602. }
  5603. good_type_id := int64(items["good_type_id"].(float64))
  5604. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5605. utils.ErrorLog("count")
  5606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5607. return
  5608. }
  5609. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5610. commdity_code := items["commdity_code"].(string)
  5611. fmt.Println(commdity_code)
  5612. prepareGoods := &models.DialysisBeforePrepareGoods{
  5613. GoodTypeId: good_type_id,
  5614. GoodId: good_id,
  5615. Count: count,
  5616. StorehouseId: houseConfig.StorehouseOutInfo,
  5617. }
  5618. beforePrepares = append(beforePrepares, prepareGoods)
  5619. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5620. GoodTypeId: good_type_id,
  5621. GoodId: good_id,
  5622. Count: count,
  5623. StorehouseId: houseConfig.StorehouseOutInfo,
  5624. }
  5625. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5626. }
  5627. for _, item := range beforePrepares {
  5628. //1.查看该患者该耗材型号最后一次出库数量
  5629. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5630. //判断当前出库数量和最后一次出库数量的大小
  5631. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  5632. if item.Count < goodInfo.Count {
  5633. cancelbefor = append(cancelbefor, item)
  5634. }
  5635. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5636. if item.Count > goodInfo.Count {
  5637. outbefor = append(outbefor, item)
  5638. }
  5639. //处理编辑耗材新增不了的问题
  5640. if goodInfo.Count == item.Count {
  5641. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  5642. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  5643. }
  5644. }
  5645. if len(cancelbefor) > 0 {
  5646. //退库
  5647. for _, item := range cancelbefor {
  5648. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5649. creater := adminInfo.AdminUser.Id
  5650. //查询该患者当天已经出库的耗材信息
  5651. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  5652. var delete_count int64 = 0
  5653. delete_count = warehouseOutInfos.Count - item.Count
  5654. //增加库存数量
  5655. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  5656. //减少实际出库库存数量
  5657. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  5658. // 删除出库完成后,要增加对应批次的库存数量
  5659. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  5660. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5661. //更新剩余库存
  5662. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  5663. var flush_count int64
  5664. for _, it := range goodListOne {
  5665. flush_count += it.StockCount
  5666. }
  5667. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5668. //查询剩余库存
  5669. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  5670. var sum_count int64
  5671. for _, item := range goodList {
  5672. sum_count += item.StockCount
  5673. }
  5674. // 在出库记录表里记录退库详情
  5675. warehouseOutInfo := &models.WarehouseOutInfo{
  5676. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5677. WarehouseOutId: warehouseOut.ID,
  5678. Status: 1,
  5679. Ctime: time.Now().Unix(),
  5680. OrgId: adminInfo.Org.Id,
  5681. Type: 1,
  5682. IsSys: 1,
  5683. SysRecordTime: record_time,
  5684. GoodTypeId: item.GoodTypeId,
  5685. GoodId: item.GoodId,
  5686. PatientId: patient_id,
  5687. ConsumableType: 2,
  5688. StorehouseId: houseConfig.StorehouseOutInfo,
  5689. IsCheck: 1,
  5690. OverCount: sum_count,
  5691. }
  5692. warehouseOutInfo.Count = item.Count
  5693. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  5694. warehouseOutInfo.Price = stockInInfo.Price
  5695. warehouseOutInfo.Dealer = stockInInfo.Dealer
  5696. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  5697. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  5698. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  5699. warehouseOutInfo.Number = warehouseOutInfos.Number
  5700. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  5701. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  5702. //查找当天是否存在出库记录
  5703. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  5704. if errcod == gorm.ErrRecordNotFound {
  5705. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  5706. //插入详情明细表
  5707. stockFlow := models.VmStockFlow{
  5708. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5709. WarehouseOutId: warehouseOut.ID,
  5710. GoodId: item.GoodId,
  5711. Number: warehouseOutInfos.Number,
  5712. ProductDate: stockInInfo.ProductDate,
  5713. ExpireDate: stockInInfo.ExpiryDate,
  5714. Count: item.Count,
  5715. Price: stockInInfo.Price,
  5716. Status: 1,
  5717. Ctime: time.Now().Unix(),
  5718. UserOrgId: adminInfo.Org.Id,
  5719. Manufacturer: stockInInfo.Manufacturer,
  5720. Dealer: stockInInfo.Dealer,
  5721. LicenseNumber: stockInInfo.LicenseNumber,
  5722. IsEdit: 2,
  5723. Creator: creater,
  5724. SystemTime: record_time,
  5725. ConsumableType: 3,
  5726. WarehousingDetailId: 0,
  5727. IsSys: 1,
  5728. UpdateCreator: creater,
  5729. PatientId: patient_id,
  5730. StorehouseId: houseConfig.StorehouseOutInfo,
  5731. }
  5732. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  5733. if errflow == gorm.ErrRecordNotFound {
  5734. //创建流水表
  5735. err := service.CreateStockFlowOne(stockFlow)
  5736. fmt.Println("err", err)
  5737. } else if errflow == nil {
  5738. //插入详情明细表
  5739. stockFlow := models.VmStockFlow{
  5740. ID: exsit.ID,
  5741. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  5742. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5743. WarehouseOutId: warehouseOut.ID,
  5744. GoodId: item.GoodId,
  5745. Number: warehouseOutInfos.Number,
  5746. ProductDate: stockInInfo.ProductDate,
  5747. ExpireDate: stockInInfo.ExpiryDate,
  5748. Count: exsit.Count - delete_count,
  5749. Price: stockInInfo.Price,
  5750. Status: 1,
  5751. Ctime: time.Now().Unix(),
  5752. UserOrgId: adminInfo.Org.Id,
  5753. Manufacturer: stockInInfo.Manufacturer,
  5754. Dealer: stockInInfo.Dealer,
  5755. LicenseNumber: stockInInfo.LicenseNumber,
  5756. IsEdit: 2,
  5757. Creator: creater,
  5758. SystemTime: record_time,
  5759. ConsumableType: 3,
  5760. WarehousingDetailId: 0,
  5761. IsSys: 1,
  5762. UpdateCreator: creater,
  5763. PatientId: patient_id,
  5764. StorehouseId: houseConfig.StorehouseOutInfo,
  5765. }
  5766. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  5767. }
  5768. } else if errcod == nil {
  5769. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  5770. //查询剩余库存
  5771. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  5772. var sum_count int64
  5773. for _, item := range goodList {
  5774. sum_count += item.StockCount
  5775. }
  5776. //创建退库单,生成退库数据
  5777. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5778. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  5779. operation_time := time.Now().Unix()
  5780. creater := adminInfo.AdminUser.Id
  5781. //创建退库单
  5782. timeStr := time.Now().Format("2006-01-02")
  5783. timeArr := strings.Split(timeStr, "-")
  5784. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  5785. total = total + 1
  5786. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5787. cancelStock := models.CancelStock{
  5788. OrderNumber: orderNumber,
  5789. OperaTime: operation_time,
  5790. OrgId: adminInfo.Org.Id,
  5791. Creater: creater,
  5792. Ctime: time.Now().Unix(),
  5793. Status: 1,
  5794. ReturnTime: record_time,
  5795. Type: 1,
  5796. StorehouseId: houseConfig.StorehouseOutInfo,
  5797. IsCheck: 1,
  5798. }
  5799. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  5800. if msgerrkonde == gorm.ErrRecordNotFound {
  5801. service.AddSigleCancelStock(&cancelStock)
  5802. }
  5803. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  5804. //查询是否有出库
  5805. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  5806. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5807. deaerler, _ := service.GetDealerById(info.Dealer)
  5808. if info.ID > 0 {
  5809. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  5810. cancelStockInfo := models.CancelStockInfo{
  5811. GoodId: item.GoodId,
  5812. CancelStockId: cancel.ID,
  5813. GoodTypeId: good.GoodTypeId,
  5814. Count: delete_count,
  5815. Price: info.Price,
  5816. Total: 0,
  5817. ProductDate: info.ProductDate,
  5818. ExpiryDate: info.ExpiryDate,
  5819. Ctime: time.Now().Unix(),
  5820. Status: 1,
  5821. OrgId: adminInfo.Org.Id,
  5822. OrderNumber: cancel.OrderNumber,
  5823. Type: 0,
  5824. Dealer: deaerler.DealerName,
  5825. Manufacturer: manufacturer.ManufacturerName,
  5826. Number: info.Number,
  5827. RegisterAccount: "",
  5828. Remark: "",
  5829. WarehouseInfoId: info.WarehouseInfotId,
  5830. PatientId: info.PatientId,
  5831. RecordDate: info.SysRecordTime,
  5832. StorehouseId: houseConfig.StorehouseOutInfo,
  5833. IsCheck: 1,
  5834. }
  5835. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5836. //退库数量增加
  5837. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  5838. //查询剩余库存
  5839. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  5840. var over_count int64
  5841. for _, it := range goodList {
  5842. over_count += it.StockCount
  5843. }
  5844. flow := models.VmStockFlow{
  5845. WarehousingId: info.WarehouseInfotId,
  5846. GoodId: item.GoodId,
  5847. Number: info.Number,
  5848. LicenseNumber: info.LicenseNumber,
  5849. Count: delete_count,
  5850. UserOrgId: adminInfo.Org.Id,
  5851. PatientId: patient_id,
  5852. SystemTime: info.SysRecordTime,
  5853. ConsumableType: 7,
  5854. IsSys: 0,
  5855. WarehousingOrder: "",
  5856. WarehouseOutId: info.WarehouseOutId,
  5857. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5858. IsEdit: 0,
  5859. CancelStockId: cancel.ID,
  5860. CancelOrderNumber: cancel.OrderNumber,
  5861. Manufacturer: manufacturer.ID,
  5862. Dealer: 0,
  5863. Creator: adminInfo.AdminUser.Id,
  5864. UpdateCreator: 0,
  5865. Status: 1,
  5866. Ctime: time.Now().Unix(),
  5867. Mtime: 0,
  5868. Price: info.Price,
  5869. WarehousingDetailId: info.WarehouseInfotId,
  5870. WarehouseOutDetailId: info.ID,
  5871. CancelOutDetailId: cancelInfo.ID,
  5872. ProductDate: info.ProductDate,
  5873. ExpireDate: info.ExpiryDate,
  5874. StorehouseId: houseConfig.StorehouseOutInfo,
  5875. OverCount: over_count,
  5876. }
  5877. service.CreateStockFlowOne(flow)
  5878. }
  5879. }
  5880. //更改自动出库的表格
  5881. details := models.BloodAutomaticReduceDetail{
  5882. WarehouseOutId: warehouseOutInfo.ID,
  5883. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  5884. PatientId: patient_id,
  5885. Ctime: time.Now().Unix(),
  5886. Mtime: time.Now().Unix(),
  5887. Status: 1,
  5888. RecordTime: record_time,
  5889. OrgId: adminInfo.Org.Id,
  5890. GoodId: item.GoodId,
  5891. GoodTypeId: item.GoodTypeId,
  5892. Count: item.Count,
  5893. StorehouseId: houseConfig.StorehouseOutInfo,
  5894. }
  5895. //查询当天耗材是否已经存在数据
  5896. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5897. if errcode == gorm.ErrRecordNotFound {
  5898. service.CreateAutoReduceRecord(&details)
  5899. } else if errcode == nil {
  5900. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5901. service.CreateAutoReduceRecord(&details)
  5902. }
  5903. //查询默认仓库
  5904. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5905. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5906. var total_count int64
  5907. for _, it := range stockList {
  5908. total_count += it.StockCount
  5909. }
  5910. //基础库插入数据
  5911. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5912. }
  5913. }
  5914. if len(outbefor) > 0 {
  5915. //出库
  5916. for _, item := range outbefor {
  5917. var last_total int64
  5918. //1.查看该患者该耗材型号最后一次出库数量
  5919. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5920. //计算当前出库和最后一次出库数据相差数据
  5921. last_total = item.Count - goodInfoOne.Count
  5922. //查询该耗材的总库存
  5923. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  5924. // 如果库存差大于剩余库存则提示库存不足
  5925. if last_total > wareinfo.StockCount {
  5926. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5927. c.ServeSuccessJSON(map[string]interface{}{
  5928. "message": "1",
  5929. "good_name": goodObj.GoodName,
  5930. "specification_name": goodObj.SpecificationName,
  5931. })
  5932. return
  5933. } else {
  5934. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5935. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5936. if err == gorm.ErrRecordNotFound {
  5937. //没有记录,则创建出库单
  5938. timeStr := time.Now().Format("2006-01-02")
  5939. timeArr := strings.Split(timeStr, "-")
  5940. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5941. total = total + 1
  5942. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5943. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5944. number = number + total
  5945. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5946. warehouseOut := models.WarehouseOut{
  5947. WarehouseOutOrderNumber: warehousing_out_order,
  5948. OperationTime: time.Now().Unix(),
  5949. OrgId: adminInfo.Org.Id,
  5950. Creater: adminInfo.AdminUser.Id,
  5951. Ctime: time.Now().Unix(),
  5952. Status: 1,
  5953. WarehouseOutTime: record_time,
  5954. Dealer: 0,
  5955. Manufacturer: 0,
  5956. Type: 1,
  5957. IsSys: 1,
  5958. StorehouseId: houseConfig.StorehouseOutInfo,
  5959. IsCheck: 1,
  5960. }
  5961. service.AddSigleWarehouseOut(&warehouseOut)
  5962. }
  5963. //出库
  5964. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  5965. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5966. //1.查看该患者该耗材型号最后一次出库数量
  5967. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5968. prepare := models.DialysisBeforePrepare{
  5969. UserOrgId: adminInfo.Org.Id,
  5970. PatientId: patient_id,
  5971. RecordDate: record_time,
  5972. GoodId: item.GoodId,
  5973. GoodTypeId: item.GoodTypeId,
  5974. Count: item.Count - goodInfoTwo.Count,
  5975. Ctime: time.Now().Unix(),
  5976. Mtime: 0,
  5977. Creater: adminInfo.AdminUser.Id,
  5978. Modifier: adminInfo.AdminUser.Id,
  5979. Status: 1,
  5980. CommdityCode: "",
  5981. NewCount: 0,
  5982. ProjectId: 0,
  5983. StorehouseId: houseConfig.StorehouseOutInfo,
  5984. }
  5985. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  5986. //增加出库数量
  5987. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  5988. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5989. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5990. var total_count int64
  5991. for _, it := range stockList {
  5992. total_count += it.StockCount
  5993. }
  5994. //基础库插入数据
  5995. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5996. //剩余库存
  5997. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5998. var flush_count int64
  5999. for _, it := range goodList {
  6000. flush_count += it.StockCount
  6001. }
  6002. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6003. }
  6004. }
  6005. }
  6006. //查询今日出库数据
  6007. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6008. for _, it := range list {
  6009. prepare := models.DialysisBeforePrepare{
  6010. UserOrgId: it.OrgId,
  6011. PatientId: patient_id,
  6012. RecordDate: it.RecordTime,
  6013. GoodId: it.GoodId,
  6014. GoodTypeId: it.GoodTypeId,
  6015. Count: it.Count,
  6016. Ctime: time.Now().Unix(),
  6017. Creater: adminInfo.AdminUser.Id,
  6018. Status: 1,
  6019. StorehouseId: houseConfig.StorehouseOutInfo,
  6020. ProjectId: it.ProjectId,
  6021. }
  6022. //删除准备表数据
  6023. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  6024. service.CreateDialysisBeforePrepareOne(&prepare)
  6025. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6026. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6027. var total_count int64
  6028. for _, it := range stockList {
  6029. total_count += it.StockCount
  6030. }
  6031. //基础库插入数据
  6032. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  6033. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  6034. var flush_count int64
  6035. for _, it := range goodList {
  6036. flush_count += it.StockCount
  6037. }
  6038. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  6039. }
  6040. }
  6041. }
  6042. //更新自动出库的地方
  6043. var errs error
  6044. if errs == nil {
  6045. c.ServeSuccessJSON(map[string]interface{}{
  6046. "msg": "修改成功",
  6047. "message": "2",
  6048. "good_name": "",
  6049. "specification_name": "",
  6050. })
  6051. return
  6052. } else {
  6053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6054. return
  6055. }
  6056. }
  6057. }
  6058. func (c *DialysisAPIController) GetDialysisGoods() {
  6059. schedualDate := c.GetString("schedule_date")
  6060. schedule_type, _ := c.GetInt64("schedule_type")
  6061. partition_id, _ := c.GetInt64("partition_id")
  6062. page, _ := c.GetInt("page")
  6063. patient_id, _ := c.GetInt64("patient_id")
  6064. schedualEndDate := int64(0)
  6065. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  6066. if parseDateErr != nil && len(schedualDate) != 0 {
  6067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6068. return
  6069. }
  6070. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  6071. if parseDateErr != nil && len(schedualDate) != 0 {
  6072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6073. return
  6074. }
  6075. schedualEndDate = endDate.Unix()
  6076. adminUser := c.GetMobileAdminUserInfo()
  6077. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  6078. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  6079. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6080. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6081. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  6082. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  6083. //获取当天该病人的透析处方
  6084. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6085. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6086. if err == gorm.ErrRecordNotFound {
  6087. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6088. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6089. if patient_id != 0 {
  6090. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6091. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6092. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6093. //获取患者总的出库数据
  6094. item.LastAutomaticReduceDetail = goodUser
  6095. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6096. item.Project = project
  6097. }
  6098. }
  6099. c.ServeSuccessJSON(map[string]interface{}{
  6100. "dialysis_goods": dialysisGoods,
  6101. "good_type": goodTypes,
  6102. "total": total,
  6103. "prescribe": prescribe,
  6104. "good_info": good_info,
  6105. "warehouseOutList": warehouseOutList,
  6106. "config": config,
  6107. "outConfig": outConfig,
  6108. "settleConfig": settleConfig,
  6109. })
  6110. return
  6111. } else if err == nil {
  6112. //获取当天排班的每个患者的库存使用情况
  6113. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6114. //获取患者总的出库数据
  6115. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6116. if patient_id != 0 {
  6117. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6118. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6119. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6120. item.Project = project
  6121. item.LastAutomaticReduceDetail = goodUser
  6122. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6123. }
  6124. }
  6125. if err == nil {
  6126. c.ServeSuccessJSON(map[string]interface{}{
  6127. "dialysis_goods": dialysisGoods,
  6128. "good_type": goodTypes,
  6129. "total": total,
  6130. "prescribe": prescribe,
  6131. "good_info": good_info,
  6132. "project": project,
  6133. "warehouseOutList": warehouseOutList,
  6134. "config": config,
  6135. "outConfig": outConfig,
  6136. "settleConfig": settleConfig,
  6137. })
  6138. return
  6139. } else {
  6140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6141. return
  6142. }
  6143. } else if err != nil {
  6144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6145. return
  6146. }
  6147. }
  6148. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  6149. start_time := c.GetString("start_time")
  6150. end_time := c.GetString("end_time")
  6151. timeLayout := "2006-01-02"
  6152. loc, _ := time.LoadLocation("Local")
  6153. var theStartTime int64
  6154. if len(start_time) > 0 {
  6155. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6156. if err != nil {
  6157. utils.ErrorLog(err.Error())
  6158. }
  6159. theStartTime = theTime.Unix()
  6160. }
  6161. var theEndtTime int64
  6162. if len(end_time) > 0 {
  6163. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6164. if err != nil {
  6165. utils.ErrorLog(err.Error())
  6166. }
  6167. theEndtTime = theTime.Unix()
  6168. }
  6169. adminUser := c.GetMobileAdminUserInfo()
  6170. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  6171. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  6172. if err == nil {
  6173. c.ServeSuccessJSON(map[string]interface{}{
  6174. "stock_out": outInfo,
  6175. "stockCount": stockCount,
  6176. })
  6177. return
  6178. } else {
  6179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6180. return
  6181. }
  6182. }
  6183. func (c *DialysisAPIController) GetStockInGoodInfo() {
  6184. patient_id, _ := c.GetInt64("patient_id", 0)
  6185. record_time := c.GetString("record_time")
  6186. adminUser := c.GetMobileAdminUserInfo()
  6187. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  6188. if parseDateErr != nil && len(record_time) != 0 {
  6189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6190. return
  6191. }
  6192. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  6193. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6194. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  6195. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  6196. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6197. //获取今日患者的透析处方参数
  6198. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6199. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  6200. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6201. c.ServeSuccessJSON(map[string]interface{}{
  6202. "good_type": goodTypes,
  6203. "good_user": goodUser,
  6204. "good_info": good_info,
  6205. "last_good_user": lastGoodUserDetial,
  6206. "project": project,
  6207. "prescription": prescribe,
  6208. "outInfo": outInfo,
  6209. "configs": configs,
  6210. })
  6211. return
  6212. }
  6213. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  6214. patient_id, _ := c.GetInt64("patient_id", 0)
  6215. record_date := c.GetString("record_time")
  6216. timeLayout := "2006-01-02"
  6217. loc, _ := time.LoadLocation("Local")
  6218. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6219. record_time := theRecordTime.Unix()
  6220. adminInfo := c.GetMobileAdminUserInfo()
  6221. dataBody := make(map[string]interface{}, 0)
  6222. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6223. if err != nil {
  6224. utils.ErrorLog(err.Error())
  6225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6226. return
  6227. }
  6228. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6229. var beforePrepares []*models.DialysisBeforePrepareGoods
  6230. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6231. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6232. goods, _ := dataBody["goods"].([]interface{})
  6233. if len(goods) > 0 {
  6234. for _, item := range goods {
  6235. items := item.(map[string]interface{})
  6236. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6237. utils.ErrorLog("good_id")
  6238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6239. return
  6240. }
  6241. good_id := int64(items["good_id"].(float64))
  6242. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6243. utils.ErrorLog("good_type_id")
  6244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6245. return
  6246. }
  6247. good_type_id := int64(items["good_type_id"].(float64))
  6248. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6249. utils.ErrorLog("count")
  6250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6251. return
  6252. }
  6253. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6254. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  6255. utils.ErrorLog("project_id")
  6256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6257. return
  6258. }
  6259. project_id := int64(items["project_id"].(float64))
  6260. new_count := int64(items["new_count"].(float64))
  6261. old_count := int64(items["old_count"].(float64))
  6262. prepare := &models.DialysisBeforePrepareGoods{
  6263. GoodId: good_id,
  6264. GoodTypeId: good_type_id,
  6265. Count: count,
  6266. ProjectId: project_id,
  6267. StorehouseId: houseConfig.StorehouseOutInfo,
  6268. NewCount: new_count,
  6269. OldCount: old_count,
  6270. }
  6271. beforePrepares = append(beforePrepares, prepare)
  6272. newPrepare := &models.NewDialysisBeforePrepareGoods{
  6273. GoodId: good_id,
  6274. GoodTypeId: good_type_id,
  6275. Count: count,
  6276. ProjectId: project_id,
  6277. StorehouseId: houseConfig.StorehouseOutInfo,
  6278. NewCount: new_count,
  6279. OldCount: old_count,
  6280. }
  6281. newBeforePrepares = append(newBeforePrepares, newPrepare)
  6282. }
  6283. }
  6284. }
  6285. //查询是否有库存
  6286. for _, item := range beforePrepares {
  6287. if item.NewCount > 0 {
  6288. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6289. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  6290. if item.Count > warehouse.Count {
  6291. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6292. c.ServeSuccessJSON(map[string]interface{}{
  6293. "message": "1",
  6294. "good_name": goodObj.GoodName,
  6295. "specification_name": goodObj.SpecificationName,
  6296. })
  6297. return
  6298. }
  6299. }
  6300. }
  6301. // 查询信息规挡的设置天数
  6302. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6303. if infor.ID > 0 && infor.WeekDay > 0 {
  6304. var cha_time int64
  6305. timeNowStr := time.Now().Format("2006-01-02")
  6306. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6307. //今日的日期减去设置的日期
  6308. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6309. if cha_time >= record_time {
  6310. //查询审核是否允许
  6311. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id)
  6312. //申请状态不允许的情况 拒绝修改
  6313. if infor.ApplicationStatus != 1 {
  6314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6315. return
  6316. }
  6317. }
  6318. }
  6319. //出库逻辑
  6320. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  6321. if err != nil {
  6322. utils.ErrorLog(err.Error())
  6323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6324. return
  6325. }
  6326. finish := models.XtDialysisFinish{
  6327. IsFinish: 1,
  6328. UserOrgId: adminInfo.Org.Id,
  6329. Status: 1,
  6330. Ctime: time.Now().Unix(),
  6331. Mtime: 0,
  6332. Module: 11,
  6333. RecordDate: record_time,
  6334. Sourse: 1,
  6335. PatientId: patient_id,
  6336. }
  6337. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6338. if dialysisFinish.ID == 0 {
  6339. service.CreateDialysisFinish(finish)
  6340. }
  6341. //查询当天出库的数据
  6342. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6343. for _, item := range list {
  6344. prepare := models.DialysisBeforePrepare{
  6345. UserOrgId: item.OrgId,
  6346. PatientId: item.PatientId,
  6347. RecordDate: item.RecordTime,
  6348. GoodId: item.GoodId,
  6349. GoodTypeId: item.GoodTypeId,
  6350. Count: item.Count,
  6351. Creater: adminInfo.AdminUser.Id,
  6352. Status: 1,
  6353. Ctime: time.Now().Unix(),
  6354. ProjectId: item.ProjectId,
  6355. StorehouseId: houseConfig.StorehouseOutInfo,
  6356. }
  6357. //清空准备表的数据
  6358. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6359. //插入准备表数据
  6360. service.CreateDialysisBeforePrepareOne(&prepare)
  6361. //查询默认仓库
  6362. //查询默认仓库
  6363. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6364. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6365. var total_count int64
  6366. for _, it := range stockList {
  6367. total_count += it.StockCount
  6368. }
  6369. //基础库插入数据
  6370. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6371. ////更新剩余库存
  6372. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6373. var flush_count int64
  6374. for _, it := range goodList {
  6375. flush_count += it.StockCount
  6376. }
  6377. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6378. if errs != nil {
  6379. goodErrcode := models.XtGoodErrcode{
  6380. UserOrgId: item.OrgId,
  6381. Errcode: "手动出库更新剩余出库失败",
  6382. GoodId: item.GoodId,
  6383. Status: 1,
  6384. Ctime: time.Now().Unix(),
  6385. Mtime: 0,
  6386. Count: 0,
  6387. StockCount: 0,
  6388. Creater: adminInfo.AdminUser.Id,
  6389. BatchNumberId: 0,
  6390. WarehouseOutId: 0,
  6391. }
  6392. service.CreateGoodErrcode(goodErrcode)
  6393. }
  6394. }
  6395. //更新自动出库的地方
  6396. var errs error
  6397. if errs == nil {
  6398. c.ServeSuccessJSON(map[string]interface{}{
  6399. "msg": "修改成功",
  6400. "message": "2",
  6401. "good_name": "",
  6402. "specification_name": "",
  6403. })
  6404. return
  6405. } else {
  6406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6407. return
  6408. }
  6409. }
  6410. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  6411. newArr = make([]*models.DialysisBeforePrepare, 0)
  6412. for i := 0; i < len(arr); i++ {
  6413. repeat := false
  6414. for j := i + 1; j < len(arr); j++ {
  6415. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  6416. repeat = true
  6417. break
  6418. }
  6419. }
  6420. if !repeat {
  6421. newArr = append(newArr, arr[i])
  6422. }
  6423. }
  6424. return
  6425. }
  6426. func (c *DialysisAPIController) GetAllDrug() {
  6427. patient_id, _ := c.GetInt64("patient_id", 0)
  6428. adminInfo := c.GetMobileAdminUserInfo()
  6429. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6430. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  6431. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  6432. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  6433. c.ServeSuccessJSON(map[string]interface{}{
  6434. "base_drug_config": drugStockConfig,
  6435. "private_drug_config": privateDrugConfig,
  6436. "base_drug_list": drugList,
  6437. "private_drug_list": privateDrugList,
  6438. })
  6439. }
  6440. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  6441. newArr = make([]*models.DialysisBeforePrepare, 0)
  6442. for i := 0; i < len(arr); i++ {
  6443. repeat := false
  6444. for j := i + 1; j < len(arr); j++ {
  6445. if arr[i].GoodId == arr[j].GoodId {
  6446. repeat = true
  6447. break
  6448. }
  6449. }
  6450. if !repeat {
  6451. newArr = append(newArr, arr[i])
  6452. }
  6453. }
  6454. return
  6455. }
  6456. func (c *DialysisAPIController) GetDepartment() {
  6457. adminInfo := c.GetMobileAdminUserInfo()
  6458. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  6459. if err == nil {
  6460. c.ServeSuccessJSON(map[string]interface{}{
  6461. "departments": departments,
  6462. })
  6463. } else {
  6464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6465. return
  6466. }
  6467. }
  6468. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  6469. types, _ := c.GetInt("type", 0)
  6470. start_time := c.GetString("start_time")
  6471. end_time := c.GetString("end_time")
  6472. orgId := c.GetMobileAdminUserInfo().Org.Id
  6473. timeLayout := "2006-01-02"
  6474. loc, _ := time.LoadLocation("Local")
  6475. var startTime int64
  6476. if len(start_time) > 0 {
  6477. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6478. if err != nil {
  6479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6480. return
  6481. }
  6482. startTime = theTime.Unix()
  6483. }
  6484. var endTime int64
  6485. if len(end_time) > 0 {
  6486. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6487. if err != nil {
  6488. utils.ErrorLog(err.Error())
  6489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6490. return
  6491. }
  6492. endTime = theTime.Unix()
  6493. }
  6494. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  6495. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  6496. if err != nil {
  6497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6498. } else {
  6499. c.ServeSuccessJSON(map[string]interface{}{
  6500. "list": list,
  6501. "type": types,
  6502. "stockTotal": stockTotal,
  6503. })
  6504. }
  6505. }
  6506. func (c *DialysisAPIController) BatchDeleteMonitor() {
  6507. ids := c.GetString("ids")
  6508. //patient_id, _ := c.GetInt64("patient_id")
  6509. //monitoring_date, _ := c.GetInt64("monitoring_date")
  6510. idArray := strings.Split(ids, ",")
  6511. err := service.BatchDeleteMonitor(idArray)
  6512. fmt.Print("err", err)
  6513. //orgid := c.GetMobileAdminUserInfo().Org.Id
  6514. //redis := service.RedisClient()
  6515. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  6516. //redis.Set(key, "", time.Second)
  6517. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  6518. //redis.Set(keyOne, "", time.Second)
  6519. //fmt.Println("keyo呢32332322332332232332",keyOne)
  6520. //redis.Close()
  6521. c.ServeSuccessJSON(map[string]interface{}{
  6522. "msg": "批量删除成功",
  6523. })
  6524. return
  6525. }
  6526. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  6527. id, _ := c.GetInt64("id")
  6528. timeLayout := "2006-01-02"
  6529. loc, _ := time.LoadLocation("Local")
  6530. start_time := time.Now().Format("2006-01-02")
  6531. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6532. nowTime := time.Now()
  6533. endTime := nowTime.AddDate(-2, 0, 0)
  6534. endTimes := endTime.Format("2006-01-02")
  6535. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", endTimes+" 00:00:00", loc)
  6536. list, _ := service.GetPatientDialysisRecordList(id, endtime.Unix(), startime.Unix())
  6537. fmt.Println("endtime232332322332322323232332", endTime.Unix())
  6538. c.ServeSuccessJSON(map[string]interface{}{
  6539. "list": list,
  6540. })
  6541. return
  6542. }
  6543. func (c *DialysisAPIController) BathDeleteAdviceList() {
  6544. dataBody := make(map[string]interface{}, 0)
  6545. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6546. ids := c.GetString("ids")
  6547. idArray := strings.Split(ids, ",")
  6548. origin, _ := c.GetInt64("origin")
  6549. if origin == 1 {
  6550. err = service.BatchDeleteAdvice(idArray)
  6551. fmt.Print("err", err)
  6552. c.ServeSuccessJSON(map[string]interface{}{
  6553. "msg": "批量删除成功",
  6554. })
  6555. return
  6556. }
  6557. if origin == 2 {
  6558. service.BatchDeleteHisAdvice(idArray)
  6559. }
  6560. }
  6561. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  6562. good_id, _ := c.GetInt64("good_id")
  6563. count, _ := c.GetInt64("count")
  6564. record_time, _ := c.GetInt64("record_time")
  6565. patient_id, _ := c.GetInt64("patient_id")
  6566. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  6567. c.ServeSuccessJSON(map[string]interface{}{
  6568. "detail": detail,
  6569. })
  6570. return
  6571. }
  6572. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  6573. good_id, _ := c.GetInt64("good_id")
  6574. record_time, _ := c.GetInt64("record_time")
  6575. patient_id, _ := c.GetInt64("patient_id")
  6576. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  6577. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  6578. fmt.Print("err", err)
  6579. c.ServeSuccessJSON(map[string]interface{}{
  6580. "msg": "批量删除成功",
  6581. })
  6582. return
  6583. }
  6584. func (c *DialysisAPIController) BatchAdviceCheck() {
  6585. ids := c.GetString("ids")
  6586. idArray := strings.Split(ids, ",")
  6587. creator, _ := c.GetInt64("creator")
  6588. origin, _ := c.GetInt64("origin")
  6589. if origin == 1 {
  6590. err := service.BatchAdviceCheck(idArray, creator)
  6591. fmt.Println(err)
  6592. list, _ := service.GetAdviceExecutionById(idArray)
  6593. c.ServeSuccessJSON(map[string]interface{}{
  6594. "list": list,
  6595. })
  6596. return
  6597. }
  6598. if origin == 2 {
  6599. service.BatchHisAdviceCheck(idArray, creator)
  6600. list, _ := service.GetHisAdviceExecutionById(idArray)
  6601. c.ServeSuccessJSON(map[string]interface{}{
  6602. "list": list,
  6603. })
  6604. return
  6605. }
  6606. }
  6607. func (c *DialysisAPIController) BatchAdviceExecution() {
  6608. ids := c.GetString("ids")
  6609. idArray := strings.Split(ids, ",")
  6610. executionTime := c.GetString("execution_time")
  6611. creator, _ := c.GetInt64("creator")
  6612. timeLayout := "2006-01-02 15:04:05"
  6613. loc, _ := time.LoadLocation("Local")
  6614. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  6615. orgin, _ := c.GetInt64("origin")
  6616. if orgin == 1 {
  6617. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  6618. list, _ := service.GetAdviceExecutionById(idArray)
  6619. fmt.Println(err)
  6620. c.ServeSuccessJSON(map[string]interface{}{
  6621. "list": list,
  6622. })
  6623. return
  6624. }
  6625. if orgin == 2 {
  6626. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  6627. list, _ := service.GetHisAdviceExecutionById(idArray)
  6628. fmt.Println(err)
  6629. c.ServeSuccessJSON(map[string]interface{}{
  6630. "list": list,
  6631. })
  6632. return
  6633. }
  6634. }
  6635. func (c *DialysisAPIController) UpdateStockGoods() {
  6636. good_id, _ := c.GetInt64("good_id")
  6637. record_time, _ := c.GetInt64("record_time")
  6638. patient_id, _ := c.GetInt64("patient_id")
  6639. count, _ := c.GetInt64("count")
  6640. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  6641. fmt.Print("err", err)
  6642. c.ServeSuccessJSON(map[string]interface{}{
  6643. "msg": "更新成功",
  6644. })
  6645. return
  6646. }
  6647. // 当前数据比上一次出库数据少
  6648. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  6649. //查询该患者当天已经出库的耗材信息
  6650. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  6651. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  6652. for i := len(goods_yc) - 1; i >= 0; i-- {
  6653. goods_yc_temp := goods_yc[i]
  6654. for j := len(goods) - 1; j >= 0; j-- {
  6655. goods_temp := goods[j]
  6656. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  6657. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  6658. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  6659. if goods_yc_temp.Count == goods_temp.Count {
  6660. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  6661. goods = append(goods[:j], goods[j+1:]...)
  6662. break
  6663. }
  6664. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  6665. if goods_yc_temp.Count > goods_temp.Count {
  6666. temp_count := goods_yc_temp.Count - goods_temp.Count
  6667. goods_yc[i].Count = temp_count
  6668. goods = append(goods[:j], goods[j+1:]...)
  6669. break
  6670. }
  6671. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  6672. if goods_yc_temp.Count < goods_temp.Count {
  6673. temp_count := goods_temp.Count - goods_yc_temp.Count
  6674. goods[j].Count = temp_count
  6675. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  6676. break
  6677. }
  6678. }
  6679. }
  6680. }
  6681. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  6682. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  6683. //退库
  6684. if len(goods_yc) > 0 {
  6685. for _, good_yc := range goods_yc {
  6686. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  6687. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  6688. }
  6689. }
  6690. return nil
  6691. }
  6692. // 耗材出库删除
  6693. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  6694. // 先根据相关信息查询当天该耗材的出库信息
  6695. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  6696. if err != nil {
  6697. return err
  6698. }
  6699. var delete_count int64 = 0
  6700. delete_count = warehouseOutInfos.Count - count
  6701. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  6702. // 在出库记录表里记录退库详情
  6703. warehouseOutInfo := &models.WarehouseOutInfo{
  6704. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6705. WarehouseOutId: warehouseOut.ID,
  6706. Status: 1,
  6707. Ctime: time.Now().Unix(),
  6708. OrgId: orgID,
  6709. Type: 1,
  6710. IsSys: 1,
  6711. SysRecordTime: record_time,
  6712. GoodTypeId: good_yc.GoodTypeId,
  6713. GoodId: good_yc.GoodId,
  6714. PatientId: good_yc.PatientId,
  6715. ConsumableType: 2,
  6716. StorehouseId: houseConfig.StorehouseOutInfo,
  6717. IsCheck: 1,
  6718. }
  6719. warehouseOutInfo.Count = count
  6720. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  6721. warehouseOutInfo.Price = stockInInfo.Price
  6722. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6723. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6724. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6725. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6726. warehouseOutInfo.Number = warehouseOutInfos.Number
  6727. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6728. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6729. //查找当天是否存在出库记录
  6730. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  6731. if errcod == gorm.ErrRecordNotFound {
  6732. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6733. //插入详情明细表
  6734. stockFlow := models.VmStockFlow{
  6735. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6736. WarehouseOutId: warehouseOut.ID,
  6737. GoodId: good_yc.GoodId,
  6738. Number: warehouseOutInfos.Number,
  6739. ProductDate: stockInInfo.ProductDate,
  6740. ExpireDate: stockInInfo.ExpiryDate,
  6741. Count: count,
  6742. Price: stockInInfo.Price,
  6743. Status: 1,
  6744. Ctime: time.Now().Unix(),
  6745. UserOrgId: good_yc.OrgId,
  6746. Manufacturer: stockInInfo.Manufacturer,
  6747. Dealer: stockInInfo.Dealer,
  6748. LicenseNumber: stockInInfo.LicenseNumber,
  6749. IsEdit: 2,
  6750. Creator: creater,
  6751. SystemTime: record_time,
  6752. ConsumableType: 3,
  6753. WarehousingDetailId: 0,
  6754. IsSys: 1,
  6755. UpdateCreator: creater,
  6756. PatientId: patient_id,
  6757. StorehouseId: houseConfig.StorehouseOutInfo,
  6758. }
  6759. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  6760. if errflow == gorm.ErrRecordNotFound {
  6761. //创建流水表
  6762. err := service.CreateStockFlowOne(stockFlow)
  6763. fmt.Println("err", err)
  6764. } else if errflow == nil {
  6765. //插入详情明细表
  6766. stockFlow := models.VmStockFlow{
  6767. ID: exsit.ID,
  6768. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6769. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6770. WarehouseOutId: warehouseOut.ID,
  6771. GoodId: good_yc.GoodId,
  6772. Number: warehouseOutInfos.Number,
  6773. ProductDate: stockInInfo.ProductDate,
  6774. ExpireDate: stockInInfo.ExpiryDate,
  6775. Count: exsit.Count - delete_count,
  6776. Price: stockInInfo.Price,
  6777. Status: 1,
  6778. Ctime: time.Now().Unix(),
  6779. UserOrgId: good_yc.OrgId,
  6780. Manufacturer: stockInInfo.Manufacturer,
  6781. Dealer: stockInInfo.Dealer,
  6782. LicenseNumber: stockInInfo.LicenseNumber,
  6783. IsEdit: 2,
  6784. Creator: creater,
  6785. SystemTime: record_time,
  6786. ConsumableType: 3,
  6787. WarehousingDetailId: 0,
  6788. IsSys: 1,
  6789. UpdateCreator: creater,
  6790. PatientId: patient_id,
  6791. StorehouseId: houseConfig.StorehouseOutInfo,
  6792. }
  6793. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  6794. }
  6795. if errOne != nil {
  6796. return errOne
  6797. }
  6798. } else if errcod == nil {
  6799. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  6800. //插入详情明细表
  6801. stockFlow := models.VmStockFlow{
  6802. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6803. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6804. WarehouseOutId: warehouseOut.ID,
  6805. GoodId: good_yc.GoodId,
  6806. Number: warehouseOutInfos.Number,
  6807. ProductDate: stockInInfo.ProductDate,
  6808. ExpireDate: stockInInfo.ExpiryDate,
  6809. Count: count,
  6810. Price: stockInInfo.Price,
  6811. Status: 1,
  6812. Ctime: time.Now().Unix(),
  6813. UserOrgId: good_yc.OrgId,
  6814. Manufacturer: stockInInfo.Manufacturer,
  6815. Dealer: stockInInfo.Dealer,
  6816. LicenseNumber: stockInInfo.LicenseNumber,
  6817. IsEdit: 2,
  6818. Creator: creater,
  6819. SystemTime: record_time,
  6820. ConsumableType: 3,
  6821. WarehousingDetailId: 0,
  6822. IsSys: 1,
  6823. UpdateCreator: creater,
  6824. PatientId: patient_id,
  6825. ReturnCount: delete_count,
  6826. StorehouseId: houseConfig.StorehouseOutInfo,
  6827. }
  6828. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  6829. if errflows == gorm.ErrRecordNotFound {
  6830. //创建流水表
  6831. service.CreateStockFlowOne(stockFlow)
  6832. } else if errflows == nil {
  6833. stockFlow := models.VmStockFlow{
  6834. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6835. ID: exsit.ID,
  6836. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6837. WarehouseOutId: warehouseOut.ID,
  6838. GoodId: good_yc.GoodId,
  6839. Number: warehouseOutInfos.Number,
  6840. ProductDate: stockInInfo.ProductDate,
  6841. ExpireDate: stockInInfo.ExpiryDate,
  6842. Count: exsit.Count - delete_count,
  6843. Price: stockInInfo.Price,
  6844. Status: 1,
  6845. Ctime: time.Now().Unix(),
  6846. UserOrgId: good_yc.OrgId,
  6847. Manufacturer: stockInInfo.Manufacturer,
  6848. Dealer: stockInInfo.Dealer,
  6849. LicenseNumber: stockInInfo.LicenseNumber,
  6850. IsEdit: 2,
  6851. Creator: creater,
  6852. SystemTime: record_time,
  6853. ConsumableType: 3,
  6854. WarehousingDetailId: 0,
  6855. IsSys: 1,
  6856. UpdateCreator: creater,
  6857. PatientId: patient_id,
  6858. ReturnCount: delete_count,
  6859. StorehouseId: houseConfig.StorehouseOutInfo,
  6860. }
  6861. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  6862. }
  6863. }
  6864. //更改自动出库的表格
  6865. details := models.BloodAutomaticReduceDetail{
  6866. WarehouseOutId: warehouseOutInfo.ID,
  6867. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6868. PatientId: patient_id,
  6869. Ctime: time.Now().Unix(),
  6870. Mtime: time.Now().Unix(),
  6871. Status: 1,
  6872. RecordTime: record_time,
  6873. OrgId: orgID,
  6874. GoodId: good_yc.GoodId,
  6875. GoodTypeId: good_yc.GoodTypeId,
  6876. Count: count,
  6877. StorehouseId: houseConfig.StorehouseOutInfo,
  6878. }
  6879. //查询当天耗材是否已经存在数据
  6880. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  6881. if errcode == gorm.ErrRecordNotFound {
  6882. errTwo := service.CreateAutoReduceRecord(&details)
  6883. if errTwo != nil {
  6884. return errTwo
  6885. }
  6886. } else if errcode == nil {
  6887. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  6888. service.CreateAutoReduceRecord(&details)
  6889. }
  6890. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  6891. //增加出库库存数量
  6892. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  6893. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  6894. fmt.Println("errOne", errOne)
  6895. // 删除出库完成后,要增加对应批次的库存数量
  6896. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  6897. if errThree != nil {
  6898. return errThree
  6899. }
  6900. if good_yc.Count == 0 {
  6901. return nil
  6902. } else {
  6903. return errors.New("退库和出库数据不匹配")
  6904. }
  6905. }
  6906. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  6907. //查询该患者当天已经出库的耗材信息
  6908. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  6909. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  6910. for i := len(goods_yc) - 1; i >= 0; i-- {
  6911. goods_yc_temp := goods_yc[i]
  6912. for j := len(goods) - 1; j >= 0; j-- {
  6913. goods_temp := goods[j]
  6914. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  6915. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  6916. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  6917. if goods_yc_temp.Count == goods_temp.Count {
  6918. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  6919. goods = append(goods[:j], goods[j+1:]...)
  6920. break
  6921. }
  6922. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  6923. if goods_yc_temp.Count > goods_temp.Count {
  6924. temp_count := goods_yc_temp.Count - goods_temp.Count
  6925. goods_yc[i].Count = temp_count
  6926. goods = append(goods[:j], goods[j+1:]...)
  6927. break
  6928. }
  6929. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  6930. if goods_yc_temp.Count < goods_temp.Count {
  6931. temp_count := goods_temp.Count - goods_yc_temp.Count
  6932. goods[j].Count = temp_count
  6933. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  6934. break
  6935. }
  6936. }
  6937. }
  6938. }
  6939. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  6940. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  6941. fmt.Println("剩余需要出库的", len(goods))
  6942. if len(goods) > 0 {
  6943. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  6944. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  6945. if err == gorm.ErrRecordNotFound {
  6946. //没有记录,则创建出库单
  6947. timeStr := time.Now().Format("2006-01-02")
  6948. timeArr := strings.Split(timeStr, "-")
  6949. total, _ := service.FindAllWarehouseOut(orgID)
  6950. total = total + 1
  6951. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6952. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6953. number = number + total
  6954. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6955. warehouseOut := models.WarehouseOut{
  6956. WarehouseOutOrderNumber: warehousing_out_order,
  6957. OperationTime: time.Now().Unix(),
  6958. OrgId: orgID,
  6959. Creater: creater,
  6960. Ctime: time.Now().Unix(),
  6961. Status: 1,
  6962. WarehouseOutTime: record_time,
  6963. Dealer: 0,
  6964. Manufacturer: 0,
  6965. Type: 1,
  6966. IsSys: 1,
  6967. StorehouseId: houseConfig.StorehouseOutInfo,
  6968. IsCheck: 1,
  6969. }
  6970. err := service.AddSigleWarehouseOut(&warehouseOut)
  6971. if err != nil {
  6972. utils.TraceLog("创建出库单失败 err = %v", err)
  6973. return err
  6974. } else {
  6975. out = warehouseOut
  6976. }
  6977. }
  6978. for _, item := range goods {
  6979. var newCount int64 = 0
  6980. for _, it := range goodOne {
  6981. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  6982. newCount = it.Count
  6983. }
  6984. }
  6985. prepare := models.DialysisBeforePrepare{
  6986. GoodTypeId: item.GoodTypeId,
  6987. GoodId: item.GoodId,
  6988. Count: item.Count,
  6989. StorehouseId: houseConfig.StorehouseOutInfo,
  6990. }
  6991. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  6992. //增加出库数量
  6993. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  6994. }
  6995. }
  6996. if len(goods_yc) > 0 {
  6997. for _, good_yc := range goods_yc {
  6998. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  6999. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  7000. }
  7001. }
  7002. return nil
  7003. }
  7004. // 耗材出库删除
  7005. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  7006. // 先根据相关信息查询当天该耗材的出库信息
  7007. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  7008. if err != nil {
  7009. return err
  7010. }
  7011. var delete_count int64 = 0
  7012. for _, ware := range warehouseOutInfos {
  7013. // 判断当前出库的数据和删除出库数量
  7014. if good_yc.Count <= ware.Count {
  7015. delete_count = good_yc.Count
  7016. } else {
  7017. delete_count = ware.Count
  7018. }
  7019. warehouseOutInfo := &models.WarehouseOutInfo{
  7020. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7021. WarehouseOutId: warehouseOut.ID,
  7022. Status: 1,
  7023. Ctime: time.Now().Unix(),
  7024. Remark: "",
  7025. OrgId: orgID,
  7026. Type: 1,
  7027. Manufacturer: 0,
  7028. Dealer: 0,
  7029. IsSys: 0,
  7030. SysRecordTime: record_time,
  7031. GoodTypeId: good_yc.GoodTypeId,
  7032. GoodId: good_yc.GoodId,
  7033. StorehouseId: warehouseOut.StorehouseId,
  7034. IsCheck: 1,
  7035. }
  7036. warehouseOutInfo.Count = delete_count
  7037. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7038. warehouseOutInfo.Price = stockInInfo.Price
  7039. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7040. if errOne != nil {
  7041. return errOne
  7042. }
  7043. // 删除出库完成后,要改变流水库存(有疑问)
  7044. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7045. fmt.Println("errOne", errOne)
  7046. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  7047. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7048. //扣减出库数量
  7049. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  7050. if errThree != nil {
  7051. return errThree
  7052. }
  7053. }
  7054. if good_yc.Count == 0 {
  7055. return nil
  7056. } else {
  7057. return errors.New("退库和出库数据不匹配")
  7058. }
  7059. }
  7060. func (this *DialysisAPIController) GetMobileScheduleList() {
  7061. limit, _ := this.GetInt64("limit")
  7062. page, _ := this.GetInt64("page")
  7063. type_options_visible, _ := this.GetInt64("type_options_visible")
  7064. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  7065. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  7066. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  7067. }
  7068. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  7069. newArr = make([]*models.HisPrescriptionProject, 0)
  7070. for i := 0; i < len(arr); i++ {
  7071. repeat := false
  7072. for j := i + 1; j < len(arr); j++ {
  7073. if arr[i].TeamId == arr[j].TeamId {
  7074. repeat = true
  7075. break
  7076. }
  7077. }
  7078. if !repeat {
  7079. newArr = append(newArr, arr[i])
  7080. }
  7081. }
  7082. return
  7083. }
  7084. func (this *DialysisAPIController) GetRoleList() {
  7085. admin_user_id, _ := this.GetInt64("admin_user_id")
  7086. orgid := this.GetMobileAdminUserInfo().Org.Id
  7087. list, err := service.GetRoleList(orgid, admin_user_id)
  7088. fmt.Println(err)
  7089. this.ServeSuccessJSON(map[string]interface{}{
  7090. "list": list,
  7091. })
  7092. return
  7093. }
  7094. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7095. fmt.Println("退库222322232322332232332322332232332233wo", good_yc.GoodId)
  7096. // 先根据相关信息查询当天该耗材的出库信息
  7097. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7098. if err != nil {
  7099. return err
  7100. }
  7101. var delete_count int64 = 0
  7102. delete_count = warehouseOutInfos.Count - count
  7103. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7104. // 删除出库完成后,要增加对应批次的库存数量
  7105. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7106. if errThree != nil {
  7107. return errThree
  7108. }
  7109. //增加退库数量
  7110. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7111. //扣减出库数量
  7112. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  7113. //查询剩余库存
  7114. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  7115. var sum_count int64
  7116. for _, item := range goodList {
  7117. sum_count += item.StockCount
  7118. }
  7119. // 在出库记录表里记录退库详情
  7120. warehouseOutInfo := &models.WarehouseOutInfo{
  7121. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7122. WarehouseOutId: warehouseOut.ID,
  7123. Status: 1,
  7124. Ctime: time.Now().Unix(),
  7125. OrgId: orgID,
  7126. Type: 1,
  7127. IsSys: 1,
  7128. SysRecordTime: record_time,
  7129. GoodTypeId: good_yc.GoodTypeId,
  7130. GoodId: good_yc.GoodId,
  7131. PatientId: good_yc.PatientId,
  7132. ConsumableType: 2,
  7133. StorehouseId: houseConfig.StorehouseOutInfo,
  7134. IsCheck: 1,
  7135. OverCount: sum_count,
  7136. }
  7137. warehouseOutInfo.Count = count
  7138. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7139. warehouseOutInfo.Price = stockInInfo.Price
  7140. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7141. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7142. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7143. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7144. warehouseOutInfo.Number = warehouseOutInfos.Number
  7145. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7146. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7147. //查找当天是否存在出库记录
  7148. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7149. if errcod == gorm.ErrRecordNotFound {
  7150. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7151. //插入详情明细表
  7152. if errOne != nil {
  7153. return errOne
  7154. }
  7155. //插入详情明细表
  7156. stockFlow := models.VmStockFlow{
  7157. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7158. WarehouseOutId: warehouseOut.ID,
  7159. GoodId: good_yc.GoodId,
  7160. Number: warehouseOutInfos.Number,
  7161. ProductDate: stockInInfo.ProductDate,
  7162. ExpireDate: stockInInfo.ExpiryDate,
  7163. Count: count,
  7164. Price: stockInInfo.Price,
  7165. Status: 1,
  7166. Ctime: time.Now().Unix(),
  7167. UserOrgId: good_yc.OrgId,
  7168. Manufacturer: stockInInfo.Manufacturer,
  7169. Dealer: stockInInfo.Dealer,
  7170. LicenseNumber: stockInInfo.LicenseNumber,
  7171. IsEdit: 2,
  7172. Creator: creater,
  7173. SystemTime: record_time,
  7174. ConsumableType: 3,
  7175. WarehousingDetailId: 0,
  7176. IsSys: 1,
  7177. UpdateCreator: creater,
  7178. PatientId: patient_id,
  7179. StorehouseId: houseConfig.StorehouseOutInfo,
  7180. OverCount: sum_count,
  7181. ProjectId: good_yc.ProjectId,
  7182. }
  7183. err := service.CreateStockFlowOne(stockFlow)
  7184. fmt.Println("err", err)
  7185. } else if errcod == nil {
  7186. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7187. }
  7188. //创建退库单
  7189. operation_time := time.Now().Unix()
  7190. //创建退库单
  7191. timeStr := time.Now().Format("2006-01-02")
  7192. timeArr := strings.Split(timeStr, "-")
  7193. total, _ := service.FindAllCancelStockTotal(orgID)
  7194. total = total + 1
  7195. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7196. cancelStock := models.CancelStock{
  7197. OrderNumber: orderNumber,
  7198. OperaTime: operation_time,
  7199. OrgId: orgID,
  7200. Creater: warehouseOut.Creater,
  7201. Ctime: time.Now().Unix(),
  7202. Status: 1,
  7203. ReturnTime: record_time,
  7204. Type: 1,
  7205. StorehouseId: stockInInfo.StorehouseId,
  7206. IsCheck: 1,
  7207. }
  7208. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  7209. if msgerrkonde == gorm.ErrRecordNotFound {
  7210. service.AddSigleCancelStock(&cancelStock)
  7211. }
  7212. cancel, _ := service.GetLastCancelStockById(orgID)
  7213. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  7214. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  7215. cancelStockInfo := models.CancelStockInfo{
  7216. GoodId: stockInInfo.GoodId,
  7217. CancelStockId: cancel.ID,
  7218. GoodTypeId: stockInInfo.GoodTypeId,
  7219. Count: delete_count,
  7220. Price: stockInInfo.PackingPrice,
  7221. Total: 0,
  7222. ProductDate: stockInInfo.ProductDate,
  7223. ExpiryDate: stockInInfo.ExpiryDate,
  7224. Ctime: time.Now().Unix(),
  7225. Status: 1,
  7226. OrgId: orgID,
  7227. OrderNumber: cancel.OrderNumber,
  7228. Type: 0,
  7229. Dealer: deaerler.DealerName,
  7230. Manufacturer: manufacturer.ManufacturerName,
  7231. Number: stockInInfo.Number,
  7232. RegisterAccount: "",
  7233. Remark: "",
  7234. WarehouseInfoId: stockInInfo.ID,
  7235. PatientId: patient_id,
  7236. RecordDate: record_time,
  7237. StorehouseId: stockInInfo.StorehouseId,
  7238. IsCheck: 1,
  7239. }
  7240. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7241. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  7242. flow := models.VmStockFlow{
  7243. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  7244. GoodId: good_yc.GoodId,
  7245. Number: warehouseOutInfos.Number,
  7246. LicenseNumber: stockInInfo.LicenseNumber,
  7247. Count: delete_count,
  7248. UserOrgId: orgID,
  7249. PatientId: patient_id,
  7250. SystemTime: record_time,
  7251. ConsumableType: 7,
  7252. IsSys: 0,
  7253. WarehousingOrder: "",
  7254. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  7255. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7256. IsEdit: 0,
  7257. CancelStockId: cancel.ID,
  7258. CancelOrderNumber: cancel.OrderNumber,
  7259. Manufacturer: manufacturer.ID,
  7260. Dealer: 0,
  7261. Creator: warehouseOut.Creater,
  7262. UpdateCreator: 0,
  7263. Status: 1,
  7264. Ctime: time.Now().Unix(),
  7265. Mtime: 0,
  7266. Price: stockInInfo.Price,
  7267. WarehousingDetailId: stockInInfo.ID,
  7268. WarehouseOutDetailId: warehouseOutInfos.ID,
  7269. CancelOutDetailId: cancelInfo.ID,
  7270. ProductDate: stockInInfo.ProductDate,
  7271. ExpireDate: stockInInfo.ExpiryDate,
  7272. StorehouseId: houseConfig.StorehouseOutInfo,
  7273. OverCount: sum_count,
  7274. }
  7275. service.CreateStockFlowOne(flow)
  7276. //更改自动出库的表格
  7277. details := models.BloodAutomaticReduceDetail{
  7278. WarehouseOutId: warehouseOutInfo.ID,
  7279. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7280. PatientId: patient_id,
  7281. Ctime: time.Now().Unix(),
  7282. Mtime: time.Now().Unix(),
  7283. Status: 1,
  7284. RecordTime: record_time,
  7285. OrgId: orgID,
  7286. GoodId: good_yc.GoodId,
  7287. GoodTypeId: good_yc.GoodTypeId,
  7288. Count: count,
  7289. StorehouseId: houseConfig.StorehouseOutInfo,
  7290. }
  7291. //查询当天耗材是否已经存在数据
  7292. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7293. if errcode == gorm.ErrRecordNotFound {
  7294. errTwo := service.CreateAutoReduceRecord(&details)
  7295. if errTwo != nil {
  7296. return errTwo
  7297. }
  7298. } else if errcode == nil {
  7299. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7300. service.CreateAutoReduceRecord(&details)
  7301. }
  7302. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7303. //增加出库库存数量
  7304. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  7305. if good_yc.Count == 0 {
  7306. return nil
  7307. } else {
  7308. return errors.New("退库和出库数据不匹配")
  7309. }
  7310. }
  7311. func (this *DialysisAPIController) SavePatientSign() {
  7312. adminUserInfo := this.GetMobileAdminUserInfo()
  7313. patient_id, _ := this.GetInt64("patient_id")
  7314. dialysis_date, _ := this.GetInt64("dialysis_date")
  7315. orgid := adminUserInfo.Org.Id
  7316. var esdata models.DialysisOrder
  7317. var err error
  7318. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  7319. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7320. return
  7321. }
  7322. esdata.Hash = esdata.Hash
  7323. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  7324. order := models.DialysisOrder{
  7325. Hash: esdata.Hash,
  7326. Url: esdata.Url,
  7327. }
  7328. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  7329. redis := service.RedisClient()
  7330. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  7331. redis.Set(key, "", time.Second)
  7332. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  7333. //清空key 值
  7334. redis.Set(keyOne, "", time.Second)
  7335. //scheduleDateStartOne := startDate.Format("2006-01-02")
  7336. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  7337. //redis.Set(keyTwo, "", time.Second)
  7338. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  7339. redis.Set(keyThree, "", time.Second)
  7340. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  7341. redis.Set(keyFour, "", time.Second)
  7342. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  7343. redis.Set(keyFive, "", time.Second)
  7344. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  7345. redis.Set(keySix, "", time.Second)
  7346. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  7347. redis.Set(keySeven, "", time.Second)
  7348. if err != nil {
  7349. fmt.Println(err)
  7350. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  7351. return
  7352. }
  7353. this.ServeSuccessJSON(map[string]interface{}{
  7354. "electronic_signature": esdata,
  7355. })
  7356. }
  7357. func (this *DialysisAPIController) GetPatientSign() {
  7358. patient_id, _ := this.GetInt64("patient_id")
  7359. dialysis_date, _ := this.GetInt64("dialysis_date")
  7360. adminUserInfo := this.GetMobileAdminUserInfo()
  7361. orgId := adminUserInfo.Org.Id
  7362. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  7363. if err != nil {
  7364. fmt.Println(err)
  7365. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  7366. return
  7367. }
  7368. this.ServeSuccessJSON(map[string]interface{}{
  7369. "dialysisOrder": dialysisOrder,
  7370. })
  7371. }
  7372. func (this *DialysisAPIController) GetScheduleByPatient() {
  7373. patient_id, _ := this.GetInt64("patient_id")
  7374. schedule_date, _ := this.GetInt64("schedule_date")
  7375. orgid := this.GetMobileAdminUserInfo().Org.Id
  7376. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  7377. this.ServeSuccessJSON(map[string]interface{}{
  7378. "schedule": schedule,
  7379. })
  7380. }
  7381. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  7382. org_id := this.GetMobileAdminUserInfo().Org.Id
  7383. patient_id, _ := this.GetInt64("patient_id")
  7384. schedule_date, _ := this.GetInt64("schedule_date")
  7385. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  7386. this.ServeSuccessJSON(map[string]interface{}{
  7387. "order": order,
  7388. })
  7389. }
  7390. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  7391. org_id := this.GetMobileAdminUserInfo().Org.Id
  7392. schedule_date := this.GetString("schedule_date")
  7393. schedule_type, _ := this.GetInt64("schedule_type")
  7394. timeLayout := "2006-01-02"
  7395. loc, _ := time.LoadLocation("Local")
  7396. var startdateunix int64
  7397. if len(schedule_date) > 0 {
  7398. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  7399. if err != nil {
  7400. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7401. return
  7402. }
  7403. startdateunix = theTime.Unix()
  7404. }
  7405. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  7406. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  7407. devices, _ := service.GetAllDevicetByListSix(org_id)
  7408. for key, item := range scheduals {
  7409. // 床位信息
  7410. for _, device := range devices {
  7411. if item.BedId == device.ID {
  7412. scheduals[key].DeviceNumber = device
  7413. break
  7414. }
  7415. }
  7416. }
  7417. this.ServeSuccessJSON(map[string]interface{}{
  7418. "list": list,
  7419. "scheduals": scheduals,
  7420. })
  7421. }
  7422. func (this *DialysisAPIController) SavePatientPicture() {
  7423. patient_id, _ := this.GetInt64("patient_id")
  7424. dialysis_date, _ := this.GetInt64("schedule_date")
  7425. avatar := this.GetString("avatar")
  7426. fmt.Println("patient_id", patient_id)
  7427. orgId := this.GetMobileAdminUserInfo().Org.Id
  7428. order := models.DialysisOrder{
  7429. Url: avatar,
  7430. }
  7431. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  7432. redis := service.RedisClient()
  7433. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  7434. redis.Set(key, "", time.Second)
  7435. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  7436. //清空key 值
  7437. redis.Set(keyOne, "", time.Second)
  7438. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  7439. redis.Set(keyThree, "", time.Second)
  7440. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  7441. redis.Set(keyFour, "", time.Second)
  7442. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  7443. redis.Set(keyFive, "", time.Second)
  7444. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  7445. redis.Set(keySix, "", time.Second)
  7446. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  7447. redis.Set(keySeven, "", time.Second)
  7448. if err != nil {
  7449. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  7450. return
  7451. }
  7452. this.ServeSuccessJSON(map[string]interface{}{
  7453. "order": order,
  7454. })
  7455. }
  7456. func (this *DialysisAPIController) ExectionMobileAdvice() {
  7457. ids := this.GetString("ids")
  7458. idSplit := strings.Split(ids, ",")
  7459. orgId := this.GetMobileAdminUserInfo().Org.Id
  7460. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  7461. execution_time := this.GetString("exce_time")
  7462. timeLayout2 := "2006-01-02 15:04:05"
  7463. loc, _ := time.LoadLocation("Local")
  7464. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  7465. if errs != nil {
  7466. utils.ErrorLog(errs.Error())
  7467. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7468. return
  7469. }
  7470. //his客户
  7471. if config.IsOpen == 1 {
  7472. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  7473. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  7474. for _, item := range list {
  7475. for _, it := range adviceList {
  7476. if item.DrugId == it.DrugId {
  7477. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  7478. }
  7479. }
  7480. }
  7481. for _, item := range list {
  7482. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  7483. var sum_out_count int64
  7484. for _, itemThree := range item.ChildDoctorAdvice {
  7485. var prescribing_number int64
  7486. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  7487. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  7488. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  7489. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  7490. }
  7491. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  7492. prescribing_number = parseIntPrescribingNumber
  7493. }
  7494. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  7495. prescribing_number = parseIntPrescribingNumber
  7496. }
  7497. sum_out_count += prescribing_number
  7498. }
  7499. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  7500. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  7501. //库存不足
  7502. if sum_out_count > drugStockOut.FlushCount {
  7503. this.ServeSuccessJSON(map[string]interface{}{
  7504. "msg": "2",
  7505. "drug": medical,
  7506. "ids": ids,
  7507. })
  7508. return
  7509. }
  7510. }
  7511. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  7512. //执行医嘱
  7513. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  7514. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  7515. for _, item := range advices {
  7516. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  7517. redis := service.RedisClient()
  7518. //清空key 值
  7519. redis.Set(key, "", time.Second)
  7520. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  7521. redis.Set(keyTwo, "", time.Second)
  7522. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  7523. redis.Set(keyThree, "", time.Second)
  7524. recordDate := theTime.Format("2006-01-02")
  7525. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  7526. redis.Set(keyFour, "", time.Second)
  7527. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  7528. redis.Set(keyFive, "", time.Second)
  7529. defer redis.Close()
  7530. }
  7531. if errs == nil {
  7532. //药品管理信息
  7533. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  7534. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  7535. if drugStockConfig.IsOpen == 1 {
  7536. for _, item := range advices {
  7537. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  7538. config, _ := service.GetDrugOpenConfigOne(orgId)
  7539. if config.IsOpen != 1 {
  7540. //查询该药品是否有库存
  7541. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  7542. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  7543. if medical.IsUse == 2 {
  7544. if config.IsOpen != 1 {
  7545. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  7546. service.HisDrugsDelivery(orgId, creater, &advice)
  7547. if orgId == 3877 || orgId == 10265 {
  7548. //查询该药品是否有出库记录
  7549. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  7550. if len(flowMap) == 0 {
  7551. errs := service.UpdateHisAdviceById(advice.ID)
  7552. if errs != nil {
  7553. drugError := models.XtDrugError{
  7554. UserOrgId: orgId,
  7555. DrugId: item.DrugId,
  7556. RecordDate: item.AdviceDate,
  7557. PatientId: item.PatientId,
  7558. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  7559. Status: 1,
  7560. Ctime: time.Now().Unix(),
  7561. Mtime: 0,
  7562. SumCount: 0,
  7563. Prescribingnumber: advice.PrescribingNumber,
  7564. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  7565. }
  7566. service.CreateDrugError(drugError)
  7567. }
  7568. this.ServeSuccessJSON(map[string]interface{}{
  7569. "msg": "2",
  7570. "drug": medical,
  7571. "ids": ids,
  7572. })
  7573. return
  7574. }
  7575. }
  7576. }
  7577. if pharmacyConfig.IsOpen != 1 {
  7578. service.HisDrugsDelivery(orgId, creater, &advice)
  7579. if orgId == 3877 || orgId == 10265 {
  7580. //查询该药品是否有出库记录
  7581. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  7582. if len(flowMap) == 0 {
  7583. errs := service.UpdateHisAdviceById(advice.ID)
  7584. if errs != nil {
  7585. drugError := models.XtDrugError{
  7586. UserOrgId: orgId,
  7587. DrugId: item.DrugId,
  7588. RecordDate: item.AdviceDate,
  7589. PatientId: item.PatientId,
  7590. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  7591. Status: 1,
  7592. Ctime: time.Now().Unix(),
  7593. Mtime: 0,
  7594. SumCount: 0,
  7595. Prescribingnumber: advice.PrescribingNumber,
  7596. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  7597. }
  7598. service.CreateDrugError(drugError)
  7599. }
  7600. this.ServeSuccessJSON(map[string]interface{}{
  7601. "msg": "2",
  7602. "drug": medical,
  7603. "ids": ids,
  7604. })
  7605. return
  7606. }
  7607. }
  7608. }
  7609. //更新字典里面的库存
  7610. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  7611. var sum_count int64
  7612. for _, its := range stockInfo {
  7613. if its.MaxUnit == medical.MaxUnit {
  7614. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  7615. }
  7616. sum_count += its.StockMaxNumber + its.StockMinNumber
  7617. }
  7618. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  7619. //剩余库存
  7620. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  7621. }
  7622. }
  7623. }
  7624. }
  7625. }
  7626. this.ServeSuccessJSON(map[string]interface{}{
  7627. "msg": "1",
  7628. "ids": ids,
  7629. })
  7630. return
  7631. } else {
  7632. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7633. }
  7634. }
  7635. fmt.Println("config233322333223", config.IsOpen)
  7636. //血透客户
  7637. if config.IsOpen == 2 || config.IsOpen == 0 {
  7638. //药品管理信息
  7639. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  7640. if drugStockConfig.IsOpen == 1 {
  7641. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  7642. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  7643. for _, item := range list {
  7644. for _, it := range adviceList {
  7645. if item.DrugId == it.DrugId {
  7646. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  7647. }
  7648. }
  7649. }
  7650. for _, item := range list {
  7651. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  7652. var sum_out_count int64
  7653. for _, itemThree := range item.ChildDoctorAdvice {
  7654. var prescribing_number int64
  7655. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  7656. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  7657. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  7658. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  7659. }
  7660. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  7661. prescribing_number = parseIntPrescribingNumber
  7662. }
  7663. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  7664. prescribing_number = parseIntPrescribingNumber
  7665. }
  7666. sum_out_count += prescribing_number
  7667. }
  7668. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  7669. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  7670. //库存不足
  7671. if sum_out_count > drugStockOut.FlushCount {
  7672. this.ServeSuccessJSON(map[string]interface{}{
  7673. "msg": "2",
  7674. "drug": medical,
  7675. "ids": ids,
  7676. })
  7677. return
  7678. }
  7679. }
  7680. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  7681. fmt.Println("creater2332243244224242424", creater)
  7682. //执行医嘱
  7683. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  7684. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  7685. for _, item := range advices {
  7686. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  7687. redis := service.RedisClient()
  7688. //清空key 值
  7689. redis.Set(key, "", time.Second)
  7690. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  7691. redis.Set(keyTwo, "", time.Second)
  7692. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  7693. redis.Set(keyThree, "", time.Second)
  7694. recordDate := theTime.Format("2006-01-02")
  7695. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  7696. redis.Set(keyFour, "", time.Second)
  7697. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  7698. redis.Set(keyFive, "", time.Second)
  7699. defer redis.Close()
  7700. }
  7701. if errs == nil {
  7702. for _, item := range advices {
  7703. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  7704. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  7705. //查询是否出库按钮开启
  7706. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  7707. if adviceSetting.IsAdviceOpen == 1 {
  7708. //查询是否出库按钮开启
  7709. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  7710. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  7711. if prescriptionConfig.IsOpen == 1 {
  7712. if medical.IsUse == 2 {
  7713. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  7714. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  7715. }
  7716. if pharmacyConfig.IsOpen != 1 {
  7717. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  7718. }
  7719. //更新字典里面的库存
  7720. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  7721. var sum_count int64
  7722. for _, its := range stockInfo {
  7723. if its.MaxUnit == medical.MaxUnit {
  7724. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  7725. }
  7726. sum_count += its.StockMaxNumber + its.StockMinNumber
  7727. }
  7728. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  7729. //剩余库存
  7730. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  7731. }
  7732. }
  7733. } else {
  7734. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  7735. if medical.IsUse == 2 {
  7736. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  7737. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  7738. }
  7739. if pharmacyConfig.IsOpen != 1 {
  7740. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  7741. }
  7742. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  7743. var sum_count int64
  7744. for _, its := range stockInfo {
  7745. if its.MaxUnit == medical.MaxUnit {
  7746. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  7747. }
  7748. sum_count += its.StockMaxNumber + its.StockMinNumber
  7749. }
  7750. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  7751. //剩余库存
  7752. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  7753. }
  7754. }
  7755. }
  7756. }
  7757. this.ServeSuccessJSON(map[string]interface{}{
  7758. "msg": "1",
  7759. "ids": ids,
  7760. })
  7761. return
  7762. } else {
  7763. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  7764. //执行医嘱
  7765. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  7766. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  7767. for _, item := range advices {
  7768. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  7769. redis := service.RedisClient()
  7770. //清空key 值
  7771. redis.Set(key, "", time.Second)
  7772. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  7773. redis.Set(keyTwo, "", time.Second)
  7774. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  7775. redis.Set(keyThree, "", time.Second)
  7776. recordDate := theTime.Format("2006-01-02")
  7777. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  7778. redis.Set(keyFour, "", time.Second)
  7779. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  7780. redis.Set(keyFive, "", time.Second)
  7781. defer redis.Close()
  7782. }
  7783. this.ServeSuccessJSON(map[string]interface{}{
  7784. "msg": "1",
  7785. "ids": ids,
  7786. })
  7787. return
  7788. }
  7789. }
  7790. }
  7791. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  7792. ids := this.GetString("ids")
  7793. idSplit := strings.Split(ids, ",")
  7794. orgId := this.GetMobileAdminUserInfo().Org.Id
  7795. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  7796. if config.IsOpen == 1 {
  7797. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  7798. this.ServeSuccessJSON(map[string]interface{}{
  7799. "msg": "1",
  7800. "ids": ids,
  7801. })
  7802. return
  7803. }
  7804. if config.IsOpen == 0 || config.IsOpen == 2 {
  7805. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  7806. this.ServeSuccessJSON(map[string]interface{}{
  7807. "msg": "1",
  7808. "ids": ids,
  7809. })
  7810. return
  7811. }
  7812. }
  7813. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  7814. ids := this.GetString("ids")
  7815. idSplit := strings.Split(ids, ",")
  7816. orgId := this.GetMobileAdminUserInfo().Org.Id
  7817. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  7818. //his
  7819. if config.IsOpen == 1 {
  7820. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  7821. theTime := time.Now()
  7822. advices := models.HisDoctorAdviceThirty{
  7823. CheckTime: theTime.Unix(),
  7824. Checker: checker,
  7825. UpdatedTime: time.Now().Unix(),
  7826. }
  7827. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  7828. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  7829. for _, item := range list {
  7830. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  7831. redis := service.RedisClient()
  7832. //清空key 值
  7833. redis.Set(key, "", time.Second)
  7834. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  7835. redis.Set(keyTwo, "", time.Second)
  7836. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  7837. redis.Set(keyThree, "", time.Second)
  7838. recordDate := theTime.Format("2006-01-02")
  7839. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  7840. redis.Set(keyFour, "", time.Second)
  7841. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  7842. redis.Set(keyFive, "", time.Second)
  7843. defer redis.Close()
  7844. }
  7845. this.ServeSuccessJSON(map[string]interface{}{
  7846. "msg": "1",
  7847. "ids": ids,
  7848. })
  7849. return
  7850. }
  7851. //血透
  7852. if config.IsOpen == 0 || config.IsOpen == 2 {
  7853. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  7854. theTime := time.Now()
  7855. advices := models.DoctorAdvice{
  7856. CheckTime: theTime.Unix(),
  7857. Checker: checker,
  7858. UpdatedTime: time.Now().Unix(),
  7859. }
  7860. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  7861. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  7862. for _, item := range list {
  7863. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  7864. redis := service.RedisClient()
  7865. //清空key 值
  7866. redis.Set(key, "", time.Second)
  7867. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  7868. redis.Set(keyTwo, "", time.Second)
  7869. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  7870. redis.Set(keyThree, "", time.Second)
  7871. recordDate := theTime.Format("2006-01-02")
  7872. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  7873. redis.Set(keyFour, "", time.Second)
  7874. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  7875. redis.Set(keyFive, "", time.Second)
  7876. defer redis.Close()
  7877. }
  7878. this.ServeSuccessJSON(map[string]interface{}{
  7879. "msg": "1",
  7880. "ids": ids,
  7881. })
  7882. return
  7883. }
  7884. }
  7885. func (this *DialysisAPIController) CheckSchedule() {
  7886. patientID, _ := this.GetInt64("patient_id")
  7887. recordDateStr := this.GetString("record_date")
  7888. nurseID, _ := this.GetInt64("start_nurse")
  7889. schedual_type, _ := this.GetInt64("schedual_type")
  7890. bedID, _ := this.GetInt64("bed")
  7891. start_time := this.GetString("start_time")
  7892. fmt.Println("patientID", patientID)
  7893. fmt.Println("recordDateStr", recordDateStr)
  7894. fmt.Println("nurseID", nurseID)
  7895. fmt.Println("schedual_type------", schedual_type)
  7896. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  7897. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7898. return
  7899. }
  7900. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  7901. if parseStartDateErr != nil {
  7902. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  7903. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7904. return
  7905. }
  7906. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  7907. if parseErr != nil {
  7908. this.ErrorLog("时间解析失败:%v", parseErr)
  7909. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7910. return
  7911. }
  7912. adminUserInfo := this.GetMobileAdminUserInfo()
  7913. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  7914. if getPatientErr != nil {
  7915. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  7916. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7917. return
  7918. } else if patient == nil {
  7919. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  7920. return
  7921. }
  7922. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  7923. if getNurseErr != nil {
  7924. this.ErrorLog("获取护士失败:%v", getNurseErr)
  7925. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7926. return
  7927. } else if nurse == nil {
  7928. this.ErrorLog("护士不存在")
  7929. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7930. return
  7931. }
  7932. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  7933. if getDeviceNumberErr != nil {
  7934. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  7935. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7936. return
  7937. } else if deviceNumber == nil {
  7938. this.ErrorLog("床位号不存在")
  7939. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7940. return
  7941. }
  7942. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  7943. if getRecordErr != nil {
  7944. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  7945. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7946. return
  7947. } else if dialysisRecord != nil {
  7948. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  7949. return
  7950. }
  7951. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  7952. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  7953. timeLayout := "2006-01-02 15:04:05"
  7954. loc, _ := time.LoadLocation("Local")
  7955. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  7956. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  7957. schedulestartTime := theStartTime.Unix()
  7958. scheduleendTime := theEndTime.Unix()
  7959. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  7960. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  7961. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  7962. //查询该床位是否有人用了
  7963. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  7964. if err == nil {
  7965. if schedule.ID == 0 {
  7966. this.ServeSuccessJSON(map[string]interface{}{
  7967. "status": 0,
  7968. "msg": "请求失败",
  7969. })
  7970. } else {
  7971. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  7972. if order.ID > 0 { //该机位被其他人占用了
  7973. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  7974. return
  7975. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  7976. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  7977. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  7978. this.ServeSuccessJSON(map[string]interface{}{
  7979. "status": 1,
  7980. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  7981. })
  7982. return
  7983. } else {
  7984. this.ServeSuccessJSON(map[string]interface{}{
  7985. "status": 0,
  7986. "msg": "",
  7987. })
  7988. }
  7989. }
  7990. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  7991. this.ServeSuccessJSON(map[string]interface{}{
  7992. "status": 2,
  7993. "msg": "当前机位已有患者在使用,请重新选择!",
  7994. })
  7995. }
  7996. }
  7997. } else {
  7998. this.ServeSuccessJSON(map[string]interface{}{
  7999. "status": 0,
  8000. "msg": "",
  8001. })
  8002. }
  8003. }
  8004. func (this *DialysisAPIController) GetNewDoctorListToday() {
  8005. orgId := this.GetMobileAdminUserInfo().Org.Id
  8006. schedule_type, _ := this.GetInt64("schedule_type")
  8007. partion_type, _ := this.GetInt64("partion_type")
  8008. start_time := this.GetString("start_time")
  8009. timeLayout := "2006-01-02"
  8010. loc, _ := time.LoadLocation("Local")
  8011. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8012. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  8013. _, config := service.FindXTHisRecordByOrgId(orgId)
  8014. appId := this.GetMobileAdminUserInfo().App.Id
  8015. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  8016. if err == nil {
  8017. this.ServeSuccessJSON(map[string]interface{}{
  8018. "list": list,
  8019. "config": config,
  8020. "doctorList": doctorList,
  8021. })
  8022. return
  8023. } else {
  8024. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8025. return
  8026. }
  8027. }
  8028. func (this *DialysisAPIController) SaveMobileInformation() {
  8029. patient_id, _ := this.GetInt64("patient_id")
  8030. record_date, _ := this.GetInt64("record_date")
  8031. startTime := this.GetString("start_time")
  8032. module, _ := this.GetInt64("module")
  8033. remark := this.GetString("remark")
  8034. timeLayout := "2006-01-02 15:04"
  8035. loc, _ := time.LoadLocation("Local")
  8036. if len(startTime) == 0 {
  8037. utils.ErrorLog("len(start_time) == 0")
  8038. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8039. return
  8040. }
  8041. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  8042. if err != nil {
  8043. utils.ErrorLog(err.Error())
  8044. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8045. return
  8046. }
  8047. StartTime := theTime.Unix()
  8048. fmt.Println("startime-------------", StartTime)
  8049. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8050. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  8051. information := models.XtDialysisInformation{
  8052. Module: module,
  8053. PatientId: patient_id,
  8054. RecordDate: record_date,
  8055. ApplicationDate: StartTime,
  8056. Creater: creater,
  8057. ApplicationStatus: 2,
  8058. Checker: 0,
  8059. CheckTime: 0,
  8060. Remark: remark,
  8061. UserOrgId: user_org_id,
  8062. Ctime: time.Now().Unix(),
  8063. Status: 1,
  8064. Mtime: 0,
  8065. }
  8066. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, user_org_id)
  8067. if infor.ID == 0 {
  8068. service.SaveDialysisInformation(information)
  8069. }
  8070. if infor.ID > 0 {
  8071. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  8072. }
  8073. this.ServeSuccessJSON(map[string]interface{}{
  8074. "information": information,
  8075. })
  8076. return
  8077. }
  8078. func (this *DialysisAPIController) GetMobileInformation() {
  8079. limit, _ := this.GetInt64("limit")
  8080. page, _ := this.GetInt64("page")
  8081. orgid := this.GetMobileAdminUserInfo().Org.Id
  8082. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  8083. appid := this.GetMobileAdminUserInfo().App.Id
  8084. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8085. patients, _ := service.GetAllpatientThirty(orgid)
  8086. this.ServeSuccessJSON(map[string]interface{}{
  8087. "information": information,
  8088. "total": total,
  8089. "doclist": doclist,
  8090. "patients": patients,
  8091. })
  8092. return
  8093. }
  8094. func (this *DialysisAPIController) GetMobileInformationOne() {
  8095. limit, _ := this.GetInt64("limit")
  8096. page, _ := this.GetInt64("page")
  8097. orgid := this.GetMobileAdminUserInfo().Org.Id
  8098. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  8099. appid := this.GetMobileAdminUserInfo().App.Id
  8100. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8101. patients, _ := service.GetAllpatientThirty(orgid)
  8102. this.ServeSuccessJSON(map[string]interface{}{
  8103. "information": information,
  8104. "total": total,
  8105. "doclist": doclist,
  8106. "patients": patients,
  8107. })
  8108. return
  8109. }
  8110. func (this *DialysisAPIController) CheckMobileInformation() {
  8111. id, _ := this.GetInt64("id")
  8112. application_status, _ := this.GetInt64("application_status")
  8113. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8114. checktime := time.Now().Unix()
  8115. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  8116. if err == nil {
  8117. this.ServeSuccessJSON(map[string]interface{}{
  8118. "msg": "ok",
  8119. })
  8120. return
  8121. }
  8122. }
  8123. func (c *DialysisAPIController) GetControlMonitorList() {
  8124. partition, _ := c.GetInt64("partition")
  8125. monitorDate := c.GetString("date")
  8126. patient_id, _ := c.GetInt64("patient_id")
  8127. pat_type, _ := c.GetInt64("pat_type")
  8128. timeLayout := "2006-01-02"
  8129. loc, _ := time.LoadLocation("Local")
  8130. var theStartTime int64
  8131. if len(monitorDate) > 0 {
  8132. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  8133. if err != nil {
  8134. theStartTime = 0
  8135. }
  8136. theStartTime = theTime.Unix()
  8137. }
  8138. adminInfo := c.GetMobileAdminUserInfo()
  8139. orgID := adminInfo.Org.Id
  8140. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  8141. if err != nil {
  8142. c.ErrorLog("获取排班信息失败:%v", err)
  8143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8144. } else {
  8145. if len(monitor) > 0 {
  8146. //获取所有床位
  8147. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  8148. //获取所有分区
  8149. zoneList, _ := service.GetAllZoneByList(orgID)
  8150. //获取透析处方
  8151. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  8152. //获取透前评估
  8153. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  8154. //获取上机
  8155. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  8156. //获取透后
  8157. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  8158. //获取透后监测
  8159. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  8160. //获取所有的患者
  8161. patients, _ := service.GetAllPatientListByListOne(orgID)
  8162. //获取所有透析模式
  8163. treatments, _ := service.GetAllTreatModeByList(orgID)
  8164. //获取所有医嘱
  8165. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  8166. //获取双人核对
  8167. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  8168. //治疗小结
  8169. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  8170. //待消毒
  8171. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  8172. for key, item := range monitor {
  8173. // 获取床位信息
  8174. for _, it := range numberList {
  8175. if item.BedId == it.ID {
  8176. monitor[key].DeviceNumber = it
  8177. break
  8178. }
  8179. }
  8180. //获取分区信息
  8181. for _, it := range zoneList {
  8182. if item.PartitionId == it.ID {
  8183. monitor[key].DeviceZone = it
  8184. }
  8185. }
  8186. for _, prescription := range prescriptions {
  8187. if item.PatientId == prescription.PatientId {
  8188. monitor[key].Prescription = prescription
  8189. break
  8190. }
  8191. }
  8192. for _, it := range checkList {
  8193. if item.PatientId == it.PatientId {
  8194. monitor[key].DoubleCheck = it
  8195. break
  8196. }
  8197. }
  8198. for _, it := range summaryList {
  8199. if item.PatientId == it.PatientId {
  8200. monitor[key].TreatmentSummaryForList = it
  8201. break
  8202. }
  8203. }
  8204. // 透前评估
  8205. for _, assessmentBefore := range assessmentBefores {
  8206. if item.PatientId == assessmentBefore.PatientId {
  8207. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  8208. break
  8209. }
  8210. }
  8211. // 透析上下机
  8212. for _, dialysisOrder := range dialysisOrders {
  8213. if item.PatientId == dialysisOrder.PatientId {
  8214. monitor[key].DialysisOrder = dialysisOrder
  8215. break
  8216. }
  8217. }
  8218. // 治疗小节
  8219. for _, afterDislysis := range AssessmentAfterDislysis {
  8220. if item.PatientId == afterDislysis.PatientId {
  8221. monitor[key].AssessmentAfterDislysis = afterDislysis
  8222. break
  8223. }
  8224. }
  8225. for _, it := range monitorlist {
  8226. if item.PatientId == it.PatientId {
  8227. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  8228. }
  8229. }
  8230. for _, it := range adviceList {
  8231. if item.PatientId == it.PatientId {
  8232. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  8233. }
  8234. }
  8235. for _, patient := range patients {
  8236. if item.PatientId == patient.ID {
  8237. monitor[key].MonitorPatients = patient
  8238. break
  8239. }
  8240. }
  8241. for _, treatment := range treatments {
  8242. if item.ModeId == treatment.ID {
  8243. monitor[key].TreatmentMode = treatment
  8244. break
  8245. }
  8246. }
  8247. for _, infor := range informationList {
  8248. if item.PatientId == infor.PatientId {
  8249. monitor[key].NewDeviceInformation = infor
  8250. break
  8251. }
  8252. }
  8253. }
  8254. }
  8255. }
  8256. patients, err := service.GetAllpatientFourty(orgID)
  8257. var mds []*models.NewMonitorDialysisScheduleList
  8258. if pat_type == 0 {
  8259. for _, item := range monitor {
  8260. mds = append(mds, item)
  8261. }
  8262. }
  8263. //待医嘱核对
  8264. if pat_type == 1 {
  8265. for _, item := range monitor {
  8266. if len(item.AdviceList) > 0 {
  8267. mds = append(mds, item)
  8268. }
  8269. }
  8270. }
  8271. //待开小结
  8272. if pat_type == 2 {
  8273. for _, item := range monitor {
  8274. if item.TreatmentSummaryForList == nil {
  8275. mds = append(mds, item)
  8276. }
  8277. }
  8278. }
  8279. //待下机
  8280. if pat_type == 3 {
  8281. for _, item := range monitor {
  8282. if item.DialysisOrder != nil {
  8283. if item.DialysisOrder.ID > 0 {
  8284. mds = append(mds, item)
  8285. }
  8286. }
  8287. }
  8288. }
  8289. //待消毒
  8290. if pat_type == 4 {
  8291. for _, item := range monitor {
  8292. if item.NewDeviceInformation == nil {
  8293. mds = append(mds, item)
  8294. }
  8295. }
  8296. }
  8297. //待双人核对
  8298. if pat_type == 5 {
  8299. for _, item := range monitor {
  8300. if item.DoubleCheck == nil {
  8301. mds = append(mds, item)
  8302. }
  8303. }
  8304. }
  8305. //医嘱未执行
  8306. if pat_type == 6 {
  8307. for _, item := range monitor {
  8308. if len(item.AdviceList) > 0 {
  8309. mds = append(mds, item)
  8310. }
  8311. }
  8312. }
  8313. //患者未签名
  8314. if pat_type == 7 {
  8315. for _, item := range monitor {
  8316. if item.DialysisOrder != nil {
  8317. if item.DialysisOrder.ID > 0 {
  8318. mds = append(mds, item)
  8319. }
  8320. }
  8321. }
  8322. }
  8323. //目标超滤于实际超滤不同
  8324. if pat_type == 8 {
  8325. for _, item := range monitor {
  8326. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  8327. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  8328. mds = append(mds, item)
  8329. }
  8330. }
  8331. }
  8332. }
  8333. //血压少于5次
  8334. if pat_type == 9 {
  8335. for _, item := range monitor {
  8336. if len(item.MonitoringRecord) < 5 {
  8337. mds = append(mds, item)
  8338. }
  8339. }
  8340. }
  8341. if pat_type == 10 {
  8342. for _, item := range monitor {
  8343. if len(item.MonitoringRecord) == 0 {
  8344. mds = append(mds, item)
  8345. }
  8346. }
  8347. }
  8348. if pat_type == 11 {
  8349. for _, item := range monitor {
  8350. if len(item.MonitoringRecord) > 0 {
  8351. mds = append(mds, item)
  8352. }
  8353. }
  8354. }
  8355. if pat_type == 12 {
  8356. for _, item := range monitor {
  8357. if len(item.MonitoringRecord) > 0 {
  8358. mds = append(mds, item)
  8359. }
  8360. }
  8361. }
  8362. if err == nil {
  8363. c.ServeSuccessJSON(map[string]interface{}{
  8364. "monitor": mds,
  8365. "patients": patients,
  8366. })
  8367. } else {
  8368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8369. }
  8370. }