dialysis_api_controller.go 315KB

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