dialysis_api_controller.go 338KB

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