dialysis_api_controller.go 307KB

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