dialysis_api_controller.go 383KB

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