dialysis_api_controller.go 286KB

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