dialysis_api_controller.go 349KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701
  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. if adminUserInfo.Org.Id != 10375 {
  2145. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2146. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2147. } else {
  2148. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2149. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2150. }
  2151. if adminUserInfo.Org.Id != 10445 {
  2152. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2153. }
  2154. //北方营口医院
  2155. if adminUserInfo.Org.Id == 10445 {
  2156. //获取最后一条透析处方数据
  2157. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2158. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2159. } else {
  2160. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2161. }
  2162. //新化博翔
  2163. if adminUserInfo.Org.Id == 10447 {
  2164. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2165. }
  2166. //阳春
  2167. if adminUserInfo.Org.Id == 10485 {
  2168. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2169. }
  2170. }
  2171. 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 {
  2172. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2173. if evaluation.SystolicBloodPressure == 0 {
  2174. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2175. pre := models.PredialysisEvaluation{
  2176. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2177. }
  2178. fmt.Println("prew", pre)
  2179. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2180. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2181. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2182. redis := service.RedisClient()
  2183. redis.Set(key, "", time.Second)
  2184. redis.Set(keyOne, "", time.Second)
  2185. defer redis.Close()
  2186. fmt.Println(getNurseErr)
  2187. }
  2188. if evaluation.DiastolicBloodPressure == 0 {
  2189. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2190. pres := models.PredialysisEvaluation{
  2191. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2192. }
  2193. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2194. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2195. redis := service.RedisClient()
  2196. redis.Set(key, "", time.Second)
  2197. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2198. redis.Set(keyOne, "", time.Second)
  2199. defer redis.Close()
  2200. fmt.Println(getNurseErr)
  2201. }
  2202. if evaluation.PulseFrequency == 0 {
  2203. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2204. press := models.PredialysisEvaluation{
  2205. PulseFrequency: evaluation.PulseFrequency,
  2206. }
  2207. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2208. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2209. redis := service.RedisClient()
  2210. redis.Set(key, "", time.Second)
  2211. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2212. redis.Set(keyOne, "", time.Second)
  2213. defer redis.Close()
  2214. fmt.Println(getNurseErr)
  2215. }
  2216. if evaluation.Temperature == 0 {
  2217. evaluation.Temperature = fmonitorRecords.Temperature
  2218. press := models.PredialysisEvaluation{
  2219. Temperature: evaluation.Temperature,
  2220. }
  2221. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2222. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2223. redis := service.RedisClient()
  2224. redis.Set(key, "", time.Second)
  2225. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2226. redis.Set(keyOne, "", time.Second)
  2227. defer redis.Close()
  2228. fmt.Println(getNurseErr)
  2229. }
  2230. }
  2231. if adminUserInfo.Org.Id == 9583 {
  2232. //获取透析处方的最后一条数据
  2233. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2234. if diaerr != nil {
  2235. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2237. return
  2238. }
  2239. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2240. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2241. }
  2242. }
  2243. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2244. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2245. }
  2246. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2247. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2248. }
  2249. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2250. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2251. }
  2252. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2253. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2254. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2255. }
  2256. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2257. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2258. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2259. }
  2260. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2261. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2262. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2263. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2264. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2265. }
  2266. if lastAssessmentAfterDislysis != nil {
  2267. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2268. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2269. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2270. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2271. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2272. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2273. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2274. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2275. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2276. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2277. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2278. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2279. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2280. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2281. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2282. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2283. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2284. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2285. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2286. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2287. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2288. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2289. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2290. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2291. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2292. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2293. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2294. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2295. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2296. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2297. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2298. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2299. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2300. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2301. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2302. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2303. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2304. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2305. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2306. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2307. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2308. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2309. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2310. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2311. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2312. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2313. if tempassessmentAfterDislysis.PatientId == 18695 {
  2314. tempassessmentAfterDislysis.ActualDisplacement = 0
  2315. }
  2316. if adminUserInfo.Org.Id != 10375 {
  2317. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2318. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2319. } else {
  2320. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2321. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2322. }
  2323. }
  2324. finish := models.XtDialysisFinish{
  2325. IsFinish: 1,
  2326. UserOrgId: adminUserInfo.Org.Id,
  2327. Status: 1,
  2328. Ctime: time.Now().Unix(),
  2329. Mtime: 0,
  2330. Module: 9,
  2331. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2332. Sourse: 1,
  2333. PatientId: tempassessmentAfterDislysis.PatientId,
  2334. }
  2335. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2336. if dialysisFinish.ID == 0 {
  2337. service.CreateDialysisFinish(finish)
  2338. }
  2339. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2340. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2341. redis := service.RedisClient()
  2342. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2343. redis.Set(keyOne, "", time.Second)
  2344. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2345. redis.Set(keyTwo, "", time.Second)
  2346. defer redis.Close()
  2347. //清空key 值
  2348. redis.Set(key, "", time.Second)
  2349. if err != nil {
  2350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2351. return
  2352. }
  2353. if dialysisOrder == nil {
  2354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2355. return
  2356. }
  2357. if dialysisOrder.Stage == 2 {
  2358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2359. return
  2360. }
  2361. if dialysisOrder.Stage == 1 {
  2362. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission)
  2363. finish := models.XtDialysisFinish{
  2364. IsFinish: 1,
  2365. UserOrgId: adminUserInfo.Org.Id,
  2366. Status: 1,
  2367. Ctime: time.Now().Unix(),
  2368. Mtime: 0,
  2369. Module: 8,
  2370. RecordDate: recordDate.Unix(),
  2371. Sourse: 1,
  2372. PatientId: id,
  2373. }
  2374. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2375. if dialysisFinish.ID == 0 {
  2376. service.CreateDialysisFinish(finish)
  2377. }
  2378. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2379. redis := service.RedisClient()
  2380. defer redis.Close()
  2381. //清空key 值
  2382. redis.Set(key, "", time.Second)
  2383. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2384. redis.Set(keyOne, "", time.Second)
  2385. //结束时候透析次数加1
  2386. service.UpdateSolutionByPatientId(id)
  2387. //下机完自动消毒,针对长沙南雅
  2388. if dialysisOrder.Stage == 1 {
  2389. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9538 || adminUserInfo.Org.Id == 10121 {
  2390. //根据床位号获取设备型号
  2391. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2392. //查询使用消毒最后一条消毒记录
  2393. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2394. fmt.Println("err", err)
  2395. if err == gorm.ErrRecordNotFound {
  2396. //查找排班
  2397. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2398. //查询改设备是否有消毒计划
  2399. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2400. //根据床位号获取设备id
  2401. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2402. //查询病人信息
  2403. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2404. var con = ""
  2405. if patients.IsInfectious == 0 {
  2406. con = ""
  2407. }
  2408. if patients.IsInfectious == 1 {
  2409. con = "无"
  2410. }
  2411. if patients.IsInfectious == 2 {
  2412. con = "有"
  2413. }
  2414. if errcode == nil {
  2415. var end_time int64
  2416. end_time = endDate.Unix() + plan.DisinfecTime*60
  2417. //新增消毒
  2418. information := models.DeviceInformation{
  2419. Date: dialysisOrder.DialysisDate,
  2420. Zone: dialysisOrder.ZoneId,
  2421. Class: dialysisOrder.SchedualType,
  2422. BedNumber: dialysisOrder.BedID,
  2423. PatientId: dialysisOrder.PatientId,
  2424. DialysisMode: scheduleByPatient.ModeId,
  2425. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2426. Disinfection: 1,
  2427. DialysisConcentration: 1,
  2428. DisinfectionStatus: 1,
  2429. Move: 1,
  2430. UserOrgId: dialysisOrder.UserOrgId,
  2431. DisinfectType: plan.Way,
  2432. DisinfectantType: plan.MachineDisinfectant,
  2433. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2434. Disinfectant: plan.Disinfectant,
  2435. Ctime: time.Now().Unix(),
  2436. Status: 1,
  2437. SignName: nurseID,
  2438. EquimentId: addmacher.ID,
  2439. DisinfectionResidue: 2,
  2440. Bed: addmacher.BedNumber,
  2441. StartTime: dialysisOrder.StartTime,
  2442. EndTime: dialysisOrder.EndTime,
  2443. Contagion: con,
  2444. WeightLoss: 0,
  2445. Hyperfiltratio: 0,
  2446. DialysisHour: "",
  2447. MachineRun: 1,
  2448. DisinfecStartime: endDate.Unix(),
  2449. DisinfecEndtime: end_time,
  2450. }
  2451. err := service.CreateInformationTwo(&information)
  2452. fmt.Println("报错", err)
  2453. }
  2454. }
  2455. }
  2456. }
  2457. dialysisOrder.Stage = 2
  2458. dialysisOrder.FinishNurse = nurseID
  2459. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2460. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2461. dialysisOrder.EndTime = endDate.Unix()
  2462. fmt.Println("ADMINWOOWOWOWOWO", adminUserInfo.Org.Id)
  2463. // 长沙南雅需求
  2464. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2465. //获取最后1条监测的数据
  2466. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2467. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2468. var accumulatedBloodVolume float64
  2469. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2470. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2471. fmt.Println(err)
  2472. // 查询未执行的医嘱
  2473. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2474. fmt.Println("doctorAdviceWOWOOWOWOWOWOWOW", doctorAdvice)
  2475. for _, item := range doctorAdvice {
  2476. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2477. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2478. redis := service.RedisClient()
  2479. //清空key 值
  2480. redis.Set(key, "", time.Second)
  2481. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2482. redis.Set(keyTwo, "", time.Second)
  2483. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2484. redis.Set(keyThree, "", time.Second)
  2485. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2486. theTime := toTime.Format("2006-01-02")
  2487. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2488. redis.Set(keyFour, "", time.Second)
  2489. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2490. redis.Set(keyFive, "", time.Second)
  2491. defer redis.Close()
  2492. }
  2493. }
  2494. go func() {
  2495. ssoDomain := beego.AppConfig.String("call_domain")
  2496. api := ssoDomain + "/index/downpatient"
  2497. values := make(url.Values)
  2498. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2499. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2500. values.Set("patient_id", strconv.FormatInt(id, 10))
  2501. http.PostForm(api, values)
  2502. }()
  2503. if err == nil {
  2504. c.ServeSuccessJSON(map[string]interface{}{
  2505. "dialysisOrder": dialysisOrder,
  2506. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2507. })
  2508. } else {
  2509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2510. }
  2511. }
  2512. }
  2513. func (c *DialysisAPIController) GetAllZone() {
  2514. adminUserInfo := c.GetMobileAdminUserInfo()
  2515. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2516. if err == nil {
  2517. c.ServeSuccessJSON(map[string]interface{}{
  2518. "zone": zone,
  2519. })
  2520. }
  2521. }
  2522. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2523. adminUserInfo := c.GetMobileAdminUserInfo()
  2524. page, _ := c.GetInt64("page", 1)
  2525. limit, _ := c.GetInt64("limit", 10)
  2526. schedulType, _ := c.GetInt64("schedul_type", 0)
  2527. startTime, _ := c.GetInt64("schedul_time", 0)
  2528. partitionType, _ := c.GetInt64("partition_type", 0)
  2529. keywords := c.GetString("keywords")
  2530. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2531. if err == nil {
  2532. c.ServeSuccessJSON(map[string]interface{}{
  2533. "schedule": dialysisSchedule,
  2534. })
  2535. }
  2536. return
  2537. }
  2538. // /m/api/dialysis/start [post]
  2539. // @param patient_id:int
  2540. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2541. // @param nurse:int 上机护士
  2542. // @param bed:int 床位号
  2543. func (this *DialysisAPIController) StartDialysis() {
  2544. patientID, _ := this.GetInt64("patient_id")
  2545. recordDateStr := this.GetString("record_date")
  2546. nurseID, _ := this.GetInt64("start_nurse")
  2547. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2548. blood_drawing, _ := this.GetInt64("blood_drawing")
  2549. schedual_type, _ := this.GetInt64("schedual_type")
  2550. bedID, _ := this.GetInt64("bed")
  2551. start_time := this.GetString("start_time")
  2552. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2553. change_nurse, _ := this.GetInt64("change_nurse")
  2554. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2555. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2556. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2557. puncture_needle := this.GetString("puncture_needle")
  2558. puncture_way := this.GetString("puncture_way")
  2559. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2560. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2561. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  2562. zone_id, _ := this.GetInt64("zone_id")
  2563. elecsign := this.GetString("url")
  2564. nuclein_date_str := this.GetString("nuclein_date_str")
  2565. schedule_remark := this.GetString("schedule_remark")
  2566. order_remark := this.GetString("order_remark")
  2567. catheter_operation := this.GetString("catheter_operation")
  2568. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2569. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2570. return
  2571. }
  2572. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2573. if parseStartDateErr != nil {
  2574. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2575. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2576. return
  2577. }
  2578. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2579. if parseErr != nil {
  2580. this.ErrorLog("时间解析失败:%v", parseErr)
  2581. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2582. return
  2583. }
  2584. adminUserInfo := this.GetMobileAdminUserInfo()
  2585. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2586. if getPatientErr != nil {
  2587. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2588. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2589. return
  2590. } else if patient == nil {
  2591. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2592. return
  2593. }
  2594. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2595. if getNurseErr != nil {
  2596. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2597. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2598. return
  2599. } else if nurse == nil {
  2600. this.ErrorLog("护士不存在")
  2601. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2602. return
  2603. }
  2604. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2605. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2606. if getDeviceNumberErr != nil {
  2607. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2608. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2609. return
  2610. } else if deviceNumber == nil {
  2611. this.ErrorLog("床位号不存在")
  2612. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2613. return
  2614. }
  2615. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2616. if getRecordErr != nil {
  2617. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2618. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2619. return
  2620. } else if dialysisRecord != nil {
  2621. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2622. return
  2623. }
  2624. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2625. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2626. timeLayout := "2006-01-02 15:04:05"
  2627. loc, _ := time.LoadLocation("Local")
  2628. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2629. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2630. schedulestartTime := theStartTime.Unix()
  2631. scheduleendTime := theEndTime.Unix()
  2632. var theNucleinDate int64
  2633. timeLayoutOne := "2006-01-02"
  2634. if len(nuclein_date_str) > 0 {
  2635. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2636. if err != nil {
  2637. utils.ErrorLog(err.Error())
  2638. }
  2639. theNucleinDate = theTime.Unix()
  2640. }
  2641. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2642. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2643. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  2644. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2645. //查询该床位是否有人用了
  2646. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2647. if err == gorm.ErrRecordNotFound { //空床位
  2648. // 修改了床位逻辑
  2649. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2650. if daySchedule.ID > 0 {
  2651. daySchedule.PartitionId = deviceNumber.ZoneID
  2652. daySchedule.BedId = bedID
  2653. daySchedule.ScheduleType = schedual_type
  2654. daySchedule.UpdatedTime = time.Now().Unix()
  2655. xtSchedule := models.Schedule{
  2656. PartitionId: deviceNumber.ZoneID,
  2657. BedId: bedID,
  2658. ScheduleType: schedual_type,
  2659. UpdatedTime: time.Now().Unix(),
  2660. }
  2661. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2662. if err != nil {
  2663. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2664. return
  2665. }
  2666. }
  2667. } else if err == nil {
  2668. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2669. if order.ID > 0 { //该机位被其他人占用了
  2670. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2671. return
  2672. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  2673. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2674. if daySchedule.ID > 0 {
  2675. err := service.UpdateScheduleTwo(daySchedule, schedule)
  2676. if err != nil {
  2677. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2678. return
  2679. }
  2680. }
  2681. }
  2682. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2683. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2684. return
  2685. }
  2686. //else if order.ID == 0 { //该床位没被占用
  2687. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2688. // if daySchedule.ID > 0 {
  2689. // //daySchedule.PartitionId = deviceNumber.ZoneID
  2690. // //daySchedule.BedId = bedID
  2691. // //daySchedule.ScheduleType = schedual_type
  2692. // //daySchedule.UpdatedTime = time.Now().Unix()
  2693. // //err := service.UpdateSchedule(&daySchedule)
  2694. // xtSchedule := models.Schedule{
  2695. // PartitionId: deviceNumber.ZoneID,
  2696. // BedId: bedID,
  2697. // ScheduleType: schedual_type,
  2698. // UpdatedTime: time.Now().Unix(),
  2699. // }
  2700. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2701. // if err != nil {
  2702. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2703. // return
  2704. // }
  2705. // }
  2706. //}
  2707. //}
  2708. } else if err != nil {
  2709. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2710. return
  2711. }
  2712. // 查询信息规挡的设置天数
  2713. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2714. if infor.ID > 0 && infor.WeekDay > 0 {
  2715. var cha_time int64
  2716. timeNowStr := time.Now().Format("2006-01-02")
  2717. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2718. //今日的日期减去设置的日期
  2719. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2720. if cha_time >= recordDate.Unix() {
  2721. //查询审核是否允许
  2722. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id)
  2723. //申请状态不允许的情况 拒绝修改
  2724. if infor.ApplicationStatus != 1 {
  2725. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2726. return
  2727. }
  2728. }
  2729. }
  2730. dialysisRecord = &models.DialysisOrder{
  2731. DialysisDate: recordDate.Unix(),
  2732. UserOrgId: adminUserInfo.Org.Id,
  2733. PatientId: patientID,
  2734. Stage: 1,
  2735. BedID: bedID,
  2736. StartNurse: nurseID,
  2737. Status: 1,
  2738. StartTime: startDate.Unix(),
  2739. CreatedTime: time.Now().Unix(),
  2740. UpdatedTime: time.Now().Unix(),
  2741. PunctureNurse: puncture_nurse,
  2742. Creator: adminUserInfo.AdminUser.Id,
  2743. Modifier: adminUserInfo.AdminUser.Id,
  2744. SchedualType: schedual_type,
  2745. WashpipeNurse: washpipe_nurse,
  2746. ChangeNurse: change_nurse,
  2747. DifficultPunctureNurse: difficult_puncture_nurse,
  2748. NewFistulaNurse: new_fistula_nurse,
  2749. ZoneId: zone_id,
  2750. QualityNurseId: quality_nurse_id,
  2751. PunctureNeedle: puncture_needle,
  2752. PunctureWay: puncture_way,
  2753. DialysisIrrigation: dialysis_irrigation,
  2754. DialysisDialyszers: dialysis_dialyszers,
  2755. BloodAccessId: blood_access_id,
  2756. Url: elecsign,
  2757. NucleinDate: theNucleinDate,
  2758. ScheduleRemark: schedule_remark,
  2759. OrderRemark: order_remark,
  2760. CatheterOperation: catheter_operation,
  2761. }
  2762. //查询该床位是否有人用了
  2763. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2764. if errorscode == gorm.ErrRecordNotFound {
  2765. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  2766. finish := models.XtDialysisFinish{
  2767. IsFinish: 1,
  2768. UserOrgId: adminUserInfo.Org.Id,
  2769. Status: 1,
  2770. Ctime: time.Now().Unix(),
  2771. Mtime: 0,
  2772. Module: 6,
  2773. RecordDate: schedulestartTime,
  2774. Sourse: 1,
  2775. PatientId: patientID,
  2776. }
  2777. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  2778. if dialysisFinish.ID == 0 {
  2779. service.CreateDialysisFinish(finish)
  2780. }
  2781. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  2782. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  2783. //统计该患者总次数
  2784. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  2785. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2786. }
  2787. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  2788. //统计该患者总次数
  2789. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  2790. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2791. }
  2792. redis := service.RedisClient()
  2793. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2794. redis.Set(key, "", time.Second)
  2795. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2796. //清空key 值
  2797. redis.Set(keyOne, "", time.Second)
  2798. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2799. //清空key 值
  2800. redis.Set(keyTwo, "", time.Second)
  2801. if createErr != nil {
  2802. this.ErrorLog("上机失败:%v", createErr)
  2803. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2804. return
  2805. }
  2806. }
  2807. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2808. var tempdispose string
  2809. // 只针对中能建
  2810. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  2811. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2812. }
  2813. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  2814. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2815. }
  2816. var ultrafiltration_rate float64
  2817. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2818. //后期预增脱水量
  2819. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2820. if prescription.ID > 0 {
  2821. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2822. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2823. if (template.TemplateId == 6 || template.TemplateId == 32 || template.TemplateId == 65 || adminUserInfo.Org.Id == 10375) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  2824. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2825. }
  2826. //针对医师汇
  2827. if adminUserInfo.Org.Id == 10121 {
  2828. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  2829. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  2830. }
  2831. //针对通道
  2832. if adminUserInfo.Org.Id == 10234 {
  2833. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  2834. }
  2835. //针对监利大垸医院
  2836. if template.TemplateId == 41 {
  2837. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  2838. }
  2839. //针对肇庆三鹤血液透析中心
  2840. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  2841. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2842. }
  2843. if adminUserInfo.Org.Id == 10469 {
  2844. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  2845. }
  2846. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  2847. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2848. }
  2849. // 只针对方济医院
  2850. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  2851. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2852. ultrafiltration_rate = value
  2853. }
  2854. //针对
  2855. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  2856. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2857. ultrafiltration_rate = ultrafiltration_rate / 1000
  2858. }
  2859. }
  2860. }
  2861. record := models.MonitoringRecord{
  2862. UserOrgId: adminUserInfo.Org.Id,
  2863. PatientId: patientID,
  2864. DialysisOrderId: dialysisRecord.ID,
  2865. MonitoringDate: schedulestartTime,
  2866. OperateTime: startDate.Unix(),
  2867. // MonitoringTime: recordTime,
  2868. MonitoringNurse: nurseID,
  2869. Dispose: tempdispose,
  2870. UltrafiltrationRate: ultrafiltration_rate,
  2871. UltrafiltrationVolume: 0,
  2872. Status: 1,
  2873. CreatedTime: time.Now().Unix(),
  2874. UpdatedTime: time.Now().Unix(),
  2875. }
  2876. //只针对广慈医院
  2877. 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 {
  2878. // 查询病人是否有透前评估数据
  2879. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2880. //如果有数据就插入
  2881. if errcode == nil {
  2882. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2883. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2884. record.BreathingRate = befor.BreathingRate
  2885. record.PulseFrequency = befor.PulseFrequency
  2886. record.Temperature = befor.Temperature
  2887. }
  2888. }
  2889. // 如果当天有插入数据,则不再往透析纪录里插入数据
  2890. if newdialysisRecord.ID > 0 {
  2891. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  2892. record.Temperature = 36.5
  2893. record.ArterialPressure = -100
  2894. record.DialysateTemperature = 36.5
  2895. record.Conductivity = 14
  2896. record.BreathingRate = "20"
  2897. record.VenousPressure = 80
  2898. record.TransmembranePressure = 60
  2899. record.Dispose = catheter_operation
  2900. }
  2901. //针对新化博翔
  2902. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  2903. record.BloodOxygenSaturation = "99"
  2904. record.Conductivity = 14
  2905. record.DialysateTemperature = 36.5
  2906. record.BreathingRate = "20"
  2907. }
  2908. //针对兰溪人民医院的需求
  2909. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 {
  2910. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2911. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2912. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2913. record.Temperature = befor.Temperature
  2914. record.PulseFrequency = befor.PulseFrequency
  2915. record.BreathingRate = befor.BreathingRate
  2916. }
  2917. //新化博翔
  2918. if adminUserInfo.Org.Id == 10447 {
  2919. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2920. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2921. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2922. record.BreathingRate = befor.BreathingRate
  2923. }
  2924. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  2925. record.PulseFrequency = 80
  2926. record.Temperature = 36.5
  2927. }
  2928. //诊断灵山圣康
  2929. if adminUserInfo.Org.Id == 10375 {
  2930. record.Conductivity = 13.8
  2931. record.DialysateTemperature = 37
  2932. record.DialysateFlow = 500
  2933. record.BloodFlowVolume = 200
  2934. record.BreathingRate = "18"
  2935. record.SodiumConcentration = 140
  2936. }
  2937. err := service.CreateMonitor(&record)
  2938. finish := models.XtDialysisFinish{
  2939. IsFinish: 1,
  2940. UserOrgId: adminUserInfo.Org.Id,
  2941. Status: 1,
  2942. Ctime: time.Now().Unix(),
  2943. Mtime: 0,
  2944. Module: 7,
  2945. RecordDate: schedulestartTime,
  2946. Sourse: 1,
  2947. PatientId: patientID,
  2948. }
  2949. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  2950. if dialysisFinish.ID == 0 {
  2951. service.CreateDialysisFinish(finish)
  2952. }
  2953. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  2954. redis := service.RedisClient()
  2955. //清空key 值
  2956. redis.Set(key, "", time.Second)
  2957. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  2958. redis.Set(keyOne, "", time.Second)
  2959. defer redis.Close()
  2960. if err != nil {
  2961. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  2962. return
  2963. }
  2964. }
  2965. go func() {
  2966. ssoDomain := beego.AppConfig.String("call_domain")
  2967. api := ssoDomain + "/index/uppatient"
  2968. values := make(url.Values)
  2969. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  2970. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2971. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  2972. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  2973. http.PostForm(api, values)
  2974. }()
  2975. this.ServeSuccessJSON(map[string]interface{}{
  2976. "dialysis_order": newdialysisRecord,
  2977. "monitor": record,
  2978. })
  2979. return
  2980. }
  2981. func (c *DialysisAPIController) PostSolution() {
  2982. id, _ := c.GetInt64("patient", 0)
  2983. recordDateStr := c.GetString("record_date")
  2984. if id <= 0 {
  2985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2986. return
  2987. }
  2988. adminUserInfo := c.GetMobileAdminUserInfo()
  2989. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2990. if patient.ID == 0 {
  2991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2992. return
  2993. }
  2994. if len(recordDateStr) == 0 {
  2995. recordDateStr = time.Now().Format("2006-01-02")
  2996. }
  2997. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2998. if parseDateErr != nil {
  2999. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3000. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3001. return
  3002. }
  3003. mode_id, _ := c.GetInt64("mode_id", 0)
  3004. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3005. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3006. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3007. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3008. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3009. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3010. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3011. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3012. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3013. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3014. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3015. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3016. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3017. kalium, _ := c.GetFloat("kalium", 0)
  3018. sodium, _ := c.GetFloat("sodium", 0)
  3019. calcium, _ := c.GetFloat("calcium", 0)
  3020. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3021. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3022. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3023. glucose, _ := c.GetFloat("glucose", 0)
  3024. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3025. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3026. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3027. conductivity, _ := c.GetFloat("conductivity", 0)
  3028. remark := c.GetString("remark")
  3029. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3030. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3031. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3032. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3033. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3034. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3035. special_medicine_other := c.GetString("special_medicine_other")
  3036. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3037. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3038. blood_access, _ := c.GetInt64("blood_access", 0)
  3039. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3040. body_fluid_other := c.GetString("body_fluid_other")
  3041. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3042. niprocart, _ := c.GetInt64("niprocart", 0)
  3043. jms, _ := c.GetInt64("jms", 0)
  3044. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3045. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3046. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3047. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3048. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3049. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3050. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3051. injector, _ := c.GetInt64("injector", 0)
  3052. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3053. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3054. safe_package, _ := c.GetInt64("package", 0)
  3055. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3056. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3057. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3058. blood := c.GetString("blood")
  3059. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3060. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3061. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3062. displace_speed := c.GetString("displace_speed")
  3063. illness, _ := c.GetInt64("illness")
  3064. amylaceum := c.GetString("amylaceum")
  3065. single_time := c.GetString("single_time")
  3066. single_water := c.GetString("single_water")
  3067. replacement_flow := c.GetString("replacement_flow")
  3068. plasma_separator := c.GetString("plasma_separator")
  3069. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3070. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3071. oxygen_flow := c.GetString("oxygen_flow")
  3072. oxygen_time := c.GetString("oxygen_time")
  3073. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3074. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3075. puncture_needle := c.GetString("puncture_needle")
  3076. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3077. epo := c.GetString("epo")
  3078. epo_count, _ := c.GetFloat("epo_count", 0)
  3079. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3080. pre_impulse := c.GetString("pre_impulse")
  3081. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3082. admin_user_id, _ := c.GetInt64("admin_user_id")
  3083. is_water := c.GetString("is_water")
  3084. add_amount, _ := c.GetFloat("add_amount")
  3085. reduce_amount, _ := c.GetFloat("reduce_amount")
  3086. prescribing_number, _ := c.GetFloat("prescribing_number")
  3087. treatment_remark := c.GetString("treatment_remark")
  3088. prescription_sodium := c.GetString("prescription_sodium")
  3089. start_sodium := c.GetString("start_sodium")
  3090. sodium_curve := c.GetString("sodium_curve")
  3091. var is_war int64
  3092. if is_water == "是" {
  3093. is_war = 1
  3094. }
  3095. if is_water == "否" {
  3096. is_war = 2
  3097. }
  3098. if is_water == "请选择" {
  3099. is_war = 0
  3100. }
  3101. drhy_water := c.GetString("drhy_water")
  3102. dry_water_hour := c.GetString("dry_water_hour")
  3103. water_machine := c.GetString("water_machine")
  3104. dialysis_remark := c.GetString("dialysis_remark")
  3105. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3106. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3107. prescription_water, _ := c.GetFloat("prescription_water")
  3108. dialysis_strainer := c.GetString("dialysis_strainer")
  3109. chaptalization := c.GetString("chaptalization")
  3110. if mode_id > 0 {
  3111. var str string
  3112. //查找该机构用的是什么透析器
  3113. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3114. if filedConfig.ID > 0 {
  3115. str = dialyzerPerfusionApparatus
  3116. } else {
  3117. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3118. }
  3119. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3120. }
  3121. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3122. //
  3123. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3124. // if appRole.UserType == 3 {
  3125. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3126. // if getPermissionErr != nil {
  3127. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3128. // return
  3129. // } else if headNursePermission == nil {
  3130. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3131. // return
  3132. // }
  3133. // }
  3134. //}
  3135. // 查询信息规挡的设置天数
  3136. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3137. if infor.ID > 0 && infor.WeekDay > 0 {
  3138. var cha_time int64
  3139. timeNowStr := time.Now().Format("2006-01-02")
  3140. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3141. //今日的日期减去设置的日期
  3142. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3143. if cha_time >= recordDate.Unix() {
  3144. //查询审核是否允许
  3145. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3146. //申请状态不允许的情况 拒绝修改
  3147. if infor.ApplicationStatus != 1 {
  3148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3149. return
  3150. }
  3151. }
  3152. }
  3153. prescription := models.DialysisPrescription{
  3154. UserOrgId: adminUserInfo.Org.Id,
  3155. PatientId: id,
  3156. RecordDate: recordDate.Unix(),
  3157. ModeId: mode_id,
  3158. DialysisDuration: dialysis_duration,
  3159. Dialyzer: dialyzer,
  3160. PerfusionApparatus: perfusion_apparatus,
  3161. BloodFlowVolume: blood_flow_volume,
  3162. DewaterAmount: dewater_amount,
  3163. DisplaceLiqui: displace_liqui,
  3164. ReplacementWay: replacement_way,
  3165. Anticoagulant: anticoagulant,
  3166. AnticoagulantShouji: anticoagulant_shouji,
  3167. AnticoagulantWeichi: anticoagulant_weichi,
  3168. AnticoagulantZongliang: anticoagulant_zongliang,
  3169. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3170. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3171. Kalium: kalium,
  3172. Sodium: sodium,
  3173. Calcium: calcium,
  3174. Bicarbonate: bicarbonate,
  3175. Glucose: glucose,
  3176. // DryWeight: dry_weight,
  3177. DialysateFlow: dialysate_flow,
  3178. DialysateTemperature: dialysate_temperature,
  3179. Conductivity: conductivity,
  3180. Remark: remark,
  3181. Status: 1,
  3182. CreatedTime: time.Now().Unix(),
  3183. UpdatedTime: time.Now().Unix(),
  3184. DialysisDurationMinute: dialysisDurationMinute,
  3185. DialysisDurationHour: dialysisDurationHour,
  3186. TargetUltrafiltration: targetUltrafiltration,
  3187. DialysateFormulation: dialysateFormulation,
  3188. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3189. BodyFluid: body_fluid,
  3190. SpecialMedicine: special_medicine,
  3191. SpecialMedicineOther: special_medicine_other,
  3192. DisplaceLiquiPart: displace_liqui_part,
  3193. DisplaceLiquiValue: displace_liqui_value,
  3194. BloodAccess: blood_access,
  3195. Ultrafiltration: ultrafiltration,
  3196. BodyFluidOther: body_fluid_other,
  3197. ReplacementTotal: replacement_total,
  3198. Niprocart: niprocart,
  3199. Jms: jms,
  3200. FistulaNeedleSet: fistula_needle_set,
  3201. FistulaNeedleSet16: fistula_needle_set_16,
  3202. Hemoperfusion: hemoperfusion,
  3203. DialyserSterilised: dialyser_sterilised,
  3204. Filtryzer: filtryzer,
  3205. TargetKtv: target_ktv,
  3206. Dialyzers: dialyzers,
  3207. Injector: injector,
  3208. Bloodlines: bloodlines,
  3209. TubingHemodialysis: tubing_hemodialysis,
  3210. Package: safe_package,
  3211. ALiquid: a_liquid,
  3212. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3213. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3214. Blood: blood,
  3215. DialysisDialyszers: dialysis_dialyszers,
  3216. DialysisIrrigation: dialysis_irrigation,
  3217. AntioxidantCommodityName: antioxidant_commodity_name,
  3218. DisplaceSpeed: displace_speed,
  3219. Illness: illness,
  3220. Amylaceum: amylaceum,
  3221. SingleWater: single_water,
  3222. SingleTime: single_time,
  3223. ReplacementFlow: replacement_flow,
  3224. PlasmaSeparator: plasma_separator,
  3225. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3226. OxygenUptake: oxygen_uptake,
  3227. OxygenTime: oxygen_time,
  3228. OxygenFlow: oxygen_flow,
  3229. HemodialysisPipelines: hemodialysis_pipelines,
  3230. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3231. PunctureNeedle: puncture_needle,
  3232. PunctureNeedleCount: puncture_needle_count,
  3233. Epo: epo,
  3234. EpoCount: epo_count,
  3235. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3236. PreImpulse: impulse,
  3237. AdminUserId: admin_user_id,
  3238. IsWater: is_war,
  3239. DrhyWater: drhy_water,
  3240. DryWaterHour: dry_water_hour,
  3241. WaterMachine: water_machine,
  3242. AddAmount: add_amount,
  3243. ReduceAmount: reduce_amount,
  3244. DialysisRemark: dialysis_remark,
  3245. PrescribingNumber: prescribing_number,
  3246. PrescriptionSodium: prescription_sodium,
  3247. StartSodium: start_sodium,
  3248. SodiumCurve: sodium_curve,
  3249. TreatmentRemark: treatment_remark,
  3250. DialysisFluidFlow: dialysis_fluid_flow,
  3251. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3252. PrescriptionWater: prescription_water,
  3253. DialysisStrainer: dialysis_strainer,
  3254. Chaptalization: chaptalization,
  3255. }
  3256. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3257. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3258. fmt.Println("appRole0000000000000", appRole.UserType)
  3259. //
  3260. if appRole.UserType == 2 || appRole.UserType == 1 {
  3261. prescription_doctor = adminUserInfo.AdminUser.Id
  3262. prescription.PrescriptionDoctor = prescription_doctor
  3263. }
  3264. if dialysisPrescription.ID == 0 { //新增
  3265. prescription.Creater = adminUserInfo.AdminUser.Id
  3266. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3267. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3268. }
  3269. } else { //修改
  3270. if dialysisPrescription.Creater == 0 {
  3271. prescription.Creater = adminUserInfo.AdminUser.Id
  3272. } else {
  3273. prescription.Creater = dialysisPrescription.Creater
  3274. if adminUserInfo.Org.Id == 9882 {
  3275. if appRole.UserType == 2 || appRole.UserType == 1 {
  3276. prescription.Creater = adminUserInfo.AdminUser.Id
  3277. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3278. }
  3279. }
  3280. }
  3281. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3282. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3283. }
  3284. //if/**/
  3285. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3286. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3287. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3288. // if getPermissionErr != nil {
  3289. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3290. // return
  3291. // } else if headNursePermission == nil {
  3292. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3293. // return
  3294. // }
  3295. //}
  3296. //prescription.Creater = dialysisPrescription.Creater
  3297. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3298. prescription.Modifier = adminUserInfo.AdminUser.Id
  3299. prescription.ID = dialysisPrescription.ID
  3300. }
  3301. solution := models.DialysisSolution{
  3302. RegistrarsId: adminUserInfo.AdminUser.Id,
  3303. UserOrgId: adminUserInfo.Org.Id,
  3304. Doctor: prescription_doctor,
  3305. PatientId: id,
  3306. ModeId: mode_id,
  3307. DialysisDuration: dialysis_duration,
  3308. PerfusionApparatus: perfusion_apparatus,
  3309. BloodFlowVolume: blood_flow_volume,
  3310. Dewater: dewater_amount,
  3311. DisplaceLiqui: displace_liqui,
  3312. ReplacementWay: replacement_way,
  3313. Anticoagulant: anticoagulant,
  3314. AnticoagulantShouji: anticoagulant_shouji,
  3315. AnticoagulantWeichi: anticoagulant_weichi,
  3316. AnticoagulantZongliang: anticoagulant_zongliang,
  3317. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3318. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3319. Kalium: kalium,
  3320. Sodium: sodium,
  3321. Calcium: calcium,
  3322. Bicarbonate: bicarbonate,
  3323. Glucose: glucose,
  3324. // DryWeight: dry_weight,
  3325. DialysateFlow: dialysate_flow,
  3326. DialysateTemperature: dialysate_temperature,
  3327. Conductivity: conductivity,
  3328. Remark: remark,
  3329. Status: 1,
  3330. CreatedTime: time.Now().Unix(),
  3331. UpdatedTime: time.Now().Unix(),
  3332. DialysisDurationMinute: dialysisDurationMinute,
  3333. DialysisDurationHour: dialysisDurationHour,
  3334. TargetUltrafiltration: targetUltrafiltration,
  3335. DialysateFormulation: dialysateFormulation,
  3336. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3337. BodyFluid: body_fluid,
  3338. SpecialMedicine: special_medicine,
  3339. SpecialMedicineOther: special_medicine_other,
  3340. DisplaceLiquiPart: displace_liqui_part,
  3341. DisplaceLiquiValue: displace_liqui_value,
  3342. BloodAccess: blood_access,
  3343. Ultrafiltration: ultrafiltration,
  3344. BodyFluidOther: body_fluid_other,
  3345. ReplacementTotal: replacement_total,
  3346. TargetKtv: target_ktv,
  3347. DialysisDialyszers: dialysis_dialyszers,
  3348. DialysisIrrigation: dialysis_irrigation,
  3349. HemodialysisPipelines: hemodialysis_pipelines,
  3350. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3351. PunctureNeedle: puncture_needle,
  3352. PunctureNeedleCount: puncture_needle_count,
  3353. Epo: epo,
  3354. EpoCount: epo_count,
  3355. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3356. PreImpulse: impulse,
  3357. SolutionStatus: 1,
  3358. DialysisRemark: dialysis_remark,
  3359. PrescribingNumber: prescribing_number,
  3360. PrescriptionSodium: prescription_sodium,
  3361. StartSodium: start_sodium,
  3362. SodiumCurve: sodium_curve,
  3363. TreatmentRemark: treatment_remark,
  3364. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3365. DialysisFluidFlow: dialysis_fluid_flow,
  3366. PrescriptionWater: prescription_water,
  3367. DialysisStrainer: dialysis_strainer,
  3368. Chaptalization: chaptalization,
  3369. }
  3370. //针对河间咸的
  3371. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  3372. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  3373. solution.DisplaceLiquiPart = 0
  3374. solution.DisplaceLiquiValue = 0
  3375. }
  3376. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  3377. prescription.DisplaceLiquiPart = 0
  3378. prescription.DisplaceLiquiValue = 0
  3379. }
  3380. }
  3381. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  3382. if solution.PrescribingNumber == 0 {
  3383. solution.PrescribingNumber = 1
  3384. }
  3385. if prescription.PrescribingNumber == 0 {
  3386. prescription.PrescribingNumber = 1
  3387. }
  3388. if solution.PrescribingNumber == 0 && id == 14682 {
  3389. solution.PrescribingNumber = 2
  3390. }
  3391. if solution.PrescribingNumber == 0 && id == 18560 {
  3392. solution.PrescribingNumber = 2
  3393. }
  3394. if prescription.PrescribingNumber == 0 && id == 14682 {
  3395. prescription.PrescribingNumber = 2
  3396. }
  3397. if prescription.PrescribingNumber == 0 && id == 18560 {
  3398. prescription.PrescribingNumber = 2
  3399. }
  3400. }
  3401. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  3402. finish := models.XtDialysisFinish{
  3403. IsFinish: 1,
  3404. UserOrgId: adminUserInfo.Org.Id,
  3405. Status: 1,
  3406. Ctime: time.Now().Unix(),
  3407. Mtime: 0,
  3408. Module: 1,
  3409. RecordDate: recordDate.Unix(),
  3410. Sourse: 1,
  3411. PatientId: id,
  3412. }
  3413. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  3414. if dialysisFinish.ID == 0 {
  3415. service.CreateDialysisFinish(finish)
  3416. }
  3417. //获取最新1条
  3418. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  3419. //更新状态
  3420. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  3421. //长沙南雅医院,自动生成抗凝剂的临时处方
  3422. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  3423. if prescribing_number == 0 {
  3424. prescribing_number = 1
  3425. }
  3426. advice := models.DoctorAdvice{
  3427. UserOrgId: adminUserInfo.Org.Id,
  3428. PatientId: id,
  3429. GroupNo: 0,
  3430. AdviceType: 2,
  3431. RecordDate: recordDate.Unix(),
  3432. AdviceDate: recordDate.Unix(),
  3433. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  3434. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  3435. AdviceDesc: "",
  3436. ReminderDate: 0,
  3437. SingleDose: prescription.AnticoagulantZongliang,
  3438. SingleDoseUnit: "iu",
  3439. DrugSpec: 0,
  3440. DrugSpecUnit: "",
  3441. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  3442. PrescribingNumberUnit: "支",
  3443. DeliveryWay: "静脉注射",
  3444. ExecutionFrequency: "上机前",
  3445. AdviceDoctor: 0,
  3446. Status: 1,
  3447. CreatedTime: time.Now().Unix(),
  3448. UpdatedTime: time.Now().Unix(),
  3449. IsPrescription: 1,
  3450. ExecutionState: 2,
  3451. StopState: 2,
  3452. IsSettle: 2,
  3453. }
  3454. // 查询排班信息
  3455. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3456. if schedulePatient.ID > 0 {
  3457. if schedulePatient.ScheduleType == 1 {
  3458. advice.StartTime = recordDate.Unix() + 6.5*60*60
  3459. }
  3460. if schedulePatient.ScheduleType == 2 {
  3461. advice.StartTime = recordDate.Unix() + 10*60*60
  3462. }
  3463. }
  3464. // 抗凝剂名称
  3465. switch anticoagulant {
  3466. case 1:
  3467. advice.AdviceName = "无肝素"
  3468. break
  3469. case 2:
  3470. advice.AdviceName = "普通肝素"
  3471. break
  3472. case 3:
  3473. advice.AdviceName = "低分子肝素"
  3474. break
  3475. case 4:
  3476. advice.AdviceName = "阿加曲班"
  3477. break
  3478. case 5:
  3479. advice.AdviceName = "枸橼酸钠"
  3480. break
  3481. case 6:
  3482. advice.AdviceName = "低分子肝素钙"
  3483. break
  3484. case 7:
  3485. advice.AdviceName = "低分子肝素钠"
  3486. break
  3487. case 8:
  3488. advice.AdviceName = "依诺肝素"
  3489. break
  3490. case 9:
  3491. advice.AdviceName = "达肝素"
  3492. break
  3493. case 10:
  3494. advice.AdviceName = "体外抗凝"
  3495. break
  3496. case 11:
  3497. advice.AdviceName = "那曲肝素"
  3498. break
  3499. case 12:
  3500. advice.AdviceName = "无抗凝剂"
  3501. break
  3502. }
  3503. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  3504. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  3505. advice.AdviceDoctor = appRole.AdminUserId
  3506. }
  3507. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  3508. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  3509. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  3510. advice.AdviceName = "低分子肝素钠注射液"
  3511. // 修改患者临时医嘱里的抗凝剂医嘱
  3512. advice.ID = advicePrescription.ID
  3513. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  3514. } else {
  3515. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  3516. advice.AdviceName = "低分子肝素钠注射液"
  3517. service.CreateDoctorAdvice(&advice)
  3518. }
  3519. }
  3520. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  3521. redis := service.RedisClient()
  3522. defer redis.Close()
  3523. //清空key 值
  3524. redis.Set(key, "", time.Second)
  3525. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  3526. redis.Set(keyOne, "", time.Second)
  3527. }
  3528. //获取key,清空redis
  3529. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3530. redis := service.RedisClient()
  3531. defer redis.Close()
  3532. //清空key 值
  3533. redis.Set(key, "", time.Second)
  3534. //清空长期医嘱的key
  3535. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3536. redis.Set(soulution_key, "", time.Second)
  3537. //查询最近透析准备表里是否存在 透析器 灌流器
  3538. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3539. redis.Set(keyOne, "", time.Second)
  3540. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  3541. redis.Set(keyTwo, "", time.Second)
  3542. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3543. redis.Set(keyThree, "", time.Second)
  3544. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  3545. redis.Set(keyFour, "", time.Second)
  3546. //splitStr := strings.Split(dialysis_dialyszers, ",")
  3547. //
  3548. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  3549. //
  3550. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  3551. //if len(mation)>0{
  3552. // for _, item := range splitStr {
  3553. // for _,it := range mation{
  3554. // if(item == it.SpecificationName){
  3555. //
  3556. // //查询最近一次的透析器
  3557. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3558. //
  3559. // if errcode == gorm.ErrRecordNotFound{
  3560. // //插入数据
  3561. // prepare := models.DialysisBeforePrepare{
  3562. // UserOrgId: adminUserInfo.Org.Id,
  3563. // PatientId: id,
  3564. // RecordDate: recordDate.Unix(),
  3565. // GoodTypeId: it.GoodTypeId,
  3566. // GoodId: it.ID,
  3567. // Count: 1,
  3568. // Ctime: time.Now().Unix(),
  3569. // Creater: adminUserInfo.AdminUser.Id,
  3570. // Status:1,
  3571. //
  3572. // }
  3573. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3574. // fmt.Println("",errcode)
  3575. // }
  3576. // }
  3577. // }
  3578. //
  3579. // }
  3580. //
  3581. // for _, item := range splitIrrigation {
  3582. // for _,it := range mation{
  3583. // if(item == it.SpecificationName){
  3584. // //查询最近一次的透析器
  3585. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3586. // if errcode == gorm.ErrRecordNotFound{
  3587. // //插入数据
  3588. // prepare := models.DialysisBeforePrepare{
  3589. // UserOrgId: adminUserInfo.Org.Id,
  3590. // PatientId: id,
  3591. // RecordDate: recordDate.Unix(),
  3592. // GoodTypeId: it.GoodTypeId,
  3593. // GoodId: it.ID,
  3594. // Count: 1,
  3595. // Ctime: time.Now().Unix(),
  3596. // Creater: adminUserInfo.AdminUser.Id,
  3597. // Status:1,
  3598. //
  3599. // }
  3600. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3601. // fmt.Println(errcode)
  3602. // }
  3603. // }
  3604. // }
  3605. // }
  3606. //}
  3607. c.ServeSuccessJSON(map[string]interface{}{
  3608. "solution": &solution,
  3609. "prescription": &prescription,
  3610. })
  3611. }
  3612. func (c *DialysisAPIController) GetAcceptsAssessment() {
  3613. patient, _ := c.GetInt64("patient", 0)
  3614. adminUserInfo := c.GetMobileAdminUserInfo()
  3615. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  3616. c.ServeSuccessJSON(map[string]interface{}{
  3617. "receiveTreatmentAsses": receiveTreatmentAsses,
  3618. })
  3619. }
  3620. func (this *DialysisAPIController) PostSignInfo() {
  3621. patientID, _ := this.GetInt64("patient_id")
  3622. recordDateStr := this.GetString("date")
  3623. if patientID <= 0 {
  3624. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3625. return
  3626. }
  3627. if len(recordDateStr) == 0 {
  3628. recordDateStr = time.Now().Format("2006-01-02")
  3629. }
  3630. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3631. if parseDateErr != nil {
  3632. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3633. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3634. return
  3635. }
  3636. adminInfo := this.GetMobileAdminUserInfo()
  3637. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  3638. if err != nil {
  3639. this.ErrorLog("签名失败:%v", err)
  3640. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3641. return
  3642. }
  3643. this.ServeSuccessJSON(map[string]interface{}{
  3644. "doctor_id": adminInfo.AdminUser.Id,
  3645. })
  3646. }
  3647. func (this *DialysisAPIController) GetLastMonitorRecord() {
  3648. patientID, _ := this.GetInt64("patient_id")
  3649. adminInfo := this.GetMobileAdminUserInfo()
  3650. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  3651. this.ServeSuccessJSON(map[string]interface{}{
  3652. "monitor": record,
  3653. })
  3654. }
  3655. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  3656. thisTime := time.Now()
  3657. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  3658. timeLayout := "2006-01-02 15:04:05"
  3659. loc, _ := time.LoadLocation("Local")
  3660. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3661. theAssessmentDateTime := theStartTime.Unix()
  3662. patientID, _ := this.GetInt64("patient_id")
  3663. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  3664. adminInfo := this.GetMobileAdminUserInfo()
  3665. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3666. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3667. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  3668. var ultrafiltration_rate float64
  3669. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3670. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3671. fmt.Println(evaluation)
  3672. fmt.Println("prescription.ID", prescription.ID)
  3673. if prescription.ID > 0 {
  3674. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3675. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3676. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375) && adminInfo.Org.Id != 9538 {
  3677. fmt.Println("hahhdahahah")
  3678. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3679. record.UltrafiltrationRate = ultrafiltration_rate
  3680. }
  3681. if adminInfo.Org.Id == 10510 {
  3682. record.UltrafiltrationRate = 0
  3683. }
  3684. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  3685. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  3686. record.UltrafiltrationRate = ultrafiltration_rate
  3687. }
  3688. if template.TemplateId == 20 || template.TemplateId == 22 {
  3689. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3690. record.UltrafiltrationRate = ultrafiltration_rate
  3691. }
  3692. // 只针对方济医院
  3693. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  3694. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3695. ultrafiltration_rate = value
  3696. record.UltrafiltrationRate = ultrafiltration_rate
  3697. }
  3698. if template.TemplateId == 41 || template.TemplateId == 47 {
  3699. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3700. record.UltrafiltrationRate = ultrafiltration_rate
  3701. }
  3702. if template.TemplateId == 43 {
  3703. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3704. record.UltrafiltrationRate = ultrafiltration_rate
  3705. }
  3706. if template.TemplateId == 46 || template.TemplateId == 54 {
  3707. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3708. record.UltrafiltrationRate = ultrafiltration_rate
  3709. }
  3710. 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 {
  3711. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  3712. record.UltrafiltrationRate = ultrafiltration_rate
  3713. }
  3714. if adminInfo.Org.Id == 10469 {
  3715. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  3716. record.UltrafiltrationRate = ultrafiltration_rate
  3717. }
  3718. if adminInfo.Org.Id == 10471 {
  3719. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3720. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3721. }
  3722. if adminInfo.Org.Id == 10460 {
  3723. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3724. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3725. }
  3726. //if template.TemplateId == 47 {
  3727. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3728. // record.UltrafiltrationRate = ultrafiltration_rate
  3729. //}
  3730. }
  3731. }
  3732. // record.UltrafiltrationRate = ultrafiltration_rate
  3733. record.UltrafiltrationVolume = 0
  3734. 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
  3735. if ultrafiltration_rate > 0 {
  3736. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  3737. record.UltrafiltrationVolume = value
  3738. }
  3739. }
  3740. 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
  3741. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  3742. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3743. record.UltrafiltrationVolume = ultrafiltration_volume
  3744. }
  3745. }
  3746. //长沙南雅
  3747. 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 {
  3748. if ultrafiltration_rate > 0 {
  3749. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3750. record.UltrafiltrationVolume = ultrafiltration_volume
  3751. }
  3752. }
  3753. if adminInfo.Org.Id == 10471 {
  3754. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3755. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3756. }
  3757. if adminInfo.Org.Id == 10460 {
  3758. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3759. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3760. }
  3761. //长沙南雅累计血容量自动计算
  3762. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  3763. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  3764. //}
  3765. if template.TemplateId == 47 || template.TemplateId == 54 {
  3766. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  3767. }
  3768. if adminInfo.Org.Id == 10510 {
  3769. record.UltrafiltrationVolume = 0
  3770. }
  3771. this.ServeSuccessJSON(map[string]interface{}{
  3772. "monitor": record,
  3773. })
  3774. }
  3775. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  3776. record_id, _ := this.GetInt64("id")
  3777. nurseID, _ := this.GetInt64("start_nurse")
  3778. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3779. bedID, _ := this.GetInt64("bed")
  3780. start_time := this.GetString("start_time")
  3781. schedual_type, _ := this.GetInt64("schedual_type")
  3782. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3783. change_nurse, _ := this.GetInt64("change_nurse")
  3784. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3785. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3786. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3787. fmt.Println("quality_nurse_id", quality_nurse_id)
  3788. patient_id, _ := this.GetInt64("patient_id")
  3789. record_date, _ := this.GetInt64("record_date")
  3790. puncture_needle := this.GetString("puncture_needle")
  3791. puncture_way := this.GetString("puncture_way")
  3792. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3793. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3794. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3795. nuclein_date_str := this.GetString("nuclein_date_str")
  3796. order_remark := this.GetString("order_remark")
  3797. schedule_remark := this.GetString("schedule_remark")
  3798. catheter_operation := this.GetString("catheter_operation")
  3799. if record_id == 0 {
  3800. this.ErrorLog("id:%v", record_id)
  3801. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3802. return
  3803. }
  3804. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3805. if parseStartDateErr != nil {
  3806. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3807. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3808. return
  3809. }
  3810. adminUserInfo := this.GetMobileAdminUserInfo()
  3811. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3812. if getNurseErr != nil {
  3813. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3814. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3815. return
  3816. } else if nurse == nil {
  3817. this.ErrorLog("护士不存在")
  3818. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3819. return
  3820. }
  3821. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3822. //if getNurseErr != nil {
  3823. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  3824. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3825. // return
  3826. //} else if nurse == nil {
  3827. // this.ErrorLog("护士不存在")
  3828. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3829. // return
  3830. //}
  3831. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3832. if getDeviceNumberErr != nil {
  3833. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3834. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3835. return
  3836. } else if deviceNumber == nil {
  3837. this.ErrorLog("床位号不存在")
  3838. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3839. return
  3840. }
  3841. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  3842. //
  3843. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  3844. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3845. // if getPermissionErr != nil {
  3846. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3847. // return
  3848. // } else if headNursePermission == nil {
  3849. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3850. // return
  3851. // }
  3852. //}
  3853. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  3854. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  3855. timeLayout := "2006-01-02 15:04:05"
  3856. loc, _ := time.LoadLocation("Local")
  3857. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3858. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  3859. schedulestartTime := theStartTime.Unix()
  3860. scheduleendTime := theEndTime.Unix()
  3861. var theNucleinDate int64
  3862. timeLayoutOne := "2006-01-02"
  3863. if len(nuclein_date_str) > 0 {
  3864. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  3865. if err != nil {
  3866. utils.ErrorLog(err.Error())
  3867. }
  3868. theNucleinDate = theTime.Unix()
  3869. }
  3870. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  3871. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3872. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  3873. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  3874. if err == gorm.ErrRecordNotFound { //空床位
  3875. // 修改了床位逻辑
  3876. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  3877. if daySchedule.ID > 0 {
  3878. //daySchedule.BedId = bedID
  3879. //daySchedule.PartitionId = deviceNumber.ZoneID
  3880. //daySchedule.ScheduleType = schedual_type
  3881. //daySchedule.UpdatedTime = time.Now().Unix()
  3882. //err := service.UpdateSchedule(&daySchedule)
  3883. xtSchedule := models.Schedule{
  3884. PartitionId: deviceNumber.ZoneID,
  3885. BedId: bedID,
  3886. ScheduleType: schedual_type,
  3887. UpdatedTime: time.Now().Unix(),
  3888. }
  3889. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3890. if err != nil {
  3891. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3892. return
  3893. }
  3894. }
  3895. } else if err == nil {
  3896. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  3897. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  3898. if daySchedule.ID > 0 {
  3899. //daySchedule.BedId = bedID
  3900. //daySchedule.PartitionId = deviceNumber.ZoneID
  3901. //
  3902. //daySchedule.ScheduleType = schedual_type
  3903. //daySchedule.UpdatedTime = time.Now().Unix()
  3904. //err := service.UpdateSchedule(&daySchedule)
  3905. xtSchedule := models.Schedule{
  3906. PartitionId: deviceNumber.ZoneID,
  3907. BedId: bedID,
  3908. ScheduleType: schedual_type,
  3909. UpdatedTime: time.Now().Unix(),
  3910. }
  3911. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3912. if err != nil {
  3913. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3914. return
  3915. }
  3916. }
  3917. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  3918. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3919. return
  3920. }
  3921. } else if err != nil {
  3922. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3923. return
  3924. }
  3925. }
  3926. dialysisRecord := &models.DialysisOrder{
  3927. ID: record_id,
  3928. UserOrgId: adminUserInfo.Org.Id,
  3929. BedID: bedID,
  3930. StartNurse: nurseID,
  3931. StartTime: startDate.Unix(),
  3932. PunctureNurse: puncture_nurse,
  3933. Creator: adminUserInfo.AdminUser.Id,
  3934. Modifier: adminUserInfo.AdminUser.Id,
  3935. WashpipeNurse: washpipe_nurse,
  3936. SchedualType: schedual_type,
  3937. ChangeNurse: change_nurse,
  3938. DifficultPunctureNurse: difficult_puncture_nurse,
  3939. NewFistulaNurse: new_fistula_nurse,
  3940. QualityNurseId: quality_nurse_id,
  3941. PunctureNeedle: puncture_needle,
  3942. PunctureWay: puncture_way,
  3943. DialysisDialyszers: dialysis_dialyszers,
  3944. DialysisIrrigation: dialysis_irrigation,
  3945. BloodAccessId: blood_access_id,
  3946. NucleinDate: theNucleinDate,
  3947. OrderRemark: order_remark,
  3948. ScheduleRemark: schedule_remark,
  3949. CatheterOperation: catheter_operation,
  3950. }
  3951. //修改床位号需要重新消毒
  3952. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  3953. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  3954. //查询第一条监测
  3955. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  3956. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  3957. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  3958. redis := service.RedisClient()
  3959. //清空key 值
  3960. redis.Set(key, "", time.Second)
  3961. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  3962. redis.Set(keyOne, "", time.Second)
  3963. defer redis.Close()
  3964. }
  3965. // 查询信息规挡的设置天数
  3966. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3967. if infor.ID > 0 && infor.WeekDay > 0 {
  3968. var cha_time int64
  3969. timeNowStr := time.Now().Format("2006-01-02")
  3970. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3971. //今日的日期减去设置的日期
  3972. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3973. if cha_time >= record_date {
  3974. //查询审核是否允许
  3975. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id)
  3976. //申请状态不允许的情况 拒绝修改
  3977. if infor.ApplicationStatus != 1 {
  3978. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3979. return
  3980. }
  3981. }
  3982. }
  3983. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  3984. order, _ := service.GetLastPatientOrder(record_id)
  3985. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  3986. redis := service.RedisClient()
  3987. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  3988. redis.Set(key, "", time.Second)
  3989. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  3990. //清空key 值
  3991. redis.Set(keyOne, "", time.Second)
  3992. scheduleDateStartOne := startDate.Format("2006-01-02")
  3993. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3994. redis.Set(keyTwo, "", time.Second)
  3995. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  3996. redis.Set(keyThree, "", time.Second)
  3997. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  3998. redis.Set(keyFour, "", time.Second)
  3999. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4000. redis.Set(keyFive, "", time.Second)
  4001. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4002. redis.Set(keySix, "", time.Second)
  4003. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4004. redis.Set(keySeven, "", time.Second)
  4005. if updateErr != nil {
  4006. this.ErrorLog("修改上机失败:%v", updateErr)
  4007. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4008. return
  4009. }
  4010. if updateErr == nil {
  4011. if tempDialysisRecord.Stage == 2 {
  4012. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4013. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4014. fmt.Println(value)
  4015. a, b := math.Modf(value)
  4016. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4017. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4018. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4019. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4020. redis := service.RedisClient()
  4021. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4022. redis.Set(key, "", time.Second)
  4023. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4024. redis.Set(keyOne, "", time.Second)
  4025. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4026. //清空key 值
  4027. redis.Set(keySix, "", time.Second)
  4028. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4029. redis.Set(keySeven, "", time.Second)
  4030. redis.Close()
  4031. if updateAssessmentErr != nil {
  4032. utils.ErrorLog("%v", updateAssessmentErr)
  4033. }
  4034. }
  4035. }
  4036. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4037. this.ServeSuccessJSON(map[string]interface{}{
  4038. "dialysis_order": dialysisRecords,
  4039. })
  4040. }
  4041. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4042. record_id, _ := c.GetInt64("id")
  4043. nurseID, _ := c.GetInt64("nurse")
  4044. end_time := c.GetString("end_time")
  4045. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4046. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4047. catheter := c.GetString("catheter")
  4048. cruor := c.GetString("cruor")
  4049. mission := c.GetString("mission")
  4050. if record_id <= 0 || nurseID <= 0 {
  4051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4052. return
  4053. }
  4054. adminUserInfo := c.GetMobileAdminUserInfo()
  4055. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4056. if getNurseErr != nil {
  4057. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4058. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4059. return
  4060. } else if nurse == nil {
  4061. c.ErrorLog("护士不存在")
  4062. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4063. return
  4064. }
  4065. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4066. if parseEndDateErr != nil {
  4067. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4069. return
  4070. }
  4071. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4072. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4073. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4074. // if getPermissionErr != nil {
  4075. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4076. // return
  4077. // } else if headNursePermission == nil {
  4078. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4079. // return
  4080. // }
  4081. //}
  4082. // 查询信息规挡的设置天数
  4083. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4084. if infor.ID > 0 {
  4085. var cha_time int64
  4086. timeNowStr := time.Now().Format("2006-01-02")
  4087. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4088. //今日的日期减去设置的日期
  4089. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4090. if cha_time >= tempDialysisRecords.DialysisDate {
  4091. //查询审核是否允许
  4092. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id)
  4093. //申请状态不允许的情况 拒绝修改
  4094. if infor.ApplicationStatus != 1 {
  4095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4096. return
  4097. }
  4098. }
  4099. }
  4100. dialysisRecord := &models.DialysisOrder{
  4101. ID: record_id,
  4102. UserOrgId: adminUserInfo.Org.Id,
  4103. EndTime: endDate.Unix(),
  4104. FinishNurse: nurseID,
  4105. FinishModifier: adminUserInfo.AdminUser.Id,
  4106. PuncturePointHaematoma: puncture_point_haematoma,
  4107. BloodAccessInternalFistula: blood_access_internal_fistula,
  4108. Catheter: catheter,
  4109. Cruor: cruor,
  4110. Mission: mission,
  4111. }
  4112. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4113. redis := service.RedisClient()
  4114. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4115. //清空key 值
  4116. redis.Set(key, "", time.Second)
  4117. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4118. //清空key 值
  4119. redis.Set(keyOne, "", time.Second)
  4120. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4121. redis.Set(keySeven, "", time.Second)
  4122. redis.Close()
  4123. if updateErr != nil {
  4124. c.ErrorLog("修改下机失败:%v", updateErr)
  4125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4126. return
  4127. }
  4128. if updateErr == nil {
  4129. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4130. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4131. a, b := math.Modf(value)
  4132. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4133. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4134. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4135. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4136. redis := service.RedisClient()
  4137. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4138. redis.Set(keyTen, "", time.Second)
  4139. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4140. redis.Set(keyTwo, "", time.Second)
  4141. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4142. redis.Set(key, "", time.Second)
  4143. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4144. redis.Set(keyThree, "", time.Second)
  4145. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4146. redis.Set(keySeven, "", time.Second)
  4147. defer redis.Close()
  4148. if updateAssessmentErr != nil {
  4149. utils.ErrorLog("%v", updateAssessmentErr)
  4150. }
  4151. }
  4152. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4153. c.ServeSuccessJSON(map[string]interface{}{
  4154. "dialysis_order": dialysisRecords,
  4155. })
  4156. }
  4157. func (c *DialysisAPIController) GetLongAdvice() {
  4158. patient_id, _ := c.GetInt64("id")
  4159. adminUserInfo := c.GetMobileAdminUserInfo()
  4160. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4161. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4162. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4163. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4164. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4165. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4166. c.ServeSuccessJSON(map[string]interface{}{
  4167. "status": "1",
  4168. })
  4169. return
  4170. } else { //开启推送提醒
  4171. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4172. var advice_three []*models.DoctorAdvice
  4173. recordDateStr := time.Now().Format("2006-01-02")
  4174. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4175. nowtime := recordDate.Unix()
  4176. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4177. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4178. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4179. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4180. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4181. for _, advice := range advices {
  4182. if advice.FrequencyType == 3 {
  4183. t := time.Now()
  4184. week := int(t.Weekday())
  4185. fmt.Println(t.Weekday())
  4186. fmt.Println(week)
  4187. switch week {
  4188. case 1:
  4189. if strings.Index(advice.WeekDay, "周一") == -1 {
  4190. advice_three = append(advice_three, advice)
  4191. }
  4192. break
  4193. case 2:
  4194. if strings.Index(advice.WeekDay, "周二") == -1 {
  4195. advice_three = append(advice_three, advice)
  4196. }
  4197. break
  4198. case 3:
  4199. if strings.Index(advice.WeekDay, "周三") == -1 {
  4200. advice_three = append(advice_three, advice)
  4201. }
  4202. break
  4203. case 4:
  4204. if strings.Index(advice.WeekDay, "周四") == -1 {
  4205. advice_three = append(advice_three, advice)
  4206. }
  4207. break
  4208. case 5:
  4209. if strings.Index(advice.WeekDay, "周五") == -1 {
  4210. advice_three = append(advice_three, advice)
  4211. }
  4212. break
  4213. case 6:
  4214. if strings.Index(advice.WeekDay, "周六") == -1 {
  4215. advice_three = append(advice_three, advice)
  4216. }
  4217. break
  4218. case 0:
  4219. if strings.Index(advice.WeekDay, "周日") == -1 {
  4220. advice_three = append(advice_three, advice)
  4221. }
  4222. break
  4223. }
  4224. }
  4225. }
  4226. for _, advice := range advices_two {
  4227. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4228. now := p.Unix()
  4229. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4230. dayStr2 := "-" + dayStr
  4231. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4232. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4233. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4234. for _, ad := range advices {
  4235. advice_three = append(advice_three, ad)
  4236. }
  4237. }
  4238. if err == nil {
  4239. c.ServeSuccessJSON(map[string]interface{}{
  4240. "status": "2",
  4241. "advices": advices,
  4242. "advices_two": RemoveRepeatedElement(advice_three),
  4243. "is_open_remind": config.IsOpenRemind,
  4244. "his_config_open": hisConfig.IsOpen,
  4245. "is_advice_open": is_advice_open.IsAdviceOpen,
  4246. "prescription_open": prescription_open.IsOpen,
  4247. })
  4248. }
  4249. }
  4250. }
  4251. func (c *DialysisAPIController) GetLongAdviceOne() {
  4252. patient_id, _ := c.GetInt64("id")
  4253. startTime := c.GetString("schedule_date")
  4254. timeLayout := "2006-01-02"
  4255. loc, _ := time.LoadLocation("Local")
  4256. var theStartTime int64
  4257. if len(startTime) > 0 {
  4258. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4259. if err != nil {
  4260. utils.ErrorLog(err.Error())
  4261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4262. return
  4263. }
  4264. theStartTime = theTime.Unix()
  4265. }
  4266. adminUserInfo := c.GetMobileAdminUserInfo()
  4267. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4268. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4269. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4270. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4271. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4272. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4273. c.ServeSuccessJSON(map[string]interface{}{
  4274. "status": "1",
  4275. })
  4276. return
  4277. } else { //开启推送提醒
  4278. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4279. var advice_three []*models.DoctorAdvice
  4280. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  4281. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  4282. for _, advice := range advices {
  4283. if advice.FrequencyType == 3 {
  4284. t := time.Now()
  4285. week := int(t.Weekday())
  4286. fmt.Println(t.Weekday())
  4287. fmt.Println(week)
  4288. switch week {
  4289. case 1:
  4290. if strings.Index(advice.WeekDay, "周一") == -1 {
  4291. advice_three = append(advice_three, advice)
  4292. }
  4293. break
  4294. case 2:
  4295. if strings.Index(advice.WeekDay, "周二") == -1 {
  4296. advice_three = append(advice_three, advice)
  4297. }
  4298. break
  4299. case 3:
  4300. if strings.Index(advice.WeekDay, "周三") == -1 {
  4301. advice_three = append(advice_three, advice)
  4302. }
  4303. break
  4304. case 4:
  4305. if strings.Index(advice.WeekDay, "周四") == -1 {
  4306. advice_three = append(advice_three, advice)
  4307. }
  4308. break
  4309. case 5:
  4310. if strings.Index(advice.WeekDay, "周五") == -1 {
  4311. advice_three = append(advice_three, advice)
  4312. }
  4313. break
  4314. case 6:
  4315. if strings.Index(advice.WeekDay, "周六") == -1 {
  4316. advice_three = append(advice_three, advice)
  4317. }
  4318. break
  4319. case 0:
  4320. if strings.Index(advice.WeekDay, "周日") == -1 {
  4321. advice_three = append(advice_three, advice)
  4322. }
  4323. break
  4324. }
  4325. }
  4326. }
  4327. for _, advice := range advices_two {
  4328. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4329. now := p.Unix()
  4330. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4331. dayStr2 := "-" + dayStr
  4332. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4333. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4334. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4335. for _, ad := range advices {
  4336. advice_three = append(advice_three, ad)
  4337. }
  4338. }
  4339. if err == nil {
  4340. c.ServeSuccessJSON(map[string]interface{}{
  4341. "status": "2",
  4342. "advices": advices,
  4343. "advices_two": RemoveRepeatedElement(advice_three),
  4344. "is_open_remind": config.IsOpenRemind,
  4345. "his_config_open": hisConfig.IsOpen,
  4346. "is_advice_open": is_advice_open.IsAdviceOpen,
  4347. "prescription_open": prescription_open.IsOpen,
  4348. })
  4349. }
  4350. }
  4351. }
  4352. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4353. newArr = make([]*models.DoctorAdvice, 0)
  4354. for i := 0; i < len(arr); i++ {
  4355. repeat := false
  4356. for j := i + 1; j < len(arr); j++ {
  4357. if arr[i].ID == arr[j].ID {
  4358. repeat = true
  4359. break
  4360. }
  4361. }
  4362. if !repeat {
  4363. newArr = append(newArr, arr[i])
  4364. }
  4365. }
  4366. return
  4367. }
  4368. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  4369. patient, _ := c.GetInt64("id", 0)
  4370. groupNo, _ := c.GetInt64("groupno", 0)
  4371. if patient <= 0 {
  4372. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4373. return
  4374. }
  4375. adminUserInfo := c.GetMobileAdminUserInfo()
  4376. dataBody := make(map[string]interface{}, 0)
  4377. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4378. if err != nil {
  4379. utils.ErrorLog(err.Error())
  4380. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4381. return
  4382. }
  4383. utils.ErrorLog("%v", dataBody)
  4384. timeLayout := "2006-01-02 15:04"
  4385. loc, _ := time.LoadLocation("Local")
  4386. timeLayout2 := "2006-01-02"
  4387. loc2, _ := time.LoadLocation("Local")
  4388. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4389. utils.ErrorLog("advice_type")
  4390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4391. return
  4392. }
  4393. adviceType := int64(2)
  4394. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4395. utils.ErrorLog("advice_date")
  4396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4397. return
  4398. }
  4399. adviceDate, _ := dataBody["advice_date"].(string)
  4400. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4401. AdviceDate := theTime.Unix()
  4402. RecordDate := theTime.Unix()
  4403. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4404. utils.ErrorLog("start_time")
  4405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4406. return
  4407. }
  4408. startTime, _ := dataBody["start_time"].(string)
  4409. if len(startTime) == 0 {
  4410. utils.ErrorLog("len(start_time) == 0")
  4411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4412. return
  4413. }
  4414. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4415. if err != nil {
  4416. utils.ErrorLog(err.Error())
  4417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4418. return
  4419. }
  4420. StartTime := theTime.Unix()
  4421. Remark := ""
  4422. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4423. remark, _ := dataBody["remark"].(string)
  4424. Remark = remark
  4425. }
  4426. var advices []*models.GroupAdvice
  4427. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4428. utils.ErrorLog("advices")
  4429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4430. return
  4431. }
  4432. adviceNames := dataBody["advices"].([]interface{})
  4433. for _, adviceNameMap := range adviceNames {
  4434. adviceNameM := adviceNameMap.(map[string]interface{})
  4435. var advice models.GroupAdvice
  4436. advice.Remark = Remark
  4437. advice.AdviceType = adviceType
  4438. advice.StartTime = StartTime
  4439. advice.AdviceDate = AdviceDate
  4440. advice.RecordDate = RecordDate
  4441. advice.Status = 1
  4442. advice.CreatedTime = time.Now().Unix()
  4443. advice.UpdatedTime = time.Now().Unix()
  4444. advice.StopState = 2
  4445. advice.ExecutionState = 2
  4446. advice.UserOrgId = adminUserInfo.Org.Id
  4447. advice.PatientId = patient
  4448. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4449. advice.IsSettle = 2
  4450. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4451. utils.ErrorLog("advice_name")
  4452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4453. return
  4454. }
  4455. adviceName, _ := adviceNameM["advice_name"].(string)
  4456. if len(adviceName) == 0 {
  4457. utils.ErrorLog("len(advice_name) == 0")
  4458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4459. return
  4460. }
  4461. advice.AdviceName = adviceName
  4462. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4463. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4464. advice.DrugSpec = drugSpec
  4465. }
  4466. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4467. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4468. advice.AdviceDesc = adviceDesc
  4469. }
  4470. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4471. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4472. advice.DrugSpecUnit = drugSpecUnit
  4473. }
  4474. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4475. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4476. // advice.SingleDose = singleDose
  4477. //}
  4478. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4479. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4480. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4481. }
  4482. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4483. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4484. advice.SingleDoseUnit = singleDoseUnit
  4485. }
  4486. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4487. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4488. // advice.PrescribingNumber = prescribingNumber
  4489. //}
  4490. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4491. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4492. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4493. }
  4494. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4495. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4496. advice.PrescribingNumberUnit = prescribingNumberUnit
  4497. }
  4498. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4499. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4500. advice.DeliveryWay = deliveryWay
  4501. }
  4502. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4503. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4504. advice.ExecutionFrequency = executionFrequency
  4505. }
  4506. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  4507. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  4508. advice.FrequencyType = frequency_type
  4509. }
  4510. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  4511. day_count := int64(adviceNameM["day_count"].(float64))
  4512. advice.DayCount = day_count
  4513. }
  4514. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  4515. week_day, _ := adviceNameM["week_day"].(string)
  4516. advice.WeekDay = week_day
  4517. }
  4518. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  4519. way := int64(adviceNameM["way"].(float64))
  4520. advice.Way = way
  4521. }
  4522. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  4523. drug_id := int64(adviceNameM["drug_id"].(float64))
  4524. advice.DrugId = drug_id
  4525. }
  4526. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  4527. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  4528. advice.DrugNameId = drug_name_id
  4529. }
  4530. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  4531. template_id, _ := adviceNameM["template_id"].(string)
  4532. advice.TemplateId = template_id
  4533. }
  4534. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  4535. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4536. advice.ExecutionFrequency = executionFrequency
  4537. }
  4538. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  4539. children := adviceNameM["child"].([]interface{})
  4540. if len(children) > 0 {
  4541. for _, childrenMap := range children {
  4542. childMap := childrenMap.(map[string]interface{})
  4543. var child models.GroupAdvice
  4544. child.Remark = Remark
  4545. child.AdviceType = adviceType
  4546. child.StartTime = StartTime
  4547. child.AdviceDate = AdviceDate
  4548. child.RecordDate = RecordDate
  4549. child.Status = 1
  4550. child.CreatedTime = time.Now().Unix()
  4551. child.UpdatedTime = time.Now().Unix()
  4552. child.StopState = 2
  4553. child.ExecutionState = 2
  4554. child.UserOrgId = adminUserInfo.Org.Id
  4555. child.PatientId = patient
  4556. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  4557. child.IsSettle = 1
  4558. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  4559. utils.ErrorLog("child advice_name")
  4560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4561. return
  4562. }
  4563. childAdviceName, _ := childMap["advice_name"].(string)
  4564. if len(childAdviceName) == 0 {
  4565. utils.ErrorLog("len(child advice_name) == 0")
  4566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4567. return
  4568. }
  4569. child.AdviceName = childAdviceName
  4570. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  4571. childAdviceDesc, _ := childMap["advice_desc"].(string)
  4572. child.AdviceDesc = childAdviceDesc
  4573. }
  4574. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  4575. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  4576. child.DrugSpec = childDrugSpec
  4577. }
  4578. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  4579. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  4580. child.DrugSpecUnit = childDrugSpecUnit
  4581. }
  4582. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  4583. child.SingleDose = childMap["single_dose"].(float64)
  4584. }
  4585. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  4586. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  4587. child.SingleDoseUnit = childSingleDoseUnit
  4588. }
  4589. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  4590. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  4591. }
  4592. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  4593. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  4594. child.PrescribingNumberUnit = childPrescribingNumberUnit
  4595. }
  4596. child.DeliveryWay = advice.DeliveryWay
  4597. child.ExecutionFrequency = advice.ExecutionFrequency
  4598. advice.Children = append(advice.Children, &child)
  4599. }
  4600. }
  4601. }
  4602. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  4603. if temp_advice.ID == 0 {
  4604. advices = append(advices, &advice)
  4605. }
  4606. }
  4607. if len(advices) > 0 {
  4608. finish := models.XtDialysisFinish{
  4609. IsFinish: 1,
  4610. UserOrgId: adminUserInfo.Org.Id,
  4611. Status: 1,
  4612. Ctime: time.Now().Unix(),
  4613. Mtime: 0,
  4614. Module: 4,
  4615. RecordDate: AdviceDate,
  4616. Sourse: 1,
  4617. PatientId: patient,
  4618. }
  4619. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  4620. if dialysisFinish.ID == 0 {
  4621. service.CreateDialysisFinish(finish)
  4622. }
  4623. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  4624. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  4625. redis := service.RedisClient()
  4626. //清空key 值
  4627. redis.Set(key, "", time.Second)
  4628. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4629. redis.Set(keyOne, "", time.Second)
  4630. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4631. defer redis.Close()
  4632. redis.Set(keyThree, "", time.Second)
  4633. if err != nil {
  4634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4635. return
  4636. }
  4637. c.ServeSuccessJSON(map[string]interface{}{
  4638. "msg": "ok",
  4639. "advices": list,
  4640. })
  4641. } else {
  4642. c.ServeSuccessJSON(map[string]interface{}{
  4643. "msg": "ok",
  4644. })
  4645. }
  4646. return
  4647. }
  4648. func (c *DialysisAPIController) UploadDryWeight() {
  4649. patient_id, _ := c.GetInt64("id")
  4650. dry_weight, _ := c.GetFloat("dry_weight")
  4651. doctor_id, _ := c.GetInt64("doctor_id")
  4652. remark := c.GetString("remark")
  4653. adminUserInfo := c.GetMobileAdminUserInfo()
  4654. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  4655. if err == gorm.ErrRecordNotFound {
  4656. dryWeight := &models.SgjPatientDryweight{
  4657. PatientId: patient_id,
  4658. DryWeight: dry_weight,
  4659. Remakes: remark,
  4660. Ctime: time.Now().Unix(),
  4661. Mtime: time.Now().Unix(),
  4662. Creator: doctor_id,
  4663. Status: 1,
  4664. UserOrgId: adminUserInfo.Org.Id,
  4665. AdjustedValue: "/",
  4666. UserId: adminUserInfo.AdminUser.Id,
  4667. }
  4668. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4669. redis := service.RedisClient()
  4670. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  4671. redis.Set(keyOne, "", time.Second)
  4672. loc, _ := time.LoadLocation("Local")
  4673. nowTime := time.Now()
  4674. nowDay := nowTime.Format("2006-01-02")
  4675. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4676. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4677. redis.Set(key, "", time.Second)
  4678. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4679. redis.Set(keyTwo, "", time.Second)
  4680. redis.Close()
  4681. if createErr == nil {
  4682. c.ServeSuccessJSON(map[string]interface{}{
  4683. "msg": "提交成功",
  4684. "weight": dryWeight,
  4685. })
  4686. }
  4687. } else {
  4688. dryWeight := &models.SgjPatientDryweight{
  4689. PatientId: patient_id,
  4690. DryWeight: dry_weight,
  4691. Remakes: remark,
  4692. Ctime: time.Now().Unix(),
  4693. Mtime: time.Now().Unix(),
  4694. Creator: doctor_id,
  4695. Status: 1,
  4696. UserOrgId: adminUserInfo.Org.Id,
  4697. AdjustedValue: "/",
  4698. UserId: adminUserInfo.AdminUser.Id,
  4699. }
  4700. var value float64
  4701. value = dry_weight - weightAdjust.DryWeight
  4702. if value < 0 {
  4703. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  4704. } else if value == 0 {
  4705. dryWeight.AdjustedValue = "/"
  4706. } else if value > 0 {
  4707. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  4708. }
  4709. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4710. redis := service.RedisClient()
  4711. loc, _ := time.LoadLocation("Local")
  4712. nowTime := time.Now()
  4713. nowDay := nowTime.Format("2006-01-02")
  4714. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4715. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4716. redis.Set(keyOne, "", time.Second)
  4717. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4718. redis.Set(key, "", time.Second)
  4719. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4720. redis.Set(keyTwo, "", time.Second)
  4721. redis.Close()
  4722. if createErr == nil {
  4723. c.ServeSuccessJSON(map[string]interface{}{
  4724. "msg": "提交成功",
  4725. "weight": dryWeight,
  4726. })
  4727. }
  4728. }
  4729. }
  4730. func (c *DialysisAPIController) GetSolution() {
  4731. patient_id, _ := c.GetInt64("patient_id")
  4732. mode_id, _ := c.GetInt64("mode_id")
  4733. adminUserInfo := c.GetMobileAdminUserInfo()
  4734. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  4735. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  4736. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  4737. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  4738. if err != nil {
  4739. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4740. return
  4741. }
  4742. c.ServeSuccessJSON(map[string]interface{}{
  4743. "solution": solution,
  4744. "prescription": prescription,
  4745. "system_prescription": system_prescription,
  4746. "dialysisPrescription": dialysisPrescription,
  4747. })
  4748. }
  4749. func (c *DialysisAPIController) GetSchedule() {
  4750. schedual_type, _ := c.GetInt64("schedual_type")
  4751. adminUserInfo := c.GetMobileAdminUserInfo()
  4752. scheduleTime, _ := c.GetInt64("record_date")
  4753. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  4754. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  4755. c.ServeSuccessJSON(map[string]interface{}{
  4756. "number": deviceNumber,
  4757. "list": list,
  4758. })
  4759. }
  4760. func (c *DialysisAPIController) GetPatientId() {
  4761. id, _ := c.GetInt64("id")
  4762. //orgid := c.GetMobileAdminUserInfo().Org.Id
  4763. patientId, _ := service.GetPatientId(id)
  4764. //获取该患者的所有传染病
  4765. list, _ := service.GetPatientInfectious(id)
  4766. c.ServeSuccessJSON(map[string]interface{}{
  4767. "patient": patientId,
  4768. "infectioulist": list,
  4769. })
  4770. }
  4771. func (this *DialysisAPIController) GetDialysisSchedule() {
  4772. schedualDate := this.GetString("date")
  4773. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  4774. if parseDateErr != nil {
  4775. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4776. return
  4777. }
  4778. adminInfo := this.GetMobileAdminUserInfo()
  4779. orgID := adminInfo.Org.Id
  4780. redis := service.RedisClient()
  4781. defer redis.Close()
  4782. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  4783. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  4784. if len(scheduals) > 0 {
  4785. //缓存数据
  4786. scheduals_json, err := json.Marshal(scheduals)
  4787. if err == nil {
  4788. redis.Set(key, scheduals_json, time.Second*30)
  4789. }
  4790. }
  4791. this.ServeSuccessJSON(map[string]interface{}{
  4792. "scheduals": scheduals,
  4793. })
  4794. }
  4795. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  4796. change_type, _ := this.GetInt64("type", 0)
  4797. record_date := this.GetString("record_time")
  4798. patient_id, _ := this.GetInt64("patient_id", 0)
  4799. timeLayout := "2006-01-02"
  4800. loc, _ := time.LoadLocation("Local")
  4801. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4802. record_time := theAdviceRecordTime.Unix()
  4803. adminUserInfo := this.GetMobileAdminUserInfo()
  4804. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  4805. if err == nil {
  4806. if len(advices) == 0 {
  4807. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4808. return
  4809. } else {
  4810. this.ServeSuccessJSON(map[string]interface{}{
  4811. "advices": advices,
  4812. "schedule": sch,
  4813. })
  4814. return
  4815. }
  4816. } else {
  4817. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4818. return
  4819. }
  4820. }
  4821. func (c *DialysisAPIController) CreateConsumables() {
  4822. record_date := c.GetString("record_time")
  4823. patient_id, _ := c.GetInt64("patient_id", 0)
  4824. active, _ := c.GetInt64("active")
  4825. adminUser := c.GetMobileAdminUserInfo()
  4826. timeLayout := "2006-01-02"
  4827. loc, _ := time.LoadLocation("Local")
  4828. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4829. record_time := theRecordTime.Unix()
  4830. // 查询信息规挡的设置天数
  4831. orgid := c.GetMobileAdminUserInfo().Org.Id
  4832. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  4833. if infor.ID > 0 {
  4834. var cha_time int64
  4835. timeNowStr := time.Now().Format("2006-01-02")
  4836. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4837. //今日的日期减去设置的日期
  4838. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4839. if cha_time >= record_time {
  4840. //查询审核是否允许
  4841. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid)
  4842. //申请状态不允许的情况 拒绝修改
  4843. if infor.ApplicationStatus != 1 {
  4844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4845. return
  4846. }
  4847. }
  4848. }
  4849. dataBody := make(map[string]interface{}, 0)
  4850. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4851. if err != nil {
  4852. utils.ErrorLog(err.Error())
  4853. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4854. return
  4855. }
  4856. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  4857. var beforePrepares []*models.DialysisBeforePrepareGoods
  4858. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  4859. var dialysisBefor []*models.DialysisBeforePrepare
  4860. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  4861. goods, _ := dataBody["goods"].([]interface{})
  4862. if len(goods) > 0 {
  4863. for _, item := range goods {
  4864. items := item.(map[string]interface{})
  4865. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4866. utils.ErrorLog("good_id")
  4867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4868. return
  4869. }
  4870. good_id := int64(items["good_id"].(float64))
  4871. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  4872. utils.ErrorLog("good_type_id")
  4873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4874. return
  4875. }
  4876. good_type_id := int64(items["good_type_id"].(float64))
  4877. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  4878. utils.ErrorLog("count")
  4879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4880. return
  4881. }
  4882. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  4883. commdity_code := items["commdity_code"].(string)
  4884. fmt.Println("commdity", commdity_code)
  4885. prepareGoods := &models.DialysisBeforePrepareGoods{
  4886. GoodTypeId: good_type_id,
  4887. GoodId: good_id,
  4888. Count: count,
  4889. StorehouseId: houseConfig.StorehouseOutInfo,
  4890. }
  4891. beforePrepares = append(beforePrepares, prepareGoods)
  4892. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  4893. GoodTypeId: good_type_id,
  4894. GoodId: good_id,
  4895. Count: count,
  4896. StorehouseId: houseConfig.StorehouseOutInfo,
  4897. }
  4898. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  4899. prepare := &models.DialysisBeforePrepare{
  4900. GoodTypeId: good_type_id,
  4901. GoodId: good_id,
  4902. Count: count,
  4903. PatientId: patient_id,
  4904. RecordDate: record_time,
  4905. UserOrgId: adminUser.Org.Id,
  4906. Status: 1,
  4907. Ctime: time.Now().Unix(),
  4908. Creater: adminUser.AdminUser.Id,
  4909. CommdityCode: commdity_code,
  4910. StorehouseId: houseConfig.StorehouseOutInfo,
  4911. }
  4912. dialysisBefor = append(dialysisBefor, prepare)
  4913. }
  4914. }
  4915. //查询是否有库存
  4916. for _, item := range dialysisBefor {
  4917. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  4918. if err == gorm.ErrRecordNotFound {
  4919. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4920. c.ServeSuccessJSON(map[string]interface{}{
  4921. "message": "1",
  4922. "good_name": goodObj.GoodName,
  4923. "specification_name": goodObj.SpecificationName,
  4924. })
  4925. return
  4926. }
  4927. if err != nil {
  4928. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4929. c.ServeSuccessJSON(map[string]interface{}{
  4930. "message": "1",
  4931. "good_name": goodObj.GoodName,
  4932. "specification_name": goodObj.SpecificationName,
  4933. })
  4934. return
  4935. }
  4936. }
  4937. //新增
  4938. if active == 1 && len(goods) > 0 {
  4939. for _, item := range dialysisBefor {
  4940. dialyPrepareOne := models.DialysisBeforePrepare{
  4941. GoodTypeId: item.GoodTypeId,
  4942. GoodId: item.GoodId,
  4943. PatientId: item.PatientId,
  4944. RecordDate: item.RecordDate,
  4945. UserOrgId: item.UserOrgId,
  4946. Count: item.Count,
  4947. Ctime: time.Now().Unix(),
  4948. Creater: item.Creater,
  4949. CommdityCode: item.CommdityCode,
  4950. Status: 1,
  4951. StorehouseId: houseConfig.StorehouseOutInfo,
  4952. }
  4953. //先清除再插入
  4954. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4955. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  4956. //查询默认仓库
  4957. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  4958. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  4959. var total_count int64
  4960. for _, it := range stockList {
  4961. total_count += it.StockCount
  4962. }
  4963. //基础库插入数据
  4964. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  4965. //更新库存
  4966. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  4967. var flush_count int64
  4968. for _, it := range goodList {
  4969. flush_count += it.StockCount
  4970. }
  4971. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  4972. }
  4973. if err == nil {
  4974. c.ServeSuccessJSON(map[string]interface{}{
  4975. "msg": "保存成功",
  4976. "message": "2",
  4977. })
  4978. return
  4979. } else {
  4980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4981. return
  4982. }
  4983. }
  4984. if len(beforePrepares) > 0 && active == 2 {
  4985. for _, item := range beforePrepares {
  4986. //1.查看该患者该耗材型号最后一次出库数量
  4987. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  4988. //判断当前出库数量和最后一次出库数量的大小
  4989. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  4990. if item.Count <= goodInfo.Count {
  4991. //退库
  4992. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  4993. //查询今日出库数据
  4994. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  4995. for _, it := range list {
  4996. prepare := models.DialysisBeforePrepare{
  4997. UserOrgId: it.OrgId,
  4998. PatientId: patient_id,
  4999. RecordDate: it.RecordTime,
  5000. GoodId: it.GoodId,
  5001. GoodTypeId: it.GoodTypeId,
  5002. Count: it.Count,
  5003. Ctime: time.Now().Unix(),
  5004. Creater: adminUser.AdminUser.Id,
  5005. Status: 1,
  5006. StorehouseId: houseConfig.StorehouseOutInfo,
  5007. }
  5008. //删除准备表数据
  5009. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5010. service.CreateDialysisBeforePrepareOne(&prepare)
  5011. }
  5012. }
  5013. var last_total int64
  5014. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5015. if item.Count >= goodInfo.Count {
  5016. //查询当前批次当前耗材最后一条出库数据
  5017. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5018. //计算当前出库和最后一次出库数据相差数据
  5019. last_total = item.Count - lastOutInfo.Count
  5020. //查询该批次剩余库存
  5021. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  5022. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  5023. if lastInfo.StockCount >= last_total {
  5024. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5025. //查询今日出库数据
  5026. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5027. for _, it := range list {
  5028. prepare := models.DialysisBeforePrepare{
  5029. UserOrgId: it.OrgId,
  5030. PatientId: patient_id,
  5031. RecordDate: it.RecordTime,
  5032. GoodId: it.GoodId,
  5033. GoodTypeId: it.GoodTypeId,
  5034. Count: it.Count,
  5035. Ctime: time.Now().Unix(),
  5036. Creater: adminUser.AdminUser.Id,
  5037. Status: 1,
  5038. StorehouseId: houseConfig.StorehouseOutInfo,
  5039. }
  5040. //删除准备表数据
  5041. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5042. service.CreateDialysisBeforePrepareOne(&prepare)
  5043. //查询默认仓库
  5044. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5045. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5046. var total_count int64
  5047. for _, it := range stockList {
  5048. total_count += it.StockCount
  5049. }
  5050. //基础库插入数据
  5051. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5052. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5053. var flush_count int64
  5054. for _, it := range goodList {
  5055. flush_count += it.StockCount
  5056. }
  5057. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5058. }
  5059. }
  5060. //如果库存不够,则出库到下一个批次
  5061. if lastInfo.StockCount < last_total {
  5062. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5063. //查询今日出库数据
  5064. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5065. for _, it := range list {
  5066. prepare := models.DialysisBeforePrepare{
  5067. UserOrgId: it.OrgId,
  5068. PatientId: patient_id,
  5069. RecordDate: it.RecordTime,
  5070. GoodId: it.GoodId,
  5071. GoodTypeId: it.GoodTypeId,
  5072. Count: it.Count,
  5073. Ctime: time.Now().Unix(),
  5074. Creater: adminUser.AdminUser.Id,
  5075. Status: 1,
  5076. StorehouseId: houseConfig.StorehouseOutInfo,
  5077. }
  5078. //删除准备表数据
  5079. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5080. service.CreateDialysisBeforePrepareOne(&prepare)
  5081. //查询默认仓库
  5082. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5083. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5084. var total_count int64
  5085. for _, it := range stockList {
  5086. total_count += it.StockCount
  5087. }
  5088. //基础库插入数据
  5089. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5090. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5091. var flush_count int64
  5092. for _, it := range goodList {
  5093. flush_count += it.StockCount
  5094. }
  5095. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5096. }
  5097. if err != nil {
  5098. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5099. c.ServeSuccessJSON(map[string]interface{}{
  5100. "message": "1",
  5101. "good_name": goodObj.GoodName,
  5102. "specification_name": goodObj.SpecificationName,
  5103. })
  5104. return
  5105. }
  5106. }
  5107. }
  5108. if err != nil {
  5109. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5110. c.ServeSuccessJSON(map[string]interface{}{
  5111. "message": "1",
  5112. "good_name": goodObj.GoodName,
  5113. "specification_name": goodObj.SpecificationName,
  5114. })
  5115. return
  5116. }
  5117. }
  5118. }
  5119. }
  5120. var errs error
  5121. if errs == nil {
  5122. c.ServeSuccessJSON(map[string]interface{}{
  5123. "msg": "提交成功",
  5124. "message": "2",
  5125. "good_name": "",
  5126. "specification_name": "",
  5127. })
  5128. return
  5129. } else {
  5130. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5131. return
  5132. }
  5133. }
  5134. func (c *DialysisAPIController) CreateStockOutInfo() {
  5135. patient_id, _ := c.GetInt64("patient_id", 0)
  5136. record_date := c.GetString("record_time")
  5137. if patient_id <= 0 {
  5138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5139. return
  5140. }
  5141. adminInfo := c.GetMobileAdminUserInfo()
  5142. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5143. timeLayout := "2006-01-02"
  5144. loc, _ := time.LoadLocation("Local")
  5145. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5146. record_time := theRecordTime.Unix()
  5147. // 查询信息规挡的设置天数
  5148. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5149. if infor.ID > 0 && infor.WeekDay > 0 {
  5150. var cha_time int64
  5151. timeNowStr := time.Now().Format("2006-01-02")
  5152. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5153. //今日的日期减去设置的日期
  5154. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5155. if cha_time >= record_time {
  5156. //查询审核是否允许
  5157. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id)
  5158. //申请状态不允许的情况 拒绝修改
  5159. if infor.ApplicationStatus != 1 {
  5160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5161. return
  5162. }
  5163. }
  5164. }
  5165. //创建步骤表
  5166. finish := models.XtDialysisFinish{
  5167. IsFinish: 1,
  5168. UserOrgId: adminInfo.Org.Id,
  5169. Status: 1,
  5170. Ctime: time.Now().Unix(),
  5171. Mtime: 0,
  5172. Module: 11,
  5173. RecordDate: record_time,
  5174. Sourse: 1,
  5175. PatientId: patient_id,
  5176. }
  5177. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  5178. if dialysisFinish.ID == 0 {
  5179. service.CreateDialysisFinish(finish)
  5180. }
  5181. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  5182. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5183. //去重
  5184. consumables = RemoveRepeatedGood(consumables)
  5185. if record.IsOpen == 1 {
  5186. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5187. //查询是否有库存
  5188. for _, item := range consumables {
  5189. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5190. if item.Count > warehouse.Count {
  5191. goodErrcode := models.XtGoodErrcode{
  5192. UserOrgId: item.UserOrgId,
  5193. Errcode: "自动出库库存不足",
  5194. GoodId: item.GoodId,
  5195. Status: 1,
  5196. Ctime: time.Now().Unix(),
  5197. Mtime: 0,
  5198. Count: 0,
  5199. StockCount: 0,
  5200. Creater: creator,
  5201. BatchNumberId: warehouse.ID,
  5202. WarehouseOutId: 0,
  5203. }
  5204. service.CreateGoodErrcode(goodErrcode)
  5205. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5206. c.ServeSuccessJSON(map[string]interface{}{
  5207. "message": "1",
  5208. "good_name": goodObj.GoodName,
  5209. "specification_name": goodObj.SpecificationName,
  5210. })
  5211. return
  5212. }
  5213. }
  5214. //查询是否有出库单
  5215. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5216. if err == gorm.ErrRecordNotFound {
  5217. //没有记录,则创建出库单
  5218. timeStr := time.Now().Format("2006-01-02")
  5219. timeArr := strings.Split(timeStr, "-")
  5220. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5221. total = total + 1
  5222. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5223. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5224. number = number + total
  5225. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5226. creater := adminInfo.AdminUser.Id
  5227. warehouseOut := models.WarehouseOut{
  5228. WarehouseOutOrderNumber: warehousing_out_order,
  5229. OperationTime: time.Now().Unix(),
  5230. OrgId: adminInfo.Org.Id,
  5231. Creater: creater,
  5232. Ctime: time.Now().Unix(),
  5233. Status: 1,
  5234. WarehouseOutTime: record_time,
  5235. Dealer: 0,
  5236. Manufacturer: 0,
  5237. Type: 1,
  5238. IsSys: 1,
  5239. StorehouseId: houseConfig.StorehouseOutInfo,
  5240. IsCheck: 1,
  5241. }
  5242. err := service.AddSigleWarehouseOut(&warehouseOut)
  5243. if err != nil {
  5244. goodErrcode := models.XtGoodErrcode{
  5245. UserOrgId: adminInfo.Org.Id,
  5246. Errcode: "创建出库单失败",
  5247. GoodId: 0,
  5248. Status: 1,
  5249. Ctime: time.Now().Unix(),
  5250. Mtime: 0,
  5251. Count: 0,
  5252. StockCount: 0,
  5253. Creater: creator,
  5254. BatchNumberId: 0,
  5255. WarehouseOutId: 0,
  5256. }
  5257. service.CreateGoodErrcode(goodErrcode)
  5258. utils.TraceLog("创建出库单失败 err = %v", err)
  5259. } else {
  5260. for _, item := range consumables {
  5261. //出库
  5262. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5263. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5264. if err == nil {
  5265. goodErrcode := models.XtGoodErrcode{
  5266. UserOrgId: adminInfo.Org.Id,
  5267. Errcode: "自动出库接口报错",
  5268. GoodId: 0,
  5269. Status: 1,
  5270. Ctime: time.Now().Unix(),
  5271. Mtime: 0,
  5272. Count: 0,
  5273. StockCount: 0,
  5274. Creater: creator,
  5275. BatchNumberId: 0,
  5276. WarehouseOutId: 0,
  5277. }
  5278. service.CreateGoodErrcode(goodErrcode)
  5279. utils.TraceLog("创建出库单失败 err = %v", err)
  5280. }
  5281. //查询
  5282. //出库数量相加
  5283. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5284. if errs != nil {
  5285. goodErrcode := models.XtGoodErrcode{
  5286. UserOrgId: item.UserOrgId,
  5287. Errcode: "创建剩余库存字段报错",
  5288. GoodId: item.GoodId,
  5289. Status: 1,
  5290. Ctime: time.Now().Unix(),
  5291. Mtime: 0,
  5292. Count: 0,
  5293. StockCount: 0,
  5294. Creater: creater,
  5295. BatchNumberId: 0,
  5296. WarehouseOutId: 0,
  5297. }
  5298. service.CreateGoodErrcode(goodErrcode)
  5299. }
  5300. }
  5301. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5302. if len(list) == 0 {
  5303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5304. return
  5305. }
  5306. for _, item := range list {
  5307. prepare := models.DialysisBeforePrepare{
  5308. UserOrgId: adminInfo.Org.Id,
  5309. PatientId: patient_id,
  5310. RecordDate: record_time,
  5311. GoodId: item.GoodId,
  5312. GoodTypeId: item.GoodTypeId,
  5313. Count: item.Count,
  5314. Creater: adminInfo.AdminUser.Id,
  5315. Status: 1,
  5316. Ctime: time.Now().Unix(),
  5317. StorehouseId: houseConfig.StorehouseOutInfo,
  5318. }
  5319. //清空准备表数据
  5320. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5321. if err != 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. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5338. if errs != nil {
  5339. goodErrcode := models.XtGoodErrcode{
  5340. UserOrgId: item.OrgId,
  5341. Errcode: "自动出库创建准备表数据报错",
  5342. GoodId: item.GoodId,
  5343. Status: 1,
  5344. Ctime: time.Now().Unix(),
  5345. Mtime: 0,
  5346. Count: 0,
  5347. StockCount: 0,
  5348. Creater: creater,
  5349. BatchNumberId: 0,
  5350. WarehouseOutId: 0,
  5351. }
  5352. service.CreateGoodErrcode(goodErrcode)
  5353. }
  5354. //查询默认仓库
  5355. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5356. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5357. var total_count int64
  5358. for _, it := range stockList {
  5359. total_count += it.StockCount
  5360. }
  5361. //基础库插入数据
  5362. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5363. if errcodes != nil {
  5364. goodErrcode := models.XtGoodErrcode{
  5365. UserOrgId: item.OrgId,
  5366. Errcode: "自动出库基础库插入数据",
  5367. GoodId: item.GoodId,
  5368. Status: 1,
  5369. Ctime: time.Now().Unix(),
  5370. Mtime: 0,
  5371. Count: 0,
  5372. StockCount: 0,
  5373. Creater: creater,
  5374. BatchNumberId: 0,
  5375. WarehouseOutId: 0,
  5376. }
  5377. service.CreateGoodErrcode(goodErrcode)
  5378. }
  5379. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5380. var flush_count int64
  5381. for _, it := range goodList {
  5382. flush_count += it.StockCount
  5383. }
  5384. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5385. if errsss != nil {
  5386. goodErrcode := models.XtGoodErrcode{
  5387. UserOrgId: item.OrgId,
  5388. Errcode: "自动出库剩余库存更新数据",
  5389. GoodId: item.GoodId,
  5390. Status: 1,
  5391. Ctime: time.Now().Unix(),
  5392. Mtime: 0,
  5393. Count: 0,
  5394. StockCount: 0,
  5395. Creater: creater,
  5396. BatchNumberId: 0,
  5397. WarehouseOutId: 0,
  5398. }
  5399. service.CreateGoodErrcode(goodErrcode)
  5400. }
  5401. }
  5402. }
  5403. //
  5404. } else if err == nil {
  5405. for _, item := range consumables {
  5406. //出库
  5407. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  5408. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  5409. if err != nil {
  5410. goodErrcode := models.XtGoodErrcode{
  5411. UserOrgId: adminInfo.Org.Id,
  5412. Errcode: "自动出库接口报错",
  5413. GoodId: 0,
  5414. Status: 1,
  5415. Ctime: time.Now().Unix(),
  5416. Mtime: 0,
  5417. Count: 0,
  5418. StockCount: 0,
  5419. Creater: creator,
  5420. BatchNumberId: 0,
  5421. WarehouseOutId: 0,
  5422. }
  5423. service.CreateGoodErrcode(goodErrcode)
  5424. }
  5425. //出库数量相加
  5426. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5427. if errss != nil {
  5428. goodErrcode := models.XtGoodErrcode{
  5429. UserOrgId: item.UserOrgId,
  5430. Errcode: "创建剩余库存字段报错",
  5431. GoodId: item.GoodId,
  5432. Status: 1,
  5433. Ctime: time.Now().Unix(),
  5434. Mtime: time.Now().Unix(),
  5435. Count: 0,
  5436. StockCount: 0,
  5437. Creater: item.Creater,
  5438. BatchNumberId: 0,
  5439. WarehouseOutId: 0,
  5440. }
  5441. service.CreateGoodErrcode(goodErrcode)
  5442. }
  5443. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5444. if len(list) == 0 {
  5445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5446. return
  5447. }
  5448. for _, item := range list {
  5449. prepare := models.DialysisBeforePrepare{
  5450. UserOrgId: adminInfo.Org.Id,
  5451. PatientId: patient_id,
  5452. RecordDate: record_time,
  5453. GoodId: item.GoodId,
  5454. GoodTypeId: item.GoodTypeId,
  5455. Count: item.Count,
  5456. Creater: adminInfo.AdminUser.Id,
  5457. Status: 1,
  5458. Ctime: time.Now().Unix(),
  5459. StorehouseId: houseConfig.StorehouseOutInfo,
  5460. }
  5461. //清空准备表数据
  5462. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5463. if errs != 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. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  5480. if errcodes != nil {
  5481. goodErrcode := models.XtGoodErrcode{
  5482. UserOrgId: adminInfo.Org.Id,
  5483. Errcode: "自动出库创建准备表数据报错",
  5484. GoodId: 0,
  5485. Status: 1,
  5486. Ctime: time.Now().Unix(),
  5487. Mtime: 0,
  5488. Count: 0,
  5489. StockCount: 0,
  5490. Creater: creator,
  5491. BatchNumberId: 0,
  5492. WarehouseOutId: 0,
  5493. }
  5494. service.CreateGoodErrcode(goodErrcode)
  5495. }
  5496. //查询默认仓库
  5497. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5498. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5499. var total_count int64
  5500. for _, it := range stockList {
  5501. total_count += it.StockCount
  5502. }
  5503. //基础库插入数据
  5504. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5505. if errcodes != nil {
  5506. goodErrcode := models.XtGoodErrcode{
  5507. UserOrgId: adminInfo.Org.Id,
  5508. Errcode: "自动出库基础库插入数据报错",
  5509. GoodId: 0,
  5510. Status: 1,
  5511. Ctime: time.Now().Unix(),
  5512. Mtime: 0,
  5513. Count: 0,
  5514. StockCount: 0,
  5515. Creater: creator,
  5516. BatchNumberId: 0,
  5517. WarehouseOutId: 0,
  5518. }
  5519. service.CreateGoodErrcode(goodErrcode)
  5520. }
  5521. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5522. var flush_count int64
  5523. for _, it := range goodList {
  5524. flush_count += it.StockCount
  5525. }
  5526. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5527. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5528. if errss != nil {
  5529. goodErrcode := models.XtGoodErrcode{
  5530. UserOrgId: item.OrgId,
  5531. Errcode: "自动出库剩余库存更新数据",
  5532. GoodId: item.GoodId,
  5533. Status: 1,
  5534. Ctime: time.Now().Unix(),
  5535. Mtime: 0,
  5536. Count: 0,
  5537. StockCount: 0,
  5538. Creater: creater,
  5539. BatchNumberId: 0,
  5540. WarehouseOutId: 0,
  5541. }
  5542. service.CreateGoodErrcode(goodErrcode)
  5543. }
  5544. }
  5545. }
  5546. }
  5547. c.ServeSuccessJSON(map[string]interface{}{
  5548. "msg": "提交成功",
  5549. "message": "2",
  5550. "good_name": "",
  5551. "specification_name": "",
  5552. })
  5553. return
  5554. } else {
  5555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  5556. return
  5557. }
  5558. }
  5559. func (c *DialysisAPIController) EditConsumables() {
  5560. patient_id, _ := c.GetInt64("patient_id", 0)
  5561. record_date := c.GetString("record_time")
  5562. if patient_id <= 0 {
  5563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5564. return
  5565. }
  5566. adminInfo := c.GetMobileAdminUserInfo()
  5567. timeLayout := "2006-01-02"
  5568. loc, _ := time.LoadLocation("Local")
  5569. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5570. record_time := theRecordTime.Unix()
  5571. // 查询信息规挡的设置天数
  5572. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5573. if infor.ID > 0 && infor.WeekDay > 0 {
  5574. var cha_time int64
  5575. timeNowStr := time.Now().Format("2006-01-02")
  5576. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5577. //今日的日期减去设置的日期
  5578. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5579. if cha_time >= record_time {
  5580. //查询审核是否允许
  5581. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id)
  5582. //申请状态不允许的情况 拒绝修改
  5583. if infor.ApplicationStatus != 1 {
  5584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5585. return
  5586. }
  5587. }
  5588. }
  5589. dataBody := make(map[string]interface{}, 0)
  5590. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5591. if err != nil {
  5592. utils.ErrorLog(err.Error())
  5593. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5594. return
  5595. }
  5596. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5597. var beforePrepares []*models.DialysisBeforePrepareGoods
  5598. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5599. var cancelbefor []*models.DialysisBeforePrepareGoods
  5600. var outbefor []*models.DialysisBeforePrepareGoods
  5601. //判断是否开启自动出库
  5602. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5603. if record.IsOpen == 1 {
  5604. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5605. goods, _ := dataBody["goods"].([]interface{})
  5606. if len(goods) > 0 {
  5607. for _, item := range goods {
  5608. items := item.(map[string]interface{})
  5609. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5610. utils.ErrorLog("good_id")
  5611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5612. return
  5613. }
  5614. good_id := int64(items["good_id"].(float64))
  5615. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5616. utils.ErrorLog("good_type_id")
  5617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5618. return
  5619. }
  5620. good_type_id := int64(items["good_type_id"].(float64))
  5621. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5622. utils.ErrorLog("count")
  5623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5624. return
  5625. }
  5626. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5627. commdity_code := items["commdity_code"].(string)
  5628. fmt.Println(commdity_code)
  5629. prepareGoods := &models.DialysisBeforePrepareGoods{
  5630. GoodTypeId: good_type_id,
  5631. GoodId: good_id,
  5632. Count: count,
  5633. StorehouseId: houseConfig.StorehouseOutInfo,
  5634. }
  5635. beforePrepares = append(beforePrepares, prepareGoods)
  5636. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5637. GoodTypeId: good_type_id,
  5638. GoodId: good_id,
  5639. Count: count,
  5640. StorehouseId: houseConfig.StorehouseOutInfo,
  5641. }
  5642. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5643. }
  5644. for _, item := range beforePrepares {
  5645. //1.查看该患者该耗材型号最后一次出库数量
  5646. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5647. //判断当前出库数量和最后一次出库数量的大小
  5648. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  5649. if item.Count < goodInfo.Count {
  5650. cancelbefor = append(cancelbefor, item)
  5651. }
  5652. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5653. if item.Count > goodInfo.Count {
  5654. outbefor = append(outbefor, item)
  5655. }
  5656. //处理编辑耗材新增不了的问题
  5657. if goodInfo.Count == item.Count {
  5658. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  5659. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  5660. }
  5661. }
  5662. if len(cancelbefor) > 0 {
  5663. //退库
  5664. for _, item := range cancelbefor {
  5665. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5666. creater := adminInfo.AdminUser.Id
  5667. //查询该患者当天已经出库的耗材信息
  5668. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  5669. var delete_count int64 = 0
  5670. delete_count = warehouseOutInfos.Count - item.Count
  5671. //增加库存数量
  5672. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  5673. //减少实际出库库存数量
  5674. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  5675. // 删除出库完成后,要增加对应批次的库存数量
  5676. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  5677. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5678. //更新剩余库存
  5679. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  5680. var flush_count int64
  5681. for _, it := range goodListOne {
  5682. flush_count += it.StockCount
  5683. }
  5684. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5685. //查询剩余库存
  5686. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  5687. var sum_count int64
  5688. for _, item := range goodList {
  5689. sum_count += item.StockCount
  5690. }
  5691. // 在出库记录表里记录退库详情
  5692. warehouseOutInfo := &models.WarehouseOutInfo{
  5693. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5694. WarehouseOutId: warehouseOut.ID,
  5695. Status: 1,
  5696. Ctime: time.Now().Unix(),
  5697. OrgId: adminInfo.Org.Id,
  5698. Type: 1,
  5699. IsSys: 1,
  5700. SysRecordTime: record_time,
  5701. GoodTypeId: item.GoodTypeId,
  5702. GoodId: item.GoodId,
  5703. PatientId: patient_id,
  5704. ConsumableType: 2,
  5705. StorehouseId: houseConfig.StorehouseOutInfo,
  5706. IsCheck: 1,
  5707. OverCount: sum_count,
  5708. }
  5709. warehouseOutInfo.Count = item.Count
  5710. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  5711. warehouseOutInfo.Price = stockInInfo.Price
  5712. warehouseOutInfo.Dealer = stockInInfo.Dealer
  5713. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  5714. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  5715. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  5716. warehouseOutInfo.Number = warehouseOutInfos.Number
  5717. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  5718. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  5719. //查找当天是否存在出库记录
  5720. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  5721. if errcod == gorm.ErrRecordNotFound {
  5722. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  5723. //插入详情明细表
  5724. stockFlow := models.VmStockFlow{
  5725. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5726. WarehouseOutId: warehouseOut.ID,
  5727. GoodId: item.GoodId,
  5728. Number: warehouseOutInfos.Number,
  5729. ProductDate: stockInInfo.ProductDate,
  5730. ExpireDate: stockInInfo.ExpiryDate,
  5731. Count: item.Count,
  5732. Price: stockInInfo.Price,
  5733. Status: 1,
  5734. Ctime: time.Now().Unix(),
  5735. UserOrgId: adminInfo.Org.Id,
  5736. Manufacturer: stockInInfo.Manufacturer,
  5737. Dealer: stockInInfo.Dealer,
  5738. LicenseNumber: stockInInfo.LicenseNumber,
  5739. IsEdit: 2,
  5740. Creator: creater,
  5741. SystemTime: record_time,
  5742. ConsumableType: 3,
  5743. WarehousingDetailId: 0,
  5744. IsSys: 1,
  5745. UpdateCreator: creater,
  5746. PatientId: patient_id,
  5747. StorehouseId: houseConfig.StorehouseOutInfo,
  5748. }
  5749. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  5750. if errflow == gorm.ErrRecordNotFound {
  5751. //创建流水表
  5752. err := service.CreateStockFlowOne(stockFlow)
  5753. fmt.Println("err", err)
  5754. } else if errflow == nil {
  5755. //插入详情明细表
  5756. stockFlow := models.VmStockFlow{
  5757. ID: exsit.ID,
  5758. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  5759. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5760. WarehouseOutId: warehouseOut.ID,
  5761. GoodId: item.GoodId,
  5762. Number: warehouseOutInfos.Number,
  5763. ProductDate: stockInInfo.ProductDate,
  5764. ExpireDate: stockInInfo.ExpiryDate,
  5765. Count: exsit.Count - delete_count,
  5766. Price: stockInInfo.Price,
  5767. Status: 1,
  5768. Ctime: time.Now().Unix(),
  5769. UserOrgId: adminInfo.Org.Id,
  5770. Manufacturer: stockInInfo.Manufacturer,
  5771. Dealer: stockInInfo.Dealer,
  5772. LicenseNumber: stockInInfo.LicenseNumber,
  5773. IsEdit: 2,
  5774. Creator: creater,
  5775. SystemTime: record_time,
  5776. ConsumableType: 3,
  5777. WarehousingDetailId: 0,
  5778. IsSys: 1,
  5779. UpdateCreator: creater,
  5780. PatientId: patient_id,
  5781. StorehouseId: houseConfig.StorehouseOutInfo,
  5782. }
  5783. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  5784. }
  5785. } else if errcod == nil {
  5786. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  5787. //查询剩余库存
  5788. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  5789. var sum_count int64
  5790. for _, item := range goodList {
  5791. sum_count += item.StockCount
  5792. }
  5793. //创建退库单,生成退库数据
  5794. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5795. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  5796. operation_time := time.Now().Unix()
  5797. creater := adminInfo.AdminUser.Id
  5798. //创建退库单
  5799. timeStr := time.Now().Format("2006-01-02")
  5800. timeArr := strings.Split(timeStr, "-")
  5801. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  5802. total = total + 1
  5803. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5804. cancelStock := models.CancelStock{
  5805. OrderNumber: orderNumber,
  5806. OperaTime: operation_time,
  5807. OrgId: adminInfo.Org.Id,
  5808. Creater: creater,
  5809. Ctime: time.Now().Unix(),
  5810. Status: 1,
  5811. ReturnTime: record_time,
  5812. Type: 1,
  5813. StorehouseId: houseConfig.StorehouseOutInfo,
  5814. IsCheck: 1,
  5815. }
  5816. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  5817. if msgerrkonde == gorm.ErrRecordNotFound {
  5818. service.AddSigleCancelStock(&cancelStock)
  5819. }
  5820. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  5821. //查询是否有出库
  5822. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  5823. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5824. deaerler, _ := service.GetDealerById(info.Dealer)
  5825. if info.ID > 0 {
  5826. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  5827. cancelStockInfo := models.CancelStockInfo{
  5828. GoodId: item.GoodId,
  5829. CancelStockId: cancel.ID,
  5830. GoodTypeId: good.GoodTypeId,
  5831. Count: delete_count,
  5832. Price: info.Price,
  5833. Total: 0,
  5834. ProductDate: info.ProductDate,
  5835. ExpiryDate: info.ExpiryDate,
  5836. Ctime: time.Now().Unix(),
  5837. Status: 1,
  5838. OrgId: adminInfo.Org.Id,
  5839. OrderNumber: cancel.OrderNumber,
  5840. Type: 0,
  5841. Dealer: deaerler.DealerName,
  5842. Manufacturer: manufacturer.ManufacturerName,
  5843. Number: info.Number,
  5844. RegisterAccount: "",
  5845. Remark: "",
  5846. WarehouseInfoId: info.WarehouseInfotId,
  5847. PatientId: info.PatientId,
  5848. RecordDate: info.SysRecordTime,
  5849. StorehouseId: houseConfig.StorehouseOutInfo,
  5850. IsCheck: 1,
  5851. }
  5852. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5853. //退库数量增加
  5854. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  5855. //查询剩余库存
  5856. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  5857. var over_count int64
  5858. for _, it := range goodList {
  5859. over_count += it.StockCount
  5860. }
  5861. flow := models.VmStockFlow{
  5862. WarehousingId: info.WarehouseInfotId,
  5863. GoodId: item.GoodId,
  5864. Number: info.Number,
  5865. LicenseNumber: info.LicenseNumber,
  5866. Count: delete_count,
  5867. UserOrgId: adminInfo.Org.Id,
  5868. PatientId: patient_id,
  5869. SystemTime: info.SysRecordTime,
  5870. ConsumableType: 7,
  5871. IsSys: 0,
  5872. WarehousingOrder: "",
  5873. WarehouseOutId: info.WarehouseOutId,
  5874. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5875. IsEdit: 0,
  5876. CancelStockId: cancel.ID,
  5877. CancelOrderNumber: cancel.OrderNumber,
  5878. Manufacturer: manufacturer.ID,
  5879. Dealer: 0,
  5880. Creator: adminInfo.AdminUser.Id,
  5881. UpdateCreator: 0,
  5882. Status: 1,
  5883. Ctime: time.Now().Unix(),
  5884. Mtime: 0,
  5885. Price: info.Price,
  5886. WarehousingDetailId: info.WarehouseInfotId,
  5887. WarehouseOutDetailId: info.ID,
  5888. CancelOutDetailId: cancelInfo.ID,
  5889. ProductDate: info.ProductDate,
  5890. ExpireDate: info.ExpiryDate,
  5891. StorehouseId: houseConfig.StorehouseOutInfo,
  5892. OverCount: over_count,
  5893. }
  5894. service.CreateStockFlowOne(flow)
  5895. }
  5896. }
  5897. //更改自动出库的表格
  5898. details := models.BloodAutomaticReduceDetail{
  5899. WarehouseOutId: warehouseOutInfo.ID,
  5900. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  5901. PatientId: patient_id,
  5902. Ctime: time.Now().Unix(),
  5903. Mtime: time.Now().Unix(),
  5904. Status: 1,
  5905. RecordTime: record_time,
  5906. OrgId: adminInfo.Org.Id,
  5907. GoodId: item.GoodId,
  5908. GoodTypeId: item.GoodTypeId,
  5909. Count: item.Count,
  5910. StorehouseId: houseConfig.StorehouseOutInfo,
  5911. }
  5912. //查询当天耗材是否已经存在数据
  5913. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5914. if errcode == gorm.ErrRecordNotFound {
  5915. service.CreateAutoReduceRecord(&details)
  5916. } else if errcode == nil {
  5917. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5918. service.CreateAutoReduceRecord(&details)
  5919. }
  5920. //查询默认仓库
  5921. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5922. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5923. var total_count int64
  5924. for _, it := range stockList {
  5925. total_count += it.StockCount
  5926. }
  5927. //基础库插入数据
  5928. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5929. }
  5930. }
  5931. if len(outbefor) > 0 {
  5932. //出库
  5933. for _, item := range outbefor {
  5934. var last_total int64
  5935. //1.查看该患者该耗材型号最后一次出库数量
  5936. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5937. //计算当前出库和最后一次出库数据相差数据
  5938. last_total = item.Count - goodInfoOne.Count
  5939. //查询该耗材的总库存
  5940. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  5941. // 如果库存差大于剩余库存则提示库存不足
  5942. if last_total > wareinfo.StockCount {
  5943. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5944. c.ServeSuccessJSON(map[string]interface{}{
  5945. "message": "1",
  5946. "good_name": goodObj.GoodName,
  5947. "specification_name": goodObj.SpecificationName,
  5948. })
  5949. return
  5950. } else {
  5951. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5952. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5953. if err == gorm.ErrRecordNotFound {
  5954. //没有记录,则创建出库单
  5955. timeStr := time.Now().Format("2006-01-02")
  5956. timeArr := strings.Split(timeStr, "-")
  5957. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5958. total = total + 1
  5959. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5960. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5961. number = number + total
  5962. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5963. warehouseOut := models.WarehouseOut{
  5964. WarehouseOutOrderNumber: warehousing_out_order,
  5965. OperationTime: time.Now().Unix(),
  5966. OrgId: adminInfo.Org.Id,
  5967. Creater: adminInfo.AdminUser.Id,
  5968. Ctime: time.Now().Unix(),
  5969. Status: 1,
  5970. WarehouseOutTime: record_time,
  5971. Dealer: 0,
  5972. Manufacturer: 0,
  5973. Type: 1,
  5974. IsSys: 1,
  5975. StorehouseId: houseConfig.StorehouseOutInfo,
  5976. IsCheck: 1,
  5977. }
  5978. service.AddSigleWarehouseOut(&warehouseOut)
  5979. }
  5980. //出库
  5981. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  5982. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5983. //1.查看该患者该耗材型号最后一次出库数量
  5984. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5985. prepare := models.DialysisBeforePrepare{
  5986. UserOrgId: adminInfo.Org.Id,
  5987. PatientId: patient_id,
  5988. RecordDate: record_time,
  5989. GoodId: item.GoodId,
  5990. GoodTypeId: item.GoodTypeId,
  5991. Count: item.Count - goodInfoTwo.Count,
  5992. Ctime: time.Now().Unix(),
  5993. Mtime: 0,
  5994. Creater: adminInfo.AdminUser.Id,
  5995. Modifier: adminInfo.AdminUser.Id,
  5996. Status: 1,
  5997. CommdityCode: "",
  5998. NewCount: 0,
  5999. ProjectId: 0,
  6000. StorehouseId: houseConfig.StorehouseOutInfo,
  6001. }
  6002. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  6003. //增加出库数量
  6004. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  6005. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6006. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6007. var total_count int64
  6008. for _, it := range stockList {
  6009. total_count += it.StockCount
  6010. }
  6011. //基础库插入数据
  6012. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6013. //剩余库存
  6014. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6015. var flush_count int64
  6016. for _, it := range goodList {
  6017. flush_count += it.StockCount
  6018. }
  6019. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6020. }
  6021. }
  6022. }
  6023. //查询今日出库数据
  6024. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6025. for _, it := range list {
  6026. prepare := models.DialysisBeforePrepare{
  6027. UserOrgId: it.OrgId,
  6028. PatientId: patient_id,
  6029. RecordDate: it.RecordTime,
  6030. GoodId: it.GoodId,
  6031. GoodTypeId: it.GoodTypeId,
  6032. Count: it.Count,
  6033. Ctime: time.Now().Unix(),
  6034. Creater: adminInfo.AdminUser.Id,
  6035. Status: 1,
  6036. StorehouseId: houseConfig.StorehouseOutInfo,
  6037. ProjectId: it.ProjectId,
  6038. }
  6039. //删除准备表数据
  6040. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  6041. service.CreateDialysisBeforePrepareOne(&prepare)
  6042. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6043. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6044. var total_count int64
  6045. for _, it := range stockList {
  6046. total_count += it.StockCount
  6047. }
  6048. //基础库插入数据
  6049. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  6050. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  6051. var flush_count int64
  6052. for _, it := range goodList {
  6053. flush_count += it.StockCount
  6054. }
  6055. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  6056. }
  6057. }
  6058. }
  6059. //更新自动出库的地方
  6060. var errs error
  6061. if errs == nil {
  6062. c.ServeSuccessJSON(map[string]interface{}{
  6063. "msg": "修改成功",
  6064. "message": "2",
  6065. "good_name": "",
  6066. "specification_name": "",
  6067. })
  6068. return
  6069. } else {
  6070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6071. return
  6072. }
  6073. }
  6074. }
  6075. func (c *DialysisAPIController) GetDialysisGoods() {
  6076. schedualDate := c.GetString("schedule_date")
  6077. schedule_type, _ := c.GetInt64("schedule_type")
  6078. partition_id, _ := c.GetInt64("partition_id")
  6079. page, _ := c.GetInt("page")
  6080. patient_id, _ := c.GetInt64("patient_id")
  6081. schedualEndDate := int64(0)
  6082. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  6083. if parseDateErr != nil && len(schedualDate) != 0 {
  6084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6085. return
  6086. }
  6087. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  6088. if parseDateErr != nil && len(schedualDate) != 0 {
  6089. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6090. return
  6091. }
  6092. schedualEndDate = endDate.Unix()
  6093. adminUser := c.GetMobileAdminUserInfo()
  6094. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  6095. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  6096. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6097. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6098. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  6099. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  6100. //获取当天该病人的透析处方
  6101. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6102. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6103. if err == gorm.ErrRecordNotFound {
  6104. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6105. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6106. if patient_id != 0 {
  6107. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6108. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6109. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6110. //获取患者总的出库数据
  6111. item.LastAutomaticReduceDetail = goodUser
  6112. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6113. item.Project = project
  6114. }
  6115. }
  6116. c.ServeSuccessJSON(map[string]interface{}{
  6117. "dialysis_goods": dialysisGoods,
  6118. "good_type": goodTypes,
  6119. "total": total,
  6120. "prescribe": prescribe,
  6121. "good_info": good_info,
  6122. "warehouseOutList": warehouseOutList,
  6123. "config": config,
  6124. "outConfig": outConfig,
  6125. "settleConfig": settleConfig,
  6126. })
  6127. return
  6128. } else if err == nil {
  6129. //获取当天排班的每个患者的库存使用情况
  6130. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6131. //获取患者总的出库数据
  6132. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6133. if patient_id != 0 {
  6134. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6135. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6136. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6137. item.Project = project
  6138. item.LastAutomaticReduceDetail = goodUser
  6139. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6140. }
  6141. }
  6142. if err == nil {
  6143. c.ServeSuccessJSON(map[string]interface{}{
  6144. "dialysis_goods": dialysisGoods,
  6145. "good_type": goodTypes,
  6146. "total": total,
  6147. "prescribe": prescribe,
  6148. "good_info": good_info,
  6149. "project": project,
  6150. "warehouseOutList": warehouseOutList,
  6151. "config": config,
  6152. "outConfig": outConfig,
  6153. "settleConfig": settleConfig,
  6154. })
  6155. return
  6156. } else {
  6157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6158. return
  6159. }
  6160. } else if err != nil {
  6161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6162. return
  6163. }
  6164. }
  6165. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  6166. start_time := c.GetString("start_time")
  6167. end_time := c.GetString("end_time")
  6168. timeLayout := "2006-01-02"
  6169. loc, _ := time.LoadLocation("Local")
  6170. var theStartTime int64
  6171. if len(start_time) > 0 {
  6172. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6173. if err != nil {
  6174. utils.ErrorLog(err.Error())
  6175. }
  6176. theStartTime = theTime.Unix()
  6177. }
  6178. var theEndtTime int64
  6179. if len(end_time) > 0 {
  6180. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6181. if err != nil {
  6182. utils.ErrorLog(err.Error())
  6183. }
  6184. theEndtTime = theTime.Unix()
  6185. }
  6186. adminUser := c.GetMobileAdminUserInfo()
  6187. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  6188. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  6189. if err == nil {
  6190. c.ServeSuccessJSON(map[string]interface{}{
  6191. "stock_out": outInfo,
  6192. "stockCount": stockCount,
  6193. })
  6194. return
  6195. } else {
  6196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6197. return
  6198. }
  6199. }
  6200. func (c *DialysisAPIController) GetStockInGoodInfo() {
  6201. patient_id, _ := c.GetInt64("patient_id", 0)
  6202. record_time := c.GetString("record_time")
  6203. adminUser := c.GetMobileAdminUserInfo()
  6204. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  6205. if parseDateErr != nil && len(record_time) != 0 {
  6206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6207. return
  6208. }
  6209. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  6210. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6211. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  6212. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  6213. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6214. //获取今日患者的透析处方参数
  6215. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6216. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  6217. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6218. c.ServeSuccessJSON(map[string]interface{}{
  6219. "good_type": goodTypes,
  6220. "good_user": goodUser,
  6221. "good_info": good_info,
  6222. "last_good_user": lastGoodUserDetial,
  6223. "project": project,
  6224. "prescription": prescribe,
  6225. "outInfo": outInfo,
  6226. "configs": configs,
  6227. })
  6228. return
  6229. }
  6230. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  6231. patient_id, _ := c.GetInt64("patient_id", 0)
  6232. record_date := c.GetString("record_time")
  6233. timeLayout := "2006-01-02"
  6234. loc, _ := time.LoadLocation("Local")
  6235. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6236. record_time := theRecordTime.Unix()
  6237. adminInfo := c.GetMobileAdminUserInfo()
  6238. dataBody := make(map[string]interface{}, 0)
  6239. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6240. if err != nil {
  6241. utils.ErrorLog(err.Error())
  6242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6243. return
  6244. }
  6245. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6246. var beforePrepares []*models.DialysisBeforePrepareGoods
  6247. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6248. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6249. goods, _ := dataBody["goods"].([]interface{})
  6250. if len(goods) > 0 {
  6251. for _, item := range goods {
  6252. items := item.(map[string]interface{})
  6253. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6254. utils.ErrorLog("good_id")
  6255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6256. return
  6257. }
  6258. good_id := int64(items["good_id"].(float64))
  6259. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6260. utils.ErrorLog("good_type_id")
  6261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6262. return
  6263. }
  6264. good_type_id := int64(items["good_type_id"].(float64))
  6265. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6266. utils.ErrorLog("count")
  6267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6268. return
  6269. }
  6270. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6271. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  6272. utils.ErrorLog("project_id")
  6273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6274. return
  6275. }
  6276. project_id := int64(items["project_id"].(float64))
  6277. new_count := int64(items["new_count"].(float64))
  6278. old_count := int64(items["old_count"].(float64))
  6279. prepare := &models.DialysisBeforePrepareGoods{
  6280. GoodId: good_id,
  6281. GoodTypeId: good_type_id,
  6282. Count: count,
  6283. ProjectId: project_id,
  6284. StorehouseId: houseConfig.StorehouseOutInfo,
  6285. NewCount: new_count,
  6286. OldCount: old_count,
  6287. }
  6288. beforePrepares = append(beforePrepares, prepare)
  6289. newPrepare := &models.NewDialysisBeforePrepareGoods{
  6290. GoodId: good_id,
  6291. GoodTypeId: good_type_id,
  6292. Count: count,
  6293. ProjectId: project_id,
  6294. StorehouseId: houseConfig.StorehouseOutInfo,
  6295. NewCount: new_count,
  6296. OldCount: old_count,
  6297. }
  6298. newBeforePrepares = append(newBeforePrepares, newPrepare)
  6299. }
  6300. }
  6301. }
  6302. //查询是否有库存
  6303. for _, item := range beforePrepares {
  6304. if item.NewCount > 0 {
  6305. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6306. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  6307. if item.Count > warehouse.Count {
  6308. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6309. c.ServeSuccessJSON(map[string]interface{}{
  6310. "message": "1",
  6311. "good_name": goodObj.GoodName,
  6312. "specification_name": goodObj.SpecificationName,
  6313. })
  6314. return
  6315. }
  6316. }
  6317. }
  6318. // 查询信息规挡的设置天数
  6319. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6320. if infor.ID > 0 && infor.WeekDay > 0 {
  6321. var cha_time int64
  6322. timeNowStr := time.Now().Format("2006-01-02")
  6323. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6324. //今日的日期减去设置的日期
  6325. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6326. if cha_time >= record_time {
  6327. //查询审核是否允许
  6328. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id)
  6329. //申请状态不允许的情况 拒绝修改
  6330. if infor.ApplicationStatus != 1 {
  6331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6332. return
  6333. }
  6334. }
  6335. }
  6336. //出库逻辑
  6337. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  6338. if err != nil {
  6339. utils.ErrorLog(err.Error())
  6340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6341. return
  6342. }
  6343. finish := models.XtDialysisFinish{
  6344. IsFinish: 1,
  6345. UserOrgId: adminInfo.Org.Id,
  6346. Status: 1,
  6347. Ctime: time.Now().Unix(),
  6348. Mtime: 0,
  6349. Module: 11,
  6350. RecordDate: record_time,
  6351. Sourse: 1,
  6352. PatientId: patient_id,
  6353. }
  6354. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6355. if dialysisFinish.ID == 0 {
  6356. service.CreateDialysisFinish(finish)
  6357. }
  6358. //查询当天出库的数据
  6359. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6360. for _, item := range list {
  6361. prepare := models.DialysisBeforePrepare{
  6362. UserOrgId: item.OrgId,
  6363. PatientId: item.PatientId,
  6364. RecordDate: item.RecordTime,
  6365. GoodId: item.GoodId,
  6366. GoodTypeId: item.GoodTypeId,
  6367. Count: item.Count,
  6368. Creater: adminInfo.AdminUser.Id,
  6369. Status: 1,
  6370. Ctime: time.Now().Unix(),
  6371. ProjectId: item.ProjectId,
  6372. StorehouseId: houseConfig.StorehouseOutInfo,
  6373. }
  6374. //清空准备表的数据
  6375. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6376. //插入准备表数据
  6377. service.CreateDialysisBeforePrepareOne(&prepare)
  6378. //查询默认仓库
  6379. //查询默认仓库
  6380. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6381. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6382. var total_count int64
  6383. for _, it := range stockList {
  6384. total_count += it.StockCount
  6385. }
  6386. //基础库插入数据
  6387. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6388. ////更新剩余库存
  6389. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6390. var flush_count int64
  6391. for _, it := range goodList {
  6392. flush_count += it.StockCount
  6393. }
  6394. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6395. if errs != nil {
  6396. goodErrcode := models.XtGoodErrcode{
  6397. UserOrgId: item.OrgId,
  6398. Errcode: "手动出库更新剩余出库失败",
  6399. GoodId: item.GoodId,
  6400. Status: 1,
  6401. Ctime: time.Now().Unix(),
  6402. Mtime: 0,
  6403. Count: 0,
  6404. StockCount: 0,
  6405. Creater: adminInfo.AdminUser.Id,
  6406. BatchNumberId: 0,
  6407. WarehouseOutId: 0,
  6408. }
  6409. service.CreateGoodErrcode(goodErrcode)
  6410. }
  6411. }
  6412. //更新自动出库的地方
  6413. var errs error
  6414. if errs == nil {
  6415. c.ServeSuccessJSON(map[string]interface{}{
  6416. "msg": "修改成功",
  6417. "message": "2",
  6418. "good_name": "",
  6419. "specification_name": "",
  6420. })
  6421. return
  6422. } else {
  6423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6424. return
  6425. }
  6426. }
  6427. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  6428. newArr = make([]*models.DialysisBeforePrepare, 0)
  6429. for i := 0; i < len(arr); i++ {
  6430. repeat := false
  6431. for j := i + 1; j < len(arr); j++ {
  6432. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  6433. repeat = true
  6434. break
  6435. }
  6436. }
  6437. if !repeat {
  6438. newArr = append(newArr, arr[i])
  6439. }
  6440. }
  6441. return
  6442. }
  6443. func (c *DialysisAPIController) GetAllDrug() {
  6444. patient_id, _ := c.GetInt64("patient_id", 0)
  6445. adminInfo := c.GetMobileAdminUserInfo()
  6446. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6447. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  6448. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  6449. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  6450. c.ServeSuccessJSON(map[string]interface{}{
  6451. "base_drug_config": drugStockConfig,
  6452. "private_drug_config": privateDrugConfig,
  6453. "base_drug_list": drugList,
  6454. "private_drug_list": privateDrugList,
  6455. })
  6456. }
  6457. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  6458. newArr = make([]*models.DialysisBeforePrepare, 0)
  6459. for i := 0; i < len(arr); i++ {
  6460. repeat := false
  6461. for j := i + 1; j < len(arr); j++ {
  6462. if arr[i].GoodId == arr[j].GoodId {
  6463. repeat = true
  6464. break
  6465. }
  6466. }
  6467. if !repeat {
  6468. newArr = append(newArr, arr[i])
  6469. }
  6470. }
  6471. return
  6472. }
  6473. func (c *DialysisAPIController) GetDepartment() {
  6474. adminInfo := c.GetMobileAdminUserInfo()
  6475. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  6476. if err == nil {
  6477. c.ServeSuccessJSON(map[string]interface{}{
  6478. "departments": departments,
  6479. })
  6480. } else {
  6481. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6482. return
  6483. }
  6484. }
  6485. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  6486. types, _ := c.GetInt("type", 0)
  6487. start_time := c.GetString("start_time")
  6488. end_time := c.GetString("end_time")
  6489. orgId := c.GetMobileAdminUserInfo().Org.Id
  6490. timeLayout := "2006-01-02"
  6491. loc, _ := time.LoadLocation("Local")
  6492. var startTime int64
  6493. if len(start_time) > 0 {
  6494. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6495. if err != nil {
  6496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6497. return
  6498. }
  6499. startTime = theTime.Unix()
  6500. }
  6501. var endTime int64
  6502. if len(end_time) > 0 {
  6503. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6504. if err != nil {
  6505. utils.ErrorLog(err.Error())
  6506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6507. return
  6508. }
  6509. endTime = theTime.Unix()
  6510. }
  6511. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  6512. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  6513. if err != nil {
  6514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6515. } else {
  6516. c.ServeSuccessJSON(map[string]interface{}{
  6517. "list": list,
  6518. "type": types,
  6519. "stockTotal": stockTotal,
  6520. })
  6521. }
  6522. }
  6523. func (c *DialysisAPIController) BatchDeleteMonitor() {
  6524. ids := c.GetString("ids")
  6525. //patient_id, _ := c.GetInt64("patient_id")
  6526. //monitoring_date, _ := c.GetInt64("monitoring_date")
  6527. idArray := strings.Split(ids, ",")
  6528. err := service.BatchDeleteMonitor(idArray)
  6529. fmt.Print("err", err)
  6530. //orgid := c.GetMobileAdminUserInfo().Org.Id
  6531. //redis := service.RedisClient()
  6532. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  6533. //redis.Set(key, "", time.Second)
  6534. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  6535. //redis.Set(keyOne, "", time.Second)
  6536. //fmt.Println("keyo呢32332322332332232332",keyOne)
  6537. //redis.Close()
  6538. c.ServeSuccessJSON(map[string]interface{}{
  6539. "msg": "批量删除成功",
  6540. })
  6541. return
  6542. }
  6543. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  6544. id, _ := c.GetInt64("id")
  6545. timeLayout := "2006-01-02"
  6546. loc, _ := time.LoadLocation("Local")
  6547. start_time := time.Now().Format("2006-01-02")
  6548. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6549. nowTime := time.Now()
  6550. endTime := nowTime.AddDate(-2, 0, 0)
  6551. endTimes := endTime.Format("2006-01-02")
  6552. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", endTimes+" 00:00:00", loc)
  6553. list, _ := service.GetPatientDialysisRecordList(id, endtime.Unix(), startime.Unix())
  6554. fmt.Println("endtime232332322332322323232332", endTime.Unix())
  6555. c.ServeSuccessJSON(map[string]interface{}{
  6556. "list": list,
  6557. })
  6558. return
  6559. }
  6560. func (c *DialysisAPIController) BathDeleteAdviceList() {
  6561. dataBody := make(map[string]interface{}, 0)
  6562. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6563. ids := c.GetString("ids")
  6564. idArray := strings.Split(ids, ",")
  6565. origin, _ := c.GetInt64("origin")
  6566. if origin == 1 {
  6567. err = service.BatchDeleteAdvice(idArray)
  6568. fmt.Print("err", err)
  6569. c.ServeSuccessJSON(map[string]interface{}{
  6570. "msg": "批量删除成功",
  6571. })
  6572. return
  6573. }
  6574. if origin == 2 {
  6575. service.BatchDeleteHisAdvice(idArray)
  6576. }
  6577. }
  6578. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  6579. good_id, _ := c.GetInt64("good_id")
  6580. count, _ := c.GetInt64("count")
  6581. record_time, _ := c.GetInt64("record_time")
  6582. patient_id, _ := c.GetInt64("patient_id")
  6583. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  6584. c.ServeSuccessJSON(map[string]interface{}{
  6585. "detail": detail,
  6586. })
  6587. return
  6588. }
  6589. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  6590. good_id, _ := c.GetInt64("good_id")
  6591. record_time, _ := c.GetInt64("record_time")
  6592. patient_id, _ := c.GetInt64("patient_id")
  6593. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  6594. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  6595. fmt.Print("err", err)
  6596. c.ServeSuccessJSON(map[string]interface{}{
  6597. "msg": "批量删除成功",
  6598. })
  6599. return
  6600. }
  6601. func (c *DialysisAPIController) BatchAdviceCheck() {
  6602. ids := c.GetString("ids")
  6603. idArray := strings.Split(ids, ",")
  6604. creator, _ := c.GetInt64("creator")
  6605. origin, _ := c.GetInt64("origin")
  6606. if origin == 1 {
  6607. err := service.BatchAdviceCheck(idArray, creator)
  6608. fmt.Println(err)
  6609. list, _ := service.GetAdviceExecutionById(idArray)
  6610. c.ServeSuccessJSON(map[string]interface{}{
  6611. "list": list,
  6612. })
  6613. return
  6614. }
  6615. if origin == 2 {
  6616. service.BatchHisAdviceCheck(idArray, creator)
  6617. list, _ := service.GetHisAdviceExecutionById(idArray)
  6618. c.ServeSuccessJSON(map[string]interface{}{
  6619. "list": list,
  6620. })
  6621. return
  6622. }
  6623. }
  6624. func (c *DialysisAPIController) BatchAdviceExecution() {
  6625. ids := c.GetString("ids")
  6626. idArray := strings.Split(ids, ",")
  6627. executionTime := c.GetString("execution_time")
  6628. creator, _ := c.GetInt64("creator")
  6629. timeLayout := "2006-01-02 15:04:05"
  6630. loc, _ := time.LoadLocation("Local")
  6631. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  6632. orgin, _ := c.GetInt64("origin")
  6633. if orgin == 1 {
  6634. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  6635. list, _ := service.GetAdviceExecutionById(idArray)
  6636. fmt.Println(err)
  6637. c.ServeSuccessJSON(map[string]interface{}{
  6638. "list": list,
  6639. })
  6640. return
  6641. }
  6642. if orgin == 2 {
  6643. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  6644. list, _ := service.GetHisAdviceExecutionById(idArray)
  6645. fmt.Println(err)
  6646. c.ServeSuccessJSON(map[string]interface{}{
  6647. "list": list,
  6648. })
  6649. return
  6650. }
  6651. }
  6652. func (c *DialysisAPIController) UpdateStockGoods() {
  6653. good_id, _ := c.GetInt64("good_id")
  6654. record_time, _ := c.GetInt64("record_time")
  6655. patient_id, _ := c.GetInt64("patient_id")
  6656. count, _ := c.GetInt64("count")
  6657. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  6658. fmt.Print("err", err)
  6659. c.ServeSuccessJSON(map[string]interface{}{
  6660. "msg": "更新成功",
  6661. })
  6662. return
  6663. }
  6664. // 当前数据比上一次出库数据少
  6665. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  6666. //查询该患者当天已经出库的耗材信息
  6667. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  6668. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  6669. for i := len(goods_yc) - 1; i >= 0; i-- {
  6670. goods_yc_temp := goods_yc[i]
  6671. for j := len(goods) - 1; j >= 0; j-- {
  6672. goods_temp := goods[j]
  6673. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  6674. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  6675. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  6676. if goods_yc_temp.Count == goods_temp.Count {
  6677. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  6678. goods = append(goods[:j], goods[j+1:]...)
  6679. break
  6680. }
  6681. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  6682. if goods_yc_temp.Count > goods_temp.Count {
  6683. temp_count := goods_yc_temp.Count - goods_temp.Count
  6684. goods_yc[i].Count = temp_count
  6685. goods = append(goods[:j], goods[j+1:]...)
  6686. break
  6687. }
  6688. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  6689. if goods_yc_temp.Count < goods_temp.Count {
  6690. temp_count := goods_temp.Count - goods_yc_temp.Count
  6691. goods[j].Count = temp_count
  6692. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  6693. break
  6694. }
  6695. }
  6696. }
  6697. }
  6698. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  6699. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  6700. //退库
  6701. if len(goods_yc) > 0 {
  6702. for _, good_yc := range goods_yc {
  6703. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  6704. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  6705. }
  6706. }
  6707. return nil
  6708. }
  6709. // 耗材出库删除
  6710. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  6711. // 先根据相关信息查询当天该耗材的出库信息
  6712. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  6713. if err != nil {
  6714. return err
  6715. }
  6716. var delete_count int64 = 0
  6717. delete_count = warehouseOutInfos.Count - count
  6718. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  6719. // 在出库记录表里记录退库详情
  6720. warehouseOutInfo := &models.WarehouseOutInfo{
  6721. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6722. WarehouseOutId: warehouseOut.ID,
  6723. Status: 1,
  6724. Ctime: time.Now().Unix(),
  6725. OrgId: orgID,
  6726. Type: 1,
  6727. IsSys: 1,
  6728. SysRecordTime: record_time,
  6729. GoodTypeId: good_yc.GoodTypeId,
  6730. GoodId: good_yc.GoodId,
  6731. PatientId: good_yc.PatientId,
  6732. ConsumableType: 2,
  6733. StorehouseId: houseConfig.StorehouseOutInfo,
  6734. IsCheck: 1,
  6735. }
  6736. warehouseOutInfo.Count = count
  6737. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  6738. warehouseOutInfo.Price = stockInInfo.Price
  6739. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6740. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6741. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6742. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6743. warehouseOutInfo.Number = warehouseOutInfos.Number
  6744. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6745. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6746. //查找当天是否存在出库记录
  6747. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  6748. if errcod == gorm.ErrRecordNotFound {
  6749. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6750. //插入详情明细表
  6751. stockFlow := models.VmStockFlow{
  6752. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6753. WarehouseOutId: warehouseOut.ID,
  6754. GoodId: good_yc.GoodId,
  6755. Number: warehouseOutInfos.Number,
  6756. ProductDate: stockInInfo.ProductDate,
  6757. ExpireDate: stockInInfo.ExpiryDate,
  6758. Count: count,
  6759. Price: stockInInfo.Price,
  6760. Status: 1,
  6761. Ctime: time.Now().Unix(),
  6762. UserOrgId: good_yc.OrgId,
  6763. Manufacturer: stockInInfo.Manufacturer,
  6764. Dealer: stockInInfo.Dealer,
  6765. LicenseNumber: stockInInfo.LicenseNumber,
  6766. IsEdit: 2,
  6767. Creator: creater,
  6768. SystemTime: record_time,
  6769. ConsumableType: 3,
  6770. WarehousingDetailId: 0,
  6771. IsSys: 1,
  6772. UpdateCreator: creater,
  6773. PatientId: patient_id,
  6774. StorehouseId: houseConfig.StorehouseOutInfo,
  6775. }
  6776. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  6777. if errflow == gorm.ErrRecordNotFound {
  6778. //创建流水表
  6779. err := service.CreateStockFlowOne(stockFlow)
  6780. fmt.Println("err", err)
  6781. } else if errflow == nil {
  6782. //插入详情明细表
  6783. stockFlow := models.VmStockFlow{
  6784. ID: exsit.ID,
  6785. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6786. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6787. WarehouseOutId: warehouseOut.ID,
  6788. GoodId: good_yc.GoodId,
  6789. Number: warehouseOutInfos.Number,
  6790. ProductDate: stockInInfo.ProductDate,
  6791. ExpireDate: stockInInfo.ExpiryDate,
  6792. Count: exsit.Count - delete_count,
  6793. Price: stockInInfo.Price,
  6794. Status: 1,
  6795. Ctime: time.Now().Unix(),
  6796. UserOrgId: good_yc.OrgId,
  6797. Manufacturer: stockInInfo.Manufacturer,
  6798. Dealer: stockInInfo.Dealer,
  6799. LicenseNumber: stockInInfo.LicenseNumber,
  6800. IsEdit: 2,
  6801. Creator: creater,
  6802. SystemTime: record_time,
  6803. ConsumableType: 3,
  6804. WarehousingDetailId: 0,
  6805. IsSys: 1,
  6806. UpdateCreator: creater,
  6807. PatientId: patient_id,
  6808. StorehouseId: houseConfig.StorehouseOutInfo,
  6809. }
  6810. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  6811. }
  6812. if errOne != nil {
  6813. return errOne
  6814. }
  6815. } else if errcod == nil {
  6816. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  6817. //插入详情明细表
  6818. stockFlow := models.VmStockFlow{
  6819. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6820. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6821. WarehouseOutId: warehouseOut.ID,
  6822. GoodId: good_yc.GoodId,
  6823. Number: warehouseOutInfos.Number,
  6824. ProductDate: stockInInfo.ProductDate,
  6825. ExpireDate: stockInInfo.ExpiryDate,
  6826. Count: count,
  6827. Price: stockInInfo.Price,
  6828. Status: 1,
  6829. Ctime: time.Now().Unix(),
  6830. UserOrgId: good_yc.OrgId,
  6831. Manufacturer: stockInInfo.Manufacturer,
  6832. Dealer: stockInInfo.Dealer,
  6833. LicenseNumber: stockInInfo.LicenseNumber,
  6834. IsEdit: 2,
  6835. Creator: creater,
  6836. SystemTime: record_time,
  6837. ConsumableType: 3,
  6838. WarehousingDetailId: 0,
  6839. IsSys: 1,
  6840. UpdateCreator: creater,
  6841. PatientId: patient_id,
  6842. ReturnCount: delete_count,
  6843. StorehouseId: houseConfig.StorehouseOutInfo,
  6844. }
  6845. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  6846. if errflows == gorm.ErrRecordNotFound {
  6847. //创建流水表
  6848. service.CreateStockFlowOne(stockFlow)
  6849. } else if errflows == nil {
  6850. stockFlow := models.VmStockFlow{
  6851. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6852. ID: exsit.ID,
  6853. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6854. WarehouseOutId: warehouseOut.ID,
  6855. GoodId: good_yc.GoodId,
  6856. Number: warehouseOutInfos.Number,
  6857. ProductDate: stockInInfo.ProductDate,
  6858. ExpireDate: stockInInfo.ExpiryDate,
  6859. Count: exsit.Count - delete_count,
  6860. Price: stockInInfo.Price,
  6861. Status: 1,
  6862. Ctime: time.Now().Unix(),
  6863. UserOrgId: good_yc.OrgId,
  6864. Manufacturer: stockInInfo.Manufacturer,
  6865. Dealer: stockInInfo.Dealer,
  6866. LicenseNumber: stockInInfo.LicenseNumber,
  6867. IsEdit: 2,
  6868. Creator: creater,
  6869. SystemTime: record_time,
  6870. ConsumableType: 3,
  6871. WarehousingDetailId: 0,
  6872. IsSys: 1,
  6873. UpdateCreator: creater,
  6874. PatientId: patient_id,
  6875. ReturnCount: delete_count,
  6876. StorehouseId: houseConfig.StorehouseOutInfo,
  6877. }
  6878. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  6879. }
  6880. }
  6881. //更改自动出库的表格
  6882. details := models.BloodAutomaticReduceDetail{
  6883. WarehouseOutId: warehouseOutInfo.ID,
  6884. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6885. PatientId: patient_id,
  6886. Ctime: time.Now().Unix(),
  6887. Mtime: time.Now().Unix(),
  6888. Status: 1,
  6889. RecordTime: record_time,
  6890. OrgId: orgID,
  6891. GoodId: good_yc.GoodId,
  6892. GoodTypeId: good_yc.GoodTypeId,
  6893. Count: count,
  6894. StorehouseId: houseConfig.StorehouseOutInfo,
  6895. }
  6896. //查询当天耗材是否已经存在数据
  6897. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  6898. if errcode == gorm.ErrRecordNotFound {
  6899. errTwo := service.CreateAutoReduceRecord(&details)
  6900. if errTwo != nil {
  6901. return errTwo
  6902. }
  6903. } else if errcode == nil {
  6904. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  6905. service.CreateAutoReduceRecord(&details)
  6906. }
  6907. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  6908. //增加出库库存数量
  6909. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  6910. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  6911. fmt.Println("errOne", errOne)
  6912. // 删除出库完成后,要增加对应批次的库存数量
  6913. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  6914. if errThree != nil {
  6915. return errThree
  6916. }
  6917. if good_yc.Count == 0 {
  6918. return nil
  6919. } else {
  6920. return errors.New("退库和出库数据不匹配")
  6921. }
  6922. }
  6923. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  6924. //查询该患者当天已经出库的耗材信息
  6925. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  6926. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  6927. for i := len(goods_yc) - 1; i >= 0; i-- {
  6928. goods_yc_temp := goods_yc[i]
  6929. for j := len(goods) - 1; j >= 0; j-- {
  6930. goods_temp := goods[j]
  6931. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  6932. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  6933. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  6934. if goods_yc_temp.Count == goods_temp.Count {
  6935. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  6936. goods = append(goods[:j], goods[j+1:]...)
  6937. break
  6938. }
  6939. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  6940. if goods_yc_temp.Count > goods_temp.Count {
  6941. temp_count := goods_yc_temp.Count - goods_temp.Count
  6942. goods_yc[i].Count = temp_count
  6943. goods = append(goods[:j], goods[j+1:]...)
  6944. break
  6945. }
  6946. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  6947. if goods_yc_temp.Count < goods_temp.Count {
  6948. temp_count := goods_temp.Count - goods_yc_temp.Count
  6949. goods[j].Count = temp_count
  6950. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  6951. break
  6952. }
  6953. }
  6954. }
  6955. }
  6956. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  6957. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  6958. fmt.Println("剩余需要出库的", len(goods))
  6959. if len(goods) > 0 {
  6960. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  6961. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  6962. if err == gorm.ErrRecordNotFound {
  6963. //没有记录,则创建出库单
  6964. timeStr := time.Now().Format("2006-01-02")
  6965. timeArr := strings.Split(timeStr, "-")
  6966. total, _ := service.FindAllWarehouseOut(orgID)
  6967. total = total + 1
  6968. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6969. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6970. number = number + total
  6971. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6972. warehouseOut := models.WarehouseOut{
  6973. WarehouseOutOrderNumber: warehousing_out_order,
  6974. OperationTime: time.Now().Unix(),
  6975. OrgId: orgID,
  6976. Creater: creater,
  6977. Ctime: time.Now().Unix(),
  6978. Status: 1,
  6979. WarehouseOutTime: record_time,
  6980. Dealer: 0,
  6981. Manufacturer: 0,
  6982. Type: 1,
  6983. IsSys: 1,
  6984. StorehouseId: houseConfig.StorehouseOutInfo,
  6985. IsCheck: 1,
  6986. }
  6987. err := service.AddSigleWarehouseOut(&warehouseOut)
  6988. if err != nil {
  6989. utils.TraceLog("创建出库单失败 err = %v", err)
  6990. return err
  6991. } else {
  6992. out = warehouseOut
  6993. }
  6994. }
  6995. for _, item := range goods {
  6996. var newCount int64 = 0
  6997. for _, it := range goodOne {
  6998. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  6999. newCount = it.Count
  7000. }
  7001. }
  7002. prepare := models.DialysisBeforePrepare{
  7003. GoodTypeId: item.GoodTypeId,
  7004. GoodId: item.GoodId,
  7005. Count: item.Count,
  7006. StorehouseId: houseConfig.StorehouseOutInfo,
  7007. }
  7008. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  7009. //增加出库数量
  7010. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  7011. }
  7012. }
  7013. if len(goods_yc) > 0 {
  7014. for _, good_yc := range goods_yc {
  7015. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7016. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  7017. }
  7018. }
  7019. return nil
  7020. }
  7021. // 耗材出库删除
  7022. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  7023. // 先根据相关信息查询当天该耗材的出库信息
  7024. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  7025. if err != nil {
  7026. return err
  7027. }
  7028. var delete_count int64 = 0
  7029. for _, ware := range warehouseOutInfos {
  7030. // 判断当前出库的数据和删除出库数量
  7031. if good_yc.Count <= ware.Count {
  7032. delete_count = good_yc.Count
  7033. } else {
  7034. delete_count = ware.Count
  7035. }
  7036. warehouseOutInfo := &models.WarehouseOutInfo{
  7037. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7038. WarehouseOutId: warehouseOut.ID,
  7039. Status: 1,
  7040. Ctime: time.Now().Unix(),
  7041. Remark: "",
  7042. OrgId: orgID,
  7043. Type: 1,
  7044. Manufacturer: 0,
  7045. Dealer: 0,
  7046. IsSys: 0,
  7047. SysRecordTime: record_time,
  7048. GoodTypeId: good_yc.GoodTypeId,
  7049. GoodId: good_yc.GoodId,
  7050. StorehouseId: warehouseOut.StorehouseId,
  7051. IsCheck: 1,
  7052. }
  7053. warehouseOutInfo.Count = delete_count
  7054. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7055. warehouseOutInfo.Price = stockInInfo.Price
  7056. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7057. if errOne != nil {
  7058. return errOne
  7059. }
  7060. // 删除出库完成后,要改变流水库存(有疑问)
  7061. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7062. fmt.Println("errOne", errOne)
  7063. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  7064. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7065. //扣减出库数量
  7066. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  7067. if errThree != nil {
  7068. return errThree
  7069. }
  7070. }
  7071. if good_yc.Count == 0 {
  7072. return nil
  7073. } else {
  7074. return errors.New("退库和出库数据不匹配")
  7075. }
  7076. }
  7077. func (this *DialysisAPIController) GetMobileScheduleList() {
  7078. limit, _ := this.GetInt64("limit")
  7079. page, _ := this.GetInt64("page")
  7080. type_options_visible, _ := this.GetInt64("type_options_visible")
  7081. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  7082. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  7083. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  7084. }
  7085. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  7086. newArr = make([]*models.HisPrescriptionProject, 0)
  7087. for i := 0; i < len(arr); i++ {
  7088. repeat := false
  7089. for j := i + 1; j < len(arr); j++ {
  7090. if arr[i].TeamId == arr[j].TeamId {
  7091. repeat = true
  7092. break
  7093. }
  7094. }
  7095. if !repeat {
  7096. newArr = append(newArr, arr[i])
  7097. }
  7098. }
  7099. return
  7100. }
  7101. func (this *DialysisAPIController) GetRoleList() {
  7102. admin_user_id, _ := this.GetInt64("admin_user_id")
  7103. orgid := this.GetMobileAdminUserInfo().Org.Id
  7104. list, err := service.GetRoleList(orgid, admin_user_id)
  7105. fmt.Println(err)
  7106. this.ServeSuccessJSON(map[string]interface{}{
  7107. "list": list,
  7108. })
  7109. return
  7110. }
  7111. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7112. fmt.Println("退库222322232322332232332322332232332233wo", good_yc.GoodId)
  7113. // 先根据相关信息查询当天该耗材的出库信息
  7114. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7115. if err != nil {
  7116. return err
  7117. }
  7118. var delete_count int64 = 0
  7119. delete_count = warehouseOutInfos.Count - count
  7120. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7121. // 删除出库完成后,要增加对应批次的库存数量
  7122. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7123. if errThree != nil {
  7124. return errThree
  7125. }
  7126. //增加退库数量
  7127. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7128. //扣减出库数量
  7129. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  7130. //查询剩余库存
  7131. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  7132. var sum_count int64
  7133. for _, item := range goodList {
  7134. sum_count += item.StockCount
  7135. }
  7136. // 在出库记录表里记录退库详情
  7137. warehouseOutInfo := &models.WarehouseOutInfo{
  7138. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7139. WarehouseOutId: warehouseOut.ID,
  7140. Status: 1,
  7141. Ctime: time.Now().Unix(),
  7142. OrgId: orgID,
  7143. Type: 1,
  7144. IsSys: 1,
  7145. SysRecordTime: record_time,
  7146. GoodTypeId: good_yc.GoodTypeId,
  7147. GoodId: good_yc.GoodId,
  7148. PatientId: good_yc.PatientId,
  7149. ConsumableType: 2,
  7150. StorehouseId: houseConfig.StorehouseOutInfo,
  7151. IsCheck: 1,
  7152. OverCount: sum_count,
  7153. }
  7154. warehouseOutInfo.Count = count
  7155. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7156. warehouseOutInfo.Price = stockInInfo.Price
  7157. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7158. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7159. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7160. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7161. warehouseOutInfo.Number = warehouseOutInfos.Number
  7162. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7163. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7164. //查找当天是否存在出库记录
  7165. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7166. if errcod == gorm.ErrRecordNotFound {
  7167. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7168. //插入详情明细表
  7169. if errOne != nil {
  7170. return errOne
  7171. }
  7172. //插入详情明细表
  7173. stockFlow := models.VmStockFlow{
  7174. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7175. WarehouseOutId: warehouseOut.ID,
  7176. GoodId: good_yc.GoodId,
  7177. Number: warehouseOutInfos.Number,
  7178. ProductDate: stockInInfo.ProductDate,
  7179. ExpireDate: stockInInfo.ExpiryDate,
  7180. Count: count,
  7181. Price: stockInInfo.Price,
  7182. Status: 1,
  7183. Ctime: time.Now().Unix(),
  7184. UserOrgId: good_yc.OrgId,
  7185. Manufacturer: stockInInfo.Manufacturer,
  7186. Dealer: stockInInfo.Dealer,
  7187. LicenseNumber: stockInInfo.LicenseNumber,
  7188. IsEdit: 2,
  7189. Creator: creater,
  7190. SystemTime: record_time,
  7191. ConsumableType: 3,
  7192. WarehousingDetailId: 0,
  7193. IsSys: 1,
  7194. UpdateCreator: creater,
  7195. PatientId: patient_id,
  7196. StorehouseId: houseConfig.StorehouseOutInfo,
  7197. OverCount: sum_count,
  7198. ProjectId: good_yc.ProjectId,
  7199. }
  7200. err := service.CreateStockFlowOne(stockFlow)
  7201. fmt.Println("err", err)
  7202. } else if errcod == nil {
  7203. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7204. }
  7205. //创建退库单
  7206. operation_time := time.Now().Unix()
  7207. //创建退库单
  7208. timeStr := time.Now().Format("2006-01-02")
  7209. timeArr := strings.Split(timeStr, "-")
  7210. total, _ := service.FindAllCancelStockTotal(orgID)
  7211. total = total + 1
  7212. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7213. cancelStock := models.CancelStock{
  7214. OrderNumber: orderNumber,
  7215. OperaTime: operation_time,
  7216. OrgId: orgID,
  7217. Creater: warehouseOut.Creater,
  7218. Ctime: time.Now().Unix(),
  7219. Status: 1,
  7220. ReturnTime: record_time,
  7221. Type: 1,
  7222. StorehouseId: stockInInfo.StorehouseId,
  7223. IsCheck: 1,
  7224. }
  7225. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  7226. if msgerrkonde == gorm.ErrRecordNotFound {
  7227. service.AddSigleCancelStock(&cancelStock)
  7228. }
  7229. cancel, _ := service.GetLastCancelStockById(orgID)
  7230. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  7231. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  7232. cancelStockInfo := models.CancelStockInfo{
  7233. GoodId: stockInInfo.GoodId,
  7234. CancelStockId: cancel.ID,
  7235. GoodTypeId: stockInInfo.GoodTypeId,
  7236. Count: delete_count,
  7237. Price: stockInInfo.PackingPrice,
  7238. Total: 0,
  7239. ProductDate: stockInInfo.ProductDate,
  7240. ExpiryDate: stockInInfo.ExpiryDate,
  7241. Ctime: time.Now().Unix(),
  7242. Status: 1,
  7243. OrgId: orgID,
  7244. OrderNumber: cancel.OrderNumber,
  7245. Type: 0,
  7246. Dealer: deaerler.DealerName,
  7247. Manufacturer: manufacturer.ManufacturerName,
  7248. Number: stockInInfo.Number,
  7249. RegisterAccount: "",
  7250. Remark: "",
  7251. WarehouseInfoId: stockInInfo.ID,
  7252. PatientId: patient_id,
  7253. RecordDate: record_time,
  7254. StorehouseId: stockInInfo.StorehouseId,
  7255. IsCheck: 1,
  7256. }
  7257. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7258. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  7259. flow := models.VmStockFlow{
  7260. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  7261. GoodId: good_yc.GoodId,
  7262. Number: warehouseOutInfos.Number,
  7263. LicenseNumber: stockInInfo.LicenseNumber,
  7264. Count: delete_count,
  7265. UserOrgId: orgID,
  7266. PatientId: patient_id,
  7267. SystemTime: record_time,
  7268. ConsumableType: 7,
  7269. IsSys: 0,
  7270. WarehousingOrder: "",
  7271. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  7272. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7273. IsEdit: 0,
  7274. CancelStockId: cancel.ID,
  7275. CancelOrderNumber: cancel.OrderNumber,
  7276. Manufacturer: manufacturer.ID,
  7277. Dealer: 0,
  7278. Creator: warehouseOut.Creater,
  7279. UpdateCreator: 0,
  7280. Status: 1,
  7281. Ctime: time.Now().Unix(),
  7282. Mtime: 0,
  7283. Price: stockInInfo.Price,
  7284. WarehousingDetailId: stockInInfo.ID,
  7285. WarehouseOutDetailId: warehouseOutInfos.ID,
  7286. CancelOutDetailId: cancelInfo.ID,
  7287. ProductDate: stockInInfo.ProductDate,
  7288. ExpireDate: stockInInfo.ExpiryDate,
  7289. StorehouseId: houseConfig.StorehouseOutInfo,
  7290. OverCount: sum_count,
  7291. }
  7292. service.CreateStockFlowOne(flow)
  7293. //更改自动出库的表格
  7294. details := models.BloodAutomaticReduceDetail{
  7295. WarehouseOutId: warehouseOutInfo.ID,
  7296. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7297. PatientId: patient_id,
  7298. Ctime: time.Now().Unix(),
  7299. Mtime: time.Now().Unix(),
  7300. Status: 1,
  7301. RecordTime: record_time,
  7302. OrgId: orgID,
  7303. GoodId: good_yc.GoodId,
  7304. GoodTypeId: good_yc.GoodTypeId,
  7305. Count: count,
  7306. StorehouseId: houseConfig.StorehouseOutInfo,
  7307. }
  7308. //查询当天耗材是否已经存在数据
  7309. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7310. if errcode == gorm.ErrRecordNotFound {
  7311. errTwo := service.CreateAutoReduceRecord(&details)
  7312. if errTwo != nil {
  7313. return errTwo
  7314. }
  7315. } else if errcode == nil {
  7316. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7317. service.CreateAutoReduceRecord(&details)
  7318. }
  7319. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7320. //增加出库库存数量
  7321. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  7322. if good_yc.Count == 0 {
  7323. return nil
  7324. } else {
  7325. return errors.New("退库和出库数据不匹配")
  7326. }
  7327. }
  7328. func (this *DialysisAPIController) SavePatientSign() {
  7329. adminUserInfo := this.GetMobileAdminUserInfo()
  7330. patient_id, _ := this.GetInt64("patient_id")
  7331. dialysis_date, _ := this.GetInt64("dialysis_date")
  7332. orgid := adminUserInfo.Org.Id
  7333. var esdata models.DialysisOrder
  7334. var err error
  7335. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  7336. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7337. return
  7338. }
  7339. esdata.Hash = esdata.Hash
  7340. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  7341. order := models.DialysisOrder{
  7342. Hash: esdata.Hash,
  7343. Url: esdata.Url,
  7344. }
  7345. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  7346. redis := service.RedisClient()
  7347. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  7348. redis.Set(key, "", time.Second)
  7349. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  7350. //清空key 值
  7351. redis.Set(keyOne, "", time.Second)
  7352. //scheduleDateStartOne := startDate.Format("2006-01-02")
  7353. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  7354. //redis.Set(keyTwo, "", time.Second)
  7355. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  7356. redis.Set(keyThree, "", time.Second)
  7357. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  7358. redis.Set(keyFour, "", time.Second)
  7359. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  7360. redis.Set(keyFive, "", time.Second)
  7361. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  7362. redis.Set(keySix, "", time.Second)
  7363. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  7364. redis.Set(keySeven, "", time.Second)
  7365. if err != nil {
  7366. fmt.Println(err)
  7367. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  7368. return
  7369. }
  7370. this.ServeSuccessJSON(map[string]interface{}{
  7371. "electronic_signature": esdata,
  7372. })
  7373. }
  7374. func (this *DialysisAPIController) GetPatientSign() {
  7375. patient_id, _ := this.GetInt64("patient_id")
  7376. dialysis_date, _ := this.GetInt64("dialysis_date")
  7377. adminUserInfo := this.GetMobileAdminUserInfo()
  7378. orgId := adminUserInfo.Org.Id
  7379. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  7380. if err != nil {
  7381. fmt.Println(err)
  7382. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  7383. return
  7384. }
  7385. this.ServeSuccessJSON(map[string]interface{}{
  7386. "dialysisOrder": dialysisOrder,
  7387. })
  7388. }
  7389. func (this *DialysisAPIController) GetScheduleByPatient() {
  7390. patient_id, _ := this.GetInt64("patient_id")
  7391. schedule_date, _ := this.GetInt64("schedule_date")
  7392. orgid := this.GetMobileAdminUserInfo().Org.Id
  7393. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  7394. this.ServeSuccessJSON(map[string]interface{}{
  7395. "schedule": schedule,
  7396. })
  7397. }
  7398. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  7399. org_id := this.GetMobileAdminUserInfo().Org.Id
  7400. patient_id, _ := this.GetInt64("patient_id")
  7401. schedule_date, _ := this.GetInt64("schedule_date")
  7402. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  7403. this.ServeSuccessJSON(map[string]interface{}{
  7404. "order": order,
  7405. })
  7406. }
  7407. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  7408. org_id := this.GetMobileAdminUserInfo().Org.Id
  7409. schedule_date := this.GetString("schedule_date")
  7410. schedule_type, _ := this.GetInt64("schedule_type")
  7411. timeLayout := "2006-01-02"
  7412. loc, _ := time.LoadLocation("Local")
  7413. var startdateunix int64
  7414. if len(schedule_date) > 0 {
  7415. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  7416. if err != nil {
  7417. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7418. return
  7419. }
  7420. startdateunix = theTime.Unix()
  7421. }
  7422. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  7423. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  7424. devices, _ := service.GetAllDevicetByListSix(org_id)
  7425. for key, item := range scheduals {
  7426. // 床位信息
  7427. for _, device := range devices {
  7428. if item.BedId == device.ID {
  7429. scheduals[key].DeviceNumber = device
  7430. break
  7431. }
  7432. }
  7433. }
  7434. this.ServeSuccessJSON(map[string]interface{}{
  7435. "list": list,
  7436. "scheduals": scheduals,
  7437. })
  7438. }
  7439. func (this *DialysisAPIController) SavePatientPicture() {
  7440. patient_id, _ := this.GetInt64("patient_id")
  7441. dialysis_date, _ := this.GetInt64("schedule_date")
  7442. avatar := this.GetString("avatar")
  7443. fmt.Println("patient_id", patient_id)
  7444. orgId := this.GetMobileAdminUserInfo().Org.Id
  7445. order := models.DialysisOrder{
  7446. Url: avatar,
  7447. }
  7448. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  7449. redis := service.RedisClient()
  7450. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  7451. redis.Set(key, "", time.Second)
  7452. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  7453. //清空key 值
  7454. redis.Set(keyOne, "", time.Second)
  7455. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  7456. redis.Set(keyThree, "", time.Second)
  7457. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  7458. redis.Set(keyFour, "", time.Second)
  7459. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  7460. redis.Set(keyFive, "", time.Second)
  7461. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  7462. redis.Set(keySix, "", time.Second)
  7463. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  7464. redis.Set(keySeven, "", time.Second)
  7465. if err != nil {
  7466. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  7467. return
  7468. }
  7469. this.ServeSuccessJSON(map[string]interface{}{
  7470. "order": order,
  7471. })
  7472. }
  7473. func (this *DialysisAPIController) ExectionMobileAdvice() {
  7474. ids := this.GetString("ids")
  7475. idSplit := strings.Split(ids, ",")
  7476. orgId := this.GetMobileAdminUserInfo().Org.Id
  7477. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  7478. execution_time := this.GetString("exce_time")
  7479. timeLayout2 := "2006-01-02 15:04:05"
  7480. loc, _ := time.LoadLocation("Local")
  7481. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  7482. if errs != nil {
  7483. utils.ErrorLog(errs.Error())
  7484. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7485. return
  7486. }
  7487. //his客户
  7488. if config.IsOpen == 1 {
  7489. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  7490. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  7491. for _, item := range list {
  7492. for _, it := range adviceList {
  7493. if item.DrugId == it.DrugId {
  7494. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  7495. }
  7496. }
  7497. }
  7498. for _, item := range list {
  7499. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  7500. var sum_out_count int64
  7501. for _, itemThree := range item.ChildDoctorAdvice {
  7502. var prescribing_number int64
  7503. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  7504. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  7505. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  7506. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  7507. }
  7508. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  7509. prescribing_number = parseIntPrescribingNumber
  7510. }
  7511. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  7512. prescribing_number = parseIntPrescribingNumber
  7513. }
  7514. sum_out_count += prescribing_number
  7515. }
  7516. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  7517. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  7518. //库存不足
  7519. if sum_out_count > drugStockOut.FlushCount {
  7520. this.ServeSuccessJSON(map[string]interface{}{
  7521. "msg": "2",
  7522. "drug": medical,
  7523. "ids": ids,
  7524. })
  7525. return
  7526. }
  7527. }
  7528. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  7529. //执行医嘱
  7530. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  7531. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  7532. for _, item := range advices {
  7533. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  7534. redis := service.RedisClient()
  7535. //清空key 值
  7536. redis.Set(key, "", time.Second)
  7537. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  7538. redis.Set(keyTwo, "", time.Second)
  7539. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  7540. redis.Set(keyThree, "", time.Second)
  7541. recordDate := theTime.Format("2006-01-02")
  7542. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  7543. redis.Set(keyFour, "", time.Second)
  7544. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  7545. redis.Set(keyFive, "", time.Second)
  7546. defer redis.Close()
  7547. }
  7548. if errs == nil {
  7549. //药品管理信息
  7550. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  7551. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  7552. if drugStockConfig.IsOpen == 1 {
  7553. for _, item := range advices {
  7554. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  7555. config, _ := service.GetDrugOpenConfigOne(orgId)
  7556. if config.IsOpen != 1 {
  7557. //查询该药品是否有库存
  7558. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  7559. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  7560. if medical.IsUse == 2 {
  7561. if config.IsOpen != 1 {
  7562. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  7563. service.HisDrugsDelivery(orgId, creater, &advice)
  7564. if orgId == 3877 || orgId == 10265 {
  7565. //查询该药品是否有出库记录
  7566. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  7567. if len(flowMap) == 0 {
  7568. errs := service.UpdateHisAdviceById(advice.ID)
  7569. if errs != nil {
  7570. drugError := models.XtDrugError{
  7571. UserOrgId: orgId,
  7572. DrugId: item.DrugId,
  7573. RecordDate: item.AdviceDate,
  7574. PatientId: item.PatientId,
  7575. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  7576. Status: 1,
  7577. Ctime: time.Now().Unix(),
  7578. Mtime: 0,
  7579. SumCount: 0,
  7580. Prescribingnumber: advice.PrescribingNumber,
  7581. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  7582. }
  7583. service.CreateDrugError(drugError)
  7584. }
  7585. this.ServeSuccessJSON(map[string]interface{}{
  7586. "msg": "2",
  7587. "drug": medical,
  7588. "ids": ids,
  7589. })
  7590. return
  7591. }
  7592. }
  7593. }
  7594. if pharmacyConfig.IsOpen != 1 {
  7595. service.HisDrugsDelivery(orgId, creater, &advice)
  7596. if orgId == 3877 || orgId == 10265 {
  7597. //查询该药品是否有出库记录
  7598. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  7599. if len(flowMap) == 0 {
  7600. errs := service.UpdateHisAdviceById(advice.ID)
  7601. if errs != nil {
  7602. drugError := models.XtDrugError{
  7603. UserOrgId: orgId,
  7604. DrugId: item.DrugId,
  7605. RecordDate: item.AdviceDate,
  7606. PatientId: item.PatientId,
  7607. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  7608. Status: 1,
  7609. Ctime: time.Now().Unix(),
  7610. Mtime: 0,
  7611. SumCount: 0,
  7612. Prescribingnumber: advice.PrescribingNumber,
  7613. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  7614. }
  7615. service.CreateDrugError(drugError)
  7616. }
  7617. this.ServeSuccessJSON(map[string]interface{}{
  7618. "msg": "2",
  7619. "drug": medical,
  7620. "ids": ids,
  7621. })
  7622. return
  7623. }
  7624. }
  7625. }
  7626. //更新字典里面的库存
  7627. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  7628. var sum_count int64
  7629. for _, its := range stockInfo {
  7630. if its.MaxUnit == medical.MaxUnit {
  7631. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  7632. }
  7633. sum_count += its.StockMaxNumber + its.StockMinNumber
  7634. }
  7635. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  7636. //剩余库存
  7637. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  7638. }
  7639. }
  7640. }
  7641. }
  7642. }
  7643. this.ServeSuccessJSON(map[string]interface{}{
  7644. "msg": "1",
  7645. "ids": ids,
  7646. })
  7647. return
  7648. } else {
  7649. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7650. }
  7651. }
  7652. fmt.Println("config233322333223", config.IsOpen)
  7653. //血透客户
  7654. if config.IsOpen == 2 || config.IsOpen == 0 {
  7655. //药品管理信息
  7656. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  7657. if drugStockConfig.IsOpen == 1 {
  7658. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  7659. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  7660. for _, item := range list {
  7661. for _, it := range adviceList {
  7662. if item.DrugId == it.DrugId {
  7663. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  7664. }
  7665. }
  7666. }
  7667. for _, item := range list {
  7668. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  7669. var sum_out_count int64
  7670. for _, itemThree := range item.ChildDoctorAdvice {
  7671. var prescribing_number int64
  7672. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  7673. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  7674. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  7675. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  7676. }
  7677. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  7678. prescribing_number = parseIntPrescribingNumber
  7679. }
  7680. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  7681. prescribing_number = parseIntPrescribingNumber
  7682. }
  7683. sum_out_count += prescribing_number
  7684. }
  7685. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  7686. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  7687. //库存不足
  7688. if sum_out_count > drugStockOut.FlushCount {
  7689. this.ServeSuccessJSON(map[string]interface{}{
  7690. "msg": "2",
  7691. "drug": medical,
  7692. "ids": ids,
  7693. })
  7694. return
  7695. }
  7696. }
  7697. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  7698. fmt.Println("creater2332243244224242424", creater)
  7699. //执行医嘱
  7700. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  7701. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  7702. for _, item := range advices {
  7703. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  7704. redis := service.RedisClient()
  7705. //清空key 值
  7706. redis.Set(key, "", time.Second)
  7707. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  7708. redis.Set(keyTwo, "", time.Second)
  7709. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  7710. redis.Set(keyThree, "", time.Second)
  7711. recordDate := theTime.Format("2006-01-02")
  7712. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  7713. redis.Set(keyFour, "", time.Second)
  7714. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  7715. redis.Set(keyFive, "", time.Second)
  7716. defer redis.Close()
  7717. }
  7718. if errs == nil {
  7719. for _, item := range advices {
  7720. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  7721. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  7722. //查询是否出库按钮开启
  7723. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  7724. if adviceSetting.IsAdviceOpen == 1 {
  7725. //查询是否出库按钮开启
  7726. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  7727. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  7728. if prescriptionConfig.IsOpen == 1 {
  7729. if medical.IsUse == 2 {
  7730. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  7731. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  7732. }
  7733. if pharmacyConfig.IsOpen != 1 {
  7734. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  7735. }
  7736. //更新字典里面的库存
  7737. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  7738. var sum_count int64
  7739. for _, its := range stockInfo {
  7740. if its.MaxUnit == medical.MaxUnit {
  7741. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  7742. }
  7743. sum_count += its.StockMaxNumber + its.StockMinNumber
  7744. }
  7745. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  7746. //剩余库存
  7747. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  7748. }
  7749. }
  7750. } else {
  7751. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  7752. if medical.IsUse == 2 {
  7753. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  7754. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  7755. }
  7756. if pharmacyConfig.IsOpen != 1 {
  7757. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  7758. }
  7759. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  7760. var sum_count int64
  7761. for _, its := range stockInfo {
  7762. if its.MaxUnit == medical.MaxUnit {
  7763. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  7764. }
  7765. sum_count += its.StockMaxNumber + its.StockMinNumber
  7766. }
  7767. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  7768. //剩余库存
  7769. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  7770. }
  7771. }
  7772. }
  7773. }
  7774. this.ServeSuccessJSON(map[string]interface{}{
  7775. "msg": "1",
  7776. "ids": ids,
  7777. })
  7778. return
  7779. } else {
  7780. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  7781. //执行医嘱
  7782. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  7783. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  7784. for _, item := range advices {
  7785. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  7786. redis := service.RedisClient()
  7787. //清空key 值
  7788. redis.Set(key, "", time.Second)
  7789. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  7790. redis.Set(keyTwo, "", time.Second)
  7791. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  7792. redis.Set(keyThree, "", time.Second)
  7793. recordDate := theTime.Format("2006-01-02")
  7794. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  7795. redis.Set(keyFour, "", time.Second)
  7796. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  7797. redis.Set(keyFive, "", time.Second)
  7798. defer redis.Close()
  7799. }
  7800. this.ServeSuccessJSON(map[string]interface{}{
  7801. "msg": "1",
  7802. "ids": ids,
  7803. })
  7804. return
  7805. }
  7806. }
  7807. }
  7808. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  7809. ids := this.GetString("ids")
  7810. idSplit := strings.Split(ids, ",")
  7811. orgId := this.GetMobileAdminUserInfo().Org.Id
  7812. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  7813. if config.IsOpen == 1 {
  7814. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  7815. this.ServeSuccessJSON(map[string]interface{}{
  7816. "msg": "1",
  7817. "ids": ids,
  7818. })
  7819. return
  7820. }
  7821. if config.IsOpen == 0 || config.IsOpen == 2 {
  7822. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  7823. this.ServeSuccessJSON(map[string]interface{}{
  7824. "msg": "1",
  7825. "ids": ids,
  7826. })
  7827. return
  7828. }
  7829. }
  7830. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  7831. ids := this.GetString("ids")
  7832. idSplit := strings.Split(ids, ",")
  7833. orgId := this.GetMobileAdminUserInfo().Org.Id
  7834. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  7835. //his
  7836. if config.IsOpen == 1 {
  7837. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  7838. theTime := time.Now()
  7839. advices := models.HisDoctorAdviceThirty{
  7840. CheckTime: theTime.Unix(),
  7841. Checker: checker,
  7842. UpdatedTime: time.Now().Unix(),
  7843. }
  7844. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  7845. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  7846. for _, item := range list {
  7847. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  7848. redis := service.RedisClient()
  7849. //清空key 值
  7850. redis.Set(key, "", time.Second)
  7851. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  7852. redis.Set(keyTwo, "", time.Second)
  7853. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  7854. redis.Set(keyThree, "", time.Second)
  7855. recordDate := theTime.Format("2006-01-02")
  7856. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  7857. redis.Set(keyFour, "", time.Second)
  7858. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  7859. redis.Set(keyFive, "", time.Second)
  7860. defer redis.Close()
  7861. }
  7862. this.ServeSuccessJSON(map[string]interface{}{
  7863. "msg": "1",
  7864. "ids": ids,
  7865. })
  7866. return
  7867. }
  7868. //血透
  7869. if config.IsOpen == 0 || config.IsOpen == 2 {
  7870. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  7871. theTime := time.Now()
  7872. advices := models.DoctorAdvice{
  7873. CheckTime: theTime.Unix(),
  7874. Checker: checker,
  7875. UpdatedTime: time.Now().Unix(),
  7876. }
  7877. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  7878. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  7879. for _, item := range list {
  7880. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  7881. redis := service.RedisClient()
  7882. //清空key 值
  7883. redis.Set(key, "", time.Second)
  7884. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  7885. redis.Set(keyTwo, "", time.Second)
  7886. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  7887. redis.Set(keyThree, "", time.Second)
  7888. recordDate := theTime.Format("2006-01-02")
  7889. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  7890. redis.Set(keyFour, "", time.Second)
  7891. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  7892. redis.Set(keyFive, "", time.Second)
  7893. defer redis.Close()
  7894. }
  7895. this.ServeSuccessJSON(map[string]interface{}{
  7896. "msg": "1",
  7897. "ids": ids,
  7898. })
  7899. return
  7900. }
  7901. }
  7902. func (this *DialysisAPIController) CheckSchedule() {
  7903. patientID, _ := this.GetInt64("patient_id")
  7904. recordDateStr := this.GetString("record_date")
  7905. nurseID, _ := this.GetInt64("start_nurse")
  7906. schedual_type, _ := this.GetInt64("schedual_type")
  7907. bedID, _ := this.GetInt64("bed")
  7908. start_time := this.GetString("start_time")
  7909. fmt.Println("patientID", patientID)
  7910. fmt.Println("recordDateStr", recordDateStr)
  7911. fmt.Println("nurseID", nurseID)
  7912. fmt.Println("schedual_type------", schedual_type)
  7913. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  7914. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7915. return
  7916. }
  7917. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  7918. if parseStartDateErr != nil {
  7919. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  7920. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7921. return
  7922. }
  7923. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  7924. if parseErr != nil {
  7925. this.ErrorLog("时间解析失败:%v", parseErr)
  7926. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7927. return
  7928. }
  7929. adminUserInfo := this.GetMobileAdminUserInfo()
  7930. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  7931. if getPatientErr != nil {
  7932. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  7933. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7934. return
  7935. } else if patient == nil {
  7936. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  7937. return
  7938. }
  7939. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  7940. if getNurseErr != nil {
  7941. this.ErrorLog("获取护士失败:%v", getNurseErr)
  7942. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7943. return
  7944. } else if nurse == nil {
  7945. this.ErrorLog("护士不存在")
  7946. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7947. return
  7948. }
  7949. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  7950. if getDeviceNumberErr != nil {
  7951. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  7952. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7953. return
  7954. } else if deviceNumber == nil {
  7955. this.ErrorLog("床位号不存在")
  7956. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7957. return
  7958. }
  7959. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  7960. if getRecordErr != nil {
  7961. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  7962. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7963. return
  7964. } else if dialysisRecord != nil {
  7965. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  7966. return
  7967. }
  7968. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  7969. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  7970. timeLayout := "2006-01-02 15:04:05"
  7971. loc, _ := time.LoadLocation("Local")
  7972. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  7973. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  7974. schedulestartTime := theStartTime.Unix()
  7975. scheduleendTime := theEndTime.Unix()
  7976. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  7977. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  7978. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  7979. //查询该床位是否有人用了
  7980. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  7981. if err == nil {
  7982. if schedule.ID == 0 {
  7983. this.ServeSuccessJSON(map[string]interface{}{
  7984. "status": 0,
  7985. "msg": "请求失败",
  7986. })
  7987. } else {
  7988. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  7989. if order.ID > 0 { //该机位被其他人占用了
  7990. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  7991. return
  7992. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  7993. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  7994. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  7995. this.ServeSuccessJSON(map[string]interface{}{
  7996. "status": 1,
  7997. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  7998. })
  7999. return
  8000. } else {
  8001. this.ServeSuccessJSON(map[string]interface{}{
  8002. "status": 0,
  8003. "msg": "",
  8004. })
  8005. }
  8006. }
  8007. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  8008. this.ServeSuccessJSON(map[string]interface{}{
  8009. "status": 2,
  8010. "msg": "当前机位已有患者在使用,请重新选择!",
  8011. })
  8012. }
  8013. }
  8014. } else {
  8015. this.ServeSuccessJSON(map[string]interface{}{
  8016. "status": 0,
  8017. "msg": "",
  8018. })
  8019. }
  8020. }
  8021. func (this *DialysisAPIController) GetNewDoctorListToday() {
  8022. orgId := this.GetMobileAdminUserInfo().Org.Id
  8023. schedule_type, _ := this.GetInt64("schedule_type")
  8024. partion_type, _ := this.GetInt64("partion_type")
  8025. start_time := this.GetString("start_time")
  8026. timeLayout := "2006-01-02"
  8027. loc, _ := time.LoadLocation("Local")
  8028. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8029. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  8030. _, config := service.FindXTHisRecordByOrgId(orgId)
  8031. appId := this.GetMobileAdminUserInfo().App.Id
  8032. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  8033. if err == nil {
  8034. this.ServeSuccessJSON(map[string]interface{}{
  8035. "list": list,
  8036. "config": config,
  8037. "doctorList": doctorList,
  8038. })
  8039. return
  8040. } else {
  8041. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8042. return
  8043. }
  8044. }
  8045. func (this *DialysisAPIController) SaveMobileInformation() {
  8046. patient_id, _ := this.GetInt64("patient_id")
  8047. record_date, _ := this.GetInt64("record_date")
  8048. startTime := this.GetString("start_time")
  8049. module, _ := this.GetInt64("module")
  8050. remark := this.GetString("remark")
  8051. timeLayout := "2006-01-02 15:04"
  8052. loc, _ := time.LoadLocation("Local")
  8053. if len(startTime) == 0 {
  8054. utils.ErrorLog("len(start_time) == 0")
  8055. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8056. return
  8057. }
  8058. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  8059. if err != nil {
  8060. utils.ErrorLog(err.Error())
  8061. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8062. return
  8063. }
  8064. StartTime := theTime.Unix()
  8065. fmt.Println("startime-------------", StartTime)
  8066. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8067. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  8068. information := models.XtDialysisInformation{
  8069. Module: module,
  8070. PatientId: patient_id,
  8071. RecordDate: record_date,
  8072. ApplicationDate: StartTime,
  8073. Creater: creater,
  8074. ApplicationStatus: 2,
  8075. Checker: 0,
  8076. CheckTime: 0,
  8077. Remark: remark,
  8078. UserOrgId: user_org_id,
  8079. Ctime: time.Now().Unix(),
  8080. Status: 1,
  8081. Mtime: 0,
  8082. }
  8083. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, user_org_id)
  8084. if infor.ID == 0 {
  8085. service.SaveDialysisInformation(information)
  8086. }
  8087. if infor.ID > 0 {
  8088. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  8089. }
  8090. this.ServeSuccessJSON(map[string]interface{}{
  8091. "information": information,
  8092. })
  8093. return
  8094. }
  8095. func (this *DialysisAPIController) GetMobileInformation() {
  8096. limit, _ := this.GetInt64("limit")
  8097. page, _ := this.GetInt64("page")
  8098. orgid := this.GetMobileAdminUserInfo().Org.Id
  8099. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  8100. appid := this.GetMobileAdminUserInfo().App.Id
  8101. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8102. patients, _ := service.GetAllpatientThirty(orgid)
  8103. this.ServeSuccessJSON(map[string]interface{}{
  8104. "information": information,
  8105. "total": total,
  8106. "doclist": doclist,
  8107. "patients": patients,
  8108. })
  8109. return
  8110. }
  8111. func (this *DialysisAPIController) GetMobileInformationOne() {
  8112. limit, _ := this.GetInt64("limit")
  8113. page, _ := this.GetInt64("page")
  8114. orgid := this.GetMobileAdminUserInfo().Org.Id
  8115. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  8116. appid := this.GetMobileAdminUserInfo().App.Id
  8117. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8118. patients, _ := service.GetAllpatientThirty(orgid)
  8119. this.ServeSuccessJSON(map[string]interface{}{
  8120. "information": information,
  8121. "total": total,
  8122. "doclist": doclist,
  8123. "patients": patients,
  8124. })
  8125. return
  8126. }
  8127. func (this *DialysisAPIController) CheckMobileInformation() {
  8128. id, _ := this.GetInt64("id")
  8129. application_status, _ := this.GetInt64("application_status")
  8130. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8131. checktime := time.Now().Unix()
  8132. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  8133. if err == nil {
  8134. this.ServeSuccessJSON(map[string]interface{}{
  8135. "msg": "ok",
  8136. })
  8137. return
  8138. }
  8139. }
  8140. func (c *DialysisAPIController) GetControlMonitorList() {
  8141. partition, _ := c.GetInt64("partition")
  8142. monitorDate := c.GetString("date")
  8143. patient_id, _ := c.GetInt64("patient_id")
  8144. pat_type, _ := c.GetInt64("pat_type")
  8145. timeLayout := "2006-01-02"
  8146. loc, _ := time.LoadLocation("Local")
  8147. var theStartTime int64
  8148. if len(monitorDate) > 0 {
  8149. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  8150. if err != nil {
  8151. theStartTime = 0
  8152. }
  8153. theStartTime = theTime.Unix()
  8154. }
  8155. adminInfo := c.GetMobileAdminUserInfo()
  8156. orgID := adminInfo.Org.Id
  8157. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  8158. if err != nil {
  8159. c.ErrorLog("获取排班信息失败:%v", err)
  8160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8161. } else {
  8162. if len(monitor) > 0 {
  8163. //获取所有床位
  8164. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  8165. //获取所有分区
  8166. zoneList, _ := service.GetAllZoneByList(orgID)
  8167. //获取透析处方
  8168. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  8169. //获取透前评估
  8170. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  8171. //获取上机
  8172. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  8173. //获取透后
  8174. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  8175. //获取透后监测
  8176. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  8177. //获取所有的患者
  8178. patients, _ := service.GetAllPatientListByListOne(orgID)
  8179. //获取所有透析模式
  8180. treatments, _ := service.GetAllTreatModeByList(orgID)
  8181. //获取所有医嘱
  8182. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  8183. //获取双人核对
  8184. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  8185. //治疗小结
  8186. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  8187. //待消毒
  8188. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  8189. for key, item := range monitor {
  8190. // 获取床位信息
  8191. for _, it := range numberList {
  8192. if item.BedId == it.ID {
  8193. monitor[key].DeviceNumber = it
  8194. break
  8195. }
  8196. }
  8197. //获取分区信息
  8198. for _, it := range zoneList {
  8199. if item.PartitionId == it.ID {
  8200. monitor[key].DeviceZone = it
  8201. }
  8202. }
  8203. for _, prescription := range prescriptions {
  8204. if item.PatientId == prescription.PatientId {
  8205. monitor[key].Prescription = prescription
  8206. break
  8207. }
  8208. }
  8209. for _, it := range checkList {
  8210. if item.PatientId == it.PatientId {
  8211. monitor[key].DoubleCheck = it
  8212. break
  8213. }
  8214. }
  8215. for _, it := range summaryList {
  8216. if item.PatientId == it.PatientId {
  8217. monitor[key].TreatmentSummaryForList = it
  8218. break
  8219. }
  8220. }
  8221. // 透前评估
  8222. for _, assessmentBefore := range assessmentBefores {
  8223. if item.PatientId == assessmentBefore.PatientId {
  8224. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  8225. break
  8226. }
  8227. }
  8228. // 透析上下机
  8229. for _, dialysisOrder := range dialysisOrders {
  8230. if item.PatientId == dialysisOrder.PatientId {
  8231. monitor[key].DialysisOrder = dialysisOrder
  8232. break
  8233. }
  8234. }
  8235. // 治疗小节
  8236. for _, afterDislysis := range AssessmentAfterDislysis {
  8237. if item.PatientId == afterDislysis.PatientId {
  8238. monitor[key].AssessmentAfterDislysis = afterDislysis
  8239. break
  8240. }
  8241. }
  8242. for _, it := range monitorlist {
  8243. if item.PatientId == it.PatientId {
  8244. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  8245. }
  8246. }
  8247. for _, it := range adviceList {
  8248. if item.PatientId == it.PatientId {
  8249. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  8250. }
  8251. }
  8252. for _, patient := range patients {
  8253. if item.PatientId == patient.ID {
  8254. monitor[key].MonitorPatients = patient
  8255. break
  8256. }
  8257. }
  8258. for _, treatment := range treatments {
  8259. if item.ModeId == treatment.ID {
  8260. monitor[key].TreatmentMode = treatment
  8261. break
  8262. }
  8263. }
  8264. for _, infor := range informationList {
  8265. if item.PatientId == infor.PatientId {
  8266. monitor[key].NewDeviceInformation = infor
  8267. break
  8268. }
  8269. }
  8270. }
  8271. }
  8272. }
  8273. patients, err := service.GetAllpatientFourty(orgID)
  8274. var mds []*models.NewMonitorDialysisScheduleList
  8275. if pat_type == 0 {
  8276. for _, item := range monitor {
  8277. mds = append(mds, item)
  8278. }
  8279. }
  8280. //待医嘱核对
  8281. if pat_type == 1 {
  8282. for _, item := range monitor {
  8283. if len(item.AdviceList) > 0 {
  8284. mds = append(mds, item)
  8285. }
  8286. }
  8287. }
  8288. //待开小结
  8289. if pat_type == 2 {
  8290. for _, item := range monitor {
  8291. if item.TreatmentSummaryForList == nil {
  8292. mds = append(mds, item)
  8293. }
  8294. }
  8295. }
  8296. //待下机
  8297. if pat_type == 3 {
  8298. for _, item := range monitor {
  8299. if item.DialysisOrder != nil {
  8300. if item.DialysisOrder.ID > 0 {
  8301. mds = append(mds, item)
  8302. }
  8303. }
  8304. }
  8305. }
  8306. //待消毒
  8307. if pat_type == 4 {
  8308. for _, item := range monitor {
  8309. if item.NewDeviceInformation == nil {
  8310. mds = append(mds, item)
  8311. }
  8312. }
  8313. }
  8314. //待双人核对
  8315. if pat_type == 5 {
  8316. for _, item := range monitor {
  8317. if item.DoubleCheck == nil {
  8318. mds = append(mds, item)
  8319. }
  8320. }
  8321. }
  8322. //医嘱未执行
  8323. if pat_type == 6 {
  8324. for _, item := range monitor {
  8325. if len(item.AdviceList) > 0 {
  8326. mds = append(mds, item)
  8327. }
  8328. }
  8329. }
  8330. //患者未签名
  8331. if pat_type == 7 {
  8332. for _, item := range monitor {
  8333. if item.DialysisOrder != nil {
  8334. if item.DialysisOrder.ID > 0 {
  8335. mds = append(mds, item)
  8336. }
  8337. }
  8338. }
  8339. }
  8340. //目标超滤于实际超滤不同
  8341. if pat_type == 8 {
  8342. for _, item := range monitor {
  8343. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  8344. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  8345. mds = append(mds, item)
  8346. }
  8347. }
  8348. }
  8349. }
  8350. //血压少于5次
  8351. if pat_type == 9 {
  8352. for _, item := range monitor {
  8353. if len(item.MonitoringRecord) < 5 {
  8354. mds = append(mds, item)
  8355. }
  8356. }
  8357. }
  8358. if pat_type == 10 {
  8359. for _, item := range monitor {
  8360. if len(item.MonitoringRecord) == 0 {
  8361. mds = append(mds, item)
  8362. }
  8363. }
  8364. }
  8365. if pat_type == 11 {
  8366. for _, item := range monitor {
  8367. if len(item.MonitoringRecord) > 0 {
  8368. mds = append(mds, item)
  8369. }
  8370. }
  8371. }
  8372. if pat_type == 12 {
  8373. for _, item := range monitor {
  8374. if len(item.MonitoringRecord) > 0 {
  8375. mds = append(mds, item)
  8376. }
  8377. }
  8378. }
  8379. if err == nil {
  8380. c.ServeSuccessJSON(map[string]interface{}{
  8381. "monitor": mds,
  8382. "patients": patients,
  8383. })
  8384. } else {
  8385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8386. }
  8387. }