dialysis_api_controller.go 386KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "math"
  7. "net/http"
  8. "net/url"
  9. "reflect"
  10. "strconv"
  11. "strings"
  12. "time"
  13. "XT_New/enums"
  14. "XT_New/models"
  15. "XT_New/service"
  16. "XT_New/utils"
  17. "github.com/astaxie/beego"
  18. "github.com/jinzhu/gorm"
  19. )
  20. // type DialysisTestAPIController struct {
  21. // MobileBaseAPIController
  22. // }
  23. // [get]/m/api/test
  24. // func (this *DialysisTestAPIController) Test() {
  25. // orgID := int64(3907)
  26. // now := time.Now()
  27. // nextWeek := now.AddDate(0, 0, 7)
  28. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  29. // nextTwoWeek := now.AddDate(0, 0, 14)
  30. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  31. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  32. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  33. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  34. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. // return
  36. // }
  37. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  38. // if exchangeErr != nil {
  39. // this.ErrorLog("%v", exchangeErr)
  40. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. // return
  42. // }
  43. // this.ServeSuccessJSON(map[string]interface{}{
  44. // // "now": now,
  45. // // "next_week": nextWeek,f
  46. // // "next_week_mon": nextWeekMon,
  47. // // "next_week_sun": nextWeekSun,
  48. // // "next_two_week_mon": nextTwoWeekMon,
  49. // // "next_two_week_sun": nextTwoWeekSun,
  50. // "next_week_schs": nextWeekSchs,
  51. // "next_two_week_schs": nextTwoWeekSchs,
  52. // })
  53. // }
  54. type DialysisAPIController struct {
  55. MobileBaseAPIAuthController
  56. }
  57. // /m/api/scheduals [get]
  58. // @param type:int
  59. // @param date:string
  60. func (this *DialysisAPIController) Scheduals() {
  61. schedualType, _ := this.GetInt64("type")
  62. schedualDate := this.GetString("date")
  63. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  64. schedualType = 0
  65. }
  66. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  67. if parseDateErr != nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. adminInfo := this.GetMobileAdminUserInfo()
  72. orgID := adminInfo.Org.Id
  73. redis := service.RedisClient()
  74. defer redis.Close()
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. //redis.Set(key, "", time.Second)
  77. scheduals_json_str, _ := redis.Get(key).Result()
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. for _, item := range scheduals {
  82. order, _ := service.GetMonitDialysisOrder(item.UserOrgId, item.PatientId, date.Unix())
  83. item.DialysisLastOrder = order
  84. solution, _ := service.GetMonitDialysisSolution(item.UserOrgId, item.PatientId, item.ModeId)
  85. item.DialysisSolution = solution
  86. }
  87. if err != nil {
  88. this.ErrorLog("获取排班信息失败:%v", err)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. } else {
  91. if len(scheduals) > 0 {
  92. devices, _ := service.GetAllDevicetByListSix(orgID)
  93. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  94. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  95. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  96. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  97. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  98. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  99. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  100. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  101. inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
  102. //monitor, _ := service.GetMonitorByListSix(orgID, date.Unix())
  103. for key, item := range scheduals {
  104. for _, infor := range inforMation {
  105. if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
  106. scheduals[key].NewDeviceInformation = infor
  107. break
  108. }
  109. }
  110. // 获取患者信息
  111. for _, patient := range patients {
  112. if item.PatientId == patient.ID {
  113. scheduals[key].SchedualPatient = patient
  114. break
  115. }
  116. }
  117. // 床位信息
  118. for _, device := range devices {
  119. if item.BedId == device.ID {
  120. scheduals[key].DeviceNumber = device
  121. break
  122. }
  123. }
  124. // 医嘱信息
  125. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  126. for _, advice := range advices {
  127. if item.PatientId == advice.PatientId {
  128. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  129. }
  130. }
  131. // 医嘱信息
  132. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  133. for _, hisAdvice := range hisAdvices {
  134. if item.PatientId == hisAdvice.PatientId {
  135. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  136. }
  137. }
  138. // 医嘱信息
  139. for _, prescription := range prescriptions {
  140. if item.PatientId == prescription.PatientId {
  141. scheduals[key].Prescription = prescription
  142. break
  143. }
  144. }
  145. // 透前评估
  146. for _, assessmentBefore := range assessmentBefores {
  147. if item.PatientId == assessmentBefore.PatientId {
  148. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  149. break
  150. }
  151. }
  152. // 透析上下机
  153. for _, dialysisOrder := range dialysisOrders {
  154. if item.PatientId == dialysisOrder.PatientId {
  155. scheduals[key].DialysisOrder = dialysisOrder
  156. break
  157. }
  158. }
  159. // 治疗小节
  160. for _, afterDislysis := range AssessmentAfterDislysis {
  161. if item.PatientId == afterDislysis.PatientId {
  162. scheduals[key].AssessmentAfterDislysis = afterDislysis
  163. break
  164. }
  165. }
  166. // 透后评估
  167. for _, treatmentSummary := range treatmentSummarys {
  168. if item.PatientId == treatmentSummary.PatientId {
  169. scheduals[key].TreatmentSummary = treatmentSummary
  170. break
  171. }
  172. }
  173. for _, check := range dobulecheck {
  174. if item.PatientId == check.PatientId {
  175. scheduals[key].DoubleCheck = check
  176. break
  177. }
  178. }
  179. //// 监测
  180. //scheduals[key].VMMonitoringRecord = make([]models.VMMonitoringRecord, 0)
  181. //for _, moni := range monitor {
  182. // if item.PatientId == moni.PatientId {
  183. // scheduals[key].VMMonitoringRecord = append(scheduals[key].VMMonitoringRecord, moni)
  184. // }
  185. //}
  186. }
  187. //缓存数据
  188. scheduals_json, err := json.Marshal(&scheduals)
  189. if err == nil {
  190. redis.Set(key, scheduals_json, time.Second*60)
  191. }
  192. }
  193. //获取今日所有的处方开的耗材
  194. _, configs := service.FindXTHisProjectByOrgId(orgID)
  195. project := make([]*models.HisPrescriptionProjectTwo, 0)
  196. if configs.ID > 0 && configs.IsOpen == 1 {
  197. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  198. }
  199. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  200. this.ServeSuccessJSON(map[string]interface{}{
  201. "scheduals": scheduals,
  202. "project": project,
  203. })
  204. }
  205. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  206. var dat []map[string]interface{}
  207. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  208. } else {
  209. }
  210. //获取今日所有的处方开的耗材
  211. _, configs := service.FindXTHisProjectByOrgId(orgID)
  212. project := make([]*models.HisPrescriptionProjectTwo, 0)
  213. if configs.ID > 0 && configs.IsOpen == 1 {
  214. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  215. }
  216. this.ServeSuccessJSON(map[string]interface{}{
  217. "scheduals": dat,
  218. "redis": "true",
  219. "date": schedualDate,
  220. "project": project,
  221. })
  222. }
  223. }
  224. // /m/api/waiting_scheduals [get]
  225. // @param date:string
  226. func (this *DialysisAPIController) WaitingScheduals() {
  227. schedualDate := this.GetString("date")
  228. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  229. if parseDateErr != nil && len(schedualDate) != 0 {
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. return
  232. }
  233. adminInfo := this.GetMobileAdminUserInfo()
  234. orgID := adminInfo.Org.Id
  235. redis := service.RedisClient()
  236. defer redis.Close()
  237. // cur_date := time.Now().Format("2006-01-02")
  238. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  239. wait_scheduals, _ := redis.Get(key).Result()
  240. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  241. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  242. if err != nil {
  243. this.ErrorLog("获取排班信息失败:%v", err)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. } else {
  246. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  247. for _, s := range scheduals {
  248. returnScheduals = append(returnScheduals, s)
  249. }
  250. if len(returnScheduals) > 0 {
  251. //缓存数据
  252. wait_scheduals_json, err := json.Marshal(scheduals)
  253. if err == nil {
  254. redis.Set(key, wait_scheduals_json, time.Second*30)
  255. }
  256. }
  257. this.ServeSuccessJSON(map[string]interface{}{
  258. "scheduals": scheduals,
  259. })
  260. }
  261. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  262. var dat []map[string]interface{}
  263. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  264. } else {
  265. }
  266. this.ServeSuccessJSON(map[string]interface{}{
  267. "scheduals": dat,
  268. "redis": "true",
  269. "date": schedualDate,
  270. })
  271. }
  272. }
  273. //else{
  274. // fmt.Println("33333333")
  275. //
  276. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  277. // if err != nil {
  278. // this.ErrorLog("获取排班信息失败:%v", err)
  279. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  280. // } else {
  281. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  282. // for _, s := range scheduals {
  283. //
  284. // returnScheduals = append(returnScheduals, s)
  285. // }
  286. //
  287. // this.ServeSuccessJSON(map[string]interface{}{
  288. // "scheduals": returnScheduals,
  289. // })
  290. // }
  291. //
  292. // }
  293. //if err == nil{
  294. //
  295. //
  296. //
  297. //
  298. //
  299. //}else{
  300. //}
  301. // /m/api/dialysis/record [get]
  302. // @param patient_id:int
  303. // @param date:string (yyyy-MM-dd)
  304. func (this *DialysisAPIController) DialysisRecord() {
  305. patientID, _ := this.GetInt64("patient_id")
  306. recordDateStr := this.GetString("date")
  307. if patientID <= 0 {
  308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  309. return
  310. }
  311. if len(recordDateStr) == 0 {
  312. recordDateStr = time.Now().Format("2006-01-02")
  313. }
  314. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  315. if parseDateErr != nil {
  316. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  318. return
  319. }
  320. adminInfo := this.GetMobileAdminUserInfo()
  321. ch := make(chan struct{})
  322. count := 24 // count 表示活动的协程个数
  323. var patient models.Patients
  324. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  325. var predialysisEvaluation *models.PredialysisEvaluation
  326. var lastPredialysisEvaluation *models.PredialysisEvaluation
  327. var doctorAdvices []*models.DoctorAdvice
  328. var dialysisOrder *models.DialysisOrder
  329. var doubleCheck *models.DoubleCheck
  330. var monitorRecords []*models.MonitoringRecord
  331. var lastMonitorRecord *models.MonitoringRecord
  332. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  333. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  334. var treatmentSummary *models.TreatmentSummary
  335. var dialysisPrescribe *models.DialysisPrescription
  336. var dialysisSolution *models.DialysisSolution
  337. var lastDialysisPrescribe *models.DialysisPrescription
  338. var systemDialysisPrescribe *models.SystemPrescription
  339. var is_project_open_config models.XtHisProjectConfig
  340. var projects []*models.HisPrescriptionProject
  341. var stockType []*models.GoodsTypeOne
  342. var prepare []*models.XtDialysisBeforePrepare
  343. var lastAssessment models.XtPatientVascularAccess
  344. var lastDryWeightDislysis *models.SgjPatientDryweight
  345. var gobalConfig models.GobalConfig
  346. var operators []*models.SgjUserAdminRoles
  347. // 先走redis,没有走数据库
  348. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  349. go func() {
  350. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  351. ch <- struct{}{}
  352. }()
  353. go func() {
  354. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  355. ch <- struct{}{}
  356. }()
  357. go func() {
  358. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  359. ch <- struct{}{}
  360. }()
  361. go func() {
  362. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  363. ch <- struct{}{}
  364. }()
  365. go func() {
  366. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  367. ch <- struct{}{}
  368. }()
  369. go func() {
  370. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  371. ch <- struct{}{}
  372. }()
  373. go func() {
  374. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  375. ch <- struct{}{}
  376. }()
  377. go func() {
  378. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  379. ch <- struct{}{}
  380. }()
  381. go func() {
  382. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  383. ch <- struct{}{}
  384. }()
  385. go func() {
  386. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  387. ch <- struct{}{}
  388. }()
  389. go func() {
  390. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  391. ch <- struct{}{}
  392. }()
  393. go func() {
  394. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  395. ch <- struct{}{}
  396. }()
  397. go func() {
  398. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  399. ch <- struct{}{}
  400. }()
  401. go func() {
  402. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  403. ch <- struct{}{}
  404. }()
  405. go func() {
  406. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  407. ch <- struct{}{}
  408. }()
  409. go func() {
  410. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  411. ch <- struct{}{}
  412. }()
  413. go func() {
  414. // 先走redis,没有走数据库
  415. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  416. ch <- struct{}{}
  417. }()
  418. go func() {
  419. // 先走redis,没有走数据库
  420. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  421. ch <- struct{}{}
  422. }()
  423. go func() {
  424. // // 先走redis,没有走数据库
  425. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  426. ch <- struct{}{}
  427. }()
  428. go func() {
  429. // 先走redis,没有走数据库
  430. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  431. ch <- struct{}{}
  432. }()
  433. go func() {
  434. // //获取最后一次血管通路
  435. // 先走redis,没有走数据库
  436. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  437. ch <- struct{}{}
  438. }()
  439. go func() {
  440. // 先走redis,没有走数据库
  441. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  442. ch <- struct{}{}
  443. }()
  444. go func() {
  445. // 先走redis,没有走数据库
  446. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  447. ch <- struct{}{}
  448. }()
  449. go func() {
  450. // 先走redis,没有走数据库
  451. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  452. ch <- struct{}{}
  453. }()
  454. for range ch {
  455. // 每次从ch中接收数据,表明一个活动的协程结束
  456. count--
  457. // 当所有活动的协程都结束时,关闭管道
  458. if count == 0 {
  459. close(ch)
  460. }
  461. }
  462. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  463. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  464. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  465. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  466. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  467. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  468. var team_projects []*models.HisPrescriptionProject
  469. //var index int64 = 0
  470. for _, item := range temp_team_projects {
  471. //组套里面非检验项目的
  472. if item.HisProject.CostClassify != 3 {
  473. projects = append(projects, item)
  474. }
  475. //组套里面检验项目的
  476. if item.HisProject.CostClassify == 3 {
  477. team_projects = append(team_projects, item)
  478. }
  479. }
  480. team_projects = RemoveRepeatedCheckRecod(team_projects)
  481. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  482. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  483. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  484. var his_advices []*models.HisDoctorAdviceInfo
  485. if is_open_config.IsOpen == 1 {
  486. // 先走redis,没有走数据库
  487. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  488. }
  489. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  490. if is_advice_open.IsAdviceOpen == 1 {
  491. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  492. }
  493. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  494. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  495. var remind_lists []models.XtCheckRemind
  496. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  497. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  498. }
  499. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  500. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  501. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  502. lastMonitor, _ := service.GetLastMonitor(patientID, date.Unix(), adminInfo.Org.Id)
  503. firstMonitor, _ := service.GetFirstMonitorOne(patientID, date.Unix(), adminInfo.Org.Id)
  504. returnData := map[string]interface{}{
  505. "patient": patient,
  506. "schedual": schedual,
  507. "prescription": dialysisPrescribe,
  508. "solution": dialysisSolution,
  509. "last_prescription": lastDialysisPrescribe,
  510. "receiver_treatment_access": receiverTreatmentAccess,
  511. "predialysis_evaluation": predialysisEvaluation,
  512. "doctor_advices": doctorAdvices,
  513. "double_check": doubleCheck,
  514. "assessment_after_dislysis": assessmentAfterDislysis,
  515. "treatment_summary": treatmentSummary,
  516. "monitor_records": monitorRecords,
  517. "dialysis_order": dialysisOrder,
  518. "operators": operators,
  519. "last_predialysis_evaluation": lastPredialysisEvaluation,
  520. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  521. "last_monitor_record": lastMonitorRecord,
  522. "config": gobalConfig,
  523. "dry_weight": lastDryWeightDislysis,
  524. "system_prescription": systemDialysisPrescribe,
  525. "his_advices": his_advices,
  526. "is_open_config": is_open_config,
  527. "stockType": stockType,
  528. "prepare": prepare,
  529. "lastAssessment": lastAssessment,
  530. "prescribeOne": prescribeOne,
  531. "is_project_open_config": is_project_open_config,
  532. "project": projects,
  533. "team_projects": team_projects,
  534. "is_advice_open": is_advice_open,
  535. "prescription_open": prescriptionConfig.IsOpen,
  536. "lastOrder": lastOrder,
  537. "remind_lists": remind_lists,
  538. "lastDialysisPrescription": lastDialysisPrescription,
  539. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  540. "dryWeightList": dryWeightList,
  541. "firstMonitor": firstMonitor,
  542. "lastMonitor": lastMonitor,
  543. }
  544. this.ServeSuccessJSON(returnData)
  545. }
  546. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  547. adminInfo := c.GetMobileAdminUserInfo()
  548. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  549. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  550. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  551. returnData := map[string]interface{}{
  552. "admin_users": adminUsers,
  553. "devices": devices,
  554. "device_numbers": device_numbers,
  555. }
  556. c.ServeSuccessJSON(returnData)
  557. }
  558. func (c *DialysisAPIController) PostAtreatmentInfo() {
  559. id, _ := c.GetInt64("patient", 0)
  560. recordDateStr := c.GetString("record_date")
  561. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  562. summaryContent := c.GetString("summaryContent")
  563. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  564. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  565. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  566. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  567. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  568. nursingRecord := c.GetString("nursing_record")
  569. fmt.Println("护理记录", nursingRecord)
  570. specialRecord := c.GetString("special_record")
  571. fmt.Println("特殊记录", specialRecord)
  572. adminUserInfo := c.GetMobileAdminUserInfo()
  573. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  574. checkStaffId = adminUserInfo.AdminUser.Id
  575. deboardNurseId = adminUserInfo.AdminUser.Id
  576. treatDoctor = adminUserInfo.AdminUser.Id
  577. if id <= 0 {
  578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  579. return
  580. }
  581. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  582. if patient.ID == 0 {
  583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  584. return
  585. }
  586. if len(recordDateStr) == 0 {
  587. recordDateStr = time.Now().Format("2006-01-02")
  588. }
  589. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  590. if parseDateErr != nil {
  591. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  593. return
  594. }
  595. summary := models.TreatmentSummary{
  596. UserOrgId: adminUserInfo.Org.Id,
  597. PatientId: id,
  598. AssessmentDate: recordDate.Unix(),
  599. Mission: propagandaAndEducationContent,
  600. DialysisSummary: summaryContent,
  601. SjNurse: changeMedicalNurseId,
  602. ZlNurse: treatNurseId,
  603. HdNurse: checkStaffId,
  604. XjNurse: deboardNurseId,
  605. ZlDoctor: treatDoctor,
  606. CreatedTime: time.Now().Unix(),
  607. Status: 1,
  608. NursingRecord: nursingRecord,
  609. SpecialRecord: specialRecord,
  610. }
  611. // 查询信息规挡的设置天数
  612. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  613. if infor.ID > 0 && infor.WeekDay > 0 {
  614. var cha_time int64
  615. timeNowStr := time.Now().Format("2006-01-02")
  616. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  617. //今日的日期减去设置的日期
  618. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  619. if cha_time >= recordDate.Unix() {
  620. //查询审核是否允许
  621. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  622. //申请状态不允许的情况 拒绝修改
  623. if infor.ApplicationStatus != 1 {
  624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  625. return
  626. }
  627. }
  628. }
  629. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  630. if treatmentSummary.ID == 0 { //新增
  631. summary.Creater = adminUserInfo.AdminUser.Id
  632. service.AddSigleSummaryRecord(&summary)
  633. finish := models.XtDialysisFinish{
  634. IsFinish: 1,
  635. UserOrgId: adminUserInfo.Org.Id,
  636. Status: 1,
  637. Ctime: time.Now().Unix(),
  638. Mtime: 0,
  639. Module: 10,
  640. RecordDate: recordDate.Unix(),
  641. Sourse: 1,
  642. PatientId: id,
  643. }
  644. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  645. if dialysisFinish.ID == 0 {
  646. service.CreateDialysisFinish(finish)
  647. }
  648. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  649. redis := service.RedisClient()
  650. //清空key 值
  651. redis.Set(key, "", time.Second)
  652. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  653. redis.Set(keyOne, "", time.Second)
  654. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  655. redis.Set(keyThree, "", time.Second)
  656. defer redis.Close()
  657. c.ServeSuccessJSON(map[string]interface{}{
  658. "summary": summary,
  659. })
  660. } else { //修改
  661. summary.Creater = treatmentSummary.Creater
  662. summary.CreatedTime = treatmentSummary.CreatedTime
  663. summary.Modifier = adminUserInfo.AdminUser.Id
  664. summary.ID = treatmentSummary.ID
  665. service.UpdateSummeRecord(&summary)
  666. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  667. redis := service.RedisClient()
  668. //清空key 值
  669. redis.Set(key, "", time.Second)
  670. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  671. redis.Set(keyOne, "", time.Second)
  672. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  673. redis.Set(keyThree, "", time.Second)
  674. defer redis.Close()
  675. c.ServeSuccessJSON(map[string]interface{}{
  676. "summary": summary,
  677. })
  678. }
  679. }
  680. func (c *DialysisAPIController) PostDoubleCheck() {
  681. id, _ := c.GetInt64("patient", 0)
  682. recordDateStr := c.GetString("record_date")
  683. checkTimeStr := c.GetString("check_time")
  684. firstCheckTimeStr := c.GetString("first_check_time")
  685. creater, _ := c.GetInt64("creater", 0)
  686. modifier, _ := c.GetInt64("modifier", 0)
  687. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  688. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  689. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  690. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  691. dialysis_item_desc := c.GetString("dialysis_item_desc")
  692. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  693. vascular_access_desc := c.GetString("vascular_access_desc")
  694. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  695. collator, _ := c.GetInt64("collator", 0)
  696. employee_number := c.GetString("employee_number")
  697. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  698. needle_batch_number := c.GetString("needle_batch_number")
  699. if id <= 0 {
  700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  701. return
  702. }
  703. adminUserInfo := c.GetMobileAdminUserInfo()
  704. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  705. if patient.ID == 0 {
  706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  707. return
  708. }
  709. if len(recordDateStr) == 0 {
  710. recordDateStr = time.Now().Format("2006-01-02")
  711. }
  712. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  713. if parseDateErr != nil {
  714. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  716. return
  717. }
  718. var checkDate int64
  719. if len(checkTimeStr) == 0 {
  720. checkDate = 0
  721. } else {
  722. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  723. checkDate = checkDateUnix.Unix()
  724. }
  725. var firstCheckDate int64
  726. if len(firstCheckTimeStr) == 0 {
  727. firstCheckDate = 0
  728. } else {
  729. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  730. firstCheckDate = firstCheckDateUnix.Unix()
  731. }
  732. if adminUserInfo.Org.Id == 10644 {
  733. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  734. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  735. if check.ID == 0 {
  736. if employee_number != list.JobNumber {
  737. c.ServeSuccessJSON(map[string]interface{}{
  738. "doubleCheck": check,
  739. "msg": "2",
  740. })
  741. return
  742. }
  743. }
  744. if check.ID > 0 {
  745. if employee_number != list.JobNumber {
  746. c.ServeSuccessJSON(map[string]interface{}{
  747. "doubleCheck": check,
  748. "msg": "2",
  749. })
  750. return
  751. }
  752. }
  753. }
  754. doubleCheck := models.DoubleCheck{
  755. UserOrgId: adminUserInfo.Org.Id,
  756. PatientId: id,
  757. DialysisItemCheck: dialysis_item_check,
  758. DialysisParameterCheck: dialysis_parameter_check,
  759. VascularAccessVerification: vascular_access_verification,
  760. PipelineConnectionCheck: pipeline_connection_check,
  761. DialysisItemDesc: dialysis_item_desc,
  762. DialysisParameterDesc: dialysis_parameter_desc,
  763. VascularAccessDesc: vascular_access_desc,
  764. PipelineConnectionDesc: pipeline_connection_desc,
  765. Collator: collator,
  766. Status: 1,
  767. CreatedTime: time.Now().Unix(),
  768. CheckDate: recordDate.Unix(),
  769. UpdatedTime: time.Now().Unix(),
  770. EmployeeNumber: employee_number,
  771. DialyzerBatchNumber: dialyzer_batch_number,
  772. NeedleBatchNumber: needle_batch_number,
  773. }
  774. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  775. if check.ID == 0 { //新增
  776. doubleCheck.FirstCheckTime = firstCheckDate
  777. doubleCheck.CheckTime = checkDate
  778. doubleCheck.Creater = creater
  779. doubleCheck.Modifier = modifier
  780. if adminUserInfo.Org.Id == 10340 {
  781. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  782. doubleCheck.Creater = order.StartNurse
  783. }
  784. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  785. //查询未核对的医嘱
  786. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  787. for _, advice := range doctorList {
  788. if advice.ExecutionStaff == modifier {
  789. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  790. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  791. return
  792. }
  793. }
  794. }
  795. // 查询信息规挡的设置天数
  796. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  797. if infor.ID > 0 && infor.WeekDay > 0 {
  798. var cha_time int64
  799. timeNowStr := time.Now().Format("2006-01-02")
  800. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  801. //今日的日期减去设置的日期
  802. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  803. if cha_time >= recordDate.Unix() {
  804. //查询审核是否允许
  805. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  806. //申请状态不允许的情况 拒绝修改
  807. if infor.ApplicationStatus != 1 {
  808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  809. return
  810. }
  811. }
  812. }
  813. err := service.AddSigleDoubleCheck(&doubleCheck)
  814. finish := models.XtDialysisFinish{
  815. IsFinish: 1,
  816. UserOrgId: adminUserInfo.Org.Id,
  817. Status: 1,
  818. Ctime: time.Now().Unix(),
  819. Mtime: 0,
  820. Module: 5,
  821. RecordDate: recordDate.Unix(),
  822. Sourse: 1,
  823. PatientId: id,
  824. }
  825. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  826. if dialysisFinish.ID == 0 {
  827. service.CreateDialysisFinish(finish)
  828. }
  829. //针对长沙南雅
  830. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  831. //查询未核对的医嘱
  832. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  833. if len(doctorList) > 0 && modifier > 0 {
  834. for _, advice := range doctorList {
  835. service.UpdateDoctorAdviceList(advice.ID, modifier)
  836. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  837. redis := service.RedisClient()
  838. //清空key 值
  839. redis.Set(key, "", time.Second)
  840. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  841. redis.Set(keyTwo, "", time.Second)
  842. theTime := time.Now()
  843. recordDate := theTime.Format("2006-01-02")
  844. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  845. redis.Set(keyFour, "", time.Second)
  846. defer redis.Close()
  847. }
  848. }
  849. }
  850. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  851. redis := service.RedisClient()
  852. //清空key 值
  853. redis.Set(key, "", time.Second)
  854. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  855. redis.Set(keyOne, "", time.Second)
  856. defer redis.Close()
  857. if err == nil {
  858. c.ServeSuccessJSON(map[string]interface{}{
  859. "doubleCheck": &doubleCheck,
  860. })
  861. }
  862. } else { //修改
  863. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  864. if infor.ID > 0 {
  865. var cha_time int64
  866. timeNowStr := time.Now().Format("2006-01-02")
  867. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  868. //今日的日期减去设置的日期
  869. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  870. if cha_time >= recordDate.Unix() {
  871. //查询审核是否允许
  872. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  873. //申请状态不允许的情况 拒绝修改
  874. if infor.ApplicationStatus != 1 {
  875. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  876. return
  877. }
  878. }
  879. }
  880. doubleCheck.FirstCheckTime = firstCheckDate
  881. doubleCheck.CheckTime = checkDate
  882. doubleCheck.Creater = creater
  883. doubleCheck.Modifier = modifier
  884. doubleCheck.CreatedTime = check.CreatedTime
  885. doubleCheck.ID = check.ID
  886. doubleCheck.EmployeeNumber = employee_number
  887. doubleCheck.NeedleBatchNumber = needle_batch_number
  888. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  889. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  890. //查询未核对的医嘱
  891. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  892. for _, advice := range doctorList {
  893. if advice.ExecutionStaff == modifier {
  894. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  895. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  896. return
  897. }
  898. }
  899. }
  900. err := service.UpdateDoubleCheck(&doubleCheck)
  901. //针对长沙南雅
  902. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  903. //查询未核对的医嘱
  904. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  905. if len(doctorList) > 0 && modifier > 0 {
  906. for _, advice := range doctorList {
  907. service.UpdateDoctorAdviceList(advice.ID, modifier)
  908. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  909. redis := service.RedisClient()
  910. //清空key 值
  911. redis.Set(key, "", time.Second)
  912. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  913. redis.Set(keyTwo, "", time.Second)
  914. theTime := time.Now()
  915. recordDate := theTime.Format("2006-01-02")
  916. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  917. redis.Set(keyFour, "", time.Second)
  918. defer redis.Close()
  919. }
  920. }
  921. }
  922. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  923. redis := service.RedisClient()
  924. //清空key 值
  925. redis.Set(key, "", time.Second)
  926. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  927. redis.Set(keyOne, "", time.Second)
  928. defer redis.Close()
  929. if err == nil {
  930. c.ServeSuccessJSON(map[string]interface{}{
  931. "doubleCheck": &doubleCheck,
  932. "msg": "1",
  933. })
  934. }
  935. }
  936. }
  937. func (c *DialysisAPIController) PostAcceptsAssessment() {
  938. id, _ := c.GetInt64("patient", 0)
  939. recordDateStr := c.GetString("record_date")
  940. way, _ := c.GetInt64("way", 0)
  941. consciousness, _ := c.GetInt64("consciousness", 0)
  942. appetite, _ := c.GetInt64("appetite", 0)
  943. condition, _ := c.GetInt64("condition", 0)
  944. posture, _ := c.GetInt64("posture")
  945. sick_condition, _ := c.GetInt64("sick_condition", 0)
  946. danger_level, _ := c.GetInt64("danger_level", 0)
  947. intake, _ := c.GetInt64("intake", 0)
  948. nutrition, _ := c.GetInt64("nutrition", 0)
  949. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  950. psychological_assessment_other := c.GetString("psychological_assessment_other")
  951. score := c.GetString("score")
  952. sick_condition_other := c.GetString("sick_condition_other")
  953. //precaution, _ := c.GetInt64("precaution", 0)
  954. precaution := c.GetString("precaution")
  955. precaution_other := c.GetString("precaution_other")
  956. psychological_other := c.GetString("psychological_other")
  957. admission_number := c.GetString("admission_number")
  958. tumble, _ := c.GetInt64("tumble")
  959. diacrisis := c.GetString("diacrisis")
  960. his_department := c.GetString("his_department")
  961. his_bed := c.GetString("his_bed")
  962. if id <= 0 {
  963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  964. return
  965. }
  966. adminUserInfo := c.GetMobileAdminUserInfo()
  967. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  968. if patient.ID == 0 {
  969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  970. return
  971. }
  972. //now := time.Now()
  973. //year, month, day := now.Date()
  974. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  975. //todayTimeStamp := today_time.Unix()
  976. if len(recordDateStr) == 0 {
  977. recordDateStr = time.Now().Format("2006-01-02")
  978. }
  979. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  980. if parseDateErr != nil {
  981. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  983. return
  984. }
  985. // 查询信息规挡的设置天数
  986. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  987. if infor.ID > 0 && infor.WeekDay > 0 {
  988. var cha_time int64
  989. timeNowStr := time.Now().Format("2006-01-02")
  990. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  991. //今日的日期减去设置的日期
  992. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  993. if cha_time >= recordDate.Unix() {
  994. //查询审核是否允许
  995. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  996. //申请状态不允许的情况 拒绝修改
  997. if infor.ApplicationStatus != 1 {
  998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  999. return
  1000. }
  1001. }
  1002. }
  1003. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1004. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1005. UserOrgId: adminUserInfo.Org.Id,
  1006. PatientId: id,
  1007. RecordDate: recordDate.Unix(),
  1008. Way: way,
  1009. Consciousness: consciousness,
  1010. Appetite: appetite,
  1011. Condition: condition,
  1012. SickCondition: sick_condition,
  1013. DangerLevel: danger_level,
  1014. Intake: intake,
  1015. Nutrition: nutrition,
  1016. PsychologicalAssessment: psychological_assessment,
  1017. PsychologicalAssessmentOther: psychological_assessment_other,
  1018. SickConditionOther: sick_condition_other,
  1019. Posture: posture,
  1020. CreatedTime: time.Now().Unix(),
  1021. UpdateTime: time.Now().Unix(),
  1022. Status: 1,
  1023. Score: score,
  1024. Precaution: precaution,
  1025. PrecautionOther: precaution_other,
  1026. PsychologicalOther: psychological_other,
  1027. AdmissionNumber: admission_number,
  1028. Tumble: tumble,
  1029. Diacrisis: diacrisis,
  1030. HisBed: his_bed,
  1031. HisDepartment: his_department,
  1032. }
  1033. if receiveTreatment.ID == 0 { //新增
  1034. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1035. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1036. finish := models.XtDialysisFinish{
  1037. IsFinish: 1,
  1038. UserOrgId: adminUserInfo.Org.Id,
  1039. Status: 1,
  1040. Ctime: time.Now().Unix(),
  1041. Mtime: 0,
  1042. Module: 2,
  1043. RecordDate: recordDate.Unix(),
  1044. Sourse: 1,
  1045. PatientId: id,
  1046. }
  1047. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1048. if dialysisFinish.ID == 0 {
  1049. service.CreateDialysisFinish(finish)
  1050. }
  1051. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1052. redis := service.RedisClient()
  1053. defer redis.Close()
  1054. //清空key 值
  1055. redis.Set(key, "", time.Second)
  1056. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1057. redis.Set(keyOne, "", time.Second)
  1058. if err == nil {
  1059. c.ServeSuccessJSON(map[string]interface{}{
  1060. "receiveTreatmentAsses": receiveTreatmentAsses,
  1061. })
  1062. }
  1063. } else { //修改
  1064. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1065. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1066. // if getPermissionErr != nil {
  1067. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1068. // return
  1069. // } else if headNursePermission == nil {
  1070. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1071. // return
  1072. // }
  1073. //}
  1074. // 查询信息规挡的设置天数
  1075. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1076. if infor.ID > 0 && infor.WeekDay > 0 {
  1077. var cha_time int64
  1078. timeNowStr := time.Now().Format("2006-01-02")
  1079. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1080. //今日的日期减去设置的日期
  1081. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1082. if cha_time >= recordDate.Unix() {
  1083. //查询审核是否允许
  1084. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1085. //申请状态不允许的情况 拒绝修改
  1086. if infor.ApplicationStatus != 1 {
  1087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1088. return
  1089. }
  1090. }
  1091. }
  1092. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1093. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1094. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1095. receiveTreatmentAsses.ID = receiveTreatment.ID
  1096. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1097. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1098. redis := service.RedisClient()
  1099. defer redis.Close()
  1100. //清空key 值
  1101. redis.Set(key, "", time.Second)
  1102. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1103. redis.Set(keyOne, "", time.Second)
  1104. if err == nil {
  1105. c.ServeSuccessJSON(map[string]interface{}{
  1106. "receiveTreatmentAsses": receiveTreatmentAsses,
  1107. })
  1108. }
  1109. }
  1110. }
  1111. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1112. id, _ := c.GetInt64("patient", 0)
  1113. recordDateStr := c.GetString("record_date")
  1114. weightAfter, _ := c.GetFloat("weight_after", 0)
  1115. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1116. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1117. fmt.Println("weight_loss", weightReduce)
  1118. temperature, _ := c.GetFloat("temperature", 0)
  1119. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1120. breathing_rate := c.GetString("breathing_rate")
  1121. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1122. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1123. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1124. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1125. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1126. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1127. cruor := c.GetString("cruor")
  1128. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1129. internalFistula := c.GetString("internal_fistula")
  1130. catheter := c.GetString("catheter")
  1131. complications := c.GetString("complication")
  1132. remark := c.GetString("remark")
  1133. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1134. dialysis_intakes := c.GetString("dialysis_intakes")
  1135. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1136. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1137. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1138. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1139. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1140. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1141. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1142. patientGose, _ := c.GetInt64("patient_gose", 0)
  1143. inpatientDepartment := c.GetString("inpatient_department")
  1144. observationContent := c.GetString("observation_content")
  1145. observationContentOther := c.GetString("observation_content_other")
  1146. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1147. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1148. in_advance_reason := c.GetString("in_advance_reason")
  1149. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1150. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1151. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1152. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1153. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1154. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1155. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1156. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1157. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1158. is_eat, _ := c.GetInt64("is_eat", 0)
  1159. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1160. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1161. channels, _ := c.GetInt64("channel", 0)
  1162. return_blood, _ := c.GetInt64("return_blood", 0)
  1163. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1164. dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1165. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1166. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1167. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1168. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1169. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1170. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1171. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1172. setting_pressure := c.GetString("setting_pressure")
  1173. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1174. diastolic_pressure := c.GetString("diastolic_pressure")
  1175. other_complication := c.GetString("other_complication")
  1176. ktv := c.GetString("ktv")
  1177. urr := c.GetString("urr")
  1178. hypertenison, _ := c.GetInt64("hypertenison")
  1179. hypopiesia, _ := c.GetInt64("hypopiesia")
  1180. leave_office_method, _ := c.GetInt64("leave_office_method")
  1181. lapse, _ := c.GetInt64("lapse")
  1182. consciousness, _ := c.GetInt64("consciousness")
  1183. fallrisk, _ := c.GetInt64("fallrisk")
  1184. machine_run := c.GetString("machine_run")
  1185. after_urea := c.GetString("after_urea")
  1186. pip_coagulation := c.GetString("pip_coagulation")
  1187. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1188. transfusion_volume := c.GetString("transfusion_volume")
  1189. last_after_weight := c.GetString("last_after_weight")
  1190. displace_liqui_value := c.GetString("displace_liqui_value")
  1191. if id <= 0 {
  1192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1193. return
  1194. }
  1195. adminUserInfo := c.GetMobileAdminUserInfo()
  1196. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1197. if patient.ID == 0 {
  1198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1199. return
  1200. }
  1201. if len(recordDateStr) == 0 {
  1202. recordDateStr = time.Now().Format("2006-01-02")
  1203. }
  1204. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1205. fmt.Println("parseDateErr", parseDateErr)
  1206. if parseDateErr != nil {
  1207. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1209. return
  1210. }
  1211. //now := time.Now()
  1212. //year, month, day := now.Date()
  1213. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1214. //todayTimeStamp := today_time.Unix()
  1215. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1216. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1217. UserOrgId: adminUserInfo.Org.Id,
  1218. PatientId: id,
  1219. AssessmentDate: recordDate.Unix(),
  1220. Temperature: temperature,
  1221. PulseFrequency: pulse_frequency,
  1222. BreathingRate: breathing_rate,
  1223. SystolicBloodPressure: systolic_blood_pressure,
  1224. DiastolicBloodPressure: diastolic_blood_pressure,
  1225. ActualUltrafiltration: actual_ultrafiltration,
  1226. ActualDisplacement: actual_displacement,
  1227. ActualTreatmentHour: actualtreatHour,
  1228. ActualTreatmentMinute: actualtreatmin,
  1229. WeightAfter: weightAfter,
  1230. AdditionalWeight: additionalWeight,
  1231. WeightLoss: weightReduce,
  1232. Cruor: cruor,
  1233. SymptomAfterDialysis: symptomsAfterDialysi,
  1234. InternalFistula: internalFistula,
  1235. Catheter: catheter,
  1236. Complication: complications,
  1237. DialysisIntakes: dialysateVolume,
  1238. CreatedTime: time.Now().Unix(),
  1239. UpdatedTime: time.Now().Unix(),
  1240. Status: 1,
  1241. Remark: remark,
  1242. BloodAccessPartId: blood_access_part_id,
  1243. BloodAccessPartOperaId: blood_access_part_opera_id,
  1244. DialysisIntakesUnit: dialysis_intakes_unit,
  1245. PuncturePointOozingBlood: puncturePointOozingBlood,
  1246. PuncturePointHaematoma: puncturePointHaematoma,
  1247. InternalFistulaTremorAc: internalFistulaTremorAc,
  1248. PatientGose: patientGose,
  1249. InpatientDepartment: inpatientDepartment,
  1250. ObservationContent: observationContent,
  1251. ObservationContentOther: observationContentOther,
  1252. DialysisProcess: dialysis_process,
  1253. InAdvanceMinute: in_advance_minute,
  1254. InAdvanceReason: in_advance_reason,
  1255. HemostasisMinute: hemostasis_minute,
  1256. HemostasisOpera: hemostasis_opera,
  1257. TremorNoise: tremor_noise,
  1258. DisequilibriumSyndrome: disequilibrium_syndrome,
  1259. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1260. ArterialTube: arterial_tube,
  1261. IntravenousTube: intravenous_tube,
  1262. Dialyzer: dialyzer,
  1263. InAdvanceReasonOther: in_advance_reason_other,
  1264. IsEat: is_eat,
  1265. CvcA: cvc_a,
  1266. CvcV: cvc_v,
  1267. Channel: channels,
  1268. ReturnBlood: return_blood,
  1269. RehydrationVolume: rehydration_volume,
  1270. DialysisDuring: dialysis_during,
  1271. StrokeVolume: stroke_volume,
  1272. BloodFlow: blood_flow,
  1273. SealingFluidDispose: sealing_fluid_dispose,
  1274. SealingFluidSpecial: sealing_fluid_special,
  1275. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1276. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1277. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1278. SettingPressure: setting_pressure,
  1279. DiastolicPressure: diastolic_pressure,
  1280. OtherComplication: other_complication,
  1281. Ktv: ktv,
  1282. Urr: urr,
  1283. Hypopiesia: hypopiesia,
  1284. Hypertenison: hypertenison,
  1285. Lapse: lapse,
  1286. LeaveOfficeMethod: leave_office_method,
  1287. Consciousness: consciousness,
  1288. Fallrisk: fallrisk,
  1289. MachineRun: machine_run,
  1290. AfterUrea: after_urea,
  1291. PipCoagulation: pip_coagulation,
  1292. AccumulatedBloodVolume: accumulated_blood_volume,
  1293. TransfusionVolume: transfusion_volume,
  1294. LastAfterWeight: last_after_weight,
  1295. DisplaceLiquiValue: displace_liqui_value,
  1296. }
  1297. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1298. // 查询信息规挡的设置天数
  1299. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1300. if infor.ID > 0 && infor.WeekDay > 0 {
  1301. var cha_time int64
  1302. timeNowStr := time.Now().Format("2006-01-02")
  1303. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1304. //今日的日期减去设置的日期
  1305. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1306. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1307. if cha_time >= recordDate.Unix() {
  1308. //查询审核是否允许
  1309. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1310. //申请状态不允许的情况 拒绝修改
  1311. if infor.ApplicationStatus != 1 {
  1312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1313. return
  1314. }
  1315. }
  1316. }
  1317. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1318. if assessmentAfter.ID == 0 { //新增
  1319. if appRole.UserType == 2 || appRole.UserType == 1 {
  1320. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1321. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1322. } else {
  1323. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1324. }
  1325. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1326. if assessmentAfterDislysis.UserOrgId != 10340 {
  1327. if assessmentAfterDislysis.WeightAfter == 0 {
  1328. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1329. }
  1330. }
  1331. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1332. //记录日志
  1333. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1334. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1335. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1336. PatientId: assessmentAfterDislysis.PatientId,
  1337. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1338. Status: 1,
  1339. ErrLog: string(byterequest),
  1340. AdminUserId: adminUserInfo.AdminUser.Id,
  1341. Ctime: 0,
  1342. Mtime: 0,
  1343. Source: "手机端保存透后评估",
  1344. }
  1345. service.CreateAfterDialysisLog(afterDialysisLog)
  1346. finish := models.XtDialysisFinish{
  1347. IsFinish: 1,
  1348. UserOrgId: adminUserInfo.Org.Id,
  1349. Status: 1,
  1350. Ctime: time.Now().Unix(),
  1351. Mtime: 0,
  1352. Module: 9,
  1353. RecordDate: recordDate.Unix(),
  1354. Sourse: 1,
  1355. PatientId: id,
  1356. }
  1357. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1358. if dialysisFinish.ID == 0 {
  1359. service.CreateDialysisFinish(finish)
  1360. }
  1361. redis := service.RedisClient()
  1362. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1363. redis.Set(keyTwo, "", time.Second)
  1364. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1365. //清空key 值
  1366. redis.Set(key, "", time.Second)
  1367. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1368. redis.Set(keyOne, "", time.Second)
  1369. defer redis.Close()
  1370. if err == nil {
  1371. c.ServeSuccessJSON(map[string]interface{}{
  1372. "assessmentAfterDislysis": assessmentAfterDislysis,
  1373. })
  1374. }
  1375. return
  1376. } else { //修改
  1377. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1378. if infor.ID > 0 && infor.WeekDay > 0 {
  1379. var cha_time int64
  1380. timeNowStr := time.Now().Format("2006-01-02")
  1381. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1382. //今日的日期减去设置的日期
  1383. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1384. if cha_time >= recordDate.Unix() {
  1385. //查询审核是否允许
  1386. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1387. //申请状态不允许的情况 拒绝修改
  1388. if infor.ApplicationStatus != 1 {
  1389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1390. return
  1391. }
  1392. }
  1393. }
  1394. if appRole.UserType == 2 || appRole.UserType == 1 {
  1395. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1396. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1397. } else {
  1398. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1399. if assessmentAfterDislysis.Creater == 0 {
  1400. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1401. }
  1402. }
  1403. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1404. assessmentAfterDislysis.ID = assessmentAfter.ID
  1405. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1406. if assessmentAfterDislysis.UserOrgId != 10340 {
  1407. if assessmentAfterDislysis.WeightAfter == 0 {
  1408. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1409. }
  1410. }
  1411. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1412. //记录日志
  1413. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1414. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1415. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1416. PatientId: assessmentAfterDislysis.PatientId,
  1417. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1418. Status: 1,
  1419. ErrLog: string(byterequest),
  1420. AdminUserId: adminUserInfo.AdminUser.Id,
  1421. Ctime: time.Now().Unix(),
  1422. Mtime: 0,
  1423. Source: "手机端修改保存透后评估",
  1424. }
  1425. service.CreateAfterDialysisLog(afterDialysisLog)
  1426. redis := service.RedisClient()
  1427. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1428. redis.Set(keyTwo, "", time.Second)
  1429. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1430. //清空key 值
  1431. redis.Set(key, "", time.Second)
  1432. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1433. redis.Set(keyOne, "", time.Second)
  1434. if err == nil {
  1435. c.ServeSuccessJSON(map[string]interface{}{
  1436. "assessmentAfterDislysis": assessmentAfterDislysis,
  1437. })
  1438. return
  1439. }
  1440. }
  1441. return
  1442. }
  1443. func (c *DialysisAPIController) PostDialysisPrescription() {
  1444. id, _ := c.GetInt64("patient", 0)
  1445. recordDateStr := c.GetString("record_date")
  1446. if id <= 0 {
  1447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1448. return
  1449. }
  1450. adminUserInfo := c.GetMobileAdminUserInfo()
  1451. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1452. if patient.ID == 0 {
  1453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1454. return
  1455. }
  1456. if len(recordDateStr) == 0 {
  1457. recordDateStr = time.Now().Format("2006-01-02")
  1458. }
  1459. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1460. if parseDateErr != nil {
  1461. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1463. return
  1464. }
  1465. mode_id, _ := c.GetInt64("mode_id", 0)
  1466. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1467. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1468. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1469. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1470. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1471. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1472. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1473. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1474. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1475. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1476. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1477. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1478. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1479. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1480. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1481. kalium, _ := c.GetFloat("kalium", 0)
  1482. sodium, _ := c.GetFloat("sodium", 0)
  1483. calcium, _ := c.GetFloat("calcium", 0)
  1484. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1485. glucose, _ := c.GetFloat("glucose", 0)
  1486. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1487. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1488. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1489. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1490. conductivity, _ := c.GetFloat("conductivity", 0)
  1491. remark := c.GetString("remark")
  1492. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1493. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1494. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1495. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1496. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1497. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1498. special_medicine_other := c.GetString("special_medicine_other")
  1499. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1500. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1501. blood_access, _ := c.GetInt64("blood_access", 0)
  1502. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1503. body_fluid_other := c.GetString("body_fluid_other")
  1504. niprocart, _ := c.GetInt64("niprocart", 0)
  1505. jms, _ := c.GetInt64("jms", 0)
  1506. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1507. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1508. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1509. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1510. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1511. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1512. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1513. injector, _ := c.GetInt64("injector", 0)
  1514. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1515. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1516. safe_package, _ := c.GetInt64("package", 0)
  1517. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1518. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1519. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1520. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1521. blood := c.GetString("blood")
  1522. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1523. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1524. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1525. displace_speed := c.GetString("displace_speed")
  1526. illness, _ := c.GetInt64("illness")
  1527. amylaceum := c.GetString("amylaceum")
  1528. single_time := c.GetString("single_time")
  1529. single_water := c.GetString("single_water")
  1530. replacement_flow := c.GetString("replacement_flow")
  1531. plasma_separator := c.GetString("plasma_separator")
  1532. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1533. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1534. oxygen_flow := c.GetString("oxygen_flow")
  1535. oxygen_time := c.GetString("oxygen_time")
  1536. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1537. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1538. puncture_needle := c.GetString("puncture_needle")
  1539. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1540. epo := c.GetString("epo")
  1541. epo_count, _ := c.GetFloat("epo_count", 0)
  1542. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1543. admin_user_id, _ := c.GetInt64("admin_user_id")
  1544. is_water := c.GetString("is_water")
  1545. var is_war int64
  1546. if is_water == "是" {
  1547. is_war = 1
  1548. }
  1549. if is_water == "否" {
  1550. is_war = 2
  1551. }
  1552. if is_water == "请选择" {
  1553. is_war = 0
  1554. }
  1555. drhy_water := c.GetString("drhy_water")
  1556. dry_water_hour := c.GetString("dry_water_hour")
  1557. water_machine := c.GetString("water_machine")
  1558. add_amount, _ := c.GetFloat("add_amount")
  1559. reduce_amount, _ := c.GetFloat("reduce_amount")
  1560. dialysis_remark := c.GetString("dialysis_remark")
  1561. prescribing_number, _ := c.GetFloat("prescribing_number")
  1562. prescription_sodium := c.GetString("prescription_sodium")
  1563. start_sodium := c.GetString("start_sodium")
  1564. sodium_curve := c.GetString("sodium_curve")
  1565. treatment_remark := c.GetString("treatment_remark")
  1566. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1567. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1568. prescription_water, _ := c.GetFloat("prescription_water")
  1569. dialysis_strainer := c.GetString("dialysis_strainer")
  1570. chaptalization := c.GetString("chaptalization")
  1571. washing_time := c.GetString("washing_time")
  1572. warsh_count := c.GetString("warsh_count")
  1573. blood_access_part_id := c.GetString("blood_access_part_id")
  1574. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1575. dialyzate := c.GetString("dialyzate")
  1576. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1577. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1578. //
  1579. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1580. // if appRole.UserType == 3 {
  1581. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1582. // if getPermissionErr != nil {
  1583. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1584. // return
  1585. // } else if headNursePermission == nil {
  1586. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1587. // return
  1588. // }
  1589. // }
  1590. //}
  1591. // 查询信息规挡的设置天数
  1592. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1593. if infor.ID > 0 && infor.WeekDay > 0 {
  1594. var cha_time int64
  1595. timeNowStr := time.Now().Format("2006-01-02")
  1596. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1597. //今日的日期减去设置的日期
  1598. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1599. if cha_time >= recordDate.Unix() {
  1600. //查询审核是否允许
  1601. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1602. //申请状态不允许的情况 拒绝修改
  1603. if infor.ApplicationStatus != 1 {
  1604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1605. return
  1606. }
  1607. }
  1608. }
  1609. if mode_id > 0 {
  1610. var str string
  1611. //查找该机构用的是什么透析器
  1612. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1613. if filedConfig.ID > 0 {
  1614. str = dialyzerPerfusionApparatus
  1615. } else {
  1616. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1617. }
  1618. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1619. }
  1620. //TODO 需要根据角色去判断
  1621. prescription := models.DialysisPrescription{
  1622. UserOrgId: adminUserInfo.Org.Id,
  1623. PatientId: id,
  1624. RecordDate: recordDate.Unix(),
  1625. ModeId: mode_id,
  1626. DialysisDuration: dialysis_duration,
  1627. Dialyzer: dialyzer,
  1628. PerfusionApparatus: perfusion_apparatus,
  1629. BloodFlowVolume: blood_flow_volume,
  1630. DewaterAmount: dewater_amount,
  1631. DisplaceLiqui: displace_liqui,
  1632. ReplacementWay: replacement_way,
  1633. Anticoagulant: anticoagulant,
  1634. AnticoagulantShouji: anticoagulant_shouji,
  1635. AnticoagulantWeichi: anticoagulant_weichi,
  1636. AnticoagulantZongliang: anticoagulant_zongliang,
  1637. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1638. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1639. Kalium: kalium,
  1640. Sodium: sodium,
  1641. Calcium: calcium,
  1642. Bicarbonate: bicarbonate,
  1643. Glucose: glucose,
  1644. // DryWeight: dry_weight,
  1645. DialysateFlow: dialysate_flow,
  1646. DialysateTemperature: dialysate_temperature,
  1647. // PrescriptionDoctor: prescription_doctor,
  1648. ReplacementTotal: replacement_total,
  1649. Conductivity: conductivity,
  1650. Remark: remark,
  1651. Status: 1,
  1652. CreatedTime: time.Now().Unix(),
  1653. UpdatedTime: time.Now().Unix(),
  1654. DialysisDurationMinute: dialysisDurationMinute,
  1655. DialysisDurationHour: dialysisDurationHour,
  1656. TargetUltrafiltration: targetUltrafiltration,
  1657. DialysateFormulation: dialysateFormulation,
  1658. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1659. BodyFluid: body_fluid,
  1660. SpecialMedicine: special_medicine,
  1661. SpecialMedicineOther: special_medicine_other,
  1662. DisplaceLiquiPart: displace_liqui_part,
  1663. DisplaceLiquiValue: displace_liqui_value,
  1664. BloodAccess: blood_access,
  1665. Ultrafiltration: ultrafiltration,
  1666. BodyFluidOther: body_fluid_other,
  1667. Niprocart: niprocart,
  1668. Jms: jms,
  1669. FistulaNeedleSet: fistula_needle_set,
  1670. FistulaNeedleSet16: fistula_needle_set_16,
  1671. Hemoperfusion: hemoperfusion,
  1672. DialyserSterilised: dialyser_sterilised,
  1673. Filtryzer: filtryzer,
  1674. Dialyzers: dialyzers,
  1675. Injector: injector,
  1676. Bloodlines: bloodlines,
  1677. TubingHemodialysis: tubing_hemodialysis,
  1678. Package: safe_package,
  1679. ALiquid: a_liquid,
  1680. TargetKtv: target_ktv,
  1681. PreImpulse: pre_impulse,
  1682. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1683. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1684. Blood: blood,
  1685. DialysisDialyszers: dialysis_dialyszers,
  1686. DialysisIrrigation: dialysis_irrigation,
  1687. AntioxidantCommodityName: antioxidant_commodity_name,
  1688. DisplaceSpeed: displace_speed,
  1689. Illness: illness,
  1690. Amylaceum: amylaceum,
  1691. SingleTime: single_time,
  1692. SingleWater: single_water,
  1693. ReplacementFlow: replacement_flow,
  1694. PlasmaSeparator: plasma_separator,
  1695. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1696. OxygenUptake: oxygen_uptake,
  1697. OxygenFlow: oxygen_flow,
  1698. OxygenTime: oxygen_time,
  1699. HemodialysisPipelines: hemodialysis_pipelines,
  1700. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1701. PunctureNeedle: puncture_needle,
  1702. PunctureNeedleCount: puncture_needle_count,
  1703. Epo: epo,
  1704. EpoCount: epo_count,
  1705. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1706. AdminUserId: admin_user_id,
  1707. IsWater: is_war,
  1708. DrhyWater: drhy_water,
  1709. DryWaterHour: dry_water_hour,
  1710. WaterMachine: water_machine,
  1711. AddAmount: add_amount,
  1712. ReduceAmount: reduce_amount,
  1713. DialysisRemark: dialysis_remark,
  1714. PrescribingNumber: prescribing_number,
  1715. StartSodium: start_sodium,
  1716. SodiumCurve: sodium_curve,
  1717. TreatmentRemark: treatment_remark,
  1718. PrescriptionSodium: prescription_sodium,
  1719. DialysisFluidFlow: dialysis_fluid_flow,
  1720. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1721. PrescriptionWater: prescription_water,
  1722. DialysisStrainer: dialysis_strainer,
  1723. Chaptalization: chaptalization,
  1724. WashingTime: washing_time,
  1725. WarshCount: warsh_count,
  1726. BloodAccessPartId: blood_access_part_id,
  1727. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1728. Dialyzate: dialyzate,
  1729. }
  1730. //查询最近透析准备表里是否存在 透析器 灌流器
  1731. //
  1732. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1733. //
  1734. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1735. //
  1736. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1737. //if len(mation)>0{
  1738. // for _, item := range splitStr {
  1739. // for _,it := range mation{
  1740. // if(item == it.SpecificationName){
  1741. //
  1742. // //查询最近一次的透析器
  1743. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1744. //
  1745. // if errcode == gorm.ErrRecordNotFound{
  1746. // //插入数据
  1747. // prepare := models.DialysisBeforePrepare{
  1748. // UserOrgId: adminUserInfo.Org.Id,
  1749. // PatientId: id,
  1750. // RecordDate: recordDate.Unix(),
  1751. // GoodTypeId: it.GoodTypeId,
  1752. // GoodId: it.ID,
  1753. // Count: 1,
  1754. // Ctime: time.Now().Unix(),
  1755. // Creater: adminUserInfo.AdminUser.Id,
  1756. // Status:1,
  1757. //
  1758. // }
  1759. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1760. // fmt.Println("",errcode)
  1761. // }
  1762. // }
  1763. // }
  1764. //
  1765. // }
  1766. //
  1767. // for _, item := range splitIrrigation {
  1768. // for _,it := range mation{
  1769. // if(item == it.SpecificationName){
  1770. // //查询最近一次的透析器
  1771. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1772. // if errcode == gorm.ErrRecordNotFound{
  1773. // //插入数据
  1774. // prepare := models.DialysisBeforePrepare{
  1775. // UserOrgId: adminUserInfo.Org.Id,
  1776. // PatientId: id,
  1777. // RecordDate: recordDate.Unix(),
  1778. // GoodTypeId: it.GoodTypeId,
  1779. // GoodId: it.ID,
  1780. // Count: 1,
  1781. // Ctime: time.Now().Unix(),
  1782. // Creater: adminUserInfo.AdminUser.Id,
  1783. // Status:1,
  1784. //
  1785. // }
  1786. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1787. // fmt.Println(errcode)
  1788. // }
  1789. // }
  1790. // }
  1791. // }
  1792. //}
  1793. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1794. if dialysisPrescription.ID == 0 { //新增
  1795. if appRole.UserType == 2 || appRole.UserType == 1 {
  1796. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1797. }
  1798. prescription.Creater = adminUserInfo.AdminUser.Id
  1799. //针对河间咸得
  1800. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1801. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1802. prescription.DisplaceLiquiPart = 0
  1803. prescription.DisplaceLiquiValue = 0
  1804. }
  1805. }
  1806. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  1807. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1808. }
  1809. err := service.AddSigleRecord(&prescription)
  1810. //记录日志
  1811. byterequest, _ := json.Marshal(prescription)
  1812. prescriptionLog := models.XtDialysisPrescriptionLog{
  1813. UserOrgId: prescription.UserOrgId,
  1814. Ctime: time.Now().Unix(),
  1815. Mtime: 0,
  1816. ErrLog: string(byterequest),
  1817. AdminUserId: adminUserInfo.AdminUser.Id,
  1818. RecordDate: prescription.RecordDate,
  1819. PatientId: prescription.PatientId,
  1820. Source: "手机端新增保存处方",
  1821. Status: 1,
  1822. }
  1823. service.CreatePrescriptionLog(prescriptionLog)
  1824. finish := models.XtDialysisFinish{
  1825. IsFinish: 1,
  1826. UserOrgId: adminUserInfo.Org.Id,
  1827. Status: 1,
  1828. Ctime: time.Now().Unix(),
  1829. Mtime: 0,
  1830. Module: 1,
  1831. RecordDate: recordDate.Unix(),
  1832. Sourse: 1,
  1833. PatientId: id,
  1834. }
  1835. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  1836. if dialysisFinish.ID == 0 {
  1837. service.CreateDialysisFinish(finish)
  1838. }
  1839. //长沙南雅医院,自动生成抗凝剂的临时处方
  1840. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  1841. if prescribing_number == 0 {
  1842. prescribing_number = 1
  1843. }
  1844. if prescribing_number == 0 && id == 14682 {
  1845. prescribing_number = 2
  1846. }
  1847. if prescribing_number == 0 && id == 18560 {
  1848. prescribing_number = 2
  1849. }
  1850. advice := models.DoctorAdvice{
  1851. UserOrgId: adminUserInfo.Org.Id,
  1852. PatientId: id,
  1853. GroupNo: 0,
  1854. AdviceType: 2,
  1855. RecordDate: recordDate.Unix(),
  1856. AdviceDate: recordDate.Unix(),
  1857. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1858. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1859. AdviceDesc: "",
  1860. ReminderDate: 0,
  1861. SingleDose: anticoagulant_zongliang,
  1862. SingleDoseUnit: "iu",
  1863. DrugSpec: 0,
  1864. DrugSpecUnit: "",
  1865. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1866. PrescribingNumberUnit: "支",
  1867. DeliveryWay: "静脉注射",
  1868. ExecutionFrequency: "上机前",
  1869. AdviceDoctor: 0,
  1870. Status: 1,
  1871. CreatedTime: time.Now().Unix(),
  1872. UpdatedTime: time.Now().Unix(),
  1873. IsPrescription: 1,
  1874. ExecutionState: 2,
  1875. StopState: 2,
  1876. IsSettle: 2,
  1877. }
  1878. // 查询排班信息
  1879. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1880. if schedulePatient.ID > 0 {
  1881. if schedulePatient.ScheduleType == 1 {
  1882. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1883. }
  1884. if schedulePatient.ScheduleType == 2 {
  1885. advice.StartTime = recordDate.Unix() + 9*60*60
  1886. }
  1887. }
  1888. // 抗凝剂名称
  1889. switch anticoagulant {
  1890. case 1:
  1891. advice.AdviceName = "无肝素"
  1892. break
  1893. case 2:
  1894. advice.AdviceName = "普通肝素"
  1895. break
  1896. case 3:
  1897. advice.AdviceName = "低分子肝素"
  1898. break
  1899. case 4:
  1900. advice.AdviceName = "阿加曲班"
  1901. break
  1902. case 5:
  1903. advice.AdviceName = "枸橼酸钠"
  1904. break
  1905. case 6:
  1906. advice.AdviceName = "低分子肝素钙"
  1907. break
  1908. case 7:
  1909. advice.AdviceName = "低分子肝素钠"
  1910. break
  1911. case 8:
  1912. advice.AdviceName = "依诺肝素"
  1913. break
  1914. case 9:
  1915. advice.AdviceName = "达肝素"
  1916. break
  1917. case 10:
  1918. advice.AdviceName = "体外抗凝"
  1919. break
  1920. case 11:
  1921. advice.AdviceName = "那曲肝素"
  1922. break
  1923. case 12:
  1924. advice.AdviceName = "无抗凝剂"
  1925. break
  1926. }
  1927. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  1928. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  1929. advice.AdviceDoctor = appRole.AdminUserId
  1930. }
  1931. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  1932. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  1933. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  1934. advice.AdviceName = "低分子肝素钠注射液"
  1935. // 修改患者临时医嘱里的抗凝剂医嘱
  1936. advice.ID = advicePrescription.ID
  1937. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  1938. } else {
  1939. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  1940. advice.AdviceName = "低分子肝素钠注射液"
  1941. // 新增患者临时医嘱里的抗凝剂医嘱
  1942. service.CreateDoctorAdvice(&advice)
  1943. }
  1944. }
  1945. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  1946. redis := service.RedisClient()
  1947. defer redis.Close()
  1948. //清空key 值
  1949. redis.Set(key, "", time.Second)
  1950. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  1951. redis.Set(keyOne, "", time.Second)
  1952. }
  1953. //获取key,清空redis
  1954. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1955. redis := service.RedisClient()
  1956. //清空key 值
  1957. redis.Set(key, "", time.Second)
  1958. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1959. //清空key 值
  1960. redis.Set(keyOne, "", time.Second)
  1961. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1962. //清空key 值
  1963. redis.Set(keyTwo, "", time.Second)
  1964. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1965. redis.Set(keySix, "", time.Second)
  1966. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1967. redis.Set(keySeven, "", time.Second)
  1968. if err == nil {
  1969. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1970. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  1971. //清空key 值
  1972. redis.Set(keyThree, "", time.Second)
  1973. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  1974. //清空key 值
  1975. redis.Set(keyFour, "", time.Second)
  1976. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  1977. redis.Set(keyFive, "", time.Second)
  1978. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1979. redis.Set(keySix, "", time.Second)
  1980. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1981. redis.Set(keySeven, "", time.Second)
  1982. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1983. //清空key 值
  1984. redis.Set(keyOne, "", time.Second)
  1985. if updateErr != nil {
  1986. utils.ErrorLog("%v", updateErr)
  1987. }
  1988. defer redis.Close()
  1989. c.ServeSuccessJSON(map[string]interface{}{
  1990. "prescription": prescription,
  1991. })
  1992. }
  1993. } else { //修改
  1994. //if mode_id > 0 {
  1995. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1996. //}
  1997. //if template.TemplateId == 1 {
  1998. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1999. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2000. // if getPermissionErr != nil {
  2001. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2002. // return
  2003. // } else if headNursePermission == nil {
  2004. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2005. // return
  2006. // }
  2007. // }
  2008. //}
  2009. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2010. prescription.Modifier = adminUserInfo.AdminUser.Id
  2011. if appRole.UserType == 2 || appRole.UserType == 1 {
  2012. prescription_doctor := adminUserInfo.AdminUser.Id
  2013. prescription.PrescriptionDoctor = prescription_doctor
  2014. } else {
  2015. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2016. }
  2017. if dialysisPrescription.Creater == 0 { //体重称
  2018. prescription.Creater = adminUserInfo.AdminUser.Id
  2019. } else {
  2020. prescription.Creater = dialysisPrescription.Creater
  2021. if adminUserInfo.Org.Id == 9882 {
  2022. if appRole.UserType == 2 || appRole.UserType == 1 {
  2023. prescription_doctor := adminUserInfo.AdminUser.Id
  2024. prescription.PrescriptionDoctor = prescription_doctor
  2025. prescription.Creater = prescription_doctor
  2026. }
  2027. }
  2028. }
  2029. prescription.ID = dialysisPrescription.ID
  2030. service.UpDateDialysisPrescription(&prescription)
  2031. //记录日志
  2032. byterequest, _ := json.Marshal(prescription)
  2033. prescriptionLog := models.XtDialysisPrescriptionLog{
  2034. UserOrgId: prescription.UserOrgId,
  2035. Ctime: time.Now().Unix(),
  2036. Mtime: 0,
  2037. ErrLog: string(byterequest),
  2038. AdminUserId: adminUserInfo.AdminUser.Id,
  2039. RecordDate: prescription.RecordDate,
  2040. PatientId: prescription.PatientId,
  2041. Source: "手机端修改处方",
  2042. Status: 1,
  2043. }
  2044. service.CreatePrescriptionLog(prescriptionLog)
  2045. finish := models.XtDialysisFinish{
  2046. IsFinish: 1,
  2047. UserOrgId: adminUserInfo.Org.Id,
  2048. Status: 1,
  2049. Ctime: time.Now().Unix(),
  2050. Mtime: 0,
  2051. Module: 1,
  2052. RecordDate: recordDate.Unix(),
  2053. Sourse: 1,
  2054. PatientId: id,
  2055. }
  2056. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2057. if dialysisFinish.ID == 0 {
  2058. service.CreateDialysisFinish(finish)
  2059. }
  2060. //修改处方
  2061. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2062. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2063. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2064. if advicePrescription.ID > 0 {
  2065. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2066. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2067. redis := service.RedisClient()
  2068. defer redis.Close()
  2069. //清空key 值
  2070. redis.Set(key, "", time.Second)
  2071. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2072. redis.Set(keyOne, "", time.Second)
  2073. }
  2074. }
  2075. //获取key,清空redis
  2076. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2077. redis := service.RedisClient()
  2078. //清空key 值
  2079. redis.Set(key, "", time.Second)
  2080. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2081. //清空key 值
  2082. redis.Set(keyOne, "", time.Second)
  2083. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2084. redis.Set(keySix, "", time.Second)
  2085. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2086. redis.Set(keySeven, "", time.Second)
  2087. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2088. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2089. //清空key 值
  2090. redis.Set(keyTwoOne, "", time.Second)
  2091. defer redis.Close()
  2092. if updateErr != nil {
  2093. utils.ErrorLog("%v", updateErr)
  2094. }
  2095. c.ServeSuccessJSON(map[string]interface{}{
  2096. "prescription": prescription,
  2097. })
  2098. }
  2099. }
  2100. func (c *DialysisAPIController) Finish() {
  2101. id, _ := c.GetInt64("patient", 0)
  2102. recordDateStr := c.GetString("record_date")
  2103. nurseID, _ := c.GetInt64("nurse")
  2104. end_time := c.GetString("end_time")
  2105. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2106. internal_fistula := c.GetString("blood_access_internal_fistula")
  2107. catheter := c.GetString("catheter")
  2108. cruor := c.GetString("cruor")
  2109. mission := c.GetString("mission")
  2110. condenser := c.GetString("condenser")
  2111. if id <= 0 || nurseID <= 0 {
  2112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2113. return
  2114. }
  2115. adminUserInfo := c.GetMobileAdminUserInfo()
  2116. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2117. if patient.ID == 0 {
  2118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2119. return
  2120. }
  2121. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2122. if getNurseErr != nil {
  2123. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2125. return
  2126. } else if nurse == nil {
  2127. c.ErrorLog("护士不存在")
  2128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2129. return
  2130. }
  2131. if len(recordDateStr) == 0 {
  2132. recordDateStr = time.Now().Format("2006-01-02")
  2133. }
  2134. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2135. if parseDateErr != nil {
  2136. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2138. return
  2139. }
  2140. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2141. if parseEndDateErr != nil {
  2142. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2144. return
  2145. }
  2146. // 查询信息规挡的设置天数
  2147. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2148. if infor.ID > 0 && infor.WeekDay > 0 {
  2149. var cha_time int64
  2150. timeNowStr := time.Now().Format("2006-01-02")
  2151. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2152. //今日的日期减去设置的日期
  2153. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2154. if cha_time >= recordDate.Unix() {
  2155. //查询审核是否允许
  2156. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2157. //申请状态不允许的情况 拒绝修改
  2158. if infor.ApplicationStatus != 1 {
  2159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2160. return
  2161. }
  2162. }
  2163. }
  2164. //now := time.Now()
  2165. //year, month, day := now.Date()
  2166. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2167. //todayTimeStamp := today_time.Unix()
  2168. // 获取当天的第一条透析纪录
  2169. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2170. if getMonitorRecordsErr != nil {
  2171. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2173. return
  2174. }
  2175. // 获取当前的最后一条透析纪录
  2176. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2177. if getMonitorRecordsErr != nil {
  2178. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2180. return
  2181. }
  2182. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2183. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2184. if getAADErr != nil {
  2185. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2187. return
  2188. }
  2189. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2190. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2191. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2192. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2193. if assessmentAfterDislysis != nil {
  2194. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2195. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2196. } else {
  2197. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2198. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2199. tempassessmentAfterDislysis.Status = 1
  2200. tempassessmentAfterDislysis.PatientId = id
  2201. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2202. }
  2203. //长沙南雅
  2204. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2205. //获取最后一条透析处方数据
  2206. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2207. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2208. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2209. }
  2210. if dialysisOrder.Stage == 1 {
  2211. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2212. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2213. fmt.Println(value)
  2214. a, b := math.Modf(value)
  2215. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2216. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2217. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2218. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2219. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2220. }
  2221. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2222. //var num1 int64
  2223. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2224. //fmt.Println(num1)
  2225. //sub := float64(num1 / 3600)
  2226. //fmt.Println(sub)
  2227. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2228. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2229. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2230. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2231. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2232. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2233. if adminUserInfo.Org.Id != 10375 {
  2234. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2235. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2236. }
  2237. if adminUserInfo.Org.Id != 10445 {
  2238. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2239. }
  2240. //北方营口医院
  2241. if adminUserInfo.Org.Id == 10445 {
  2242. //获取最后一条透析处方数据
  2243. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2244. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2245. } else {
  2246. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2247. }
  2248. //新化博翔
  2249. if adminUserInfo.Org.Id == 10447 {
  2250. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2251. }
  2252. //阳春
  2253. if adminUserInfo.Org.Id == 10485 {
  2254. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2255. }
  2256. if adminUserInfo.Org.Id == 10551 {
  2257. //获取最后一条透析处方数据
  2258. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2259. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2260. }
  2261. if adminUserInfo.Org.Id == 10580 {
  2262. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2263. }
  2264. if adminUserInfo.Org.Id == 10612 {
  2265. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2266. }
  2267. }
  2268. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 10243 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10414 || adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 {
  2269. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2270. if evaluation.SystolicBloodPressure == 0 {
  2271. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2272. pre := models.PredialysisEvaluation{
  2273. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2274. }
  2275. fmt.Println("prew", pre)
  2276. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2277. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2278. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2279. redis := service.RedisClient()
  2280. redis.Set(key, "", time.Second)
  2281. redis.Set(keyOne, "", time.Second)
  2282. defer redis.Close()
  2283. fmt.Println(getNurseErr)
  2284. }
  2285. if evaluation.DiastolicBloodPressure == 0 {
  2286. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2287. pres := models.PredialysisEvaluation{
  2288. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2289. }
  2290. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2291. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2292. redis := service.RedisClient()
  2293. redis.Set(key, "", time.Second)
  2294. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2295. redis.Set(keyOne, "", time.Second)
  2296. defer redis.Close()
  2297. fmt.Println(getNurseErr)
  2298. }
  2299. if evaluation.PulseFrequency == 0 {
  2300. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2301. press := models.PredialysisEvaluation{
  2302. PulseFrequency: evaluation.PulseFrequency,
  2303. }
  2304. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2305. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2306. redis := service.RedisClient()
  2307. redis.Set(key, "", time.Second)
  2308. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2309. redis.Set(keyOne, "", time.Second)
  2310. defer redis.Close()
  2311. fmt.Println(getNurseErr)
  2312. }
  2313. if evaluation.Temperature == 0 {
  2314. evaluation.Temperature = fmonitorRecords.Temperature
  2315. press := models.PredialysisEvaluation{
  2316. Temperature: evaluation.Temperature,
  2317. }
  2318. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2319. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2320. redis := service.RedisClient()
  2321. redis.Set(key, "", time.Second)
  2322. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2323. redis.Set(keyOne, "", time.Second)
  2324. defer redis.Close()
  2325. fmt.Println(getNurseErr)
  2326. }
  2327. }
  2328. if adminUserInfo.Org.Id == 9583 {
  2329. //获取透析处方的最后一条数据
  2330. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2331. if diaerr != nil {
  2332. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2334. return
  2335. }
  2336. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2337. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2338. }
  2339. }
  2340. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2341. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2342. }
  2343. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2344. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2345. }
  2346. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2347. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2348. }
  2349. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2350. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2351. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2352. }
  2353. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2354. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2355. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2356. }
  2357. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2358. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2359. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2360. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2361. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2362. }
  2363. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2364. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2365. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2366. }
  2367. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2368. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2369. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2370. }
  2371. if lastAssessmentAfterDislysis != nil {
  2372. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2373. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2374. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2375. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2376. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2377. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2378. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2379. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2380. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2381. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2382. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2383. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2384. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2385. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2386. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2387. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2388. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2389. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2390. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2391. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2392. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2393. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2394. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2395. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2396. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2397. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2398. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2399. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2400. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2401. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2402. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2403. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2404. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2405. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2406. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2407. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2408. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2409. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2410. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2411. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2412. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2413. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2414. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2415. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2416. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2417. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2418. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2419. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2420. if tempassessmentAfterDislysis.PatientId == 18695 {
  2421. tempassessmentAfterDislysis.ActualDisplacement = 0
  2422. }
  2423. if adminUserInfo.Org.Id != 10375 {
  2424. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2425. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2426. }
  2427. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2428. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2429. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2430. }
  2431. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2432. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2433. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2434. }
  2435. }
  2436. finish := models.XtDialysisFinish{
  2437. IsFinish: 1,
  2438. UserOrgId: adminUserInfo.Org.Id,
  2439. Status: 1,
  2440. Ctime: time.Now().Unix(),
  2441. Mtime: 0,
  2442. Module: 9,
  2443. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2444. Sourse: 1,
  2445. PatientId: tempassessmentAfterDislysis.PatientId,
  2446. }
  2447. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2448. if dialysisFinish.ID == 0 {
  2449. service.CreateDialysisFinish(finish)
  2450. }
  2451. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2452. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2453. redis := service.RedisClient()
  2454. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2455. redis.Set(keyOne, "", time.Second)
  2456. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2457. redis.Set(keyTwo, "", time.Second)
  2458. defer redis.Close()
  2459. //清空key 值
  2460. redis.Set(key, "", time.Second)
  2461. if err != nil {
  2462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2463. return
  2464. }
  2465. if dialysisOrder == nil {
  2466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2467. return
  2468. }
  2469. if dialysisOrder.Stage == 2 {
  2470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2471. return
  2472. }
  2473. if dialysisOrder.Stage == 1 {
  2474. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2475. finish := models.XtDialysisFinish{
  2476. IsFinish: 1,
  2477. UserOrgId: adminUserInfo.Org.Id,
  2478. Status: 1,
  2479. Ctime: time.Now().Unix(),
  2480. Mtime: 0,
  2481. Module: 8,
  2482. RecordDate: recordDate.Unix(),
  2483. Sourse: 1,
  2484. PatientId: id,
  2485. }
  2486. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2487. if dialysisFinish.ID == 0 {
  2488. service.CreateDialysisFinish(finish)
  2489. }
  2490. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2491. redis := service.RedisClient()
  2492. defer redis.Close()
  2493. //清空key 值
  2494. redis.Set(key, "", time.Second)
  2495. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2496. redis.Set(keyOne, "", time.Second)
  2497. //结束时候透析次数加1
  2498. service.UpdateSolutionByPatientId(id)
  2499. //下机完自动消毒,针对长沙南雅
  2500. if dialysisOrder.Stage == 1 {
  2501. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9538 || adminUserInfo.Org.Id == 10121 || adminUserInfo.Org.Id == 10612 {
  2502. //根据床位号获取设备型号
  2503. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2504. //查询使用消毒最后一条消毒记录
  2505. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2506. fmt.Println("err", err)
  2507. if err == gorm.ErrRecordNotFound {
  2508. //查找排班
  2509. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2510. //查询改设备是否有消毒计划
  2511. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2512. //根据床位号获取设备id
  2513. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2514. //查询病人信息
  2515. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2516. var con = ""
  2517. if patients.IsInfectious == 0 {
  2518. con = ""
  2519. }
  2520. if patients.IsInfectious == 1 {
  2521. con = "无"
  2522. }
  2523. if patients.IsInfectious == 2 {
  2524. con = "有"
  2525. }
  2526. if errcode == nil {
  2527. var end_time int64
  2528. end_time = endDate.Unix() + plan.DisinfecTime*60
  2529. //新增消毒
  2530. information := models.DeviceInformation{
  2531. Date: dialysisOrder.DialysisDate,
  2532. Zone: dialysisOrder.ZoneId,
  2533. Class: dialysisOrder.SchedualType,
  2534. BedNumber: dialysisOrder.BedID,
  2535. PatientId: dialysisOrder.PatientId,
  2536. DialysisMode: scheduleByPatient.ModeId,
  2537. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2538. Disinfection: 1,
  2539. DialysisConcentration: 1,
  2540. DisinfectionStatus: 1,
  2541. Move: 1,
  2542. UserOrgId: dialysisOrder.UserOrgId,
  2543. DisinfectType: plan.Way,
  2544. DisinfectantType: plan.MachineDisinfectant,
  2545. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2546. Disinfectant: plan.Disinfectant,
  2547. Ctime: time.Now().Unix(),
  2548. Status: 1,
  2549. SignName: nurseID,
  2550. EquimentId: addmacher.ID,
  2551. DisinfectionResidue: 2,
  2552. Bed: addmacher.BedNumber,
  2553. StartTime: dialysisOrder.StartTime,
  2554. EndTime: dialysisOrder.EndTime,
  2555. Contagion: con,
  2556. WeightLoss: 0,
  2557. Hyperfiltratio: 0,
  2558. DialysisHour: "",
  2559. MachineRun: 1,
  2560. DisinfecStartime: endDate.Unix(),
  2561. DisinfecEndtime: end_time,
  2562. }
  2563. err := service.CreateInformationTwo(&information)
  2564. fmt.Println("报错", err)
  2565. }
  2566. }
  2567. }
  2568. }
  2569. dialysisOrder.Stage = 2
  2570. dialysisOrder.FinishNurse = nurseID
  2571. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2572. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2573. dialysisOrder.EndTime = endDate.Unix()
  2574. // 长沙南雅需求
  2575. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2576. //获取最后1条监测的数据
  2577. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2578. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2579. var accumulatedBloodVolume float64
  2580. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2581. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2582. fmt.Println(err)
  2583. // 查询未执行的医嘱
  2584. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2585. for _, item := range doctorAdvice {
  2586. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2587. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2588. redis := service.RedisClient()
  2589. //清空key 值
  2590. redis.Set(key, "", time.Second)
  2591. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2592. redis.Set(keyTwo, "", time.Second)
  2593. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2594. redis.Set(keyThree, "", time.Second)
  2595. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2596. theTime := toTime.Format("2006-01-02")
  2597. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2598. redis.Set(keyFour, "", time.Second)
  2599. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2600. redis.Set(keyFive, "", time.Second)
  2601. defer redis.Close()
  2602. }
  2603. }
  2604. go func() {
  2605. ssoDomain := beego.AppConfig.String("call_domain")
  2606. api := ssoDomain + "/index/downpatient"
  2607. values := make(url.Values)
  2608. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2609. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2610. values.Set("patient_id", strconv.FormatInt(id, 10))
  2611. http.PostForm(api, values)
  2612. }()
  2613. if err == nil {
  2614. c.ServeSuccessJSON(map[string]interface{}{
  2615. "dialysisOrder": dialysisOrder,
  2616. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2617. })
  2618. } else {
  2619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2620. }
  2621. }
  2622. }
  2623. func (c *DialysisAPIController) GetAllZone() {
  2624. adminUserInfo := c.GetMobileAdminUserInfo()
  2625. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2626. if err == nil {
  2627. c.ServeSuccessJSON(map[string]interface{}{
  2628. "zone": zone,
  2629. })
  2630. }
  2631. }
  2632. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2633. adminUserInfo := c.GetMobileAdminUserInfo()
  2634. page, _ := c.GetInt64("page", 1)
  2635. limit, _ := c.GetInt64("limit", 10)
  2636. schedulType, _ := c.GetInt64("schedul_type", 0)
  2637. startTime, _ := c.GetInt64("schedul_time", 0)
  2638. partitionType, _ := c.GetInt64("partition_type", 0)
  2639. keywords := c.GetString("keywords")
  2640. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2641. if err == nil {
  2642. c.ServeSuccessJSON(map[string]interface{}{
  2643. "schedule": dialysisSchedule,
  2644. })
  2645. }
  2646. return
  2647. }
  2648. // /m/api/dialysis/start [post]
  2649. // @param patient_id:int
  2650. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2651. // @param nurse:int 上机护士
  2652. // @param bed:int 床位号
  2653. func (this *DialysisAPIController) StartDialysis() {
  2654. patientID, _ := this.GetInt64("patient_id")
  2655. recordDateStr := this.GetString("record_date")
  2656. nurseID, _ := this.GetInt64("start_nurse")
  2657. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2658. blood_drawing, _ := this.GetInt64("blood_drawing")
  2659. schedual_type, _ := this.GetInt64("schedual_type")
  2660. bedID, _ := this.GetInt64("bed")
  2661. start_time := this.GetString("start_time")
  2662. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2663. change_nurse, _ := this.GetInt64("change_nurse")
  2664. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2665. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2666. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2667. puncture_needle := this.GetString("puncture_needle")
  2668. puncture_way := this.GetString("puncture_way")
  2669. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2670. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2671. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  2672. zone_id, _ := this.GetInt64("zone_id")
  2673. elecsign := this.GetString("url")
  2674. nuclein_date_str := this.GetString("nuclein_date_str")
  2675. schedule_remark := this.GetString("schedule_remark")
  2676. order_remark := this.GetString("order_remark")
  2677. catheter_operation := this.GetString("catheter_operation")
  2678. blood_flow_volume := this.GetString("blood_flow_volume")
  2679. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2680. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2681. return
  2682. }
  2683. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2684. if parseStartDateErr != nil {
  2685. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2686. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2687. return
  2688. }
  2689. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2690. if parseErr != nil {
  2691. this.ErrorLog("时间解析失败:%v", parseErr)
  2692. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2693. return
  2694. }
  2695. adminUserInfo := this.GetMobileAdminUserInfo()
  2696. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2697. if getPatientErr != nil {
  2698. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2699. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2700. return
  2701. } else if patient == nil {
  2702. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2703. return
  2704. }
  2705. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2706. if getNurseErr != nil {
  2707. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2708. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2709. return
  2710. } else if nurse == nil {
  2711. this.ErrorLog("护士不存在")
  2712. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2713. return
  2714. }
  2715. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2716. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2717. if getDeviceNumberErr != nil {
  2718. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2719. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2720. return
  2721. } else if deviceNumber == nil {
  2722. this.ErrorLog("床位号不存在")
  2723. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2724. return
  2725. }
  2726. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2727. if getRecordErr != nil {
  2728. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2729. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2730. return
  2731. } else if dialysisRecord != nil {
  2732. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2733. return
  2734. }
  2735. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2736. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2737. timeLayout := "2006-01-02 15:04:05"
  2738. loc, _ := time.LoadLocation("Local")
  2739. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2740. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2741. schedulestartTime := theStartTime.Unix()
  2742. scheduleendTime := theEndTime.Unix()
  2743. var theNucleinDate int64
  2744. timeLayoutOne := "2006-01-02"
  2745. if len(nuclein_date_str) > 0 {
  2746. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2747. if err != nil {
  2748. utils.ErrorLog(err.Error())
  2749. }
  2750. theNucleinDate = theTime.Unix()
  2751. }
  2752. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2753. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2754. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  2755. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2756. //查询该床位是否有人用了
  2757. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2758. if err == gorm.ErrRecordNotFound { //空床位
  2759. // 修改了床位逻辑
  2760. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2761. if daySchedule.ID > 0 {
  2762. daySchedule.PartitionId = deviceNumber.ZoneID
  2763. daySchedule.BedId = bedID
  2764. daySchedule.ScheduleType = schedual_type
  2765. daySchedule.UpdatedTime = time.Now().Unix()
  2766. xtSchedule := models.Schedule{
  2767. PartitionId: deviceNumber.ZoneID,
  2768. BedId: bedID,
  2769. ScheduleType: schedual_type,
  2770. UpdatedTime: time.Now().Unix(),
  2771. }
  2772. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2773. if err != nil {
  2774. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2775. return
  2776. }
  2777. }
  2778. } else if err == nil {
  2779. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2780. if order.ID > 0 { //该机位被其他人占用了
  2781. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2782. return
  2783. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  2784. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2785. if daySchedule.ID > 0 {
  2786. err := service.UpdateScheduleTwo(daySchedule, schedule)
  2787. if err != nil {
  2788. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2789. return
  2790. }
  2791. }
  2792. }
  2793. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2794. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2795. return
  2796. }
  2797. //else if order.ID == 0 { //该床位没被占用
  2798. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2799. // if daySchedule.ID > 0 {
  2800. // //daySchedule.PartitionId = deviceNumber.ZoneID
  2801. // //daySchedule.BedId = bedID
  2802. // //daySchedule.ScheduleType = schedual_type
  2803. // //daySchedule.UpdatedTime = time.Now().Unix()
  2804. // //err := service.UpdateSchedule(&daySchedule)
  2805. // xtSchedule := models.Schedule{
  2806. // PartitionId: deviceNumber.ZoneID,
  2807. // BedId: bedID,
  2808. // ScheduleType: schedual_type,
  2809. // UpdatedTime: time.Now().Unix(),
  2810. // }
  2811. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2812. // if err != nil {
  2813. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2814. // return
  2815. // }
  2816. // }
  2817. //}
  2818. //}
  2819. } else if err != nil {
  2820. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2821. return
  2822. }
  2823. // 查询信息规挡的设置天数
  2824. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2825. if infor.ID > 0 && infor.WeekDay > 0 {
  2826. var cha_time int64
  2827. timeNowStr := time.Now().Format("2006-01-02")
  2828. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2829. //今日的日期减去设置的日期
  2830. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2831. if cha_time >= recordDate.Unix() {
  2832. //查询审核是否允许
  2833. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  2834. //申请状态不允许的情况 拒绝修改
  2835. if infor.ApplicationStatus != 1 {
  2836. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2837. return
  2838. }
  2839. }
  2840. }
  2841. dialysisRecord = &models.DialysisOrder{
  2842. DialysisDate: recordDate.Unix(),
  2843. UserOrgId: adminUserInfo.Org.Id,
  2844. PatientId: patientID,
  2845. Stage: 1,
  2846. BedID: bedID,
  2847. StartNurse: nurseID,
  2848. Status: 1,
  2849. StartTime: startDate.Unix(),
  2850. CreatedTime: time.Now().Unix(),
  2851. UpdatedTime: time.Now().Unix(),
  2852. PunctureNurse: puncture_nurse,
  2853. Creator: adminUserInfo.AdminUser.Id,
  2854. Modifier: adminUserInfo.AdminUser.Id,
  2855. SchedualType: schedual_type,
  2856. WashpipeNurse: washpipe_nurse,
  2857. ChangeNurse: change_nurse,
  2858. DifficultPunctureNurse: difficult_puncture_nurse,
  2859. NewFistulaNurse: new_fistula_nurse,
  2860. ZoneId: zone_id,
  2861. QualityNurseId: quality_nurse_id,
  2862. PunctureNeedle: puncture_needle,
  2863. PunctureWay: puncture_way,
  2864. DialysisIrrigation: dialysis_irrigation,
  2865. DialysisDialyszers: dialysis_dialyszers,
  2866. BloodAccessId: blood_access_id,
  2867. Url: elecsign,
  2868. NucleinDate: theNucleinDate,
  2869. ScheduleRemark: schedule_remark,
  2870. OrderRemark: order_remark,
  2871. CatheterOperation: catheter_operation,
  2872. BloodFlowVolume: blood_flow_volume,
  2873. BloodDrawing: blood_drawing,
  2874. }
  2875. //查询该床位是否有人用了
  2876. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2877. if errorscode == gorm.ErrRecordNotFound {
  2878. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  2879. finish := models.XtDialysisFinish{
  2880. IsFinish: 1,
  2881. UserOrgId: adminUserInfo.Org.Id,
  2882. Status: 1,
  2883. Ctime: time.Now().Unix(),
  2884. Mtime: 0,
  2885. Module: 6,
  2886. RecordDate: schedulestartTime,
  2887. Sourse: 1,
  2888. PatientId: patientID,
  2889. }
  2890. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  2891. if dialysisFinish.ID == 0 {
  2892. service.CreateDialysisFinish(finish)
  2893. }
  2894. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  2895. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  2896. //统计该患者总次数
  2897. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  2898. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2899. }
  2900. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  2901. //统计该患者总次数
  2902. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  2903. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2904. }
  2905. redis := service.RedisClient()
  2906. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2907. redis.Set(key, "", time.Second)
  2908. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2909. //清空key 值
  2910. redis.Set(keyOne, "", time.Second)
  2911. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2912. //清空key 值
  2913. redis.Set(keyTwo, "", time.Second)
  2914. if createErr != nil {
  2915. this.ErrorLog("上机失败:%v", createErr)
  2916. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2917. return
  2918. }
  2919. }
  2920. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2921. var tempdispose string
  2922. // 只针对中能建
  2923. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  2924. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2925. }
  2926. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  2927. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2928. }
  2929. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  2930. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2931. //}
  2932. var ultrafiltration_rate float64
  2933. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2934. //后期预增脱水量
  2935. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2936. if prescription.ID > 0 {
  2937. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2938. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2939. if (template.TemplateId == 6 || template.TemplateId == 32 || template.TemplateId == 65 || adminUserInfo.Org.Id == 10375 || adminUserInfo.Org.Id == 10599) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  2940. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2941. }
  2942. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  2943. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  2944. }
  2945. //针对医师汇
  2946. if adminUserInfo.Org.Id == 10121 {
  2947. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  2948. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  2949. }
  2950. //针对通道
  2951. if adminUserInfo.Org.Id == 10234 {
  2952. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  2953. }
  2954. //针对监利大垸医院
  2955. if template.TemplateId == 41 {
  2956. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  2957. }
  2958. //针对肇庆三鹤血液透析中心
  2959. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  2960. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2961. }
  2962. if adminUserInfo.Org.Id == 10469 {
  2963. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  2964. }
  2965. if adminUserInfo.Org.Id == 10667 {
  2966. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  2967. }
  2968. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  2969. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2970. }
  2971. // 只针对方济医院
  2972. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  2973. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2974. ultrafiltration_rate = value
  2975. }
  2976. //针对
  2977. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  2978. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2979. ultrafiltration_rate = ultrafiltration_rate / 1000
  2980. }
  2981. if adminUserInfo.Org.Id == 10551 {
  2982. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2983. ultrafiltration_rate = ultrafiltration_rate / 1000
  2984. }
  2985. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  2986. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2987. ultrafiltration_rate = ultrafiltration_rate / 1000
  2988. }
  2989. if adminUserInfo.Org.Id == 10580 {
  2990. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2991. ultrafiltration_rate = ultrafiltration_rate / 1000
  2992. }
  2993. if adminUserInfo.Org.Id == 10629 {
  2994. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2995. ultrafiltration_rate = ultrafiltration_rate / 1000
  2996. }
  2997. if adminUserInfo.Org.Id == 10644 {
  2998. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2999. ultrafiltration_rate = ultrafiltration_rate / 1000
  3000. }
  3001. if adminUserInfo.Org.Id == 10667 {
  3002. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3003. ultrafiltration_rate = ultrafiltration_rate / 1000
  3004. }
  3005. }
  3006. }
  3007. record := models.MonitoringRecord{
  3008. UserOrgId: adminUserInfo.Org.Id,
  3009. PatientId: patientID,
  3010. DialysisOrderId: dialysisRecord.ID,
  3011. MonitoringDate: schedulestartTime,
  3012. OperateTime: startDate.Unix(),
  3013. // MonitoringTime: recordTime,
  3014. MonitoringNurse: nurseID,
  3015. Dispose: tempdispose,
  3016. UltrafiltrationRate: ultrafiltration_rate,
  3017. UltrafiltrationVolume: 0,
  3018. Status: 1,
  3019. CreatedTime: time.Now().Unix(),
  3020. UpdatedTime: time.Now().Unix(),
  3021. }
  3022. //只针对广慈医院
  3023. if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.Org.Id == 9987 || adminUserInfo.Org.Id == 9526 || template.TemplateId == 32 || adminUserInfo.Org.Id == 9918 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 4 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10517 || adminUserInfo.Org.Id == 10679 {
  3024. // 查询病人是否有透前评估数据
  3025. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3026. //如果有数据就插入
  3027. if errcode == nil {
  3028. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3029. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3030. record.BreathingRate = befor.BreathingRate
  3031. record.PulseFrequency = befor.PulseFrequency
  3032. record.Temperature = befor.Temperature
  3033. }
  3034. }
  3035. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3036. if newdialysisRecord.ID > 0 {
  3037. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3038. record.Temperature = 36.5
  3039. record.ArterialPressure = -100
  3040. record.DialysateTemperature = 36.5
  3041. record.Conductivity = 14
  3042. record.BreathingRate = "20"
  3043. record.VenousPressure = 80
  3044. record.TransmembranePressure = 60
  3045. record.Dispose = catheter_operation
  3046. }
  3047. //针对新化博翔
  3048. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3049. record.BloodOxygenSaturation = "99"
  3050. record.Conductivity = 14
  3051. record.DialysateTemperature = 36.5
  3052. record.BreathingRate = "20"
  3053. }
  3054. //针对兰溪人民医院的需求
  3055. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3056. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3057. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3058. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3059. record.Temperature = befor.Temperature
  3060. record.PulseFrequency = befor.PulseFrequency
  3061. record.BreathingRate = befor.BreathingRate
  3062. }
  3063. //针对乐山友谊医院的需求
  3064. if adminUserInfo.Org.Id == 10677 {
  3065. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3066. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3067. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3068. record.Temperature = befor.Temperature
  3069. record.PulseFrequency = befor.PulseFrequency
  3070. record.BreathingRate = befor.BreathingRate
  3071. }
  3072. //新化博翔
  3073. if adminUserInfo.Org.Id == 10447 {
  3074. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3075. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3076. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3077. record.BreathingRate = befor.BreathingRate
  3078. }
  3079. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3080. record.PulseFrequency = 80
  3081. record.Temperature = 36.5
  3082. }
  3083. //诊断灵山圣康
  3084. if adminUserInfo.Org.Id == 10375 {
  3085. record.Conductivity = 13.8
  3086. record.DialysateTemperature = 37
  3087. record.DialysateFlow = 500
  3088. record.BloodFlowVolume = 200
  3089. record.BreathingRate = "18"
  3090. record.SodiumConcentration = 140
  3091. }
  3092. //江成肾病医院
  3093. if adminUserInfo.Org.Id == 10517 {
  3094. record.SodiumConcentration = 138
  3095. record.DialysateTemperature = 36.5
  3096. }
  3097. err := service.CreateMonitor(&record)
  3098. //记录日志
  3099. byterequest, _ := json.Marshal(record)
  3100. monitorRecordLog := models.XtMonitorRecordLog{
  3101. RecordDate: record.MonitoringDate,
  3102. PatientId: record.PatientId,
  3103. Module: 1,
  3104. AdminUserId: adminUserInfo.AdminUser.Id,
  3105. Ctime: time.Now().Unix(),
  3106. Mtime: 0,
  3107. Status: 1,
  3108. UserOrgId: record.UserOrgId,
  3109. ErrLog: string(byterequest),
  3110. Source: "执行上机时新增监测",
  3111. }
  3112. service.CreateMonitorRecordLog(monitorRecordLog)
  3113. finish := models.XtDialysisFinish{
  3114. IsFinish: 1,
  3115. UserOrgId: adminUserInfo.Org.Id,
  3116. Status: 1,
  3117. Ctime: time.Now().Unix(),
  3118. Mtime: 0,
  3119. Module: 7,
  3120. RecordDate: schedulestartTime,
  3121. Sourse: 1,
  3122. PatientId: patientID,
  3123. }
  3124. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3125. if dialysisFinish.ID == 0 {
  3126. service.CreateDialysisFinish(finish)
  3127. }
  3128. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3129. redis := service.RedisClient()
  3130. //清空key 值
  3131. redis.Set(key, "", time.Second)
  3132. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3133. redis.Set(keyOne, "", time.Second)
  3134. defer redis.Close()
  3135. if err != nil {
  3136. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3137. return
  3138. }
  3139. }
  3140. go func() {
  3141. ssoDomain := beego.AppConfig.String("call_domain")
  3142. api := ssoDomain + "/index/uppatient"
  3143. values := make(url.Values)
  3144. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3145. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3146. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3147. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3148. http.PostForm(api, values)
  3149. }()
  3150. this.ServeSuccessJSON(map[string]interface{}{
  3151. "dialysis_order": newdialysisRecord,
  3152. "monitor": record,
  3153. })
  3154. return
  3155. }
  3156. func (c *DialysisAPIController) PostSolution() {
  3157. id, _ := c.GetInt64("patient", 0)
  3158. recordDateStr := c.GetString("record_date")
  3159. if id <= 0 {
  3160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3161. return
  3162. }
  3163. adminUserInfo := c.GetMobileAdminUserInfo()
  3164. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3165. if patient.ID == 0 {
  3166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3167. return
  3168. }
  3169. if len(recordDateStr) == 0 {
  3170. recordDateStr = time.Now().Format("2006-01-02")
  3171. }
  3172. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3173. if parseDateErr != nil {
  3174. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3175. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3176. return
  3177. }
  3178. mode_id, _ := c.GetInt64("mode_id", 0)
  3179. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3180. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3181. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3182. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3183. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3184. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3185. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3186. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3187. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3188. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3189. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3190. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3191. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3192. kalium, _ := c.GetFloat("kalium", 0)
  3193. sodium, _ := c.GetFloat("sodium", 0)
  3194. calcium, _ := c.GetFloat("calcium", 0)
  3195. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3196. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3197. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3198. glucose, _ := c.GetFloat("glucose", 0)
  3199. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3200. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3201. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3202. conductivity, _ := c.GetFloat("conductivity", 0)
  3203. remark := c.GetString("remark")
  3204. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3205. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3206. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3207. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3208. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3209. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3210. special_medicine_other := c.GetString("special_medicine_other")
  3211. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3212. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3213. blood_access, _ := c.GetInt64("blood_access", 0)
  3214. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3215. body_fluid_other := c.GetString("body_fluid_other")
  3216. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3217. niprocart, _ := c.GetInt64("niprocart", 0)
  3218. jms, _ := c.GetInt64("jms", 0)
  3219. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3220. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3221. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3222. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3223. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3224. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3225. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3226. injector, _ := c.GetInt64("injector", 0)
  3227. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3228. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3229. safe_package, _ := c.GetInt64("package", 0)
  3230. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3231. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3232. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3233. blood := c.GetString("blood")
  3234. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3235. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3236. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3237. displace_speed := c.GetString("displace_speed")
  3238. illness, _ := c.GetInt64("illness")
  3239. amylaceum := c.GetString("amylaceum")
  3240. single_time := c.GetString("single_time")
  3241. single_water := c.GetString("single_water")
  3242. replacement_flow := c.GetString("replacement_flow")
  3243. plasma_separator := c.GetString("plasma_separator")
  3244. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3245. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3246. oxygen_flow := c.GetString("oxygen_flow")
  3247. oxygen_time := c.GetString("oxygen_time")
  3248. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3249. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3250. puncture_needle := c.GetString("puncture_needle")
  3251. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3252. epo := c.GetString("epo")
  3253. epo_count, _ := c.GetFloat("epo_count", 0)
  3254. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3255. pre_impulse := c.GetString("pre_impulse")
  3256. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3257. admin_user_id, _ := c.GetInt64("admin_user_id")
  3258. is_water := c.GetString("is_water")
  3259. add_amount, _ := c.GetFloat("add_amount")
  3260. reduce_amount, _ := c.GetFloat("reduce_amount")
  3261. prescribing_number, _ := c.GetFloat("prescribing_number")
  3262. treatment_remark := c.GetString("treatment_remark")
  3263. prescription_sodium := c.GetString("prescription_sodium")
  3264. start_sodium := c.GetString("start_sodium")
  3265. sodium_curve := c.GetString("sodium_curve")
  3266. var is_war int64
  3267. if is_water == "是" {
  3268. is_war = 1
  3269. }
  3270. if is_water == "否" {
  3271. is_war = 2
  3272. }
  3273. if is_water == "请选择" {
  3274. is_war = 0
  3275. }
  3276. drhy_water := c.GetString("drhy_water")
  3277. dry_water_hour := c.GetString("dry_water_hour")
  3278. water_machine := c.GetString("water_machine")
  3279. dialysis_remark := c.GetString("dialysis_remark")
  3280. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3281. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3282. prescription_water, _ := c.GetFloat("prescription_water")
  3283. dialysis_strainer := c.GetString("dialysis_strainer")
  3284. chaptalization := c.GetString("chaptalization")
  3285. washing_time := c.GetString("washing_time")
  3286. warsh_count := c.GetString("warsh_count")
  3287. blood_access_part_id := c.GetString("blood_access_part_id")
  3288. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3289. dialyzate := c.GetString("dialyzate")
  3290. if mode_id > 0 {
  3291. var str string
  3292. //查找该机构用的是什么透析器
  3293. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3294. if filedConfig.ID > 0 {
  3295. str = dialyzerPerfusionApparatus
  3296. } else {
  3297. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3298. }
  3299. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3300. }
  3301. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3302. //
  3303. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3304. // if appRole.UserType == 3 {
  3305. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3306. // if getPermissionErr != nil {
  3307. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3308. // return
  3309. // } else if headNursePermission == nil {
  3310. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3311. // return
  3312. // }
  3313. // }
  3314. //}
  3315. // 查询信息规挡的设置天数
  3316. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3317. if infor.ID > 0 && infor.WeekDay > 0 {
  3318. var cha_time int64
  3319. timeNowStr := time.Now().Format("2006-01-02")
  3320. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3321. //今日的日期减去设置的日期
  3322. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3323. if cha_time >= recordDate.Unix() {
  3324. //查询审核是否允许
  3325. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3326. //申请状态不允许的情况 拒绝修改
  3327. if infor.ApplicationStatus != 1 {
  3328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3329. return
  3330. }
  3331. }
  3332. }
  3333. prescription := models.DialysisPrescription{
  3334. UserOrgId: adminUserInfo.Org.Id,
  3335. PatientId: id,
  3336. RecordDate: recordDate.Unix(),
  3337. ModeId: mode_id,
  3338. DialysisDuration: dialysis_duration,
  3339. Dialyzer: dialyzer,
  3340. PerfusionApparatus: perfusion_apparatus,
  3341. BloodFlowVolume: blood_flow_volume,
  3342. DewaterAmount: dewater_amount,
  3343. DisplaceLiqui: displace_liqui,
  3344. ReplacementWay: replacement_way,
  3345. Anticoagulant: anticoagulant,
  3346. AnticoagulantShouji: anticoagulant_shouji,
  3347. AnticoagulantWeichi: anticoagulant_weichi,
  3348. AnticoagulantZongliang: anticoagulant_zongliang,
  3349. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3350. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3351. Kalium: kalium,
  3352. Sodium: sodium,
  3353. Calcium: calcium,
  3354. Bicarbonate: bicarbonate,
  3355. Glucose: glucose,
  3356. // DryWeight: dry_weight,
  3357. DialysateFlow: dialysate_flow,
  3358. DialysateTemperature: dialysate_temperature,
  3359. Conductivity: conductivity,
  3360. Remark: remark,
  3361. Status: 1,
  3362. CreatedTime: time.Now().Unix(),
  3363. UpdatedTime: time.Now().Unix(),
  3364. DialysisDurationMinute: dialysisDurationMinute,
  3365. DialysisDurationHour: dialysisDurationHour,
  3366. TargetUltrafiltration: targetUltrafiltration,
  3367. DialysateFormulation: dialysateFormulation,
  3368. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3369. BodyFluid: body_fluid,
  3370. SpecialMedicine: special_medicine,
  3371. SpecialMedicineOther: special_medicine_other,
  3372. DisplaceLiquiPart: displace_liqui_part,
  3373. DisplaceLiquiValue: displace_liqui_value,
  3374. BloodAccess: blood_access,
  3375. Ultrafiltration: ultrafiltration,
  3376. BodyFluidOther: body_fluid_other,
  3377. ReplacementTotal: replacement_total,
  3378. Niprocart: niprocart,
  3379. Jms: jms,
  3380. FistulaNeedleSet: fistula_needle_set,
  3381. FistulaNeedleSet16: fistula_needle_set_16,
  3382. Hemoperfusion: hemoperfusion,
  3383. DialyserSterilised: dialyser_sterilised,
  3384. Filtryzer: filtryzer,
  3385. TargetKtv: target_ktv,
  3386. Dialyzers: dialyzers,
  3387. Injector: injector,
  3388. Bloodlines: bloodlines,
  3389. TubingHemodialysis: tubing_hemodialysis,
  3390. Package: safe_package,
  3391. ALiquid: a_liquid,
  3392. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3393. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3394. Blood: blood,
  3395. DialysisDialyszers: dialysis_dialyszers,
  3396. DialysisIrrigation: dialysis_irrigation,
  3397. AntioxidantCommodityName: antioxidant_commodity_name,
  3398. DisplaceSpeed: displace_speed,
  3399. Illness: illness,
  3400. Amylaceum: amylaceum,
  3401. SingleWater: single_water,
  3402. SingleTime: single_time,
  3403. ReplacementFlow: replacement_flow,
  3404. PlasmaSeparator: plasma_separator,
  3405. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3406. OxygenUptake: oxygen_uptake,
  3407. OxygenTime: oxygen_time,
  3408. OxygenFlow: oxygen_flow,
  3409. HemodialysisPipelines: hemodialysis_pipelines,
  3410. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3411. PunctureNeedle: puncture_needle,
  3412. PunctureNeedleCount: puncture_needle_count,
  3413. Epo: epo,
  3414. EpoCount: epo_count,
  3415. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3416. PreImpulse: impulse,
  3417. AdminUserId: admin_user_id,
  3418. IsWater: is_war,
  3419. DrhyWater: drhy_water,
  3420. DryWaterHour: dry_water_hour,
  3421. WaterMachine: water_machine,
  3422. AddAmount: add_amount,
  3423. ReduceAmount: reduce_amount,
  3424. DialysisRemark: dialysis_remark,
  3425. PrescribingNumber: prescribing_number,
  3426. PrescriptionSodium: prescription_sodium,
  3427. StartSodium: start_sodium,
  3428. SodiumCurve: sodium_curve,
  3429. TreatmentRemark: treatment_remark,
  3430. DialysisFluidFlow: dialysis_fluid_flow,
  3431. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3432. PrescriptionWater: prescription_water,
  3433. DialysisStrainer: dialysis_strainer,
  3434. Chaptalization: chaptalization,
  3435. WashingTime: washing_time,
  3436. WarshCount: warsh_count,
  3437. BloodAccessPartId: blood_access_part_id,
  3438. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3439. Dialyzate: dialyzate,
  3440. }
  3441. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3442. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3443. //
  3444. if appRole.UserType == 2 || appRole.UserType == 1 {
  3445. prescription_doctor = adminUserInfo.AdminUser.Id
  3446. prescription.PrescriptionDoctor = prescription_doctor
  3447. }
  3448. if dialysisPrescription.ID == 0 { //新增
  3449. prescription.Creater = adminUserInfo.AdminUser.Id
  3450. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3451. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3452. }
  3453. } else { //修改
  3454. if dialysisPrescription.Creater == 0 {
  3455. prescription.Creater = adminUserInfo.AdminUser.Id
  3456. } else {
  3457. prescription.Creater = dialysisPrescription.Creater
  3458. if adminUserInfo.Org.Id == 9882 {
  3459. if appRole.UserType == 2 || appRole.UserType == 1 {
  3460. prescription.Creater = adminUserInfo.AdminUser.Id
  3461. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3462. }
  3463. }
  3464. }
  3465. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3466. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3467. }
  3468. //if/**/
  3469. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3470. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3471. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3472. // if getPermissionErr != nil {
  3473. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3474. // return
  3475. // } else if headNursePermission == nil {
  3476. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3477. // return
  3478. // }
  3479. //}
  3480. //prescription.Creater = dialysisPrescription.Creater
  3481. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3482. prescription.Modifier = adminUserInfo.AdminUser.Id
  3483. prescription.ID = dialysisPrescription.ID
  3484. }
  3485. solution := models.DialysisSolution{
  3486. RegistrarsId: adminUserInfo.AdminUser.Id,
  3487. UserOrgId: adminUserInfo.Org.Id,
  3488. Doctor: prescription_doctor,
  3489. PatientId: id,
  3490. ModeId: mode_id,
  3491. DialysisDuration: dialysis_duration,
  3492. PerfusionApparatus: perfusion_apparatus,
  3493. BloodFlowVolume: blood_flow_volume,
  3494. Dewater: dewater_amount,
  3495. DisplaceLiqui: displace_liqui,
  3496. ReplacementWay: replacement_way,
  3497. Anticoagulant: anticoagulant,
  3498. AnticoagulantShouji: anticoagulant_shouji,
  3499. AnticoagulantWeichi: anticoagulant_weichi,
  3500. AnticoagulantZongliang: anticoagulant_zongliang,
  3501. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3502. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3503. Kalium: kalium,
  3504. Sodium: sodium,
  3505. Calcium: calcium,
  3506. Bicarbonate: bicarbonate,
  3507. Glucose: glucose,
  3508. // DryWeight: dry_weight,
  3509. DialysateFlow: dialysate_flow,
  3510. DialysateTemperature: dialysate_temperature,
  3511. Conductivity: conductivity,
  3512. Remark: remark,
  3513. Status: 1,
  3514. CreatedTime: time.Now().Unix(),
  3515. UpdatedTime: time.Now().Unix(),
  3516. DialysisDurationMinute: dialysisDurationMinute,
  3517. DialysisDurationHour: dialysisDurationHour,
  3518. TargetUltrafiltration: targetUltrafiltration,
  3519. DialysateFormulation: dialysateFormulation,
  3520. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3521. BodyFluid: body_fluid,
  3522. SpecialMedicine: special_medicine,
  3523. SpecialMedicineOther: special_medicine_other,
  3524. DisplaceLiquiPart: displace_liqui_part,
  3525. DisplaceLiquiValue: displace_liqui_value,
  3526. BloodAccess: blood_access,
  3527. Ultrafiltration: ultrafiltration,
  3528. BodyFluidOther: body_fluid_other,
  3529. ReplacementTotal: replacement_total,
  3530. TargetKtv: target_ktv,
  3531. DialysisDialyszers: dialysis_dialyszers,
  3532. DialysisIrrigation: dialysis_irrigation,
  3533. HemodialysisPipelines: hemodialysis_pipelines,
  3534. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3535. PunctureNeedle: puncture_needle,
  3536. PunctureNeedleCount: puncture_needle_count,
  3537. Epo: epo,
  3538. EpoCount: epo_count,
  3539. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3540. PreImpulse: impulse,
  3541. SolutionStatus: 1,
  3542. DialysisRemark: dialysis_remark,
  3543. PrescribingNumber: prescribing_number,
  3544. PrescriptionSodium: prescription_sodium,
  3545. StartSodium: start_sodium,
  3546. SodiumCurve: sodium_curve,
  3547. TreatmentRemark: treatment_remark,
  3548. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3549. DialysisFluidFlow: dialysis_fluid_flow,
  3550. PrescriptionWater: prescription_water,
  3551. DialysisStrainer: dialysis_strainer,
  3552. Chaptalization: chaptalization,
  3553. WashingTime: washing_time,
  3554. WarshCount: warsh_count,
  3555. BloodAccessPartId: blood_access_part_id,
  3556. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3557. Dialyzate: dialyzate,
  3558. }
  3559. //针对河间咸的
  3560. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  3561. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  3562. solution.DisplaceLiquiPart = 0
  3563. solution.DisplaceLiquiValue = 0
  3564. }
  3565. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  3566. prescription.DisplaceLiquiPart = 0
  3567. prescription.DisplaceLiquiValue = 0
  3568. }
  3569. }
  3570. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  3571. if solution.PrescribingNumber == 0 {
  3572. solution.PrescribingNumber = 1
  3573. }
  3574. if prescription.PrescribingNumber == 0 {
  3575. prescription.PrescribingNumber = 1
  3576. }
  3577. if solution.PrescribingNumber == 0 && id == 14682 {
  3578. solution.PrescribingNumber = 2
  3579. }
  3580. if solution.PrescribingNumber == 0 && id == 18560 {
  3581. solution.PrescribingNumber = 2
  3582. }
  3583. if prescription.PrescribingNumber == 0 && id == 14682 {
  3584. prescription.PrescribingNumber = 2
  3585. }
  3586. if prescription.PrescribingNumber == 0 && id == 18560 {
  3587. prescription.PrescribingNumber = 2
  3588. }
  3589. }
  3590. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  3591. //记录日志
  3592. byterequest, _ := json.Marshal(prescription)
  3593. prescriptionLog := models.XtDialysisPrescriptionLog{
  3594. UserOrgId: prescription.UserOrgId,
  3595. Ctime: time.Now().Unix(),
  3596. Mtime: 0,
  3597. ErrLog: string(byterequest),
  3598. AdminUserId: adminUserInfo.AdminUser.Id,
  3599. RecordDate: prescription.RecordDate,
  3600. PatientId: prescription.PatientId,
  3601. Source: "手机端新增长期处方",
  3602. Status: 1,
  3603. }
  3604. service.CreatePrescriptionLog(prescriptionLog)
  3605. finish := models.XtDialysisFinish{
  3606. IsFinish: 1,
  3607. UserOrgId: adminUserInfo.Org.Id,
  3608. Status: 1,
  3609. Ctime: time.Now().Unix(),
  3610. Mtime: 0,
  3611. Module: 1,
  3612. RecordDate: recordDate.Unix(),
  3613. Sourse: 1,
  3614. PatientId: id,
  3615. }
  3616. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  3617. if dialysisFinish.ID == 0 {
  3618. service.CreateDialysisFinish(finish)
  3619. }
  3620. //获取最新1条
  3621. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  3622. //更新状态
  3623. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  3624. //长沙南雅医院,自动生成抗凝剂的临时处方
  3625. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  3626. if prescribing_number == 0 {
  3627. prescribing_number = 1
  3628. }
  3629. advice := models.DoctorAdvice{
  3630. UserOrgId: adminUserInfo.Org.Id,
  3631. PatientId: id,
  3632. GroupNo: 0,
  3633. AdviceType: 2,
  3634. RecordDate: recordDate.Unix(),
  3635. AdviceDate: recordDate.Unix(),
  3636. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  3637. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  3638. AdviceDesc: "",
  3639. ReminderDate: 0,
  3640. SingleDose: prescription.AnticoagulantZongliang,
  3641. SingleDoseUnit: "iu",
  3642. DrugSpec: 0,
  3643. DrugSpecUnit: "",
  3644. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  3645. PrescribingNumberUnit: "支",
  3646. DeliveryWay: "静脉注射",
  3647. ExecutionFrequency: "上机前",
  3648. AdviceDoctor: 0,
  3649. Status: 1,
  3650. CreatedTime: time.Now().Unix(),
  3651. UpdatedTime: time.Now().Unix(),
  3652. IsPrescription: 1,
  3653. ExecutionState: 2,
  3654. StopState: 2,
  3655. IsSettle: 2,
  3656. }
  3657. // 查询排班信息
  3658. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3659. if schedulePatient.ID > 0 {
  3660. if schedulePatient.ScheduleType == 1 {
  3661. advice.StartTime = recordDate.Unix() + 6.5*60*60
  3662. }
  3663. if schedulePatient.ScheduleType == 2 {
  3664. advice.StartTime = recordDate.Unix() + 9*60*60
  3665. }
  3666. }
  3667. // 抗凝剂名称
  3668. switch anticoagulant {
  3669. case 1:
  3670. advice.AdviceName = "无肝素"
  3671. break
  3672. case 2:
  3673. advice.AdviceName = "普通肝素"
  3674. break
  3675. case 3:
  3676. advice.AdviceName = "低分子肝素"
  3677. break
  3678. case 4:
  3679. advice.AdviceName = "阿加曲班"
  3680. break
  3681. case 5:
  3682. advice.AdviceName = "枸橼酸钠"
  3683. break
  3684. case 6:
  3685. advice.AdviceName = "低分子肝素钙"
  3686. break
  3687. case 7:
  3688. advice.AdviceName = "低分子肝素钠"
  3689. break
  3690. case 8:
  3691. advice.AdviceName = "依诺肝素"
  3692. break
  3693. case 9:
  3694. advice.AdviceName = "达肝素"
  3695. break
  3696. case 10:
  3697. advice.AdviceName = "体外抗凝"
  3698. break
  3699. case 11:
  3700. advice.AdviceName = "那曲肝素"
  3701. break
  3702. case 12:
  3703. advice.AdviceName = "无抗凝剂"
  3704. break
  3705. }
  3706. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  3707. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  3708. advice.AdviceDoctor = appRole.AdminUserId
  3709. }
  3710. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  3711. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  3712. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  3713. advice.AdviceName = "低分子肝素钠注射液"
  3714. // 修改患者临时医嘱里的抗凝剂医嘱
  3715. advice.ID = advicePrescription.ID
  3716. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  3717. } else {
  3718. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  3719. advice.AdviceName = "低分子肝素钠注射液"
  3720. service.CreateDoctorAdvice(&advice)
  3721. }
  3722. }
  3723. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  3724. redis := service.RedisClient()
  3725. defer redis.Close()
  3726. //清空key 值
  3727. redis.Set(key, "", time.Second)
  3728. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  3729. redis.Set(keyOne, "", time.Second)
  3730. }
  3731. //获取key,清空redis
  3732. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3733. redis := service.RedisClient()
  3734. defer redis.Close()
  3735. //清空key 值
  3736. redis.Set(key, "", time.Second)
  3737. //清空长期医嘱的key
  3738. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3739. redis.Set(soulution_key, "", time.Second)
  3740. //查询最近透析准备表里是否存在 透析器 灌流器
  3741. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3742. redis.Set(keyOne, "", time.Second)
  3743. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  3744. redis.Set(keyTwo, "", time.Second)
  3745. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3746. redis.Set(keyThree, "", time.Second)
  3747. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  3748. redis.Set(keyFour, "", time.Second)
  3749. //splitStr := strings.Split(dialysis_dialyszers, ",")
  3750. //
  3751. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  3752. //
  3753. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  3754. //if len(mation)>0{
  3755. // for _, item := range splitStr {
  3756. // for _,it := range mation{
  3757. // if(item == it.SpecificationName){
  3758. //
  3759. // //查询最近一次的透析器
  3760. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3761. //
  3762. // if errcode == gorm.ErrRecordNotFound{
  3763. // //插入数据
  3764. // prepare := models.DialysisBeforePrepare{
  3765. // UserOrgId: adminUserInfo.Org.Id,
  3766. // PatientId: id,
  3767. // RecordDate: recordDate.Unix(),
  3768. // GoodTypeId: it.GoodTypeId,
  3769. // GoodId: it.ID,
  3770. // Count: 1,
  3771. // Ctime: time.Now().Unix(),
  3772. // Creater: adminUserInfo.AdminUser.Id,
  3773. // Status:1,
  3774. //
  3775. // }
  3776. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3777. // fmt.Println("",errcode)
  3778. // }
  3779. // }
  3780. // }
  3781. //
  3782. // }
  3783. //
  3784. // for _, item := range splitIrrigation {
  3785. // for _,it := range mation{
  3786. // if(item == it.SpecificationName){
  3787. // //查询最近一次的透析器
  3788. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3789. // if errcode == gorm.ErrRecordNotFound{
  3790. // //插入数据
  3791. // prepare := models.DialysisBeforePrepare{
  3792. // UserOrgId: adminUserInfo.Org.Id,
  3793. // PatientId: id,
  3794. // RecordDate: recordDate.Unix(),
  3795. // GoodTypeId: it.GoodTypeId,
  3796. // GoodId: it.ID,
  3797. // Count: 1,
  3798. // Ctime: time.Now().Unix(),
  3799. // Creater: adminUserInfo.AdminUser.Id,
  3800. // Status:1,
  3801. //
  3802. // }
  3803. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3804. // fmt.Println(errcode)
  3805. // }
  3806. // }
  3807. // }
  3808. // }
  3809. //}
  3810. c.ServeSuccessJSON(map[string]interface{}{
  3811. "solution": &solution,
  3812. "prescription": &prescription,
  3813. })
  3814. }
  3815. func (c *DialysisAPIController) GetAcceptsAssessment() {
  3816. patient, _ := c.GetInt64("patient", 0)
  3817. adminUserInfo := c.GetMobileAdminUserInfo()
  3818. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  3819. c.ServeSuccessJSON(map[string]interface{}{
  3820. "receiveTreatmentAsses": receiveTreatmentAsses,
  3821. })
  3822. }
  3823. func (this *DialysisAPIController) PostSignInfo() {
  3824. patientID, _ := this.GetInt64("patient_id")
  3825. recordDateStr := this.GetString("date")
  3826. if patientID <= 0 {
  3827. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3828. return
  3829. }
  3830. if len(recordDateStr) == 0 {
  3831. recordDateStr = time.Now().Format("2006-01-02")
  3832. }
  3833. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3834. if parseDateErr != nil {
  3835. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3836. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3837. return
  3838. }
  3839. adminInfo := this.GetMobileAdminUserInfo()
  3840. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  3841. if err != nil {
  3842. this.ErrorLog("签名失败:%v", err)
  3843. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3844. return
  3845. }
  3846. this.ServeSuccessJSON(map[string]interface{}{
  3847. "doctor_id": adminInfo.AdminUser.Id,
  3848. })
  3849. }
  3850. func (this *DialysisAPIController) GetLastMonitorRecord() {
  3851. patientID, _ := this.GetInt64("patient_id")
  3852. adminInfo := this.GetMobileAdminUserInfo()
  3853. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  3854. this.ServeSuccessJSON(map[string]interface{}{
  3855. "monitor": record,
  3856. })
  3857. }
  3858. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  3859. thisTime := time.Now()
  3860. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  3861. timeLayout := "2006-01-02 15:04:05"
  3862. loc, _ := time.LoadLocation("Local")
  3863. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3864. theAssessmentDateTime := theStartTime.Unix()
  3865. patientID, _ := this.GetInt64("patient_id")
  3866. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  3867. adminInfo := this.GetMobileAdminUserInfo()
  3868. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3869. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3870. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  3871. var ultrafiltration_rate float64
  3872. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3873. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3874. fmt.Println(evaluation)
  3875. fmt.Println("prescription.ID", prescription.ID)
  3876. if prescription.ID > 0 {
  3877. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3878. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3879. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  3880. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3881. record.UltrafiltrationRate = ultrafiltration_rate
  3882. }
  3883. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  3884. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3885. record.UltrafiltrationRate = ultrafiltration_rate
  3886. }
  3887. if adminInfo.Org.Id == 10510 {
  3888. record.UltrafiltrationRate = 0
  3889. }
  3890. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  3891. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  3892. record.UltrafiltrationRate = ultrafiltration_rate
  3893. }
  3894. if template.TemplateId == 20 || template.TemplateId == 22 {
  3895. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3896. record.UltrafiltrationRate = ultrafiltration_rate
  3897. }
  3898. // 只针对方济医院
  3899. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  3900. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3901. ultrafiltration_rate = value
  3902. record.UltrafiltrationRate = ultrafiltration_rate
  3903. }
  3904. if template.TemplateId == 41 || template.TemplateId == 47 {
  3905. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3906. record.UltrafiltrationRate = ultrafiltration_rate
  3907. }
  3908. if template.TemplateId == 43 {
  3909. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3910. record.UltrafiltrationRate = ultrafiltration_rate
  3911. }
  3912. if template.TemplateId == 46 || template.TemplateId == 54 {
  3913. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3914. record.UltrafiltrationRate = ultrafiltration_rate
  3915. }
  3916. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 9829 || adminInfo.Org.Id == 10440 || adminInfo.Org.Id == 10610 || adminInfo.Org.Id == 10537 {
  3917. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  3918. record.UltrafiltrationRate = ultrafiltration_rate
  3919. }
  3920. if adminInfo.Org.Id == 10469 {
  3921. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  3922. record.UltrafiltrationRate = ultrafiltration_rate
  3923. }
  3924. if adminInfo.Org.Id == 10667 {
  3925. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  3926. record.UltrafiltrationRate = ultrafiltration_rate
  3927. }
  3928. if adminInfo.Org.Id == 10471 {
  3929. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3930. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3931. }
  3932. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  3933. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3934. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3935. }
  3936. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  3937. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3938. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3939. }
  3940. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  3941. record.UltrafiltrationRate = 0
  3942. }
  3943. //if template.TemplateId == 47 {
  3944. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3945. // record.UltrafiltrationRate = ultrafiltration_rate
  3946. //}
  3947. }
  3948. }
  3949. // record.UltrafiltrationRate = ultrafiltration_rate
  3950. record.UltrafiltrationVolume = 0
  3951. 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
  3952. if ultrafiltration_rate > 0 {
  3953. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  3954. record.UltrafiltrationVolume = value
  3955. }
  3956. }
  3957. if template.TemplateId == 6 || template.TemplateId == 65 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 || template.TemplateId == 41 || template.TemplateId == 43 || template.TemplateId == 47 || template.TemplateId == 54 || adminInfo.Org.Id == 10599 { //adminInfo.Org.Id == 9538
  3958. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  3959. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3960. record.UltrafiltrationVolume = ultrafiltration_volume
  3961. }
  3962. }
  3963. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  3964. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3965. record.UltrafiltrationVolume = ultrafiltration_volume
  3966. }
  3967. //长沙南雅
  3968. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 10469 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10610 || adminInfo.Org.Id == 10537 || adminInfo.Org.Id == 10667 {
  3969. if ultrafiltration_rate > 0 {
  3970. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3971. record.UltrafiltrationVolume = ultrafiltration_volume
  3972. }
  3973. }
  3974. if adminInfo.Org.Id == 10471 {
  3975. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3976. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3977. }
  3978. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  3979. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3980. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3981. }
  3982. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  3983. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3984. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3985. }
  3986. //长沙南雅累计血容量自动计算
  3987. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  3988. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  3989. //}
  3990. if template.TemplateId == 47 || template.TemplateId == 54 {
  3991. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  3992. }
  3993. if adminInfo.Org.Id == 10510 {
  3994. record.UltrafiltrationVolume = 0
  3995. }
  3996. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  3997. this.ServeSuccessJSON(map[string]interface{}{
  3998. "monitor": record,
  3999. "lastMonitorRecordList": lastMonitorRecordList,
  4000. })
  4001. }
  4002. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4003. record_id, _ := this.GetInt64("id")
  4004. nurseID, _ := this.GetInt64("start_nurse")
  4005. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4006. bedID, _ := this.GetInt64("bed")
  4007. start_time := this.GetString("start_time")
  4008. schedual_type, _ := this.GetInt64("schedual_type")
  4009. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4010. change_nurse, _ := this.GetInt64("change_nurse")
  4011. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4012. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4013. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4014. patient_id, _ := this.GetInt64("patient_id")
  4015. record_date, _ := this.GetInt64("record_date")
  4016. puncture_needle := this.GetString("puncture_needle")
  4017. puncture_way := this.GetString("puncture_way")
  4018. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4019. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4020. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4021. nuclein_date_str := this.GetString("nuclein_date_str")
  4022. order_remark := this.GetString("order_remark")
  4023. schedule_remark := this.GetString("schedule_remark")
  4024. catheter_operation := this.GetString("catheter_operation")
  4025. blood_flow_volume := this.GetString("blood_flow_volume")
  4026. blood_drawing, _ := this.GetInt64("blood_drawing")
  4027. if record_id == 0 {
  4028. this.ErrorLog("id:%v", record_id)
  4029. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4030. return
  4031. }
  4032. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4033. if parseStartDateErr != nil {
  4034. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4035. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4036. return
  4037. }
  4038. adminUserInfo := this.GetMobileAdminUserInfo()
  4039. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4040. if getNurseErr != nil {
  4041. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4042. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4043. return
  4044. } else if nurse == nil {
  4045. this.ErrorLog("护士不存在")
  4046. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4047. return
  4048. }
  4049. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4050. //if getNurseErr != nil {
  4051. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4052. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4053. // return
  4054. //} else if nurse == nil {
  4055. // this.ErrorLog("护士不存在")
  4056. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4057. // return
  4058. //}
  4059. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4060. if getDeviceNumberErr != nil {
  4061. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4062. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4063. return
  4064. } else if deviceNumber == nil {
  4065. this.ErrorLog("床位号不存在")
  4066. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4067. return
  4068. }
  4069. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4070. //
  4071. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4072. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4073. // if getPermissionErr != nil {
  4074. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4075. // return
  4076. // } else if headNursePermission == nil {
  4077. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4078. // return
  4079. // }
  4080. //}
  4081. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4082. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4083. timeLayout := "2006-01-02 15:04:05"
  4084. loc, _ := time.LoadLocation("Local")
  4085. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4086. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4087. schedulestartTime := theStartTime.Unix()
  4088. scheduleendTime := theEndTime.Unix()
  4089. var theNucleinDate int64
  4090. timeLayoutOne := "2006-01-02"
  4091. if len(nuclein_date_str) > 0 {
  4092. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4093. if err != nil {
  4094. utils.ErrorLog(err.Error())
  4095. }
  4096. theNucleinDate = theTime.Unix()
  4097. }
  4098. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4099. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4100. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4101. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4102. if err == gorm.ErrRecordNotFound { //空床位
  4103. // 修改了床位逻辑
  4104. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4105. if daySchedule.ID > 0 {
  4106. //daySchedule.BedId = bedID
  4107. //daySchedule.PartitionId = deviceNumber.ZoneID
  4108. //daySchedule.ScheduleType = schedual_type
  4109. //daySchedule.UpdatedTime = time.Now().Unix()
  4110. //err := service.UpdateSchedule(&daySchedule)
  4111. xtSchedule := models.Schedule{
  4112. PartitionId: deviceNumber.ZoneID,
  4113. BedId: bedID,
  4114. ScheduleType: schedual_type,
  4115. UpdatedTime: time.Now().Unix(),
  4116. }
  4117. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4118. if err != nil {
  4119. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4120. return
  4121. }
  4122. }
  4123. } else if err == nil {
  4124. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4125. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4126. if daySchedule.ID > 0 {
  4127. //daySchedule.BedId = bedID
  4128. //daySchedule.PartitionId = deviceNumber.ZoneID
  4129. //
  4130. //daySchedule.ScheduleType = schedual_type
  4131. //daySchedule.UpdatedTime = time.Now().Unix()
  4132. //err := service.UpdateSchedule(&daySchedule)
  4133. xtSchedule := models.Schedule{
  4134. PartitionId: deviceNumber.ZoneID,
  4135. BedId: bedID,
  4136. ScheduleType: schedual_type,
  4137. UpdatedTime: time.Now().Unix(),
  4138. }
  4139. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4140. if err != nil {
  4141. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4142. return
  4143. }
  4144. }
  4145. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4146. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4147. return
  4148. }
  4149. } else if err != nil {
  4150. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4151. return
  4152. }
  4153. }
  4154. dialysisRecord := &models.DialysisOrder{
  4155. ID: record_id,
  4156. UserOrgId: adminUserInfo.Org.Id,
  4157. BedID: bedID,
  4158. StartNurse: nurseID,
  4159. StartTime: startDate.Unix(),
  4160. PunctureNurse: puncture_nurse,
  4161. Creator: adminUserInfo.AdminUser.Id,
  4162. Modifier: adminUserInfo.AdminUser.Id,
  4163. WashpipeNurse: washpipe_nurse,
  4164. SchedualType: schedual_type,
  4165. ChangeNurse: change_nurse,
  4166. DifficultPunctureNurse: difficult_puncture_nurse,
  4167. NewFistulaNurse: new_fistula_nurse,
  4168. QualityNurseId: quality_nurse_id,
  4169. PunctureNeedle: puncture_needle,
  4170. PunctureWay: puncture_way,
  4171. DialysisDialyszers: dialysis_dialyszers,
  4172. DialysisIrrigation: dialysis_irrigation,
  4173. BloodAccessId: blood_access_id,
  4174. NucleinDate: theNucleinDate,
  4175. OrderRemark: order_remark,
  4176. ScheduleRemark: schedule_remark,
  4177. CatheterOperation: catheter_operation,
  4178. BloodFlowVolume: blood_flow_volume,
  4179. BloodDrawing: blood_drawing,
  4180. }
  4181. //修改床位号需要重新消毒
  4182. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4183. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4184. //查询第一条监测
  4185. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4186. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4187. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4188. redis := service.RedisClient()
  4189. //清空key 值
  4190. redis.Set(key, "", time.Second)
  4191. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4192. redis.Set(keyOne, "", time.Second)
  4193. defer redis.Close()
  4194. }
  4195. // 查询信息规挡的设置天数
  4196. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4197. if infor.ID > 0 && infor.WeekDay > 0 {
  4198. var cha_time int64
  4199. timeNowStr := time.Now().Format("2006-01-02")
  4200. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4201. //今日的日期减去设置的日期
  4202. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4203. if cha_time >= record_date {
  4204. //查询审核是否允许
  4205. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4206. //申请状态不允许的情况 拒绝修改
  4207. if infor.ApplicationStatus != 1 {
  4208. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4209. return
  4210. }
  4211. }
  4212. }
  4213. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4214. order, _ := service.GetLastPatientOrder(record_id)
  4215. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4216. redis := service.RedisClient()
  4217. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4218. redis.Set(key, "", time.Second)
  4219. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4220. //清空key 值
  4221. redis.Set(keyOne, "", time.Second)
  4222. scheduleDateStartOne := startDate.Format("2006-01-02")
  4223. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4224. redis.Set(keyTwo, "", time.Second)
  4225. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4226. redis.Set(keyThree, "", time.Second)
  4227. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4228. redis.Set(keyFour, "", time.Second)
  4229. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4230. redis.Set(keyFive, "", time.Second)
  4231. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4232. redis.Set(keySix, "", time.Second)
  4233. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4234. redis.Set(keySeven, "", time.Second)
  4235. if updateErr != nil {
  4236. this.ErrorLog("修改上机失败:%v", updateErr)
  4237. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4238. return
  4239. }
  4240. if updateErr == nil {
  4241. if tempDialysisRecord.Stage == 2 {
  4242. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4243. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4244. fmt.Println(value)
  4245. a, b := math.Modf(value)
  4246. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4247. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4248. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4249. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4250. redis := service.RedisClient()
  4251. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4252. redis.Set(key, "", time.Second)
  4253. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4254. redis.Set(keyOne, "", time.Second)
  4255. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4256. //清空key 值
  4257. redis.Set(keySix, "", time.Second)
  4258. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4259. redis.Set(keySeven, "", time.Second)
  4260. redis.Close()
  4261. if updateAssessmentErr != nil {
  4262. utils.ErrorLog("%v", updateAssessmentErr)
  4263. }
  4264. }
  4265. }
  4266. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4267. this.ServeSuccessJSON(map[string]interface{}{
  4268. "dialysis_order": dialysisRecords,
  4269. })
  4270. }
  4271. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4272. record_id, _ := c.GetInt64("id")
  4273. nurseID, _ := c.GetInt64("nurse")
  4274. end_time := c.GetString("end_time")
  4275. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4276. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4277. catheter := c.GetString("catheter")
  4278. cruor := c.GetString("cruor")
  4279. mission := c.GetString("mission")
  4280. condenser := c.GetString("condenser")
  4281. if record_id <= 0 || nurseID <= 0 {
  4282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4283. return
  4284. }
  4285. adminUserInfo := c.GetMobileAdminUserInfo()
  4286. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4287. if getNurseErr != nil {
  4288. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4290. return
  4291. } else if nurse == nil {
  4292. c.ErrorLog("护士不存在")
  4293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4294. return
  4295. }
  4296. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4297. if parseEndDateErr != nil {
  4298. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4300. return
  4301. }
  4302. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4303. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4304. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4305. // if getPermissionErr != nil {
  4306. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4307. // return
  4308. // } else if headNursePermission == nil {
  4309. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4310. // return
  4311. // }
  4312. //}
  4313. // 查询信息规挡的设置天数
  4314. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4315. if infor.ID > 0 {
  4316. var cha_time int64
  4317. timeNowStr := time.Now().Format("2006-01-02")
  4318. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4319. //今日的日期减去设置的日期
  4320. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4321. if cha_time >= tempDialysisRecords.DialysisDate {
  4322. //查询审核是否允许
  4323. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  4324. //申请状态不允许的情况 拒绝修改
  4325. if infor.ApplicationStatus != 1 {
  4326. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4327. return
  4328. }
  4329. }
  4330. }
  4331. dialysisRecord := &models.DialysisOrder{
  4332. ID: record_id,
  4333. UserOrgId: adminUserInfo.Org.Id,
  4334. EndTime: endDate.Unix(),
  4335. FinishNurse: nurseID,
  4336. FinishModifier: adminUserInfo.AdminUser.Id,
  4337. PuncturePointHaematoma: puncture_point_haematoma,
  4338. BloodAccessInternalFistula: blood_access_internal_fistula,
  4339. Catheter: catheter,
  4340. Cruor: cruor,
  4341. Mission: mission,
  4342. Condenser: condenser,
  4343. }
  4344. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4345. redis := service.RedisClient()
  4346. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4347. //清空key 值
  4348. redis.Set(key, "", time.Second)
  4349. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4350. //清空key 值
  4351. redis.Set(keyOne, "", time.Second)
  4352. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4353. redis.Set(keySeven, "", time.Second)
  4354. redis.Close()
  4355. if updateErr != nil {
  4356. c.ErrorLog("修改下机失败:%v", updateErr)
  4357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4358. return
  4359. }
  4360. if updateErr == nil {
  4361. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4362. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4363. a, b := math.Modf(value)
  4364. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4365. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4366. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4367. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4368. redis := service.RedisClient()
  4369. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4370. redis.Set(keyTen, "", time.Second)
  4371. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4372. redis.Set(keyTwo, "", time.Second)
  4373. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4374. redis.Set(key, "", time.Second)
  4375. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4376. redis.Set(keyThree, "", time.Second)
  4377. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4378. redis.Set(keySeven, "", time.Second)
  4379. defer redis.Close()
  4380. if updateAssessmentErr != nil {
  4381. utils.ErrorLog("%v", updateAssessmentErr)
  4382. }
  4383. }
  4384. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4385. c.ServeSuccessJSON(map[string]interface{}{
  4386. "dialysis_order": dialysisRecords,
  4387. })
  4388. }
  4389. func (c *DialysisAPIController) GetLongAdvice() {
  4390. patient_id, _ := c.GetInt64("id")
  4391. adminUserInfo := c.GetMobileAdminUserInfo()
  4392. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4393. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4394. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4395. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4396. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4397. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4398. c.ServeSuccessJSON(map[string]interface{}{
  4399. "status": "1",
  4400. })
  4401. return
  4402. } else { //开启推送提醒
  4403. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4404. var advice_three []*models.DoctorAdvice
  4405. recordDateStr := time.Now().Format("2006-01-02")
  4406. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4407. nowtime := recordDate.Unix()
  4408. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4409. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4410. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4411. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4412. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4413. for _, advice := range advices {
  4414. if advice.FrequencyType == 3 {
  4415. t := time.Now()
  4416. week := int(t.Weekday())
  4417. fmt.Println(t.Weekday())
  4418. fmt.Println(week)
  4419. switch week {
  4420. case 1:
  4421. if strings.Index(advice.WeekDay, "周一") == -1 {
  4422. advice_three = append(advice_three, advice)
  4423. }
  4424. break
  4425. case 2:
  4426. if strings.Index(advice.WeekDay, "周二") == -1 {
  4427. advice_three = append(advice_three, advice)
  4428. }
  4429. break
  4430. case 3:
  4431. if strings.Index(advice.WeekDay, "周三") == -1 {
  4432. advice_three = append(advice_three, advice)
  4433. }
  4434. break
  4435. case 4:
  4436. if strings.Index(advice.WeekDay, "周四") == -1 {
  4437. advice_three = append(advice_three, advice)
  4438. }
  4439. break
  4440. case 5:
  4441. if strings.Index(advice.WeekDay, "周五") == -1 {
  4442. advice_three = append(advice_three, advice)
  4443. }
  4444. break
  4445. case 6:
  4446. if strings.Index(advice.WeekDay, "周六") == -1 {
  4447. advice_three = append(advice_three, advice)
  4448. }
  4449. break
  4450. case 0:
  4451. if strings.Index(advice.WeekDay, "周日") == -1 {
  4452. advice_three = append(advice_three, advice)
  4453. }
  4454. break
  4455. }
  4456. }
  4457. }
  4458. for _, advice := range advices_two {
  4459. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4460. now := p.Unix()
  4461. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4462. dayStr2 := "-" + dayStr
  4463. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4464. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4465. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4466. for _, ad := range advices {
  4467. advice_three = append(advice_three, ad)
  4468. }
  4469. }
  4470. if err == nil {
  4471. c.ServeSuccessJSON(map[string]interface{}{
  4472. "status": "2",
  4473. "advices": advices,
  4474. "advices_two": RemoveRepeatedElement(advice_three),
  4475. "is_open_remind": config.IsOpenRemind,
  4476. "his_config_open": hisConfig.IsOpen,
  4477. "is_advice_open": is_advice_open.IsAdviceOpen,
  4478. "prescription_open": prescription_open.IsOpen,
  4479. })
  4480. }
  4481. }
  4482. }
  4483. func (c *DialysisAPIController) GetLongAdviceOne() {
  4484. patient_id, _ := c.GetInt64("id")
  4485. startTime := c.GetString("schedule_date")
  4486. timeLayout := "2006-01-02"
  4487. loc, _ := time.LoadLocation("Local")
  4488. var theStartTime int64
  4489. if len(startTime) > 0 {
  4490. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4491. if err != nil {
  4492. utils.ErrorLog(err.Error())
  4493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4494. return
  4495. }
  4496. theStartTime = theTime.Unix()
  4497. }
  4498. adminUserInfo := c.GetMobileAdminUserInfo()
  4499. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4500. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4501. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4502. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4503. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4504. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4505. c.ServeSuccessJSON(map[string]interface{}{
  4506. "status": "1",
  4507. })
  4508. return
  4509. } else { //开启推送提醒
  4510. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4511. var advice_three []*models.DoctorAdvice
  4512. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  4513. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  4514. for _, advice := range advices {
  4515. if advice.FrequencyType == 3 {
  4516. t := time.Now()
  4517. week := int(t.Weekday())
  4518. fmt.Println(t.Weekday())
  4519. fmt.Println(week)
  4520. switch week {
  4521. case 1:
  4522. if strings.Index(advice.WeekDay, "周一") == -1 {
  4523. advice_three = append(advice_three, advice)
  4524. }
  4525. break
  4526. case 2:
  4527. if strings.Index(advice.WeekDay, "周二") == -1 {
  4528. advice_three = append(advice_three, advice)
  4529. }
  4530. break
  4531. case 3:
  4532. if strings.Index(advice.WeekDay, "周三") == -1 {
  4533. advice_three = append(advice_three, advice)
  4534. }
  4535. break
  4536. case 4:
  4537. if strings.Index(advice.WeekDay, "周四") == -1 {
  4538. advice_three = append(advice_three, advice)
  4539. }
  4540. break
  4541. case 5:
  4542. if strings.Index(advice.WeekDay, "周五") == -1 {
  4543. advice_three = append(advice_three, advice)
  4544. }
  4545. break
  4546. case 6:
  4547. if strings.Index(advice.WeekDay, "周六") == -1 {
  4548. advice_three = append(advice_three, advice)
  4549. }
  4550. break
  4551. case 0:
  4552. if strings.Index(advice.WeekDay, "周日") == -1 {
  4553. advice_three = append(advice_three, advice)
  4554. }
  4555. break
  4556. }
  4557. }
  4558. }
  4559. for _, advice := range advices_two {
  4560. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4561. now := p.Unix()
  4562. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4563. dayStr2 := "-" + dayStr
  4564. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4565. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4566. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4567. for _, ad := range advices {
  4568. advice_three = append(advice_three, ad)
  4569. }
  4570. }
  4571. if err == nil {
  4572. c.ServeSuccessJSON(map[string]interface{}{
  4573. "status": "2",
  4574. "advices": advices,
  4575. "advices_two": RemoveRepeatedElement(advice_three),
  4576. "is_open_remind": config.IsOpenRemind,
  4577. "his_config_open": hisConfig.IsOpen,
  4578. "is_advice_open": is_advice_open.IsAdviceOpen,
  4579. "prescription_open": prescription_open.IsOpen,
  4580. })
  4581. }
  4582. }
  4583. }
  4584. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4585. newArr = make([]*models.DoctorAdvice, 0)
  4586. for i := 0; i < len(arr); i++ {
  4587. repeat := false
  4588. for j := i + 1; j < len(arr); j++ {
  4589. if arr[i].ID == arr[j].ID {
  4590. repeat = true
  4591. break
  4592. }
  4593. }
  4594. if !repeat {
  4595. newArr = append(newArr, arr[i])
  4596. }
  4597. }
  4598. return
  4599. }
  4600. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  4601. patient, _ := c.GetInt64("id", 0)
  4602. groupNo, _ := c.GetInt64("groupno", 0)
  4603. if patient <= 0 {
  4604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4605. return
  4606. }
  4607. adminUserInfo := c.GetMobileAdminUserInfo()
  4608. dataBody := make(map[string]interface{}, 0)
  4609. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4610. if err != nil {
  4611. utils.ErrorLog(err.Error())
  4612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4613. return
  4614. }
  4615. utils.ErrorLog("%v", dataBody)
  4616. timeLayout := "2006-01-02 15:04"
  4617. loc, _ := time.LoadLocation("Local")
  4618. timeLayout2 := "2006-01-02"
  4619. loc2, _ := time.LoadLocation("Local")
  4620. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4621. utils.ErrorLog("advice_type")
  4622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4623. return
  4624. }
  4625. adviceType := int64(2)
  4626. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4627. utils.ErrorLog("advice_date")
  4628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4629. return
  4630. }
  4631. adviceDate, _ := dataBody["advice_date"].(string)
  4632. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4633. AdviceDate := theTime.Unix()
  4634. RecordDate := theTime.Unix()
  4635. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4636. utils.ErrorLog("start_time")
  4637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4638. return
  4639. }
  4640. startTime, _ := dataBody["start_time"].(string)
  4641. if len(startTime) == 0 {
  4642. utils.ErrorLog("len(start_time) == 0")
  4643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4644. return
  4645. }
  4646. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4647. if err != nil {
  4648. utils.ErrorLog(err.Error())
  4649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4650. return
  4651. }
  4652. StartTime := theTime.Unix()
  4653. Remark := ""
  4654. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4655. remark, _ := dataBody["remark"].(string)
  4656. Remark = remark
  4657. }
  4658. var advices []*models.GroupAdvice
  4659. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4660. utils.ErrorLog("advices")
  4661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4662. return
  4663. }
  4664. adviceNames := dataBody["advices"].([]interface{})
  4665. for _, adviceNameMap := range adviceNames {
  4666. adviceNameM := adviceNameMap.(map[string]interface{})
  4667. var advice models.GroupAdvice
  4668. advice.Remark = Remark
  4669. advice.AdviceType = adviceType
  4670. advice.StartTime = StartTime
  4671. advice.AdviceDate = AdviceDate
  4672. advice.RecordDate = RecordDate
  4673. advice.Status = 1
  4674. advice.CreatedTime = time.Now().Unix()
  4675. advice.UpdatedTime = time.Now().Unix()
  4676. advice.StopState = 2
  4677. advice.ExecutionState = 2
  4678. advice.UserOrgId = adminUserInfo.Org.Id
  4679. advice.PatientId = patient
  4680. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4681. advice.IsSettle = 2
  4682. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4683. utils.ErrorLog("advice_name")
  4684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4685. return
  4686. }
  4687. adviceName, _ := adviceNameM["advice_name"].(string)
  4688. if len(adviceName) == 0 {
  4689. utils.ErrorLog("len(advice_name) == 0")
  4690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4691. return
  4692. }
  4693. advice.AdviceName = adviceName
  4694. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4695. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4696. advice.DrugSpec = drugSpec
  4697. }
  4698. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4699. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4700. advice.AdviceDesc = adviceDesc
  4701. }
  4702. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4703. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4704. advice.DrugSpecUnit = drugSpecUnit
  4705. }
  4706. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4707. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4708. // advice.SingleDose = singleDose
  4709. //}
  4710. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4711. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4712. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4713. }
  4714. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4715. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4716. advice.SingleDoseUnit = singleDoseUnit
  4717. }
  4718. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4719. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4720. // advice.PrescribingNumber = prescribingNumber
  4721. //}
  4722. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4723. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4724. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4725. }
  4726. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4727. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4728. advice.PrescribingNumberUnit = prescribingNumberUnit
  4729. }
  4730. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4731. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4732. advice.DeliveryWay = deliveryWay
  4733. }
  4734. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4735. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4736. advice.ExecutionFrequency = executionFrequency
  4737. }
  4738. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  4739. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  4740. advice.FrequencyType = frequency_type
  4741. }
  4742. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  4743. day_count := int64(adviceNameM["day_count"].(float64))
  4744. advice.DayCount = day_count
  4745. }
  4746. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  4747. week_day, _ := adviceNameM["week_day"].(string)
  4748. advice.WeekDay = week_day
  4749. }
  4750. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  4751. way := int64(adviceNameM["way"].(float64))
  4752. advice.Way = way
  4753. }
  4754. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  4755. drug_id := int64(adviceNameM["drug_id"].(float64))
  4756. advice.DrugId = drug_id
  4757. }
  4758. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  4759. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  4760. advice.DrugNameId = drug_name_id
  4761. }
  4762. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  4763. remark, _ := adviceNameM["remark"].(string)
  4764. advice.Remark = remark
  4765. }
  4766. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  4767. groupno := int64(adviceNameM["groupno"].(float64))
  4768. advice.GroupNo = groupno
  4769. }
  4770. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  4771. template_id, _ := adviceNameM["template_id"].(string)
  4772. advice.TemplateId = template_id
  4773. }
  4774. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  4775. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4776. advice.ExecutionFrequency = executionFrequency
  4777. }
  4778. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  4779. children := adviceNameM["child"].([]interface{})
  4780. if len(children) > 0 {
  4781. for _, childrenMap := range children {
  4782. childMap := childrenMap.(map[string]interface{})
  4783. var child models.GroupAdvice
  4784. child.Remark = Remark
  4785. child.AdviceType = adviceType
  4786. child.StartTime = StartTime
  4787. child.AdviceDate = AdviceDate
  4788. child.RecordDate = RecordDate
  4789. child.Status = 1
  4790. child.CreatedTime = time.Now().Unix()
  4791. child.UpdatedTime = time.Now().Unix()
  4792. child.StopState = 2
  4793. child.ExecutionState = 2
  4794. child.UserOrgId = adminUserInfo.Org.Id
  4795. child.PatientId = patient
  4796. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  4797. child.IsSettle = 1
  4798. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  4799. utils.ErrorLog("child advice_name")
  4800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4801. return
  4802. }
  4803. childAdviceName, _ := childMap["advice_name"].(string)
  4804. if len(childAdviceName) == 0 {
  4805. utils.ErrorLog("len(child advice_name) == 0")
  4806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4807. return
  4808. }
  4809. child.AdviceName = childAdviceName
  4810. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  4811. childAdviceDesc, _ := childMap["advice_desc"].(string)
  4812. child.AdviceDesc = childAdviceDesc
  4813. }
  4814. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  4815. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  4816. child.DrugSpec = childDrugSpec
  4817. }
  4818. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  4819. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  4820. child.DrugSpecUnit = childDrugSpecUnit
  4821. }
  4822. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  4823. child.SingleDose = childMap["single_dose"].(float64)
  4824. }
  4825. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  4826. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  4827. child.SingleDoseUnit = childSingleDoseUnit
  4828. }
  4829. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  4830. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  4831. }
  4832. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  4833. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  4834. child.PrescribingNumberUnit = childPrescribingNumberUnit
  4835. }
  4836. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  4837. groupno := int64(childMap["groupno"].(float64))
  4838. advice.GroupNo = groupno
  4839. }
  4840. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  4841. remark, _ := childMap["remark"].(string)
  4842. child.Remark = remark
  4843. }
  4844. child.DeliveryWay = advice.DeliveryWay
  4845. child.ExecutionFrequency = advice.ExecutionFrequency
  4846. advice.Children = append(advice.Children, &child)
  4847. }
  4848. }
  4849. }
  4850. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  4851. if temp_advice.ID == 0 {
  4852. advices = append(advices, &advice)
  4853. }
  4854. }
  4855. if len(advices) > 0 {
  4856. finish := models.XtDialysisFinish{
  4857. IsFinish: 1,
  4858. UserOrgId: adminUserInfo.Org.Id,
  4859. Status: 1,
  4860. Ctime: time.Now().Unix(),
  4861. Mtime: 0,
  4862. Module: 4,
  4863. RecordDate: AdviceDate,
  4864. Sourse: 1,
  4865. PatientId: patient,
  4866. }
  4867. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  4868. if dialysisFinish.ID == 0 {
  4869. service.CreateDialysisFinish(finish)
  4870. }
  4871. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  4872. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  4873. for _, item := range advices {
  4874. byterequest, _ := json.Marshal(item)
  4875. adviceLog := models.XtDoctorAdviceLog{
  4876. UserOrgId: adminUserInfo.Org.Id,
  4877. PatientId: patient,
  4878. AdminUserId: adminUserInfo.AdminUser.Id,
  4879. Module: 1,
  4880. ErrLog: string(byterequest),
  4881. Status: 1,
  4882. Ctime: time.Now().Unix(),
  4883. Mtime: 0,
  4884. Source: "手机端医嘱推送",
  4885. RecordDate: item.AdviceDate,
  4886. }
  4887. service.CreateDoctorAdviceLog(adviceLog)
  4888. }
  4889. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  4890. redis := service.RedisClient()
  4891. //清空key 值
  4892. redis.Set(key, "", time.Second)
  4893. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4894. redis.Set(keyOne, "", time.Second)
  4895. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4896. defer redis.Close()
  4897. redis.Set(keyThree, "", time.Second)
  4898. if err != nil {
  4899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4900. return
  4901. }
  4902. c.ServeSuccessJSON(map[string]interface{}{
  4903. "msg": "ok",
  4904. "advices": list,
  4905. })
  4906. } else {
  4907. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  4908. for _, item := range advices {
  4909. byterequest, _ := json.Marshal(item)
  4910. adviceLog := models.XtDoctorAdviceLog{
  4911. UserOrgId: adminUserInfo.Org.Id,
  4912. PatientId: patient,
  4913. AdminUserId: adminUserInfo.AdminUser.Id,
  4914. Module: 1,
  4915. ErrLog: string(byterequest),
  4916. Status: 1,
  4917. Ctime: time.Now().Unix(),
  4918. Mtime: 0,
  4919. Source: "手机端医嘱推送",
  4920. RecordDate: item.AdviceDate,
  4921. }
  4922. service.CreateDoctorAdviceLog(adviceLog)
  4923. }
  4924. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  4925. redis := service.RedisClient()
  4926. //清空key 值
  4927. redis.Set(key, "", time.Second)
  4928. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4929. redis.Set(keyOne, "", time.Second)
  4930. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4931. defer redis.Close()
  4932. redis.Set(keyThree, "", time.Second)
  4933. if err != nil {
  4934. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4935. return
  4936. }
  4937. c.ServeSuccessJSON(map[string]interface{}{
  4938. "msg": "ok",
  4939. "advices": list,
  4940. })
  4941. }
  4942. } else {
  4943. c.ServeSuccessJSON(map[string]interface{}{
  4944. "msg": "ok",
  4945. })
  4946. }
  4947. return
  4948. }
  4949. func (c *DialysisAPIController) UploadDryWeight() {
  4950. patient_id, _ := c.GetInt64("id")
  4951. dry_weight, _ := c.GetFloat("dry_weight")
  4952. doctor_id, _ := c.GetInt64("doctor_id")
  4953. remark := c.GetString("remark")
  4954. adminUserInfo := c.GetMobileAdminUserInfo()
  4955. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  4956. if err == gorm.ErrRecordNotFound {
  4957. dryWeight := &models.SgjPatientDryweight{
  4958. PatientId: patient_id,
  4959. DryWeight: dry_weight,
  4960. Remakes: remark,
  4961. Ctime: time.Now().Unix(),
  4962. Mtime: time.Now().Unix(),
  4963. Creator: doctor_id,
  4964. Status: 1,
  4965. UserOrgId: adminUserInfo.Org.Id,
  4966. AdjustedValue: "/",
  4967. UserId: adminUserInfo.AdminUser.Id,
  4968. }
  4969. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4970. redis := service.RedisClient()
  4971. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  4972. redis.Set(keyOne, "", time.Second)
  4973. loc, _ := time.LoadLocation("Local")
  4974. nowTime := time.Now()
  4975. nowDay := nowTime.Format("2006-01-02")
  4976. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4977. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4978. redis.Set(key, "", time.Second)
  4979. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4980. redis.Set(keyTwo, "", time.Second)
  4981. redis.Close()
  4982. if createErr == nil {
  4983. c.ServeSuccessJSON(map[string]interface{}{
  4984. "msg": "提交成功",
  4985. "weight": dryWeight,
  4986. })
  4987. }
  4988. } else {
  4989. dryWeight := &models.SgjPatientDryweight{
  4990. PatientId: patient_id,
  4991. DryWeight: dry_weight,
  4992. Remakes: remark,
  4993. Ctime: time.Now().Unix(),
  4994. Mtime: time.Now().Unix(),
  4995. Creator: doctor_id,
  4996. Status: 1,
  4997. UserOrgId: adminUserInfo.Org.Id,
  4998. AdjustedValue: "/",
  4999. UserId: adminUserInfo.AdminUser.Id,
  5000. }
  5001. var value float64
  5002. value = dry_weight - weightAdjust.DryWeight
  5003. if value < 0 {
  5004. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5005. } else if value == 0 {
  5006. dryWeight.AdjustedValue = "/"
  5007. } else if value > 0 {
  5008. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5009. }
  5010. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5011. redis := service.RedisClient()
  5012. loc, _ := time.LoadLocation("Local")
  5013. nowTime := time.Now()
  5014. nowDay := nowTime.Format("2006-01-02")
  5015. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5016. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5017. redis.Set(keyOne, "", time.Second)
  5018. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5019. redis.Set(key, "", time.Second)
  5020. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5021. redis.Set(keyTwo, "", time.Second)
  5022. redis.Close()
  5023. if createErr == nil {
  5024. c.ServeSuccessJSON(map[string]interface{}{
  5025. "msg": "提交成功",
  5026. "weight": dryWeight,
  5027. })
  5028. }
  5029. }
  5030. }
  5031. func (c *DialysisAPIController) GetSolution() {
  5032. patient_id, _ := c.GetInt64("patient_id")
  5033. mode_id, _ := c.GetInt64("mode_id")
  5034. adminUserInfo := c.GetMobileAdminUserInfo()
  5035. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5036. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5037. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5038. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5039. if err != nil {
  5040. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5041. return
  5042. }
  5043. c.ServeSuccessJSON(map[string]interface{}{
  5044. "solution": solution,
  5045. "prescription": prescription,
  5046. "system_prescription": system_prescription,
  5047. "dialysisPrescription": dialysisPrescription,
  5048. })
  5049. }
  5050. func (c *DialysisAPIController) GetSchedule() {
  5051. schedual_type, _ := c.GetInt64("schedual_type")
  5052. adminUserInfo := c.GetMobileAdminUserInfo()
  5053. scheduleTime, _ := c.GetInt64("record_date")
  5054. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5055. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5056. c.ServeSuccessJSON(map[string]interface{}{
  5057. "number": deviceNumber,
  5058. "list": list,
  5059. })
  5060. }
  5061. func (c *DialysisAPIController) GetPatientId() {
  5062. id, _ := c.GetInt64("id")
  5063. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5064. patientId, _ := service.GetPatientId(id)
  5065. //获取该患者的所有传染病
  5066. list, _ := service.GetPatientInfectious(id)
  5067. c.ServeSuccessJSON(map[string]interface{}{
  5068. "patient": patientId,
  5069. "infectioulist": list,
  5070. })
  5071. }
  5072. func (this *DialysisAPIController) GetDialysisSchedule() {
  5073. schedualDate := this.GetString("date")
  5074. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5075. if parseDateErr != nil {
  5076. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5077. return
  5078. }
  5079. adminInfo := this.GetMobileAdminUserInfo()
  5080. orgID := adminInfo.Org.Id
  5081. redis := service.RedisClient()
  5082. defer redis.Close()
  5083. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5084. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5085. if len(scheduals) > 0 {
  5086. //缓存数据
  5087. scheduals_json, err := json.Marshal(scheduals)
  5088. if err == nil {
  5089. redis.Set(key, scheduals_json, time.Second*30)
  5090. }
  5091. }
  5092. this.ServeSuccessJSON(map[string]interface{}{
  5093. "scheduals": scheduals,
  5094. })
  5095. }
  5096. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5097. change_type, _ := this.GetInt64("type", 0)
  5098. record_date := this.GetString("record_time")
  5099. patient_id, _ := this.GetInt64("patient_id", 0)
  5100. timeLayout := "2006-01-02"
  5101. loc, _ := time.LoadLocation("Local")
  5102. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5103. record_time := theAdviceRecordTime.Unix()
  5104. adminUserInfo := this.GetMobileAdminUserInfo()
  5105. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5106. if err == nil {
  5107. if len(advices) == 0 {
  5108. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5109. return
  5110. } else {
  5111. this.ServeSuccessJSON(map[string]interface{}{
  5112. "advices": advices,
  5113. "schedule": sch,
  5114. })
  5115. return
  5116. }
  5117. } else {
  5118. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5119. return
  5120. }
  5121. }
  5122. func (c *DialysisAPIController) CreateConsumables() {
  5123. record_date := c.GetString("record_time")
  5124. patient_id, _ := c.GetInt64("patient_id", 0)
  5125. active, _ := c.GetInt64("active")
  5126. adminUser := c.GetMobileAdminUserInfo()
  5127. timeLayout := "2006-01-02"
  5128. loc, _ := time.LoadLocation("Local")
  5129. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5130. record_time := theRecordTime.Unix()
  5131. // 查询信息规挡的设置天数
  5132. orgid := c.GetMobileAdminUserInfo().Org.Id
  5133. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5134. if infor.ID > 0 {
  5135. var cha_time int64
  5136. timeNowStr := time.Now().Format("2006-01-02")
  5137. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5138. //今日的日期减去设置的日期
  5139. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5140. if cha_time >= record_time {
  5141. //查询审核是否允许
  5142. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5143. //申请状态不允许的情况 拒绝修改
  5144. if infor.ApplicationStatus != 1 {
  5145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5146. return
  5147. }
  5148. }
  5149. }
  5150. dataBody := make(map[string]interface{}, 0)
  5151. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5152. if err != nil {
  5153. utils.ErrorLog(err.Error())
  5154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5155. return
  5156. }
  5157. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5158. var beforePrepares []*models.DialysisBeforePrepareGoods
  5159. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5160. var dialysisBefor []*models.DialysisBeforePrepare
  5161. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5162. goods, _ := dataBody["goods"].([]interface{})
  5163. if len(goods) > 0 {
  5164. for _, item := range goods {
  5165. items := item.(map[string]interface{})
  5166. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5167. utils.ErrorLog("good_id")
  5168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5169. return
  5170. }
  5171. good_id := int64(items["good_id"].(float64))
  5172. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5173. utils.ErrorLog("good_type_id")
  5174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5175. return
  5176. }
  5177. good_type_id := int64(items["good_type_id"].(float64))
  5178. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5179. utils.ErrorLog("count")
  5180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5181. return
  5182. }
  5183. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5184. commdity_code := items["commdity_code"].(string)
  5185. fmt.Println("commdity", commdity_code)
  5186. prepareGoods := &models.DialysisBeforePrepareGoods{
  5187. GoodTypeId: good_type_id,
  5188. GoodId: good_id,
  5189. Count: count,
  5190. StorehouseId: houseConfig.StorehouseOutInfo,
  5191. }
  5192. beforePrepares = append(beforePrepares, prepareGoods)
  5193. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5194. GoodTypeId: good_type_id,
  5195. GoodId: good_id,
  5196. Count: count,
  5197. StorehouseId: houseConfig.StorehouseOutInfo,
  5198. }
  5199. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5200. prepare := &models.DialysisBeforePrepare{
  5201. GoodTypeId: good_type_id,
  5202. GoodId: good_id,
  5203. Count: count,
  5204. PatientId: patient_id,
  5205. RecordDate: record_time,
  5206. UserOrgId: adminUser.Org.Id,
  5207. Status: 1,
  5208. Ctime: time.Now().Unix(),
  5209. Creater: adminUser.AdminUser.Id,
  5210. CommdityCode: commdity_code,
  5211. StorehouseId: houseConfig.StorehouseOutInfo,
  5212. }
  5213. dialysisBefor = append(dialysisBefor, prepare)
  5214. }
  5215. }
  5216. //查询是否有库存
  5217. for _, item := range dialysisBefor {
  5218. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5219. if err == gorm.ErrRecordNotFound {
  5220. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5221. c.ServeSuccessJSON(map[string]interface{}{
  5222. "message": "1",
  5223. "good_name": goodObj.GoodName,
  5224. "specification_name": goodObj.SpecificationName,
  5225. })
  5226. return
  5227. }
  5228. if err != nil {
  5229. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5230. c.ServeSuccessJSON(map[string]interface{}{
  5231. "message": "1",
  5232. "good_name": goodObj.GoodName,
  5233. "specification_name": goodObj.SpecificationName,
  5234. })
  5235. return
  5236. }
  5237. }
  5238. //新增
  5239. if active == 1 && len(goods) > 0 {
  5240. for _, item := range dialysisBefor {
  5241. dialyPrepareOne := models.DialysisBeforePrepare{
  5242. GoodTypeId: item.GoodTypeId,
  5243. GoodId: item.GoodId,
  5244. PatientId: item.PatientId,
  5245. RecordDate: item.RecordDate,
  5246. UserOrgId: item.UserOrgId,
  5247. Count: item.Count,
  5248. Ctime: time.Now().Unix(),
  5249. Creater: item.Creater,
  5250. CommdityCode: item.CommdityCode,
  5251. Status: 1,
  5252. StorehouseId: houseConfig.StorehouseOutInfo,
  5253. }
  5254. //先清除再插入
  5255. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5256. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5257. //查询默认仓库
  5258. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5259. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5260. var total_count int64
  5261. for _, it := range stockList {
  5262. total_count += it.StockCount
  5263. }
  5264. //基础库插入数据
  5265. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5266. //更新库存
  5267. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5268. var flush_count int64
  5269. for _, it := range goodList {
  5270. flush_count += it.StockCount
  5271. }
  5272. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5273. }
  5274. if err == nil {
  5275. c.ServeSuccessJSON(map[string]interface{}{
  5276. "msg": "保存成功",
  5277. "message": "2",
  5278. })
  5279. return
  5280. } else {
  5281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5282. return
  5283. }
  5284. }
  5285. if len(beforePrepares) > 0 && active == 2 {
  5286. for _, item := range beforePrepares {
  5287. //1.查看该患者该耗材型号最后一次出库数量
  5288. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5289. //判断当前出库数量和最后一次出库数量的大小
  5290. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  5291. if item.Count <= goodInfo.Count {
  5292. //退库
  5293. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  5294. //查询今日出库数据
  5295. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5296. for _, it := range list {
  5297. prepare := models.DialysisBeforePrepare{
  5298. UserOrgId: it.OrgId,
  5299. PatientId: patient_id,
  5300. RecordDate: it.RecordTime,
  5301. GoodId: it.GoodId,
  5302. GoodTypeId: it.GoodTypeId,
  5303. Count: it.Count,
  5304. Ctime: time.Now().Unix(),
  5305. Creater: adminUser.AdminUser.Id,
  5306. Status: 1,
  5307. StorehouseId: houseConfig.StorehouseOutInfo,
  5308. }
  5309. //删除准备表数据
  5310. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5311. service.CreateDialysisBeforePrepareOne(&prepare)
  5312. }
  5313. }
  5314. var last_total int64
  5315. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5316. if item.Count >= goodInfo.Count {
  5317. //查询当前批次当前耗材最后一条出库数据
  5318. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5319. //计算当前出库和最后一次出库数据相差数据
  5320. last_total = item.Count - lastOutInfo.Count
  5321. //查询该批次剩余库存
  5322. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  5323. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  5324. if lastInfo.StockCount >= last_total {
  5325. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5326. //查询今日出库数据
  5327. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5328. for _, it := range list {
  5329. prepare := models.DialysisBeforePrepare{
  5330. UserOrgId: it.OrgId,
  5331. PatientId: patient_id,
  5332. RecordDate: it.RecordTime,
  5333. GoodId: it.GoodId,
  5334. GoodTypeId: it.GoodTypeId,
  5335. Count: it.Count,
  5336. Ctime: time.Now().Unix(),
  5337. Creater: adminUser.AdminUser.Id,
  5338. Status: 1,
  5339. StorehouseId: houseConfig.StorehouseOutInfo,
  5340. }
  5341. //删除准备表数据
  5342. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5343. service.CreateDialysisBeforePrepareOne(&prepare)
  5344. //查询默认仓库
  5345. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5346. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5347. var total_count int64
  5348. for _, it := range stockList {
  5349. total_count += it.StockCount
  5350. }
  5351. //基础库插入数据
  5352. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5353. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5354. var flush_count int64
  5355. for _, it := range goodList {
  5356. flush_count += it.StockCount
  5357. }
  5358. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5359. }
  5360. }
  5361. //如果库存不够,则出库到下一个批次
  5362. if lastInfo.StockCount < last_total {
  5363. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5364. //查询今日出库数据
  5365. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5366. for _, it := range list {
  5367. prepare := models.DialysisBeforePrepare{
  5368. UserOrgId: it.OrgId,
  5369. PatientId: patient_id,
  5370. RecordDate: it.RecordTime,
  5371. GoodId: it.GoodId,
  5372. GoodTypeId: it.GoodTypeId,
  5373. Count: it.Count,
  5374. Ctime: time.Now().Unix(),
  5375. Creater: adminUser.AdminUser.Id,
  5376. Status: 1,
  5377. StorehouseId: houseConfig.StorehouseOutInfo,
  5378. }
  5379. //删除准备表数据
  5380. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5381. service.CreateDialysisBeforePrepareOne(&prepare)
  5382. //查询默认仓库
  5383. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5384. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5385. var total_count int64
  5386. for _, it := range stockList {
  5387. total_count += it.StockCount
  5388. }
  5389. //基础库插入数据
  5390. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5391. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5392. var flush_count int64
  5393. for _, it := range goodList {
  5394. flush_count += it.StockCount
  5395. }
  5396. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5397. }
  5398. if err != nil {
  5399. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5400. c.ServeSuccessJSON(map[string]interface{}{
  5401. "message": "1",
  5402. "good_name": goodObj.GoodName,
  5403. "specification_name": goodObj.SpecificationName,
  5404. })
  5405. return
  5406. }
  5407. }
  5408. }
  5409. if err != nil {
  5410. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5411. c.ServeSuccessJSON(map[string]interface{}{
  5412. "message": "1",
  5413. "good_name": goodObj.GoodName,
  5414. "specification_name": goodObj.SpecificationName,
  5415. })
  5416. return
  5417. }
  5418. }
  5419. }
  5420. }
  5421. var errs error
  5422. if errs == nil {
  5423. c.ServeSuccessJSON(map[string]interface{}{
  5424. "msg": "提交成功",
  5425. "message": "2",
  5426. "good_name": "",
  5427. "specification_name": "",
  5428. })
  5429. return
  5430. } else {
  5431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5432. return
  5433. }
  5434. }
  5435. func (c *DialysisAPIController) CreateStockOutInfo() {
  5436. patient_id, _ := c.GetInt64("patient_id", 0)
  5437. record_date := c.GetString("record_time")
  5438. if patient_id <= 0 {
  5439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5440. return
  5441. }
  5442. adminInfo := c.GetMobileAdminUserInfo()
  5443. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5444. timeLayout := "2006-01-02"
  5445. loc, _ := time.LoadLocation("Local")
  5446. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5447. record_time := theRecordTime.Unix()
  5448. // 查询信息规挡的设置天数
  5449. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5450. if infor.ID > 0 && infor.WeekDay > 0 {
  5451. var cha_time int64
  5452. timeNowStr := time.Now().Format("2006-01-02")
  5453. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5454. //今日的日期减去设置的日期
  5455. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5456. if cha_time >= record_time {
  5457. //查询审核是否允许
  5458. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  5459. //申请状态不允许的情况 拒绝修改
  5460. if infor.ApplicationStatus != 1 {
  5461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5462. return
  5463. }
  5464. }
  5465. }
  5466. //创建步骤表
  5467. finish := models.XtDialysisFinish{
  5468. IsFinish: 1,
  5469. UserOrgId: adminInfo.Org.Id,
  5470. Status: 1,
  5471. Ctime: time.Now().Unix(),
  5472. Mtime: 0,
  5473. Module: 11,
  5474. RecordDate: record_time,
  5475. Sourse: 1,
  5476. PatientId: patient_id,
  5477. }
  5478. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  5479. if dialysisFinish.ID == 0 {
  5480. service.CreateDialysisFinish(finish)
  5481. }
  5482. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  5483. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5484. //去重
  5485. consumables = RemoveRepeatedGood(consumables)
  5486. if adminInfo.Org.Id == 9919 {
  5487. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5488. //查询是否有库存
  5489. for _, item := range consumables {
  5490. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5491. if item.Count > warehouse.Count {
  5492. goodErrcode := models.XtGoodErrcode{
  5493. UserOrgId: item.UserOrgId,
  5494. Errcode: "自动出库库存不足",
  5495. GoodId: item.GoodId,
  5496. Status: 1,
  5497. Ctime: time.Now().Unix(),
  5498. Mtime: 0,
  5499. Count: 0,
  5500. StockCount: 0,
  5501. Creater: creator,
  5502. BatchNumberId: warehouse.ID,
  5503. WarehouseOutId: 0,
  5504. }
  5505. service.CreateGoodErrcode(goodErrcode)
  5506. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5507. c.ServeSuccessJSON(map[string]interface{}{
  5508. "message": "1",
  5509. "good_name": goodObj.GoodName,
  5510. "specification_name": goodObj.SpecificationName,
  5511. })
  5512. return
  5513. }
  5514. }
  5515. //查询是否有出库单
  5516. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5517. if err == gorm.ErrRecordNotFound {
  5518. //没有记录,则创建出库单
  5519. timeStr := time.Now().Format("2006-01-02")
  5520. timeArr := strings.Split(timeStr, "-")
  5521. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5522. total = total + 1
  5523. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5524. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5525. number = number + total
  5526. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5527. creater := adminInfo.AdminUser.Id
  5528. warehouseOut := models.WarehouseOut{
  5529. WarehouseOutOrderNumber: warehousing_out_order,
  5530. OperationTime: time.Now().Unix(),
  5531. OrgId: adminInfo.Org.Id,
  5532. Creater: creater,
  5533. Ctime: time.Now().Unix(),
  5534. Status: 1,
  5535. WarehouseOutTime: record_time,
  5536. Dealer: 0,
  5537. Manufacturer: 0,
  5538. Type: 1,
  5539. IsSys: 1,
  5540. StorehouseId: houseConfig.StorehouseOutInfo,
  5541. IsCheck: 1,
  5542. }
  5543. err := service.AddSigleWarehouseOut(&warehouseOut)
  5544. if err != nil {
  5545. goodErrcode := models.XtGoodErrcode{
  5546. UserOrgId: adminInfo.Org.Id,
  5547. Errcode: "创建出库单失败",
  5548. GoodId: 0,
  5549. Status: 1,
  5550. Ctime: time.Now().Unix(),
  5551. Mtime: 0,
  5552. Count: 0,
  5553. StockCount: 0,
  5554. Creater: creator,
  5555. BatchNumberId: 0,
  5556. WarehouseOutId: 0,
  5557. }
  5558. service.CreateGoodErrcode(goodErrcode)
  5559. utils.TraceLog("创建出库单失败 err = %v", err)
  5560. } else {
  5561. for _, item := range consumables {
  5562. //出库
  5563. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5564. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5565. if err == nil {
  5566. goodErrcode := models.XtGoodErrcode{
  5567. UserOrgId: adminInfo.Org.Id,
  5568. Errcode: "自动出库接口报错",
  5569. GoodId: 0,
  5570. Status: 1,
  5571. Ctime: time.Now().Unix(),
  5572. Mtime: 0,
  5573. Count: 0,
  5574. StockCount: 0,
  5575. Creater: creator,
  5576. BatchNumberId: 0,
  5577. WarehouseOutId: 0,
  5578. }
  5579. service.CreateGoodErrcode(goodErrcode)
  5580. utils.TraceLog("创建出库单失败 err = %v", err)
  5581. }
  5582. //查询
  5583. //出库数量相加
  5584. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5585. if errs != nil {
  5586. goodErrcode := models.XtGoodErrcode{
  5587. UserOrgId: item.UserOrgId,
  5588. Errcode: "创建剩余库存字段报错",
  5589. GoodId: item.GoodId,
  5590. Status: 1,
  5591. Ctime: time.Now().Unix(),
  5592. Mtime: 0,
  5593. Count: 0,
  5594. StockCount: 0,
  5595. Creater: creater,
  5596. BatchNumberId: 0,
  5597. WarehouseOutId: 0,
  5598. }
  5599. service.CreateGoodErrcode(goodErrcode)
  5600. }
  5601. }
  5602. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5603. if len(list) == 0 {
  5604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5605. return
  5606. }
  5607. for _, item := range list {
  5608. prepare := models.DialysisBeforePrepare{
  5609. UserOrgId: adminInfo.Org.Id,
  5610. PatientId: patient_id,
  5611. RecordDate: record_time,
  5612. GoodId: item.GoodId,
  5613. GoodTypeId: item.GoodTypeId,
  5614. Count: item.Count,
  5615. Creater: adminInfo.AdminUser.Id,
  5616. Status: 1,
  5617. Ctime: time.Now().Unix(),
  5618. StorehouseId: houseConfig.StorehouseOutInfo,
  5619. }
  5620. //清空准备表数据
  5621. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5622. if err != nil {
  5623. goodErrcode := models.XtGoodErrcode{
  5624. UserOrgId: item.OrgId,
  5625. Errcode: "自动出库清空准备表数据报错",
  5626. GoodId: item.GoodId,
  5627. Status: 1,
  5628. Ctime: time.Now().Unix(),
  5629. Mtime: 0,
  5630. Count: 0,
  5631. StockCount: 0,
  5632. Creater: creater,
  5633. BatchNumberId: 0,
  5634. WarehouseOutId: 0,
  5635. }
  5636. service.CreateGoodErrcode(goodErrcode)
  5637. }
  5638. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5639. if errs != nil {
  5640. goodErrcode := models.XtGoodErrcode{
  5641. UserOrgId: item.OrgId,
  5642. Errcode: "自动出库创建准备表数据报错",
  5643. GoodId: item.GoodId,
  5644. Status: 1,
  5645. Ctime: time.Now().Unix(),
  5646. Mtime: 0,
  5647. Count: 0,
  5648. StockCount: 0,
  5649. Creater: creater,
  5650. BatchNumberId: 0,
  5651. WarehouseOutId: 0,
  5652. }
  5653. service.CreateGoodErrcode(goodErrcode)
  5654. }
  5655. //查询默认仓库
  5656. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5657. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5658. var total_count int64
  5659. for _, it := range stockList {
  5660. total_count += it.StockCount
  5661. }
  5662. //基础库插入数据
  5663. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5664. if errcodes != nil {
  5665. goodErrcode := models.XtGoodErrcode{
  5666. UserOrgId: item.OrgId,
  5667. Errcode: "自动出库基础库插入数据",
  5668. GoodId: item.GoodId,
  5669. Status: 1,
  5670. Ctime: time.Now().Unix(),
  5671. Mtime: 0,
  5672. Count: 0,
  5673. StockCount: 0,
  5674. Creater: creater,
  5675. BatchNumberId: 0,
  5676. WarehouseOutId: 0,
  5677. }
  5678. service.CreateGoodErrcode(goodErrcode)
  5679. }
  5680. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5681. var flush_count int64
  5682. for _, it := range goodList {
  5683. flush_count += it.StockCount
  5684. }
  5685. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5686. if errsss != nil {
  5687. goodErrcode := models.XtGoodErrcode{
  5688. UserOrgId: item.OrgId,
  5689. Errcode: "自动出库剩余库存更新数据",
  5690. GoodId: item.GoodId,
  5691. Status: 1,
  5692. Ctime: time.Now().Unix(),
  5693. Mtime: 0,
  5694. Count: 0,
  5695. StockCount: 0,
  5696. Creater: creater,
  5697. BatchNumberId: 0,
  5698. WarehouseOutId: 0,
  5699. }
  5700. service.CreateGoodErrcode(goodErrcode)
  5701. }
  5702. }
  5703. }
  5704. //
  5705. } else if err == nil {
  5706. for _, item := range consumables {
  5707. //出库
  5708. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  5709. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  5710. if err != nil {
  5711. goodErrcode := models.XtGoodErrcode{
  5712. UserOrgId: adminInfo.Org.Id,
  5713. Errcode: "自动出库接口报错",
  5714. GoodId: 0,
  5715. Status: 1,
  5716. Ctime: time.Now().Unix(),
  5717. Mtime: 0,
  5718. Count: 0,
  5719. StockCount: 0,
  5720. Creater: creator,
  5721. BatchNumberId: 0,
  5722. WarehouseOutId: 0,
  5723. }
  5724. service.CreateGoodErrcode(goodErrcode)
  5725. }
  5726. //出库数量相加
  5727. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5728. if errss != nil {
  5729. goodErrcode := models.XtGoodErrcode{
  5730. UserOrgId: item.UserOrgId,
  5731. Errcode: "创建剩余库存字段报错",
  5732. GoodId: item.GoodId,
  5733. Status: 1,
  5734. Ctime: time.Now().Unix(),
  5735. Mtime: time.Now().Unix(),
  5736. Count: 0,
  5737. StockCount: 0,
  5738. Creater: item.Creater,
  5739. BatchNumberId: 0,
  5740. WarehouseOutId: 0,
  5741. }
  5742. service.CreateGoodErrcode(goodErrcode)
  5743. }
  5744. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5745. if len(list) == 0 {
  5746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5747. return
  5748. }
  5749. for _, item := range list {
  5750. prepare := models.DialysisBeforePrepare{
  5751. UserOrgId: adminInfo.Org.Id,
  5752. PatientId: patient_id,
  5753. RecordDate: record_time,
  5754. GoodId: item.GoodId,
  5755. GoodTypeId: item.GoodTypeId,
  5756. Count: item.Count,
  5757. Creater: adminInfo.AdminUser.Id,
  5758. Status: 1,
  5759. Ctime: time.Now().Unix(),
  5760. StorehouseId: houseConfig.StorehouseOutInfo,
  5761. }
  5762. //清空准备表数据
  5763. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5764. if errs != nil {
  5765. goodErrcode := models.XtGoodErrcode{
  5766. UserOrgId: adminInfo.Org.Id,
  5767. Errcode: "自动出库清空准备表数据报错",
  5768. GoodId: 0,
  5769. Status: 1,
  5770. Ctime: time.Now().Unix(),
  5771. Mtime: 0,
  5772. Count: 0,
  5773. StockCount: 0,
  5774. Creater: creator,
  5775. BatchNumberId: 0,
  5776. WarehouseOutId: 0,
  5777. }
  5778. service.CreateGoodErrcode(goodErrcode)
  5779. }
  5780. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  5781. if errcodes != nil {
  5782. goodErrcode := models.XtGoodErrcode{
  5783. UserOrgId: adminInfo.Org.Id,
  5784. Errcode: "自动出库创建准备表数据报错",
  5785. GoodId: 0,
  5786. Status: 1,
  5787. Ctime: time.Now().Unix(),
  5788. Mtime: 0,
  5789. Count: 0,
  5790. StockCount: 0,
  5791. Creater: creator,
  5792. BatchNumberId: 0,
  5793. WarehouseOutId: 0,
  5794. }
  5795. service.CreateGoodErrcode(goodErrcode)
  5796. }
  5797. //查询默认仓库
  5798. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5799. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5800. var total_count int64
  5801. for _, it := range stockList {
  5802. total_count += it.StockCount
  5803. }
  5804. //基础库插入数据
  5805. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5806. if errcodes != nil {
  5807. goodErrcode := models.XtGoodErrcode{
  5808. UserOrgId: adminInfo.Org.Id,
  5809. Errcode: "自动出库基础库插入数据报错",
  5810. GoodId: 0,
  5811. Status: 1,
  5812. Ctime: time.Now().Unix(),
  5813. Mtime: 0,
  5814. Count: 0,
  5815. StockCount: 0,
  5816. Creater: creator,
  5817. BatchNumberId: 0,
  5818. WarehouseOutId: 0,
  5819. }
  5820. service.CreateGoodErrcode(goodErrcode)
  5821. }
  5822. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5823. var flush_count int64
  5824. for _, it := range goodList {
  5825. flush_count += it.StockCount
  5826. }
  5827. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5828. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5829. if errss != nil {
  5830. goodErrcode := models.XtGoodErrcode{
  5831. UserOrgId: item.OrgId,
  5832. Errcode: "自动出库剩余库存更新数据",
  5833. GoodId: item.GoodId,
  5834. Status: 1,
  5835. Ctime: time.Now().Unix(),
  5836. Mtime: 0,
  5837. Count: 0,
  5838. StockCount: 0,
  5839. Creater: creater,
  5840. BatchNumberId: 0,
  5841. WarehouseOutId: 0,
  5842. }
  5843. service.CreateGoodErrcode(goodErrcode)
  5844. }
  5845. }
  5846. }
  5847. }
  5848. c.ServeSuccessJSON(map[string]interface{}{
  5849. "msg": "提交成功",
  5850. "message": "2",
  5851. "good_name": "",
  5852. "specification_name": "",
  5853. })
  5854. return
  5855. }
  5856. if record.IsOpen == 1 {
  5857. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5858. //查询是否有库存
  5859. for _, item := range consumables {
  5860. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5861. if item.Count > warehouse.Count {
  5862. goodErrcode := models.XtGoodErrcode{
  5863. UserOrgId: item.UserOrgId,
  5864. Errcode: "自动出库库存不足",
  5865. GoodId: item.GoodId,
  5866. Status: 1,
  5867. Ctime: time.Now().Unix(),
  5868. Mtime: 0,
  5869. Count: 0,
  5870. StockCount: 0,
  5871. Creater: creator,
  5872. BatchNumberId: warehouse.ID,
  5873. WarehouseOutId: 0,
  5874. }
  5875. service.CreateGoodErrcode(goodErrcode)
  5876. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5877. c.ServeSuccessJSON(map[string]interface{}{
  5878. "message": "1",
  5879. "good_name": goodObj.GoodName,
  5880. "specification_name": goodObj.SpecificationName,
  5881. })
  5882. return
  5883. }
  5884. }
  5885. //查询是否有出库单
  5886. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5887. if err == gorm.ErrRecordNotFound {
  5888. //没有记录,则创建出库单
  5889. timeStr := time.Now().Format("2006-01-02")
  5890. timeArr := strings.Split(timeStr, "-")
  5891. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5892. total = total + 1
  5893. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5894. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5895. number = number + total
  5896. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5897. creater := adminInfo.AdminUser.Id
  5898. warehouseOut := models.WarehouseOut{
  5899. WarehouseOutOrderNumber: warehousing_out_order,
  5900. OperationTime: time.Now().Unix(),
  5901. OrgId: adminInfo.Org.Id,
  5902. Creater: creater,
  5903. Ctime: time.Now().Unix(),
  5904. Status: 1,
  5905. WarehouseOutTime: record_time,
  5906. Dealer: 0,
  5907. Manufacturer: 0,
  5908. Type: 1,
  5909. IsSys: 1,
  5910. StorehouseId: houseConfig.StorehouseOutInfo,
  5911. IsCheck: 1,
  5912. }
  5913. err := service.AddSigleWarehouseOut(&warehouseOut)
  5914. if err != nil {
  5915. goodErrcode := models.XtGoodErrcode{
  5916. UserOrgId: adminInfo.Org.Id,
  5917. Errcode: "创建出库单失败",
  5918. GoodId: 0,
  5919. Status: 1,
  5920. Ctime: time.Now().Unix(),
  5921. Mtime: 0,
  5922. Count: 0,
  5923. StockCount: 0,
  5924. Creater: creator,
  5925. BatchNumberId: 0,
  5926. WarehouseOutId: 0,
  5927. }
  5928. service.CreateGoodErrcode(goodErrcode)
  5929. utils.TraceLog("创建出库单失败 err = %v", err)
  5930. } else {
  5931. for _, item := range consumables {
  5932. //出库
  5933. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5934. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5935. if err == nil {
  5936. goodErrcode := models.XtGoodErrcode{
  5937. UserOrgId: adminInfo.Org.Id,
  5938. Errcode: "自动出库接口报错",
  5939. GoodId: 0,
  5940. Status: 1,
  5941. Ctime: time.Now().Unix(),
  5942. Mtime: 0,
  5943. Count: 0,
  5944. StockCount: 0,
  5945. Creater: creator,
  5946. BatchNumberId: 0,
  5947. WarehouseOutId: 0,
  5948. }
  5949. service.CreateGoodErrcode(goodErrcode)
  5950. utils.TraceLog("创建出库单失败 err = %v", err)
  5951. }
  5952. //查询
  5953. //出库数量相加
  5954. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5955. if errs != nil {
  5956. goodErrcode := models.XtGoodErrcode{
  5957. UserOrgId: item.UserOrgId,
  5958. Errcode: "创建剩余库存字段报错",
  5959. GoodId: item.GoodId,
  5960. Status: 1,
  5961. Ctime: time.Now().Unix(),
  5962. Mtime: 0,
  5963. Count: 0,
  5964. StockCount: 0,
  5965. Creater: creater,
  5966. BatchNumberId: 0,
  5967. WarehouseOutId: 0,
  5968. }
  5969. service.CreateGoodErrcode(goodErrcode)
  5970. }
  5971. }
  5972. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5973. if len(list) == 0 {
  5974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5975. return
  5976. }
  5977. for _, item := range list {
  5978. prepare := models.DialysisBeforePrepare{
  5979. UserOrgId: adminInfo.Org.Id,
  5980. PatientId: patient_id,
  5981. RecordDate: record_time,
  5982. GoodId: item.GoodId,
  5983. GoodTypeId: item.GoodTypeId,
  5984. Count: item.Count,
  5985. Creater: adminInfo.AdminUser.Id,
  5986. Status: 1,
  5987. Ctime: time.Now().Unix(),
  5988. StorehouseId: houseConfig.StorehouseOutInfo,
  5989. }
  5990. //清空准备表数据
  5991. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5992. if err != nil {
  5993. goodErrcode := models.XtGoodErrcode{
  5994. UserOrgId: item.OrgId,
  5995. Errcode: "自动出库清空准备表数据报错",
  5996. GoodId: item.GoodId,
  5997. Status: 1,
  5998. Ctime: time.Now().Unix(),
  5999. Mtime: 0,
  6000. Count: 0,
  6001. StockCount: 0,
  6002. Creater: creater,
  6003. BatchNumberId: 0,
  6004. WarehouseOutId: 0,
  6005. }
  6006. service.CreateGoodErrcode(goodErrcode)
  6007. }
  6008. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6009. if errs != nil {
  6010. goodErrcode := models.XtGoodErrcode{
  6011. UserOrgId: item.OrgId,
  6012. Errcode: "自动出库创建准备表数据报错",
  6013. GoodId: item.GoodId,
  6014. Status: 1,
  6015. Ctime: time.Now().Unix(),
  6016. Mtime: 0,
  6017. Count: 0,
  6018. StockCount: 0,
  6019. Creater: creater,
  6020. BatchNumberId: 0,
  6021. WarehouseOutId: 0,
  6022. }
  6023. service.CreateGoodErrcode(goodErrcode)
  6024. }
  6025. //查询默认仓库
  6026. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6027. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6028. var total_count int64
  6029. for _, it := range stockList {
  6030. total_count += it.StockCount
  6031. }
  6032. //基础库插入数据
  6033. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6034. if errcodes != nil {
  6035. goodErrcode := models.XtGoodErrcode{
  6036. UserOrgId: item.OrgId,
  6037. Errcode: "自动出库基础库插入数据",
  6038. GoodId: item.GoodId,
  6039. Status: 1,
  6040. Ctime: time.Now().Unix(),
  6041. Mtime: 0,
  6042. Count: 0,
  6043. StockCount: 0,
  6044. Creater: creater,
  6045. BatchNumberId: 0,
  6046. WarehouseOutId: 0,
  6047. }
  6048. service.CreateGoodErrcode(goodErrcode)
  6049. }
  6050. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6051. var flush_count int64
  6052. for _, it := range goodList {
  6053. flush_count += it.StockCount
  6054. }
  6055. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6056. if errsss != nil {
  6057. goodErrcode := models.XtGoodErrcode{
  6058. UserOrgId: item.OrgId,
  6059. Errcode: "自动出库剩余库存更新数据",
  6060. GoodId: item.GoodId,
  6061. Status: 1,
  6062. Ctime: time.Now().Unix(),
  6063. Mtime: 0,
  6064. Count: 0,
  6065. StockCount: 0,
  6066. Creater: creater,
  6067. BatchNumberId: 0,
  6068. WarehouseOutId: 0,
  6069. }
  6070. service.CreateGoodErrcode(goodErrcode)
  6071. }
  6072. }
  6073. }
  6074. //
  6075. } else if err == nil {
  6076. for _, item := range consumables {
  6077. //出库
  6078. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6079. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6080. if err != nil {
  6081. goodErrcode := models.XtGoodErrcode{
  6082. UserOrgId: adminInfo.Org.Id,
  6083. Errcode: "自动出库接口报错",
  6084. GoodId: 0,
  6085. Status: 1,
  6086. Ctime: time.Now().Unix(),
  6087. Mtime: 0,
  6088. Count: 0,
  6089. StockCount: 0,
  6090. Creater: creator,
  6091. BatchNumberId: 0,
  6092. WarehouseOutId: 0,
  6093. }
  6094. service.CreateGoodErrcode(goodErrcode)
  6095. }
  6096. //出库数量相加
  6097. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6098. if errss != nil {
  6099. goodErrcode := models.XtGoodErrcode{
  6100. UserOrgId: item.UserOrgId,
  6101. Errcode: "创建剩余库存字段报错",
  6102. GoodId: item.GoodId,
  6103. Status: 1,
  6104. Ctime: time.Now().Unix(),
  6105. Mtime: time.Now().Unix(),
  6106. Count: 0,
  6107. StockCount: 0,
  6108. Creater: item.Creater,
  6109. BatchNumberId: 0,
  6110. WarehouseOutId: 0,
  6111. }
  6112. service.CreateGoodErrcode(goodErrcode)
  6113. }
  6114. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6115. if len(list) == 0 {
  6116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6117. return
  6118. }
  6119. for _, item := range list {
  6120. prepare := models.DialysisBeforePrepare{
  6121. UserOrgId: adminInfo.Org.Id,
  6122. PatientId: patient_id,
  6123. RecordDate: record_time,
  6124. GoodId: item.GoodId,
  6125. GoodTypeId: item.GoodTypeId,
  6126. Count: item.Count,
  6127. Creater: adminInfo.AdminUser.Id,
  6128. Status: 1,
  6129. Ctime: time.Now().Unix(),
  6130. StorehouseId: houseConfig.StorehouseOutInfo,
  6131. }
  6132. //清空准备表数据
  6133. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6134. if errs != nil {
  6135. goodErrcode := models.XtGoodErrcode{
  6136. UserOrgId: adminInfo.Org.Id,
  6137. Errcode: "自动出库清空准备表数据报错",
  6138. GoodId: 0,
  6139. Status: 1,
  6140. Ctime: time.Now().Unix(),
  6141. Mtime: 0,
  6142. Count: 0,
  6143. StockCount: 0,
  6144. Creater: creator,
  6145. BatchNumberId: 0,
  6146. WarehouseOutId: 0,
  6147. }
  6148. service.CreateGoodErrcode(goodErrcode)
  6149. }
  6150. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6151. if errcodes != nil {
  6152. goodErrcode := models.XtGoodErrcode{
  6153. UserOrgId: adminInfo.Org.Id,
  6154. Errcode: "自动出库创建准备表数据报错",
  6155. GoodId: 0,
  6156. Status: 1,
  6157. Ctime: time.Now().Unix(),
  6158. Mtime: 0,
  6159. Count: 0,
  6160. StockCount: 0,
  6161. Creater: creator,
  6162. BatchNumberId: 0,
  6163. WarehouseOutId: 0,
  6164. }
  6165. service.CreateGoodErrcode(goodErrcode)
  6166. }
  6167. //查询默认仓库
  6168. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6169. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6170. var total_count int64
  6171. for _, it := range stockList {
  6172. total_count += it.StockCount
  6173. }
  6174. //基础库插入数据
  6175. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6176. if errcodes != nil {
  6177. goodErrcode := models.XtGoodErrcode{
  6178. UserOrgId: adminInfo.Org.Id,
  6179. Errcode: "自动出库基础库插入数据报错",
  6180. GoodId: 0,
  6181. Status: 1,
  6182. Ctime: time.Now().Unix(),
  6183. Mtime: 0,
  6184. Count: 0,
  6185. StockCount: 0,
  6186. Creater: creator,
  6187. BatchNumberId: 0,
  6188. WarehouseOutId: 0,
  6189. }
  6190. service.CreateGoodErrcode(goodErrcode)
  6191. }
  6192. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6193. var flush_count int64
  6194. for _, it := range goodList {
  6195. flush_count += it.StockCount
  6196. }
  6197. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6198. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6199. if errss != nil {
  6200. goodErrcode := models.XtGoodErrcode{
  6201. UserOrgId: item.OrgId,
  6202. Errcode: "自动出库剩余库存更新数据",
  6203. GoodId: item.GoodId,
  6204. Status: 1,
  6205. Ctime: time.Now().Unix(),
  6206. Mtime: 0,
  6207. Count: 0,
  6208. StockCount: 0,
  6209. Creater: creater,
  6210. BatchNumberId: 0,
  6211. WarehouseOutId: 0,
  6212. }
  6213. service.CreateGoodErrcode(goodErrcode)
  6214. }
  6215. }
  6216. }
  6217. }
  6218. c.ServeSuccessJSON(map[string]interface{}{
  6219. "msg": "提交成功",
  6220. "message": "2",
  6221. "good_name": "",
  6222. "specification_name": "",
  6223. })
  6224. return
  6225. } else {
  6226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6227. return
  6228. }
  6229. }
  6230. func (c *DialysisAPIController) EditConsumables() {
  6231. patient_id, _ := c.GetInt64("patient_id", 0)
  6232. record_date := c.GetString("record_time")
  6233. if patient_id <= 0 {
  6234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6235. return
  6236. }
  6237. adminInfo := c.GetMobileAdminUserInfo()
  6238. timeLayout := "2006-01-02"
  6239. loc, _ := time.LoadLocation("Local")
  6240. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6241. record_time := theRecordTime.Unix()
  6242. // 查询信息规挡的设置天数
  6243. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6244. if infor.ID > 0 && infor.WeekDay > 0 {
  6245. var cha_time int64
  6246. timeNowStr := time.Now().Format("2006-01-02")
  6247. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6248. //今日的日期减去设置的日期
  6249. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6250. if cha_time >= record_time {
  6251. //查询审核是否允许
  6252. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6253. //申请状态不允许的情况 拒绝修改
  6254. if infor.ApplicationStatus != 1 {
  6255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6256. return
  6257. }
  6258. }
  6259. }
  6260. dataBody := make(map[string]interface{}, 0)
  6261. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6262. if err != nil {
  6263. utils.ErrorLog(err.Error())
  6264. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6265. return
  6266. }
  6267. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6268. var beforePrepares []*models.DialysisBeforePrepareGoods
  6269. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6270. var cancelbefor []*models.DialysisBeforePrepareGoods
  6271. var outbefor []*models.DialysisBeforePrepareGoods
  6272. //判断是否开启自动出库
  6273. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6274. if record.IsOpen == 1 {
  6275. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6276. goods, _ := dataBody["goods"].([]interface{})
  6277. if len(goods) > 0 {
  6278. for _, item := range goods {
  6279. items := item.(map[string]interface{})
  6280. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6281. utils.ErrorLog("good_id")
  6282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6283. return
  6284. }
  6285. good_id := int64(items["good_id"].(float64))
  6286. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6287. utils.ErrorLog("good_type_id")
  6288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6289. return
  6290. }
  6291. good_type_id := int64(items["good_type_id"].(float64))
  6292. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6293. utils.ErrorLog("count")
  6294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6295. return
  6296. }
  6297. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6298. commdity_code := items["commdity_code"].(string)
  6299. fmt.Println(commdity_code)
  6300. prepareGoods := &models.DialysisBeforePrepareGoods{
  6301. GoodTypeId: good_type_id,
  6302. GoodId: good_id,
  6303. Count: count,
  6304. StorehouseId: houseConfig.StorehouseOutInfo,
  6305. }
  6306. beforePrepares = append(beforePrepares, prepareGoods)
  6307. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6308. GoodTypeId: good_type_id,
  6309. GoodId: good_id,
  6310. Count: count,
  6311. StorehouseId: houseConfig.StorehouseOutInfo,
  6312. }
  6313. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6314. }
  6315. for _, item := range beforePrepares {
  6316. //1.查看该患者该耗材型号最后一次出库数量
  6317. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6318. //判断当前出库数量和最后一次出库数量的大小
  6319. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  6320. if item.Count < goodInfo.Count {
  6321. cancelbefor = append(cancelbefor, item)
  6322. }
  6323. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6324. if item.Count > goodInfo.Count {
  6325. outbefor = append(outbefor, item)
  6326. }
  6327. //处理编辑耗材新增不了的问题
  6328. if goodInfo.Count == item.Count {
  6329. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  6330. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  6331. }
  6332. }
  6333. if len(cancelbefor) > 0 {
  6334. //退库
  6335. for _, item := range cancelbefor {
  6336. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6337. creater := adminInfo.AdminUser.Id
  6338. //查询该患者当天已经出库的耗材信息
  6339. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  6340. var delete_count int64 = 0
  6341. delete_count = warehouseOutInfos.Count - item.Count
  6342. //增加库存数量
  6343. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  6344. //减少实际出库库存数量
  6345. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  6346. // 删除出库完成后,要增加对应批次的库存数量
  6347. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  6348. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6349. //更新剩余库存
  6350. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6351. var flush_count int64
  6352. for _, it := range goodListOne {
  6353. flush_count += it.StockCount
  6354. }
  6355. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6356. //查询剩余库存
  6357. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6358. var sum_count int64
  6359. for _, item := range goodList {
  6360. sum_count += item.StockCount
  6361. }
  6362. // 在出库记录表里记录退库详情
  6363. warehouseOutInfo := &models.WarehouseOutInfo{
  6364. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6365. WarehouseOutId: warehouseOut.ID,
  6366. Status: 1,
  6367. Ctime: time.Now().Unix(),
  6368. OrgId: adminInfo.Org.Id,
  6369. Type: 1,
  6370. IsSys: 1,
  6371. SysRecordTime: record_time,
  6372. GoodTypeId: item.GoodTypeId,
  6373. GoodId: item.GoodId,
  6374. PatientId: patient_id,
  6375. ConsumableType: 2,
  6376. StorehouseId: houseConfig.StorehouseOutInfo,
  6377. IsCheck: 1,
  6378. OverCount: sum_count,
  6379. }
  6380. warehouseOutInfo.Count = item.Count
  6381. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  6382. warehouseOutInfo.Price = stockInInfo.Price
  6383. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6384. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6385. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6386. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6387. warehouseOutInfo.Number = warehouseOutInfos.Number
  6388. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6389. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6390. //查找当天是否存在出库记录
  6391. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  6392. if errcod == gorm.ErrRecordNotFound {
  6393. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6394. //插入详情明细表
  6395. stockFlow := models.VmStockFlow{
  6396. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6397. WarehouseOutId: warehouseOut.ID,
  6398. GoodId: item.GoodId,
  6399. Number: warehouseOutInfos.Number,
  6400. ProductDate: stockInInfo.ProductDate,
  6401. ExpireDate: stockInInfo.ExpiryDate,
  6402. Count: item.Count,
  6403. Price: stockInInfo.Price,
  6404. Status: 1,
  6405. Ctime: record_time,
  6406. UserOrgId: adminInfo.Org.Id,
  6407. Manufacturer: stockInInfo.Manufacturer,
  6408. Dealer: stockInInfo.Dealer,
  6409. LicenseNumber: stockInInfo.LicenseNumber,
  6410. IsEdit: 2,
  6411. Creator: creater,
  6412. SystemTime: record_time,
  6413. ConsumableType: 3,
  6414. WarehousingDetailId: 0,
  6415. IsSys: 1,
  6416. UpdateCreator: creater,
  6417. PatientId: patient_id,
  6418. StorehouseId: houseConfig.StorehouseOutInfo,
  6419. }
  6420. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  6421. if errflow == gorm.ErrRecordNotFound {
  6422. //创建流水表
  6423. err := service.CreateStockFlowOne(stockFlow)
  6424. fmt.Println("err", err)
  6425. } else if errflow == nil {
  6426. //插入详情明细表
  6427. stockFlow := models.VmStockFlow{
  6428. ID: exsit.ID,
  6429. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6430. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6431. WarehouseOutId: warehouseOut.ID,
  6432. GoodId: item.GoodId,
  6433. Number: warehouseOutInfos.Number,
  6434. ProductDate: stockInInfo.ProductDate,
  6435. ExpireDate: stockInInfo.ExpiryDate,
  6436. Count: exsit.Count - delete_count,
  6437. Price: stockInInfo.Price,
  6438. Status: 1,
  6439. Ctime: record_time,
  6440. UserOrgId: adminInfo.Org.Id,
  6441. Manufacturer: stockInInfo.Manufacturer,
  6442. Dealer: stockInInfo.Dealer,
  6443. LicenseNumber: stockInInfo.LicenseNumber,
  6444. IsEdit: 2,
  6445. Creator: creater,
  6446. SystemTime: record_time,
  6447. ConsumableType: 3,
  6448. WarehousingDetailId: 0,
  6449. IsSys: 1,
  6450. UpdateCreator: creater,
  6451. PatientId: patient_id,
  6452. StorehouseId: houseConfig.StorehouseOutInfo,
  6453. }
  6454. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  6455. }
  6456. } else if errcod == nil {
  6457. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  6458. //查询剩余库存
  6459. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6460. var sum_count int64
  6461. for _, item := range goodList {
  6462. sum_count += item.StockCount
  6463. }
  6464. //创建退库单,生成退库数据
  6465. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6466. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  6467. operation_time := time.Now().Unix()
  6468. creater := adminInfo.AdminUser.Id
  6469. //创建退库单
  6470. timeStr := time.Now().Format("2006-01-02")
  6471. timeArr := strings.Split(timeStr, "-")
  6472. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  6473. total = total + 1
  6474. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6475. cancelStock := models.CancelStock{
  6476. OrderNumber: orderNumber,
  6477. OperaTime: operation_time,
  6478. OrgId: adminInfo.Org.Id,
  6479. Creater: creater,
  6480. Ctime: time.Now().Unix(),
  6481. Status: 1,
  6482. ReturnTime: record_time,
  6483. Type: 1,
  6484. StorehouseId: houseConfig.StorehouseOutInfo,
  6485. IsCheck: 1,
  6486. }
  6487. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  6488. if msgerrkonde == gorm.ErrRecordNotFound {
  6489. service.AddSigleCancelStock(&cancelStock)
  6490. }
  6491. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  6492. //查询是否有出库
  6493. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  6494. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6495. deaerler, _ := service.GetDealerById(info.Dealer)
  6496. if info.ID > 0 {
  6497. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  6498. cancelStockInfo := models.CancelStockInfo{
  6499. GoodId: item.GoodId,
  6500. CancelStockId: cancel.ID,
  6501. GoodTypeId: good.GoodTypeId,
  6502. Count: delete_count,
  6503. Price: info.Price,
  6504. Total: 0,
  6505. ProductDate: info.ProductDate,
  6506. ExpiryDate: info.ExpiryDate,
  6507. Ctime: time.Now().Unix(),
  6508. Status: 1,
  6509. OrgId: adminInfo.Org.Id,
  6510. OrderNumber: cancel.OrderNumber,
  6511. Type: 0,
  6512. Dealer: deaerler.DealerName,
  6513. Manufacturer: manufacturer.ManufacturerName,
  6514. Number: info.Number,
  6515. RegisterAccount: "",
  6516. Remark: "",
  6517. WarehouseInfoId: info.WarehouseInfotId,
  6518. PatientId: info.PatientId,
  6519. RecordDate: info.SysRecordTime,
  6520. StorehouseId: houseConfig.StorehouseOutInfo,
  6521. IsCheck: 1,
  6522. }
  6523. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6524. //退库数量增加
  6525. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  6526. //查询剩余库存
  6527. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6528. var over_count int64
  6529. for _, it := range goodList {
  6530. over_count += it.StockCount
  6531. }
  6532. flow := models.VmStockFlow{
  6533. WarehousingId: info.WarehouseInfotId,
  6534. GoodId: item.GoodId,
  6535. Number: info.Number,
  6536. LicenseNumber: info.LicenseNumber,
  6537. Count: delete_count,
  6538. UserOrgId: adminInfo.Org.Id,
  6539. PatientId: patient_id,
  6540. SystemTime: info.SysRecordTime,
  6541. ConsumableType: 7,
  6542. IsSys: 0,
  6543. WarehousingOrder: "",
  6544. WarehouseOutId: info.WarehouseOutId,
  6545. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6546. IsEdit: 0,
  6547. CancelStockId: cancel.ID,
  6548. CancelOrderNumber: cancel.OrderNumber,
  6549. Manufacturer: manufacturer.ID,
  6550. Dealer: 0,
  6551. Creator: adminInfo.AdminUser.Id,
  6552. UpdateCreator: 0,
  6553. Status: 1,
  6554. Ctime: record_time,
  6555. Mtime: 0,
  6556. Price: info.Price,
  6557. WarehousingDetailId: info.WarehouseInfotId,
  6558. WarehouseOutDetailId: info.ID,
  6559. CancelOutDetailId: cancelInfo.ID,
  6560. ProductDate: info.ProductDate,
  6561. ExpireDate: info.ExpiryDate,
  6562. StorehouseId: houseConfig.StorehouseOutInfo,
  6563. OverCount: over_count,
  6564. }
  6565. service.CreateStockFlowOne(flow)
  6566. }
  6567. }
  6568. //更改自动出库的表格
  6569. details := models.BloodAutomaticReduceDetail{
  6570. WarehouseOutId: warehouseOutInfo.ID,
  6571. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6572. PatientId: patient_id,
  6573. Ctime: time.Now().Unix(),
  6574. Mtime: time.Now().Unix(),
  6575. Status: 1,
  6576. RecordTime: record_time,
  6577. OrgId: adminInfo.Org.Id,
  6578. GoodId: item.GoodId,
  6579. GoodTypeId: item.GoodTypeId,
  6580. Count: item.Count,
  6581. StorehouseId: houseConfig.StorehouseOutInfo,
  6582. }
  6583. //查询当天耗材是否已经存在数据
  6584. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6585. if errcode == gorm.ErrRecordNotFound {
  6586. service.CreateAutoReduceRecord(&details)
  6587. } else if errcode == nil {
  6588. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6589. service.CreateAutoReduceRecord(&details)
  6590. }
  6591. //查询默认仓库
  6592. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6593. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6594. var total_count int64
  6595. for _, it := range stockList {
  6596. total_count += it.StockCount
  6597. }
  6598. //基础库插入数据
  6599. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6600. }
  6601. }
  6602. if len(outbefor) > 0 {
  6603. //出库
  6604. for _, item := range outbefor {
  6605. var last_total int64
  6606. //1.查看该患者该耗材型号最后一次出库数量
  6607. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6608. //计算当前出库和最后一次出库数据相差数据
  6609. last_total = item.Count - goodInfoOne.Count
  6610. //查询该耗材的总库存
  6611. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  6612. // 如果库存差大于剩余库存则提示库存不足
  6613. if last_total > wareinfo.StockCount {
  6614. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6615. c.ServeSuccessJSON(map[string]interface{}{
  6616. "message": "1",
  6617. "good_name": goodObj.GoodName,
  6618. "specification_name": goodObj.SpecificationName,
  6619. })
  6620. return
  6621. } else {
  6622. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6623. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6624. if err == gorm.ErrRecordNotFound {
  6625. //没有记录,则创建出库单
  6626. timeStr := time.Now().Format("2006-01-02")
  6627. timeArr := strings.Split(timeStr, "-")
  6628. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6629. total = total + 1
  6630. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6631. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6632. number = number + total
  6633. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6634. warehouseOut := models.WarehouseOut{
  6635. WarehouseOutOrderNumber: warehousing_out_order,
  6636. OperationTime: time.Now().Unix(),
  6637. OrgId: adminInfo.Org.Id,
  6638. Creater: adminInfo.AdminUser.Id,
  6639. Ctime: time.Now().Unix(),
  6640. Status: 1,
  6641. WarehouseOutTime: record_time,
  6642. Dealer: 0,
  6643. Manufacturer: 0,
  6644. Type: 1,
  6645. IsSys: 1,
  6646. StorehouseId: houseConfig.StorehouseOutInfo,
  6647. IsCheck: 1,
  6648. }
  6649. service.AddSigleWarehouseOut(&warehouseOut)
  6650. }
  6651. //出库
  6652. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  6653. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6654. //1.查看该患者该耗材型号最后一次出库数量
  6655. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6656. prepare := models.DialysisBeforePrepare{
  6657. UserOrgId: adminInfo.Org.Id,
  6658. PatientId: patient_id,
  6659. RecordDate: record_time,
  6660. GoodId: item.GoodId,
  6661. GoodTypeId: item.GoodTypeId,
  6662. Count: item.Count - goodInfoTwo.Count,
  6663. Ctime: time.Now().Unix(),
  6664. Mtime: 0,
  6665. Creater: adminInfo.AdminUser.Id,
  6666. Modifier: adminInfo.AdminUser.Id,
  6667. Status: 1,
  6668. CommdityCode: "",
  6669. NewCount: 0,
  6670. ProjectId: 0,
  6671. StorehouseId: houseConfig.StorehouseOutInfo,
  6672. }
  6673. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  6674. //增加出库数量
  6675. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  6676. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6677. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6678. var total_count int64
  6679. for _, it := range stockList {
  6680. total_count += it.StockCount
  6681. }
  6682. //基础库插入数据
  6683. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6684. //剩余库存
  6685. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6686. var flush_count int64
  6687. for _, it := range goodList {
  6688. flush_count += it.StockCount
  6689. }
  6690. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6691. }
  6692. }
  6693. }
  6694. //查询今日出库数据
  6695. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6696. for _, it := range list {
  6697. prepare := models.DialysisBeforePrepare{
  6698. UserOrgId: it.OrgId,
  6699. PatientId: patient_id,
  6700. RecordDate: it.RecordTime,
  6701. GoodId: it.GoodId,
  6702. GoodTypeId: it.GoodTypeId,
  6703. Count: it.Count,
  6704. Ctime: time.Now().Unix(),
  6705. Creater: adminInfo.AdminUser.Id,
  6706. Status: 1,
  6707. StorehouseId: houseConfig.StorehouseOutInfo,
  6708. ProjectId: it.ProjectId,
  6709. }
  6710. //删除准备表数据
  6711. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  6712. service.CreateDialysisBeforePrepareOne(&prepare)
  6713. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6714. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6715. var total_count int64
  6716. for _, it := range stockList {
  6717. total_count += it.StockCount
  6718. }
  6719. //基础库插入数据
  6720. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  6721. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  6722. var flush_count int64
  6723. for _, it := range goodList {
  6724. flush_count += it.StockCount
  6725. }
  6726. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  6727. }
  6728. }
  6729. }
  6730. //更新自动出库的地方
  6731. var errs error
  6732. if errs == nil {
  6733. c.ServeSuccessJSON(map[string]interface{}{
  6734. "msg": "修改成功",
  6735. "message": "2",
  6736. "good_name": "",
  6737. "specification_name": "",
  6738. })
  6739. return
  6740. } else {
  6741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6742. return
  6743. }
  6744. }
  6745. }
  6746. func (c *DialysisAPIController) GetDialysisGoods() {
  6747. schedualDate := c.GetString("schedule_date")
  6748. schedule_type, _ := c.GetInt64("schedule_type")
  6749. partition_id, _ := c.GetInt64("partition_id")
  6750. page, _ := c.GetInt("page")
  6751. patient_id, _ := c.GetInt64("patient_id")
  6752. schedualEndDate := int64(0)
  6753. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  6754. if parseDateErr != nil && len(schedualDate) != 0 {
  6755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6756. return
  6757. }
  6758. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  6759. if parseDateErr != nil && len(schedualDate) != 0 {
  6760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6761. return
  6762. }
  6763. schedualEndDate = endDate.Unix()
  6764. adminUser := c.GetMobileAdminUserInfo()
  6765. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  6766. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  6767. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6768. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6769. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  6770. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  6771. //获取当天该病人的透析处方
  6772. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6773. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6774. if err == gorm.ErrRecordNotFound {
  6775. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6776. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6777. if patient_id != 0 {
  6778. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6779. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6780. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6781. //获取患者总的出库数据
  6782. item.LastAutomaticReduceDetail = goodUser
  6783. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6784. item.Project = project
  6785. for _, it := range item.AutomaticReduceDetail {
  6786. var total int64
  6787. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  6788. for _, its := range auto {
  6789. total += its.Count
  6790. }
  6791. it.Count = total
  6792. }
  6793. }
  6794. }
  6795. c.ServeSuccessJSON(map[string]interface{}{
  6796. "dialysis_goods": dialysisGoods,
  6797. "good_type": goodTypes,
  6798. "total": total,
  6799. "prescribe": prescribe,
  6800. "good_info": good_info,
  6801. "warehouseOutList": warehouseOutList,
  6802. "config": config,
  6803. "outConfig": outConfig,
  6804. "settleConfig": settleConfig,
  6805. })
  6806. return
  6807. } else if err == nil {
  6808. //获取当天排班的每个患者的库存使用情况
  6809. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6810. //获取患者总的出库数据
  6811. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6812. if patient_id != 0 {
  6813. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6814. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6815. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6816. item.Project = project
  6817. item.LastAutomaticReduceDetail = goodUser
  6818. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6819. for _, it := range item.AutomaticReduceDetail {
  6820. var total int64
  6821. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  6822. for _, its := range auto {
  6823. total += its.Count
  6824. }
  6825. it.Count = total
  6826. }
  6827. }
  6828. }
  6829. if err == nil {
  6830. c.ServeSuccessJSON(map[string]interface{}{
  6831. "dialysis_goods": dialysisGoods,
  6832. "good_type": goodTypes,
  6833. "total": total,
  6834. "prescribe": prescribe,
  6835. "good_info": good_info,
  6836. "project": project,
  6837. "warehouseOutList": warehouseOutList,
  6838. "config": config,
  6839. "outConfig": outConfig,
  6840. "settleConfig": settleConfig,
  6841. })
  6842. return
  6843. } else {
  6844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6845. return
  6846. }
  6847. } else if err != nil {
  6848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6849. return
  6850. }
  6851. }
  6852. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  6853. start_time := c.GetString("start_time")
  6854. end_time := c.GetString("end_time")
  6855. timeLayout := "2006-01-02"
  6856. loc, _ := time.LoadLocation("Local")
  6857. var theStartTime int64
  6858. if len(start_time) > 0 {
  6859. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6860. if err != nil {
  6861. utils.ErrorLog(err.Error())
  6862. }
  6863. theStartTime = theTime.Unix()
  6864. }
  6865. var theEndtTime int64
  6866. if len(end_time) > 0 {
  6867. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6868. if err != nil {
  6869. utils.ErrorLog(err.Error())
  6870. }
  6871. theEndtTime = theTime.Unix()
  6872. }
  6873. adminUser := c.GetMobileAdminUserInfo()
  6874. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  6875. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  6876. if err == nil {
  6877. c.ServeSuccessJSON(map[string]interface{}{
  6878. "stock_out": outInfo,
  6879. "stockCount": stockCount,
  6880. })
  6881. return
  6882. } else {
  6883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6884. return
  6885. }
  6886. }
  6887. func (c *DialysisAPIController) GetStockInGoodInfo() {
  6888. patient_id, _ := c.GetInt64("patient_id", 0)
  6889. record_time := c.GetString("record_time")
  6890. adminUser := c.GetMobileAdminUserInfo()
  6891. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  6892. if parseDateErr != nil && len(record_time) != 0 {
  6893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6894. return
  6895. }
  6896. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  6897. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6898. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  6899. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  6900. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6901. //获取今日患者的透析处方参数
  6902. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6903. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  6904. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6905. c.ServeSuccessJSON(map[string]interface{}{
  6906. "good_type": goodTypes,
  6907. "good_user": goodUser,
  6908. "good_info": good_info,
  6909. "last_good_user": lastGoodUserDetial,
  6910. "project": project,
  6911. "prescription": prescribe,
  6912. "outInfo": outInfo,
  6913. "configs": configs,
  6914. })
  6915. return
  6916. }
  6917. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  6918. patient_id, _ := c.GetInt64("patient_id", 0)
  6919. record_date := c.GetString("record_time")
  6920. timeLayout := "2006-01-02"
  6921. loc, _ := time.LoadLocation("Local")
  6922. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6923. record_time := theRecordTime.Unix()
  6924. adminInfo := c.GetMobileAdminUserInfo()
  6925. dataBody := make(map[string]interface{}, 0)
  6926. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6927. if err != nil {
  6928. utils.ErrorLog(err.Error())
  6929. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6930. return
  6931. }
  6932. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6933. var beforePrepares []*models.DialysisBeforePrepareGoods
  6934. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6935. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6936. goods, _ := dataBody["goods"].([]interface{})
  6937. if len(goods) > 0 {
  6938. for _, item := range goods {
  6939. items := item.(map[string]interface{})
  6940. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6941. utils.ErrorLog("good_id")
  6942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6943. return
  6944. }
  6945. good_id := int64(items["good_id"].(float64))
  6946. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6947. utils.ErrorLog("good_type_id")
  6948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6949. return
  6950. }
  6951. good_type_id := int64(items["good_type_id"].(float64))
  6952. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6953. utils.ErrorLog("count")
  6954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6955. return
  6956. }
  6957. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6958. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  6959. utils.ErrorLog("project_id")
  6960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6961. return
  6962. }
  6963. project_id := int64(items["project_id"].(float64))
  6964. new_count := int64(items["new_count"].(float64))
  6965. old_count := int64(items["old_count"].(float64))
  6966. prepare := &models.DialysisBeforePrepareGoods{
  6967. GoodId: good_id,
  6968. GoodTypeId: good_type_id,
  6969. Count: count,
  6970. ProjectId: project_id,
  6971. StorehouseId: houseConfig.StorehouseOutInfo,
  6972. NewCount: new_count,
  6973. OldCount: old_count,
  6974. }
  6975. beforePrepares = append(beforePrepares, prepare)
  6976. newPrepare := &models.NewDialysisBeforePrepareGoods{
  6977. GoodId: good_id,
  6978. GoodTypeId: good_type_id,
  6979. Count: count,
  6980. ProjectId: project_id,
  6981. StorehouseId: houseConfig.StorehouseOutInfo,
  6982. NewCount: new_count,
  6983. OldCount: old_count,
  6984. }
  6985. newBeforePrepares = append(newBeforePrepares, newPrepare)
  6986. }
  6987. }
  6988. }
  6989. //查询是否有库存
  6990. for _, item := range beforePrepares {
  6991. if item.NewCount > 0 {
  6992. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6993. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  6994. if item.Count > warehouse.Count {
  6995. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6996. c.ServeSuccessJSON(map[string]interface{}{
  6997. "message": "1",
  6998. "good_name": goodObj.GoodName,
  6999. "specification_name": goodObj.SpecificationName,
  7000. })
  7001. return
  7002. }
  7003. }
  7004. }
  7005. // 查询信息规挡的设置天数
  7006. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7007. if infor.ID > 0 && infor.WeekDay > 0 {
  7008. var cha_time int64
  7009. timeNowStr := time.Now().Format("2006-01-02")
  7010. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7011. //今日的日期减去设置的日期
  7012. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7013. if cha_time >= record_time {
  7014. //查询审核是否允许
  7015. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7016. //申请状态不允许的情况 拒绝修改
  7017. if infor.ApplicationStatus != 1 {
  7018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7019. return
  7020. }
  7021. }
  7022. }
  7023. //出库逻辑
  7024. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  7025. if err != nil {
  7026. utils.ErrorLog(err.Error())
  7027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7028. return
  7029. }
  7030. finish := models.XtDialysisFinish{
  7031. IsFinish: 1,
  7032. UserOrgId: adminInfo.Org.Id,
  7033. Status: 1,
  7034. Ctime: time.Now().Unix(),
  7035. Mtime: 0,
  7036. Module: 11,
  7037. RecordDate: record_time,
  7038. Sourse: 1,
  7039. PatientId: patient_id,
  7040. }
  7041. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  7042. if dialysisFinish.ID == 0 {
  7043. service.CreateDialysisFinish(finish)
  7044. }
  7045. //查询当天出库的数据
  7046. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7047. for _, item := range list {
  7048. prepare := models.DialysisBeforePrepare{
  7049. UserOrgId: item.OrgId,
  7050. PatientId: item.PatientId,
  7051. RecordDate: item.RecordTime,
  7052. GoodId: item.GoodId,
  7053. GoodTypeId: item.GoodTypeId,
  7054. Count: item.Count,
  7055. Creater: adminInfo.AdminUser.Id,
  7056. Status: 1,
  7057. Ctime: time.Now().Unix(),
  7058. ProjectId: item.ProjectId,
  7059. StorehouseId: houseConfig.StorehouseOutInfo,
  7060. }
  7061. //清空准备表的数据
  7062. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7063. //插入准备表数据
  7064. service.CreateDialysisBeforePrepareOne(&prepare)
  7065. //查询默认仓库
  7066. //查询默认仓库
  7067. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7068. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7069. var total_count int64
  7070. for _, it := range stockList {
  7071. total_count += it.StockCount
  7072. }
  7073. //基础库插入数据
  7074. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7075. ////更新剩余库存
  7076. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7077. var flush_count int64
  7078. for _, it := range goodList {
  7079. flush_count += it.StockCount
  7080. }
  7081. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7082. if errs != nil {
  7083. goodErrcode := models.XtGoodErrcode{
  7084. UserOrgId: item.OrgId,
  7085. Errcode: "手动出库更新剩余出库失败",
  7086. GoodId: item.GoodId,
  7087. Status: 1,
  7088. Ctime: time.Now().Unix(),
  7089. Mtime: 0,
  7090. Count: 0,
  7091. StockCount: 0,
  7092. Creater: adminInfo.AdminUser.Id,
  7093. BatchNumberId: 0,
  7094. WarehouseOutId: 0,
  7095. }
  7096. service.CreateGoodErrcode(goodErrcode)
  7097. }
  7098. }
  7099. //更新自动出库的地方
  7100. var errs error
  7101. if errs == nil {
  7102. c.ServeSuccessJSON(map[string]interface{}{
  7103. "msg": "修改成功",
  7104. "message": "2",
  7105. "good_name": "",
  7106. "specification_name": "",
  7107. })
  7108. return
  7109. } else {
  7110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7111. return
  7112. }
  7113. }
  7114. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7115. newArr = make([]*models.DialysisBeforePrepare, 0)
  7116. for i := 0; i < len(arr); i++ {
  7117. repeat := false
  7118. for j := i + 1; j < len(arr); j++ {
  7119. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7120. repeat = true
  7121. break
  7122. }
  7123. }
  7124. if !repeat {
  7125. newArr = append(newArr, arr[i])
  7126. }
  7127. }
  7128. return
  7129. }
  7130. func (c *DialysisAPIController) GetAllDrug() {
  7131. patient_id, _ := c.GetInt64("patient_id", 0)
  7132. adminInfo := c.GetMobileAdminUserInfo()
  7133. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7134. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7135. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7136. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7137. c.ServeSuccessJSON(map[string]interface{}{
  7138. "base_drug_config": drugStockConfig,
  7139. "private_drug_config": privateDrugConfig,
  7140. "base_drug_list": drugList,
  7141. "private_drug_list": privateDrugList,
  7142. })
  7143. }
  7144. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7145. newArr = make([]*models.DialysisBeforePrepare, 0)
  7146. for i := 0; i < len(arr); i++ {
  7147. repeat := false
  7148. for j := i + 1; j < len(arr); j++ {
  7149. if arr[i].GoodId == arr[j].GoodId {
  7150. repeat = true
  7151. break
  7152. }
  7153. }
  7154. if !repeat {
  7155. newArr = append(newArr, arr[i])
  7156. }
  7157. }
  7158. return
  7159. }
  7160. func (c *DialysisAPIController) GetDepartment() {
  7161. adminInfo := c.GetMobileAdminUserInfo()
  7162. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7163. if err == nil {
  7164. c.ServeSuccessJSON(map[string]interface{}{
  7165. "departments": departments,
  7166. })
  7167. } else {
  7168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7169. return
  7170. }
  7171. }
  7172. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7173. types, _ := c.GetInt("type", 0)
  7174. start_time := c.GetString("start_time")
  7175. end_time := c.GetString("end_time")
  7176. orgId := c.GetMobileAdminUserInfo().Org.Id
  7177. timeLayout := "2006-01-02"
  7178. loc, _ := time.LoadLocation("Local")
  7179. var startTime int64
  7180. if len(start_time) > 0 {
  7181. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7182. if err != nil {
  7183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7184. return
  7185. }
  7186. startTime = theTime.Unix()
  7187. }
  7188. var endTime int64
  7189. if len(end_time) > 0 {
  7190. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7191. if err != nil {
  7192. utils.ErrorLog(err.Error())
  7193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7194. return
  7195. }
  7196. endTime = theTime.Unix()
  7197. }
  7198. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7199. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7200. if err != nil {
  7201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7202. } else {
  7203. c.ServeSuccessJSON(map[string]interface{}{
  7204. "list": list,
  7205. "type": types,
  7206. "stockTotal": stockTotal,
  7207. })
  7208. }
  7209. }
  7210. func (c *DialysisAPIController) GetPrescriptionList() {
  7211. start_time := c.GetString("start_time")
  7212. end_time := c.GetString("end_time")
  7213. schedule_type, _ := c.GetInt64("schedule_type")
  7214. partion_id, _ := c.GetInt64("partion_id")
  7215. orgId := c.GetMobileAdminUserInfo().Org.Id
  7216. timeLayout := "2006-01-02"
  7217. loc, _ := time.LoadLocation("Local")
  7218. var startTime int64
  7219. if len(start_time) > 0 {
  7220. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7221. if err != nil {
  7222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7223. return
  7224. }
  7225. startTime = theTime.Unix()
  7226. }
  7227. var endTime int64
  7228. if len(end_time) > 0 {
  7229. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7230. if err != nil {
  7231. utils.ErrorLog(err.Error())
  7232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7233. return
  7234. }
  7235. endTime = theTime.Unix()
  7236. }
  7237. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7238. fmt.Println("schedulelist22222222", schedulelist)
  7239. c.ServeSuccessJSON(map[string]interface{}{
  7240. "list": schedulelist,
  7241. })
  7242. return
  7243. }
  7244. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7245. ids := c.GetString("ids")
  7246. //patient_id, _ := c.GetInt64("patient_id")
  7247. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7248. idArray := strings.Split(ids, ",")
  7249. err := service.BatchDeleteMonitor(idArray)
  7250. fmt.Print("err", err)
  7251. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7252. //redis := service.RedisClient()
  7253. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7254. //redis.Set(key, "", time.Second)
  7255. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7256. //redis.Set(keyOne, "", time.Second)
  7257. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7258. //redis.Close()
  7259. c.ServeSuccessJSON(map[string]interface{}{
  7260. "msg": "批量删除成功",
  7261. })
  7262. return
  7263. }
  7264. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7265. id, _ := c.GetInt64("id")
  7266. timeLayout := "2006-01-02"
  7267. loc, _ := time.LoadLocation("Local")
  7268. //start_time := time.Now().Format("2006-01-02")
  7269. start_time := c.GetString("start_time")
  7270. end_time := c.GetString("end_time")
  7271. var startdateunix int64
  7272. if len(start_time) > 0 {
  7273. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7274. if err != nil {
  7275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7276. return
  7277. }
  7278. startdateunix = theTime.Unix()
  7279. }
  7280. var enddateunix int64
  7281. if len(end_time) > 0 {
  7282. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7283. if err != nil {
  7284. utils.ErrorLog(err.Error())
  7285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7286. return
  7287. }
  7288. enddateunix = theTime.Unix()
  7289. }
  7290. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7291. //nowTime := time.Now()
  7292. //endTime := nowTime.AddDate(-30, 0, 0)
  7293. //endTimes := endTime.Format("2006-01-02")
  7294. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7295. org_id := c.GetMobileAdminUserInfo().Org.Id
  7296. //if org_id == 10579 {
  7297. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7298. // c.ServeSuccessJSON(map[string]interface{}{
  7299. // "list": list,
  7300. // })
  7301. // return
  7302. //} else {
  7303. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7304. // c.ServeSuccessJSON(map[string]interface{}{
  7305. // "list": list,
  7306. // })
  7307. // return
  7308. //}
  7309. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  7310. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7311. c.ServeSuccessJSON(map[string]interface{}{
  7312. "list": list,
  7313. })
  7314. return
  7315. } else {
  7316. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7317. c.ServeSuccessJSON(map[string]interface{}{
  7318. "list": list,
  7319. })
  7320. }
  7321. return
  7322. }
  7323. func (c *DialysisAPIController) BathDeleteAdviceList() {
  7324. dataBody := make(map[string]interface{}, 0)
  7325. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7326. ids := c.GetString("ids")
  7327. idArray := strings.Split(ids, ",")
  7328. origin, _ := c.GetInt64("origin")
  7329. if origin == 1 {
  7330. err = service.BatchDeleteAdvice(idArray)
  7331. fmt.Print("err", err)
  7332. c.ServeSuccessJSON(map[string]interface{}{
  7333. "msg": "批量删除成功",
  7334. })
  7335. return
  7336. }
  7337. if origin == 2 {
  7338. service.BatchDeleteHisAdvice(idArray)
  7339. }
  7340. }
  7341. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  7342. good_id, _ := c.GetInt64("good_id")
  7343. count, _ := c.GetInt64("count")
  7344. record_time, _ := c.GetInt64("record_time")
  7345. patient_id, _ := c.GetInt64("patient_id")
  7346. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  7347. c.ServeSuccessJSON(map[string]interface{}{
  7348. "detail": detail,
  7349. })
  7350. return
  7351. }
  7352. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  7353. good_id, _ := c.GetInt64("good_id")
  7354. record_time, _ := c.GetInt64("record_time")
  7355. patient_id, _ := c.GetInt64("patient_id")
  7356. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  7357. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  7358. fmt.Print("err", err)
  7359. c.ServeSuccessJSON(map[string]interface{}{
  7360. "msg": "批量删除成功",
  7361. })
  7362. return
  7363. }
  7364. func (c *DialysisAPIController) BatchAdviceCheck() {
  7365. ids := c.GetString("ids")
  7366. idArray := strings.Split(ids, ",")
  7367. creator, _ := c.GetInt64("creator")
  7368. origin, _ := c.GetInt64("origin")
  7369. if origin == 1 {
  7370. err := service.BatchAdviceCheck(idArray, creator)
  7371. fmt.Println(err)
  7372. list, _ := service.GetAdviceExecutionById(idArray)
  7373. c.ServeSuccessJSON(map[string]interface{}{
  7374. "list": list,
  7375. })
  7376. return
  7377. }
  7378. if origin == 2 {
  7379. service.BatchHisAdviceCheck(idArray, creator)
  7380. list, _ := service.GetHisAdviceExecutionById(idArray)
  7381. c.ServeSuccessJSON(map[string]interface{}{
  7382. "list": list,
  7383. })
  7384. return
  7385. }
  7386. }
  7387. func (c *DialysisAPIController) BatchAdviceExecution() {
  7388. ids := c.GetString("ids")
  7389. idArray := strings.Split(ids, ",")
  7390. executionTime := c.GetString("execution_time")
  7391. creator, _ := c.GetInt64("creator")
  7392. timeLayout := "2006-01-02 15:04:05"
  7393. loc, _ := time.LoadLocation("Local")
  7394. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  7395. orgin, _ := c.GetInt64("origin")
  7396. if orgin == 1 {
  7397. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  7398. list, _ := service.GetAdviceExecutionById(idArray)
  7399. fmt.Println(err)
  7400. c.ServeSuccessJSON(map[string]interface{}{
  7401. "list": list,
  7402. })
  7403. return
  7404. }
  7405. if orgin == 2 {
  7406. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  7407. list, _ := service.GetHisAdviceExecutionById(idArray)
  7408. fmt.Println(err)
  7409. c.ServeSuccessJSON(map[string]interface{}{
  7410. "list": list,
  7411. })
  7412. return
  7413. }
  7414. }
  7415. func (c *DialysisAPIController) UpdateStockGoods() {
  7416. good_id, _ := c.GetInt64("good_id")
  7417. record_time, _ := c.GetInt64("record_time")
  7418. patient_id, _ := c.GetInt64("patient_id")
  7419. count, _ := c.GetInt64("count")
  7420. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  7421. fmt.Print("err", err)
  7422. c.ServeSuccessJSON(map[string]interface{}{
  7423. "msg": "更新成功",
  7424. })
  7425. return
  7426. }
  7427. // 当前数据比上一次出库数据少
  7428. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  7429. //查询该患者当天已经出库的耗材信息
  7430. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7431. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7432. for i := len(goods_yc) - 1; i >= 0; i-- {
  7433. goods_yc_temp := goods_yc[i]
  7434. for j := len(goods) - 1; j >= 0; j-- {
  7435. goods_temp := goods[j]
  7436. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7437. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7438. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7439. if goods_yc_temp.Count == goods_temp.Count {
  7440. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7441. goods = append(goods[:j], goods[j+1:]...)
  7442. break
  7443. }
  7444. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7445. if goods_yc_temp.Count > goods_temp.Count {
  7446. temp_count := goods_yc_temp.Count - goods_temp.Count
  7447. goods_yc[i].Count = temp_count
  7448. goods = append(goods[:j], goods[j+1:]...)
  7449. break
  7450. }
  7451. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7452. if goods_yc_temp.Count < goods_temp.Count {
  7453. temp_count := goods_temp.Count - goods_yc_temp.Count
  7454. goods[j].Count = temp_count
  7455. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7456. break
  7457. }
  7458. }
  7459. }
  7460. }
  7461. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7462. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7463. //退库
  7464. if len(goods_yc) > 0 {
  7465. for _, good_yc := range goods_yc {
  7466. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7467. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  7468. }
  7469. }
  7470. return nil
  7471. }
  7472. // 耗材出库删除
  7473. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7474. // 先根据相关信息查询当天该耗材的出库信息
  7475. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7476. if err != nil {
  7477. return err
  7478. }
  7479. var delete_count int64 = 0
  7480. delete_count = warehouseOutInfos.Count - count
  7481. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7482. // 在出库记录表里记录退库详情
  7483. warehouseOutInfo := &models.WarehouseOutInfo{
  7484. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7485. WarehouseOutId: warehouseOut.ID,
  7486. Status: 1,
  7487. Ctime: time.Now().Unix(),
  7488. OrgId: orgID,
  7489. Type: 1,
  7490. IsSys: 1,
  7491. SysRecordTime: record_time,
  7492. GoodTypeId: good_yc.GoodTypeId,
  7493. GoodId: good_yc.GoodId,
  7494. PatientId: good_yc.PatientId,
  7495. ConsumableType: 2,
  7496. StorehouseId: houseConfig.StorehouseOutInfo,
  7497. IsCheck: 1,
  7498. }
  7499. warehouseOutInfo.Count = count
  7500. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7501. warehouseOutInfo.Price = stockInInfo.Price
  7502. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7503. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7504. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7505. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7506. warehouseOutInfo.Number = warehouseOutInfos.Number
  7507. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7508. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7509. //查找当天是否存在出库记录
  7510. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7511. if errcod == gorm.ErrRecordNotFound {
  7512. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7513. //插入详情明细表
  7514. stockFlow := models.VmStockFlow{
  7515. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7516. WarehouseOutId: warehouseOut.ID,
  7517. GoodId: good_yc.GoodId,
  7518. Number: warehouseOutInfos.Number,
  7519. ProductDate: stockInInfo.ProductDate,
  7520. ExpireDate: stockInInfo.ExpiryDate,
  7521. Count: count,
  7522. Price: stockInInfo.Price,
  7523. Status: 1,
  7524. Ctime: time.Now().Unix(),
  7525. UserOrgId: good_yc.OrgId,
  7526. Manufacturer: stockInInfo.Manufacturer,
  7527. Dealer: stockInInfo.Dealer,
  7528. LicenseNumber: stockInInfo.LicenseNumber,
  7529. IsEdit: 2,
  7530. Creator: creater,
  7531. SystemTime: record_time,
  7532. ConsumableType: 3,
  7533. WarehousingDetailId: 0,
  7534. IsSys: 1,
  7535. UpdateCreator: creater,
  7536. PatientId: patient_id,
  7537. StorehouseId: houseConfig.StorehouseOutInfo,
  7538. }
  7539. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7540. if errflow == gorm.ErrRecordNotFound {
  7541. //创建流水表
  7542. err := service.CreateStockFlowOne(stockFlow)
  7543. fmt.Println("err", err)
  7544. } else if errflow == nil {
  7545. //插入详情明细表
  7546. stockFlow := models.VmStockFlow{
  7547. ID: exsit.ID,
  7548. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7549. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7550. WarehouseOutId: warehouseOut.ID,
  7551. GoodId: good_yc.GoodId,
  7552. Number: warehouseOutInfos.Number,
  7553. ProductDate: stockInInfo.ProductDate,
  7554. ExpireDate: stockInInfo.ExpiryDate,
  7555. Count: exsit.Count - delete_count,
  7556. Price: stockInInfo.Price,
  7557. Status: 1,
  7558. Ctime: time.Now().Unix(),
  7559. UserOrgId: good_yc.OrgId,
  7560. Manufacturer: stockInInfo.Manufacturer,
  7561. Dealer: stockInInfo.Dealer,
  7562. LicenseNumber: stockInInfo.LicenseNumber,
  7563. IsEdit: 2,
  7564. Creator: creater,
  7565. SystemTime: record_time,
  7566. ConsumableType: 3,
  7567. WarehousingDetailId: 0,
  7568. IsSys: 1,
  7569. UpdateCreator: creater,
  7570. PatientId: patient_id,
  7571. StorehouseId: houseConfig.StorehouseOutInfo,
  7572. }
  7573. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7574. }
  7575. if errOne != nil {
  7576. return errOne
  7577. }
  7578. } else if errcod == nil {
  7579. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7580. //插入详情明细表
  7581. stockFlow := models.VmStockFlow{
  7582. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7583. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7584. WarehouseOutId: warehouseOut.ID,
  7585. GoodId: good_yc.GoodId,
  7586. Number: warehouseOutInfos.Number,
  7587. ProductDate: stockInInfo.ProductDate,
  7588. ExpireDate: stockInInfo.ExpiryDate,
  7589. Count: count,
  7590. Price: stockInInfo.Price,
  7591. Status: 1,
  7592. Ctime: time.Now().Unix(),
  7593. UserOrgId: good_yc.OrgId,
  7594. Manufacturer: stockInInfo.Manufacturer,
  7595. Dealer: stockInInfo.Dealer,
  7596. LicenseNumber: stockInInfo.LicenseNumber,
  7597. IsEdit: 2,
  7598. Creator: creater,
  7599. SystemTime: record_time,
  7600. ConsumableType: 3,
  7601. WarehousingDetailId: 0,
  7602. IsSys: 1,
  7603. UpdateCreator: creater,
  7604. PatientId: patient_id,
  7605. ReturnCount: delete_count,
  7606. StorehouseId: houseConfig.StorehouseOutInfo,
  7607. }
  7608. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7609. if errflows == gorm.ErrRecordNotFound {
  7610. //创建流水表
  7611. service.CreateStockFlowOne(stockFlow)
  7612. } else if errflows == nil {
  7613. stockFlow := models.VmStockFlow{
  7614. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7615. ID: exsit.ID,
  7616. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7617. WarehouseOutId: warehouseOut.ID,
  7618. GoodId: good_yc.GoodId,
  7619. Number: warehouseOutInfos.Number,
  7620. ProductDate: stockInInfo.ProductDate,
  7621. ExpireDate: stockInInfo.ExpiryDate,
  7622. Count: exsit.Count - delete_count,
  7623. Price: stockInInfo.Price,
  7624. Status: 1,
  7625. Ctime: time.Now().Unix(),
  7626. UserOrgId: good_yc.OrgId,
  7627. Manufacturer: stockInInfo.Manufacturer,
  7628. Dealer: stockInInfo.Dealer,
  7629. LicenseNumber: stockInInfo.LicenseNumber,
  7630. IsEdit: 2,
  7631. Creator: creater,
  7632. SystemTime: record_time,
  7633. ConsumableType: 3,
  7634. WarehousingDetailId: 0,
  7635. IsSys: 1,
  7636. UpdateCreator: creater,
  7637. PatientId: patient_id,
  7638. ReturnCount: delete_count,
  7639. StorehouseId: houseConfig.StorehouseOutInfo,
  7640. }
  7641. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7642. }
  7643. }
  7644. //更改自动出库的表格
  7645. details := models.BloodAutomaticReduceDetail{
  7646. WarehouseOutId: warehouseOutInfo.ID,
  7647. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7648. PatientId: patient_id,
  7649. Ctime: time.Now().Unix(),
  7650. Mtime: time.Now().Unix(),
  7651. Status: 1,
  7652. RecordTime: record_time,
  7653. OrgId: orgID,
  7654. GoodId: good_yc.GoodId,
  7655. GoodTypeId: good_yc.GoodTypeId,
  7656. Count: count,
  7657. StorehouseId: houseConfig.StorehouseOutInfo,
  7658. }
  7659. //查询当天耗材是否已经存在数据
  7660. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7661. if errcode == gorm.ErrRecordNotFound {
  7662. errTwo := service.CreateAutoReduceRecord(&details)
  7663. if errTwo != nil {
  7664. return errTwo
  7665. }
  7666. } else if errcode == nil {
  7667. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7668. service.CreateAutoReduceRecord(&details)
  7669. }
  7670. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7671. //增加出库库存数量
  7672. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  7673. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7674. fmt.Println("errOne", errOne)
  7675. // 删除出库完成后,要增加对应批次的库存数量
  7676. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7677. if errThree != nil {
  7678. return errThree
  7679. }
  7680. if good_yc.Count == 0 {
  7681. return nil
  7682. } else {
  7683. return errors.New("退库和出库数据不匹配")
  7684. }
  7685. }
  7686. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  7687. //查询该患者当天已经出库的耗材信息
  7688. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7689. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7690. for i := len(goods_yc) - 1; i >= 0; i-- {
  7691. goods_yc_temp := goods_yc[i]
  7692. for j := len(goods) - 1; j >= 0; j-- {
  7693. goods_temp := goods[j]
  7694. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7695. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7696. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7697. if goods_yc_temp.Count == goods_temp.Count {
  7698. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7699. goods = append(goods[:j], goods[j+1:]...)
  7700. break
  7701. }
  7702. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7703. if goods_yc_temp.Count > goods_temp.Count {
  7704. temp_count := goods_yc_temp.Count - goods_temp.Count
  7705. goods_yc[i].Count = temp_count
  7706. goods = append(goods[:j], goods[j+1:]...)
  7707. break
  7708. }
  7709. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7710. if goods_yc_temp.Count < goods_temp.Count {
  7711. temp_count := goods_temp.Count - goods_yc_temp.Count
  7712. goods[j].Count = temp_count
  7713. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7714. break
  7715. }
  7716. }
  7717. }
  7718. }
  7719. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7720. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7721. fmt.Println("剩余需要出库的", len(goods))
  7722. if len(goods) > 0 {
  7723. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  7724. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7725. if err == gorm.ErrRecordNotFound {
  7726. //没有记录,则创建出库单
  7727. timeStr := time.Now().Format("2006-01-02")
  7728. timeArr := strings.Split(timeStr, "-")
  7729. total, _ := service.FindAllWarehouseOut(orgID)
  7730. total = total + 1
  7731. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7732. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7733. number = number + total
  7734. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7735. warehouseOut := models.WarehouseOut{
  7736. WarehouseOutOrderNumber: warehousing_out_order,
  7737. OperationTime: time.Now().Unix(),
  7738. OrgId: orgID,
  7739. Creater: creater,
  7740. Ctime: time.Now().Unix(),
  7741. Status: 1,
  7742. WarehouseOutTime: record_time,
  7743. Dealer: 0,
  7744. Manufacturer: 0,
  7745. Type: 1,
  7746. IsSys: 1,
  7747. StorehouseId: houseConfig.StorehouseOutInfo,
  7748. IsCheck: 1,
  7749. }
  7750. err := service.AddSigleWarehouseOut(&warehouseOut)
  7751. if err != nil {
  7752. utils.TraceLog("创建出库单失败 err = %v", err)
  7753. return err
  7754. } else {
  7755. out = warehouseOut
  7756. }
  7757. }
  7758. for _, item := range goods {
  7759. var newCount int64 = 0
  7760. for _, it := range goodOne {
  7761. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  7762. newCount = it.Count
  7763. }
  7764. }
  7765. prepare := models.DialysisBeforePrepare{
  7766. GoodTypeId: item.GoodTypeId,
  7767. GoodId: item.GoodId,
  7768. Count: item.Count,
  7769. StorehouseId: houseConfig.StorehouseOutInfo,
  7770. }
  7771. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  7772. //增加出库数量
  7773. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  7774. }
  7775. }
  7776. if len(goods_yc) > 0 {
  7777. for _, good_yc := range goods_yc {
  7778. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7779. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  7780. }
  7781. }
  7782. return nil
  7783. }
  7784. // 耗材出库删除
  7785. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  7786. // 先根据相关信息查询当天该耗材的出库信息
  7787. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  7788. if err != nil {
  7789. return err
  7790. }
  7791. var delete_count int64 = 0
  7792. for _, ware := range warehouseOutInfos {
  7793. // 判断当前出库的数据和删除出库数量
  7794. if good_yc.Count <= ware.Count {
  7795. delete_count = good_yc.Count
  7796. } else {
  7797. delete_count = ware.Count
  7798. }
  7799. warehouseOutInfo := &models.WarehouseOutInfo{
  7800. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7801. WarehouseOutId: warehouseOut.ID,
  7802. Status: 1,
  7803. Ctime: time.Now().Unix(),
  7804. Remark: "",
  7805. OrgId: orgID,
  7806. Type: 1,
  7807. Manufacturer: 0,
  7808. Dealer: 0,
  7809. IsSys: 0,
  7810. SysRecordTime: record_time,
  7811. GoodTypeId: good_yc.GoodTypeId,
  7812. GoodId: good_yc.GoodId,
  7813. StorehouseId: warehouseOut.StorehouseId,
  7814. IsCheck: 1,
  7815. }
  7816. warehouseOutInfo.Count = delete_count
  7817. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7818. warehouseOutInfo.Price = stockInInfo.Price
  7819. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7820. if errOne != nil {
  7821. return errOne
  7822. }
  7823. // 删除出库完成后,要改变流水库存(有疑问)
  7824. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7825. fmt.Println("errOne", errOne)
  7826. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  7827. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7828. //扣减出库数量
  7829. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  7830. if errThree != nil {
  7831. return errThree
  7832. }
  7833. }
  7834. if good_yc.Count == 0 {
  7835. return nil
  7836. } else {
  7837. return errors.New("退库和出库数据不匹配")
  7838. }
  7839. }
  7840. func (this *DialysisAPIController) GetMobileScheduleList() {
  7841. limit, _ := this.GetInt64("limit")
  7842. page, _ := this.GetInt64("page")
  7843. type_options_visible, _ := this.GetInt64("type_options_visible")
  7844. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  7845. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  7846. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  7847. }
  7848. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  7849. newArr = make([]*models.HisPrescriptionProject, 0)
  7850. for i := 0; i < len(arr); i++ {
  7851. repeat := false
  7852. for j := i + 1; j < len(arr); j++ {
  7853. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  7854. repeat = true
  7855. break
  7856. }
  7857. }
  7858. if !repeat {
  7859. newArr = append(newArr, arr[i])
  7860. }
  7861. }
  7862. return
  7863. }
  7864. func (this *DialysisAPIController) GetRoleList() {
  7865. admin_user_id, _ := this.GetInt64("admin_user_id")
  7866. orgid := this.GetMobileAdminUserInfo().Org.Id
  7867. list, err := service.GetRoleList(orgid, admin_user_id)
  7868. fmt.Println(err)
  7869. this.ServeSuccessJSON(map[string]interface{}{
  7870. "list": list,
  7871. })
  7872. return
  7873. }
  7874. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7875. // 先根据相关信息查询当天该耗材的出库信息
  7876. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7877. if err != nil {
  7878. return err
  7879. }
  7880. var delete_count int64 = 0
  7881. delete_count = warehouseOutInfos.Count - count
  7882. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7883. // 删除出库完成后,要增加对应批次的库存数量
  7884. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7885. if errThree != nil {
  7886. return errThree
  7887. }
  7888. //增加退库数量
  7889. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7890. //扣减出库数量
  7891. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  7892. //查询剩余库存
  7893. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  7894. var sum_count int64
  7895. for _, item := range goodList {
  7896. sum_count += item.StockCount
  7897. }
  7898. // 在出库记录表里记录退库详情
  7899. warehouseOutInfo := &models.WarehouseOutInfo{
  7900. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7901. WarehouseOutId: warehouseOut.ID,
  7902. Status: 1,
  7903. Ctime: time.Now().Unix(),
  7904. OrgId: orgID,
  7905. Type: 1,
  7906. IsSys: 1,
  7907. SysRecordTime: record_time,
  7908. GoodTypeId: good_yc.GoodTypeId,
  7909. GoodId: good_yc.GoodId,
  7910. PatientId: good_yc.PatientId,
  7911. ConsumableType: 2,
  7912. StorehouseId: houseConfig.StorehouseOutInfo,
  7913. IsCheck: 1,
  7914. OverCount: sum_count,
  7915. }
  7916. warehouseOutInfo.Count = count
  7917. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7918. warehouseOutInfo.Price = stockInInfo.Price
  7919. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7920. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7921. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7922. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7923. warehouseOutInfo.Number = warehouseOutInfos.Number
  7924. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7925. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7926. //查找当天是否存在出库记录
  7927. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7928. if errcod == gorm.ErrRecordNotFound {
  7929. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7930. //插入详情明细表
  7931. if errOne != nil {
  7932. return errOne
  7933. }
  7934. //插入详情明细表
  7935. stockFlow := models.VmStockFlow{
  7936. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7937. WarehouseOutId: warehouseOut.ID,
  7938. GoodId: good_yc.GoodId,
  7939. Number: warehouseOutInfos.Number,
  7940. ProductDate: stockInInfo.ProductDate,
  7941. ExpireDate: stockInInfo.ExpiryDate,
  7942. Count: count,
  7943. Price: stockInInfo.Price,
  7944. Status: 1,
  7945. Ctime: record_time,
  7946. UserOrgId: good_yc.OrgId,
  7947. Manufacturer: stockInInfo.Manufacturer,
  7948. Dealer: stockInInfo.Dealer,
  7949. LicenseNumber: stockInInfo.LicenseNumber,
  7950. IsEdit: 2,
  7951. Creator: creater,
  7952. SystemTime: record_time,
  7953. ConsumableType: 3,
  7954. WarehousingDetailId: 0,
  7955. IsSys: 1,
  7956. UpdateCreator: creater,
  7957. PatientId: patient_id,
  7958. StorehouseId: houseConfig.StorehouseOutInfo,
  7959. OverCount: sum_count,
  7960. ProjectId: good_yc.ProjectId,
  7961. }
  7962. err := service.CreateStockFlowOne(stockFlow)
  7963. fmt.Println("err", err)
  7964. } else if errcod == nil {
  7965. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7966. }
  7967. //创建退库单
  7968. operation_time := time.Now().Unix()
  7969. //创建退库单
  7970. timeStr := time.Now().Format("2006-01-02")
  7971. timeArr := strings.Split(timeStr, "-")
  7972. total, _ := service.FindAllCancelStockTotal(orgID)
  7973. total = total + 1
  7974. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7975. cancelStock := models.CancelStock{
  7976. OrderNumber: orderNumber,
  7977. OperaTime: operation_time,
  7978. OrgId: orgID,
  7979. Creater: warehouseOut.Creater,
  7980. Ctime: time.Now().Unix(),
  7981. Status: 1,
  7982. ReturnTime: record_time,
  7983. Type: 1,
  7984. StorehouseId: stockInInfo.StorehouseId,
  7985. IsCheck: 1,
  7986. }
  7987. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  7988. if msgerrkonde == gorm.ErrRecordNotFound {
  7989. service.AddSigleCancelStock(&cancelStock)
  7990. }
  7991. cancel, _ := service.GetLastCancelStockById(orgID)
  7992. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  7993. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  7994. cancelStockInfo := models.CancelStockInfo{
  7995. GoodId: stockInInfo.GoodId,
  7996. CancelStockId: cancel.ID,
  7997. GoodTypeId: stockInInfo.GoodTypeId,
  7998. Count: delete_count,
  7999. Price: stockInInfo.PackingPrice,
  8000. Total: 0,
  8001. ProductDate: stockInInfo.ProductDate,
  8002. ExpiryDate: stockInInfo.ExpiryDate,
  8003. Ctime: record_time,
  8004. Status: 1,
  8005. OrgId: orgID,
  8006. OrderNumber: cancel.OrderNumber,
  8007. Type: 0,
  8008. Dealer: deaerler.DealerName,
  8009. Manufacturer: manufacturer.ManufacturerName,
  8010. Number: stockInInfo.Number,
  8011. RegisterAccount: "",
  8012. Remark: "",
  8013. WarehouseInfoId: stockInInfo.ID,
  8014. PatientId: patient_id,
  8015. RecordDate: record_time,
  8016. StorehouseId: stockInInfo.StorehouseId,
  8017. IsCheck: 1,
  8018. }
  8019. service.CreateCancelStockInfoOne(&cancelStockInfo)
  8020. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  8021. flow := models.VmStockFlow{
  8022. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  8023. GoodId: good_yc.GoodId,
  8024. Number: warehouseOutInfos.Number,
  8025. LicenseNumber: stockInInfo.LicenseNumber,
  8026. Count: delete_count,
  8027. UserOrgId: orgID,
  8028. PatientId: patient_id,
  8029. SystemTime: record_time,
  8030. ConsumableType: 7,
  8031. IsSys: 0,
  8032. WarehousingOrder: "",
  8033. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  8034. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8035. IsEdit: 0,
  8036. CancelStockId: cancel.ID,
  8037. CancelOrderNumber: cancel.OrderNumber,
  8038. Manufacturer: manufacturer.ID,
  8039. Dealer: 0,
  8040. Creator: warehouseOut.Creater,
  8041. UpdateCreator: 0,
  8042. Status: 1,
  8043. Ctime: record_time,
  8044. Mtime: 0,
  8045. Price: stockInInfo.Price,
  8046. WarehousingDetailId: stockInInfo.ID,
  8047. WarehouseOutDetailId: warehouseOutInfos.ID,
  8048. CancelOutDetailId: cancelInfo.ID,
  8049. ProductDate: stockInInfo.ProductDate,
  8050. ExpireDate: stockInInfo.ExpiryDate,
  8051. StorehouseId: houseConfig.StorehouseOutInfo,
  8052. OverCount: sum_count,
  8053. }
  8054. service.CreateStockFlowOne(flow)
  8055. //更改自动出库的表格
  8056. details := models.BloodAutomaticReduceDetail{
  8057. WarehouseOutId: warehouseOutInfo.ID,
  8058. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8059. PatientId: patient_id,
  8060. Ctime: time.Now().Unix(),
  8061. Mtime: time.Now().Unix(),
  8062. Status: 1,
  8063. RecordTime: record_time,
  8064. OrgId: orgID,
  8065. GoodId: good_yc.GoodId,
  8066. GoodTypeId: good_yc.GoodTypeId,
  8067. Count: count,
  8068. StorehouseId: houseConfig.StorehouseOutInfo,
  8069. }
  8070. //查询当天耗材是否已经存在数据
  8071. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8072. if errcode == gorm.ErrRecordNotFound {
  8073. errTwo := service.CreateAutoReduceRecord(&details)
  8074. if errTwo != nil {
  8075. return errTwo
  8076. }
  8077. } else if errcode == nil {
  8078. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8079. service.CreateAutoReduceRecord(&details)
  8080. }
  8081. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8082. //增加出库库存数量
  8083. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8084. if good_yc.Count == 0 {
  8085. return nil
  8086. } else {
  8087. return errors.New("退库和出库数据不匹配")
  8088. }
  8089. }
  8090. func (this *DialysisAPIController) SavePatientSign() {
  8091. adminUserInfo := this.GetMobileAdminUserInfo()
  8092. patient_id, _ := this.GetInt64("patient_id")
  8093. dialysis_date, _ := this.GetInt64("dialysis_date")
  8094. orgid := adminUserInfo.Org.Id
  8095. var esdata models.DialysisOrder
  8096. var err error
  8097. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8098. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8099. return
  8100. }
  8101. esdata.Hash = esdata.Hash
  8102. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8103. order := models.DialysisOrder{
  8104. Hash: esdata.Hash,
  8105. Url: esdata.Url,
  8106. }
  8107. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8108. redis := service.RedisClient()
  8109. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8110. redis.Set(key, "", time.Second)
  8111. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8112. //清空key 值
  8113. redis.Set(keyOne, "", time.Second)
  8114. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8115. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8116. //redis.Set(keyTwo, "", time.Second)
  8117. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8118. redis.Set(keyThree, "", time.Second)
  8119. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8120. redis.Set(keyFour, "", time.Second)
  8121. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8122. redis.Set(keyFive, "", time.Second)
  8123. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8124. redis.Set(keySix, "", time.Second)
  8125. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8126. redis.Set(keySeven, "", time.Second)
  8127. if err != nil {
  8128. fmt.Println(err)
  8129. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8130. return
  8131. }
  8132. this.ServeSuccessJSON(map[string]interface{}{
  8133. "electronic_signature": esdata,
  8134. })
  8135. }
  8136. func (this *DialysisAPIController) GetPatientSign() {
  8137. patient_id, _ := this.GetInt64("patient_id")
  8138. dialysis_date, _ := this.GetInt64("dialysis_date")
  8139. adminUserInfo := this.GetMobileAdminUserInfo()
  8140. orgId := adminUserInfo.Org.Id
  8141. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8142. if err != nil {
  8143. fmt.Println(err)
  8144. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8145. return
  8146. }
  8147. this.ServeSuccessJSON(map[string]interface{}{
  8148. "dialysisOrder": dialysisOrder,
  8149. })
  8150. }
  8151. func (this *DialysisAPIController) GetScheduleByPatient() {
  8152. patient_id, _ := this.GetInt64("patient_id")
  8153. schedule_date, _ := this.GetInt64("schedule_date")
  8154. orgid := this.GetMobileAdminUserInfo().Org.Id
  8155. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8156. this.ServeSuccessJSON(map[string]interface{}{
  8157. "schedule": schedule,
  8158. })
  8159. }
  8160. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8161. org_id := this.GetMobileAdminUserInfo().Org.Id
  8162. patient_id, _ := this.GetInt64("patient_id")
  8163. schedule_date, _ := this.GetInt64("schedule_date")
  8164. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8165. this.ServeSuccessJSON(map[string]interface{}{
  8166. "order": order,
  8167. })
  8168. }
  8169. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8170. org_id := this.GetMobileAdminUserInfo().Org.Id
  8171. schedule_date := this.GetString("schedule_date")
  8172. schedule_type, _ := this.GetInt64("schedule_type")
  8173. timeLayout := "2006-01-02"
  8174. loc, _ := time.LoadLocation("Local")
  8175. var startdateunix int64
  8176. if len(schedule_date) > 0 {
  8177. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8178. if err != nil {
  8179. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8180. return
  8181. }
  8182. startdateunix = theTime.Unix()
  8183. }
  8184. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8185. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8186. devices, _ := service.GetAllDevicetByListSix(org_id)
  8187. for key, item := range scheduals {
  8188. // 床位信息
  8189. for _, device := range devices {
  8190. if item.BedId == device.ID {
  8191. scheduals[key].DeviceNumber = device
  8192. break
  8193. }
  8194. }
  8195. }
  8196. this.ServeSuccessJSON(map[string]interface{}{
  8197. "list": list,
  8198. "scheduals": scheduals,
  8199. })
  8200. }
  8201. func (this *DialysisAPIController) SavePatientPicture() {
  8202. patient_id, _ := this.GetInt64("patient_id")
  8203. dialysis_date, _ := this.GetInt64("schedule_date")
  8204. avatar := this.GetString("avatar")
  8205. fmt.Println("patient_id", patient_id)
  8206. orgId := this.GetMobileAdminUserInfo().Org.Id
  8207. order := models.DialysisOrder{
  8208. Url: avatar,
  8209. }
  8210. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8211. redis := service.RedisClient()
  8212. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8213. redis.Set(key, "", time.Second)
  8214. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8215. //清空key 值
  8216. redis.Set(keyOne, "", time.Second)
  8217. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8218. redis.Set(keyThree, "", time.Second)
  8219. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8220. redis.Set(keyFour, "", time.Second)
  8221. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8222. redis.Set(keyFive, "", time.Second)
  8223. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8224. redis.Set(keySix, "", time.Second)
  8225. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8226. redis.Set(keySeven, "", time.Second)
  8227. if err != nil {
  8228. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8229. return
  8230. }
  8231. this.ServeSuccessJSON(map[string]interface{}{
  8232. "order": order,
  8233. })
  8234. }
  8235. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8236. ids := this.GetString("ids")
  8237. idSplit := strings.Split(ids, ",")
  8238. orgId := this.GetMobileAdminUserInfo().Org.Id
  8239. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8240. execution_time := this.GetString("exce_time")
  8241. timeLayout2 := "2006-01-02 15:04:05"
  8242. loc, _ := time.LoadLocation("Local")
  8243. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8244. if errs != nil {
  8245. utils.ErrorLog(errs.Error())
  8246. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8247. return
  8248. }
  8249. //his客户
  8250. if config.IsOpen == 1 {
  8251. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8252. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8253. for _, item := range list {
  8254. for _, it := range adviceList {
  8255. if item.DrugId == it.DrugId {
  8256. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8257. }
  8258. }
  8259. }
  8260. for _, item := range list {
  8261. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8262. var sum_out_count int64
  8263. for _, itemThree := range item.ChildDoctorAdvice {
  8264. var prescribing_number int64
  8265. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8266. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8267. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8268. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8269. }
  8270. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8271. prescribing_number = parseIntPrescribingNumber
  8272. }
  8273. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8274. prescribing_number = parseIntPrescribingNumber
  8275. }
  8276. sum_out_count += prescribing_number
  8277. }
  8278. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8279. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8280. //库存不足
  8281. if sum_out_count > drugStockOut.FlushCount {
  8282. this.ServeSuccessJSON(map[string]interface{}{
  8283. "msg": "2",
  8284. "drug": medical,
  8285. "ids": ids,
  8286. })
  8287. return
  8288. }
  8289. }
  8290. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8291. //执行医嘱
  8292. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8293. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  8294. for _, item := range advices {
  8295. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8296. redis := service.RedisClient()
  8297. //清空key 值
  8298. redis.Set(key, "", time.Second)
  8299. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8300. redis.Set(keyTwo, "", time.Second)
  8301. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8302. redis.Set(keyThree, "", time.Second)
  8303. recordDate := theTime.Format("2006-01-02")
  8304. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8305. redis.Set(keyFour, "", time.Second)
  8306. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8307. redis.Set(keyFive, "", time.Second)
  8308. defer redis.Close()
  8309. }
  8310. if errs == nil {
  8311. //药品管理信息
  8312. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8313. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8314. if drugStockConfig.IsOpen == 1 {
  8315. for _, item := range advices {
  8316. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  8317. config, _ := service.GetDrugOpenConfigOne(orgId)
  8318. if config.IsOpen != 1 {
  8319. //查询该药品是否有库存
  8320. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8321. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  8322. if medical.IsUse == 2 {
  8323. if config.IsOpen != 1 {
  8324. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8325. service.HisDrugsDelivery(orgId, creater, &advice)
  8326. if orgId == 3877 || orgId == 10265 {
  8327. //查询该药品是否有出库记录
  8328. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8329. if len(flowMap) == 0 {
  8330. errs := service.UpdateHisAdviceById(advice.ID)
  8331. if errs != nil {
  8332. drugError := models.XtDrugError{
  8333. UserOrgId: orgId,
  8334. DrugId: item.DrugId,
  8335. RecordDate: item.AdviceDate,
  8336. PatientId: item.PatientId,
  8337. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8338. Status: 1,
  8339. Ctime: time.Now().Unix(),
  8340. Mtime: 0,
  8341. SumCount: 0,
  8342. Prescribingnumber: advice.PrescribingNumber,
  8343. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8344. }
  8345. service.CreateDrugError(drugError)
  8346. }
  8347. this.ServeSuccessJSON(map[string]interface{}{
  8348. "msg": "2",
  8349. "drug": medical,
  8350. "ids": ids,
  8351. })
  8352. return
  8353. }
  8354. }
  8355. }
  8356. if pharmacyConfig.IsOpen != 1 {
  8357. service.HisDrugsDelivery(orgId, creater, &advice)
  8358. if orgId == 3877 || orgId == 10265 {
  8359. //查询该药品是否有出库记录
  8360. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8361. if len(flowMap) == 0 {
  8362. errs := service.UpdateHisAdviceById(advice.ID)
  8363. if errs != nil {
  8364. drugError := models.XtDrugError{
  8365. UserOrgId: orgId,
  8366. DrugId: item.DrugId,
  8367. RecordDate: item.AdviceDate,
  8368. PatientId: item.PatientId,
  8369. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8370. Status: 1,
  8371. Ctime: time.Now().Unix(),
  8372. Mtime: 0,
  8373. SumCount: 0,
  8374. Prescribingnumber: advice.PrescribingNumber,
  8375. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8376. }
  8377. service.CreateDrugError(drugError)
  8378. }
  8379. this.ServeSuccessJSON(map[string]interface{}{
  8380. "msg": "2",
  8381. "drug": medical,
  8382. "ids": ids,
  8383. })
  8384. return
  8385. }
  8386. }
  8387. }
  8388. //更新字典里面的库存
  8389. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8390. var sum_count int64
  8391. for _, its := range stockInfo {
  8392. if its.MaxUnit == medical.MaxUnit {
  8393. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8394. }
  8395. sum_count += its.StockMaxNumber + its.StockMinNumber
  8396. }
  8397. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8398. //剩余库存
  8399. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8400. }
  8401. }
  8402. }
  8403. }
  8404. }
  8405. this.ServeSuccessJSON(map[string]interface{}{
  8406. "msg": "1",
  8407. "ids": ids,
  8408. })
  8409. return
  8410. } else {
  8411. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8412. }
  8413. }
  8414. //血透客户
  8415. if config.IsOpen == 2 || config.IsOpen == 0 {
  8416. //药品管理信息
  8417. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8418. if drugStockConfig.IsOpen == 1 {
  8419. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  8420. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  8421. for _, item := range list {
  8422. for _, it := range adviceList {
  8423. if item.DrugId == it.DrugId {
  8424. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8425. }
  8426. }
  8427. }
  8428. for _, item := range list {
  8429. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8430. var sum_out_count int64
  8431. for _, itemThree := range item.ChildDoctorAdvice {
  8432. var prescribing_number int64
  8433. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8434. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8435. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8436. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8437. }
  8438. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8439. prescribing_number = parseIntPrescribingNumber
  8440. }
  8441. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8442. prescribing_number = parseIntPrescribingNumber
  8443. }
  8444. sum_out_count += prescribing_number
  8445. }
  8446. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8447. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8448. //库存不足
  8449. if sum_out_count > drugStockOut.FlushCount {
  8450. this.ServeSuccessJSON(map[string]interface{}{
  8451. "msg": "2",
  8452. "drug": medical,
  8453. "ids": ids,
  8454. })
  8455. return
  8456. }
  8457. }
  8458. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8459. //执行医嘱
  8460. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8461. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8462. for _, item := range advices {
  8463. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8464. redis := service.RedisClient()
  8465. //清空key 值
  8466. redis.Set(key, "", time.Second)
  8467. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8468. redis.Set(keyTwo, "", time.Second)
  8469. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8470. redis.Set(keyThree, "", time.Second)
  8471. recordDate := theTime.Format("2006-01-02")
  8472. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8473. redis.Set(keyFour, "", time.Second)
  8474. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8475. redis.Set(keyFive, "", time.Second)
  8476. defer redis.Close()
  8477. }
  8478. if errs == nil {
  8479. for _, item := range advices {
  8480. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8481. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8482. //查询是否出库按钮开启
  8483. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  8484. if adviceSetting.IsAdviceOpen == 1 {
  8485. //查询是否出库按钮开启
  8486. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  8487. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8488. if prescriptionConfig.IsOpen == 1 {
  8489. if medical.IsUse == 2 {
  8490. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8491. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8492. }
  8493. if pharmacyConfig.IsOpen != 1 {
  8494. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8495. }
  8496. //更新字典里面的库存
  8497. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8498. var sum_count int64
  8499. for _, its := range stockInfo {
  8500. if its.MaxUnit == medical.MaxUnit {
  8501. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8502. }
  8503. sum_count += its.StockMaxNumber + its.StockMinNumber
  8504. }
  8505. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8506. //剩余库存
  8507. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8508. }
  8509. }
  8510. } else {
  8511. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8512. if medical.IsUse == 2 {
  8513. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8514. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8515. }
  8516. if pharmacyConfig.IsOpen != 1 {
  8517. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8518. }
  8519. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8520. var sum_count int64
  8521. for _, its := range stockInfo {
  8522. if its.MaxUnit == medical.MaxUnit {
  8523. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8524. }
  8525. sum_count += its.StockMaxNumber + its.StockMinNumber
  8526. }
  8527. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8528. //剩余库存
  8529. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8530. }
  8531. }
  8532. }
  8533. }
  8534. this.ServeSuccessJSON(map[string]interface{}{
  8535. "msg": "1",
  8536. "ids": ids,
  8537. })
  8538. return
  8539. } else {
  8540. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8541. //执行医嘱
  8542. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8543. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8544. for _, item := range advices {
  8545. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8546. redis := service.RedisClient()
  8547. //清空key 值
  8548. redis.Set(key, "", time.Second)
  8549. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8550. redis.Set(keyTwo, "", time.Second)
  8551. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8552. redis.Set(keyThree, "", time.Second)
  8553. recordDate := theTime.Format("2006-01-02")
  8554. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8555. redis.Set(keyFour, "", time.Second)
  8556. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8557. redis.Set(keyFive, "", time.Second)
  8558. defer redis.Close()
  8559. }
  8560. this.ServeSuccessJSON(map[string]interface{}{
  8561. "msg": "1",
  8562. "ids": ids,
  8563. })
  8564. return
  8565. }
  8566. }
  8567. }
  8568. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  8569. ids := this.GetString("ids")
  8570. idSplit := strings.Split(ids, ",")
  8571. orgId := this.GetMobileAdminUserInfo().Org.Id
  8572. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8573. if config.IsOpen == 1 {
  8574. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  8575. this.ServeSuccessJSON(map[string]interface{}{
  8576. "msg": "1",
  8577. "ids": ids,
  8578. })
  8579. return
  8580. }
  8581. if config.IsOpen == 0 || config.IsOpen == 2 {
  8582. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  8583. this.ServeSuccessJSON(map[string]interface{}{
  8584. "msg": "1",
  8585. "ids": ids,
  8586. })
  8587. return
  8588. }
  8589. }
  8590. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  8591. ids := this.GetString("ids")
  8592. idSplit := strings.Split(ids, ",")
  8593. orgId := this.GetMobileAdminUserInfo().Org.Id
  8594. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8595. //his
  8596. if config.IsOpen == 1 {
  8597. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8598. theTime := time.Now()
  8599. advices := models.HisDoctorAdviceThirty{
  8600. CheckTime: theTime.Unix(),
  8601. Checker: checker,
  8602. UpdatedTime: time.Now().Unix(),
  8603. }
  8604. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  8605. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8606. for _, item := range list {
  8607. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8608. redis := service.RedisClient()
  8609. //清空key 值
  8610. redis.Set(key, "", time.Second)
  8611. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8612. redis.Set(keyTwo, "", time.Second)
  8613. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8614. redis.Set(keyThree, "", time.Second)
  8615. recordDate := theTime.Format("2006-01-02")
  8616. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8617. redis.Set(keyFour, "", time.Second)
  8618. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8619. redis.Set(keyFive, "", time.Second)
  8620. defer redis.Close()
  8621. }
  8622. this.ServeSuccessJSON(map[string]interface{}{
  8623. "msg": "1",
  8624. "ids": ids,
  8625. })
  8626. return
  8627. }
  8628. //血透
  8629. if config.IsOpen == 0 || config.IsOpen == 2 {
  8630. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8631. theTime := time.Now()
  8632. advices := models.DoctorAdvice{
  8633. CheckTime: theTime.Unix(),
  8634. Checker: checker,
  8635. UpdatedTime: time.Now().Unix(),
  8636. }
  8637. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  8638. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8639. for _, item := range list {
  8640. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8641. redis := service.RedisClient()
  8642. //清空key 值
  8643. redis.Set(key, "", time.Second)
  8644. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8645. redis.Set(keyTwo, "", time.Second)
  8646. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8647. redis.Set(keyThree, "", time.Second)
  8648. recordDate := theTime.Format("2006-01-02")
  8649. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8650. redis.Set(keyFour, "", time.Second)
  8651. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8652. redis.Set(keyFive, "", time.Second)
  8653. defer redis.Close()
  8654. }
  8655. this.ServeSuccessJSON(map[string]interface{}{
  8656. "msg": "1",
  8657. "ids": ids,
  8658. })
  8659. return
  8660. }
  8661. }
  8662. func (this *DialysisAPIController) CheckSchedule() {
  8663. patientID, _ := this.GetInt64("patient_id")
  8664. recordDateStr := this.GetString("record_date")
  8665. nurseID, _ := this.GetInt64("start_nurse")
  8666. schedual_type, _ := this.GetInt64("schedual_type")
  8667. bedID, _ := this.GetInt64("bed")
  8668. start_time := this.GetString("start_time")
  8669. fmt.Println("patientID", patientID)
  8670. fmt.Println("recordDateStr", recordDateStr)
  8671. fmt.Println("nurseID", nurseID)
  8672. fmt.Println("schedual_type------", schedual_type)
  8673. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  8674. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8675. return
  8676. }
  8677. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  8678. if parseStartDateErr != nil {
  8679. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  8680. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8681. return
  8682. }
  8683. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8684. if parseErr != nil {
  8685. this.ErrorLog("时间解析失败:%v", parseErr)
  8686. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8687. return
  8688. }
  8689. adminUserInfo := this.GetMobileAdminUserInfo()
  8690. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  8691. if getPatientErr != nil {
  8692. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  8693. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8694. return
  8695. } else if patient == nil {
  8696. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8697. return
  8698. }
  8699. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  8700. if getNurseErr != nil {
  8701. this.ErrorLog("获取护士失败:%v", getNurseErr)
  8702. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8703. return
  8704. } else if nurse == nil {
  8705. this.ErrorLog("护士不存在")
  8706. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8707. return
  8708. }
  8709. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  8710. if getDeviceNumberErr != nil {
  8711. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  8712. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8713. return
  8714. } else if deviceNumber == nil {
  8715. this.ErrorLog("床位号不存在")
  8716. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8717. return
  8718. }
  8719. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  8720. if getRecordErr != nil {
  8721. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  8722. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8723. return
  8724. } else if dialysisRecord != nil {
  8725. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  8726. return
  8727. }
  8728. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  8729. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  8730. timeLayout := "2006-01-02 15:04:05"
  8731. loc, _ := time.LoadLocation("Local")
  8732. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  8733. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  8734. schedulestartTime := theStartTime.Unix()
  8735. scheduleendTime := theEndTime.Unix()
  8736. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  8737. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  8738. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8739. //查询该床位是否有人用了
  8740. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8741. if err == nil {
  8742. if schedule.ID == 0 {
  8743. this.ServeSuccessJSON(map[string]interface{}{
  8744. "status": 0,
  8745. "msg": "请求失败",
  8746. })
  8747. } else {
  8748. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  8749. if order.ID > 0 { //该机位被其他人占用了
  8750. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  8751. return
  8752. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  8753. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  8754. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  8755. this.ServeSuccessJSON(map[string]interface{}{
  8756. "status": 1,
  8757. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  8758. })
  8759. return
  8760. } else {
  8761. this.ServeSuccessJSON(map[string]interface{}{
  8762. "status": 0,
  8763. "msg": "",
  8764. })
  8765. }
  8766. }
  8767. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  8768. this.ServeSuccessJSON(map[string]interface{}{
  8769. "status": 2,
  8770. "msg": "当前机位已有患者在使用,请重新选择!",
  8771. })
  8772. }
  8773. }
  8774. } else {
  8775. this.ServeSuccessJSON(map[string]interface{}{
  8776. "status": 0,
  8777. "msg": "",
  8778. })
  8779. }
  8780. }
  8781. func (this *DialysisAPIController) GetNewDoctorListToday() {
  8782. orgId := this.GetMobileAdminUserInfo().Org.Id
  8783. schedule_type, _ := this.GetInt64("schedule_type")
  8784. partion_type, _ := this.GetInt64("partion_type")
  8785. start_time := this.GetString("start_time")
  8786. timeLayout := "2006-01-02"
  8787. loc, _ := time.LoadLocation("Local")
  8788. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8789. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  8790. _, config := service.FindXTHisRecordByOrgId(orgId)
  8791. appId := this.GetMobileAdminUserInfo().App.Id
  8792. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  8793. if err == nil {
  8794. this.ServeSuccessJSON(map[string]interface{}{
  8795. "list": list,
  8796. "config": config,
  8797. "doctorList": doctorList,
  8798. })
  8799. return
  8800. } else {
  8801. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8802. return
  8803. }
  8804. }
  8805. func (this *DialysisAPIController) SaveMobileInformation() {
  8806. patient_id, _ := this.GetInt64("patient_id")
  8807. record_date, _ := this.GetInt64("record_date")
  8808. startTime := this.GetString("start_time")
  8809. module, _ := this.GetInt64("module")
  8810. remark := this.GetString("remark")
  8811. timeLayout := "2006-01-02 15:04"
  8812. loc, _ := time.LoadLocation("Local")
  8813. if len(startTime) == 0 {
  8814. utils.ErrorLog("len(start_time) == 0")
  8815. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8816. return
  8817. }
  8818. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  8819. if err != nil {
  8820. utils.ErrorLog(err.Error())
  8821. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8822. return
  8823. }
  8824. StartTime := theTime.Unix()
  8825. fmt.Println("startime-------------", StartTime)
  8826. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8827. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  8828. information := models.XtDialysisInformation{
  8829. Module: module,
  8830. PatientId: patient_id,
  8831. RecordDate: record_date,
  8832. ApplicationDate: StartTime,
  8833. Creater: creater,
  8834. ApplicationStatus: 2,
  8835. Checker: 0,
  8836. CheckTime: 0,
  8837. Remark: remark,
  8838. UserOrgId: user_org_id,
  8839. Ctime: time.Now().Unix(),
  8840. Status: 1,
  8841. Mtime: 0,
  8842. }
  8843. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  8844. if infor.ID == 0 {
  8845. service.SaveDialysisInformation(information)
  8846. }
  8847. if infor.ID > 0 {
  8848. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  8849. }
  8850. this.ServeSuccessJSON(map[string]interface{}{
  8851. "information": information,
  8852. })
  8853. return
  8854. }
  8855. func (this *DialysisAPIController) GetMobileInformation() {
  8856. limit, _ := this.GetInt64("limit")
  8857. page, _ := this.GetInt64("page")
  8858. orgid := this.GetMobileAdminUserInfo().Org.Id
  8859. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  8860. appid := this.GetMobileAdminUserInfo().App.Id
  8861. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8862. patients, _ := service.GetAllpatientThirty(orgid)
  8863. this.ServeSuccessJSON(map[string]interface{}{
  8864. "information": information,
  8865. "total": total,
  8866. "doclist": doclist,
  8867. "patients": patients,
  8868. })
  8869. return
  8870. }
  8871. func (this *DialysisAPIController) GetMobileInformationOne() {
  8872. limit, _ := this.GetInt64("limit")
  8873. page, _ := this.GetInt64("page")
  8874. orgid := this.GetMobileAdminUserInfo().Org.Id
  8875. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  8876. appid := this.GetMobileAdminUserInfo().App.Id
  8877. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8878. patients, _ := service.GetAllpatientThirty(orgid)
  8879. this.ServeSuccessJSON(map[string]interface{}{
  8880. "information": information,
  8881. "total": total,
  8882. "doclist": doclist,
  8883. "patients": patients,
  8884. })
  8885. return
  8886. }
  8887. func (this *DialysisAPIController) CheckMobileInformation() {
  8888. id, _ := this.GetInt64("id")
  8889. application_status, _ := this.GetInt64("application_status")
  8890. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8891. checktime := time.Now().Unix()
  8892. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  8893. if err == nil {
  8894. this.ServeSuccessJSON(map[string]interface{}{
  8895. "msg": "ok",
  8896. })
  8897. return
  8898. }
  8899. }
  8900. func (c *DialysisAPIController) GetControlMonitorList() {
  8901. partition, _ := c.GetInt64("partition")
  8902. monitorDate := c.GetString("date")
  8903. patient_id, _ := c.GetInt64("patient_id")
  8904. pat_type, _ := c.GetInt64("pat_type")
  8905. timeLayout := "2006-01-02"
  8906. loc, _ := time.LoadLocation("Local")
  8907. var theStartTime int64
  8908. if len(monitorDate) > 0 {
  8909. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  8910. if err != nil {
  8911. theStartTime = 0
  8912. }
  8913. theStartTime = theTime.Unix()
  8914. }
  8915. adminInfo := c.GetMobileAdminUserInfo()
  8916. orgID := adminInfo.Org.Id
  8917. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  8918. if err != nil {
  8919. c.ErrorLog("获取排班信息失败:%v", err)
  8920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8921. } else {
  8922. if len(monitor) > 0 {
  8923. //获取所有床位
  8924. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  8925. //获取所有分区
  8926. zoneList, _ := service.GetAllZoneByList(orgID)
  8927. //获取透析处方
  8928. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  8929. //获取透前评估
  8930. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  8931. //获取上机
  8932. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  8933. //获取透后
  8934. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  8935. //获取透后监测
  8936. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  8937. //获取所有的患者
  8938. patients, _ := service.GetAllPatientListByListOne(orgID)
  8939. //获取所有透析模式
  8940. treatments, _ := service.GetAllTreatModeByList(orgID)
  8941. //获取所有医嘱
  8942. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  8943. //获取双人核对
  8944. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  8945. //治疗小结
  8946. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  8947. //待消毒
  8948. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  8949. for key, item := range monitor {
  8950. // 获取床位信息
  8951. for _, it := range numberList {
  8952. if item.BedId == it.ID {
  8953. monitor[key].DeviceNumber = it
  8954. break
  8955. }
  8956. }
  8957. //获取分区信息
  8958. for _, it := range zoneList {
  8959. if item.PartitionId == it.ID {
  8960. monitor[key].DeviceZone = it
  8961. }
  8962. }
  8963. for _, prescription := range prescriptions {
  8964. if item.PatientId == prescription.PatientId {
  8965. monitor[key].Prescription = prescription
  8966. break
  8967. }
  8968. }
  8969. for _, it := range checkList {
  8970. if item.PatientId == it.PatientId {
  8971. monitor[key].DoubleCheck = it
  8972. break
  8973. }
  8974. }
  8975. for _, it := range summaryList {
  8976. if item.PatientId == it.PatientId {
  8977. monitor[key].TreatmentSummaryForList = it
  8978. break
  8979. }
  8980. }
  8981. // 透前评估
  8982. for _, assessmentBefore := range assessmentBefores {
  8983. if item.PatientId == assessmentBefore.PatientId {
  8984. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  8985. break
  8986. }
  8987. }
  8988. // 透析上下机
  8989. for _, dialysisOrder := range dialysisOrders {
  8990. if item.PatientId == dialysisOrder.PatientId {
  8991. monitor[key].DialysisOrder = dialysisOrder
  8992. break
  8993. }
  8994. }
  8995. // 治疗小节
  8996. for _, afterDislysis := range AssessmentAfterDislysis {
  8997. if item.PatientId == afterDislysis.PatientId {
  8998. monitor[key].AssessmentAfterDislysis = afterDislysis
  8999. break
  9000. }
  9001. }
  9002. for _, it := range monitorlist {
  9003. if item.PatientId == it.PatientId {
  9004. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  9005. }
  9006. }
  9007. for _, it := range adviceList {
  9008. if item.PatientId == it.PatientId {
  9009. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  9010. }
  9011. }
  9012. for _, patient := range patients {
  9013. if item.PatientId == patient.ID {
  9014. monitor[key].MonitorPatients = patient
  9015. break
  9016. }
  9017. }
  9018. for _, treatment := range treatments {
  9019. if item.ModeId == treatment.ID {
  9020. monitor[key].TreatmentMode = treatment
  9021. break
  9022. }
  9023. }
  9024. for _, infor := range informationList {
  9025. if item.PatientId == infor.PatientId {
  9026. monitor[key].NewDeviceInformation = infor
  9027. break
  9028. }
  9029. }
  9030. }
  9031. }
  9032. }
  9033. patients, err := service.GetAllpatientFourty(orgID)
  9034. var mds []*models.NewMonitorDialysisScheduleList
  9035. if pat_type == 0 {
  9036. for _, item := range monitor {
  9037. mds = append(mds, item)
  9038. }
  9039. }
  9040. //待医嘱核对
  9041. if pat_type == 1 {
  9042. for _, item := range monitor {
  9043. if len(item.AdviceList) > 0 {
  9044. mds = append(mds, item)
  9045. }
  9046. }
  9047. }
  9048. //待开小结
  9049. if pat_type == 2 {
  9050. for _, item := range monitor {
  9051. if item.TreatmentSummaryForList == nil {
  9052. mds = append(mds, item)
  9053. }
  9054. }
  9055. }
  9056. //待下机
  9057. if pat_type == 3 {
  9058. for _, item := range monitor {
  9059. if item.DialysisOrder != nil {
  9060. if item.DialysisOrder.ID > 0 {
  9061. mds = append(mds, item)
  9062. }
  9063. }
  9064. }
  9065. }
  9066. //待消毒
  9067. if pat_type == 4 {
  9068. for _, item := range monitor {
  9069. if item.NewDeviceInformation == nil {
  9070. mds = append(mds, item)
  9071. }
  9072. }
  9073. }
  9074. //待双人核对
  9075. if pat_type == 5 {
  9076. for _, item := range monitor {
  9077. if item.DoubleCheck == nil {
  9078. mds = append(mds, item)
  9079. }
  9080. }
  9081. }
  9082. //医嘱未执行
  9083. if pat_type == 6 {
  9084. for _, item := range monitor {
  9085. if len(item.AdviceList) > 0 {
  9086. mds = append(mds, item)
  9087. }
  9088. }
  9089. }
  9090. //患者未签名
  9091. if pat_type == 7 {
  9092. for _, item := range monitor {
  9093. if item.DialysisOrder != nil {
  9094. if item.DialysisOrder.ID > 0 {
  9095. mds = append(mds, item)
  9096. }
  9097. }
  9098. }
  9099. }
  9100. //目标超滤于实际超滤不同
  9101. if pat_type == 8 {
  9102. for _, item := range monitor {
  9103. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9104. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9105. mds = append(mds, item)
  9106. }
  9107. }
  9108. }
  9109. }
  9110. //血压少于5次
  9111. if pat_type == 9 {
  9112. for _, item := range monitor {
  9113. if len(item.MonitoringRecord) < 5 {
  9114. mds = append(mds, item)
  9115. }
  9116. }
  9117. }
  9118. if pat_type == 10 {
  9119. for _, item := range monitor {
  9120. if len(item.MonitoringRecord) == 0 {
  9121. mds = append(mds, item)
  9122. }
  9123. }
  9124. }
  9125. if pat_type == 11 {
  9126. for _, item := range monitor {
  9127. if len(item.MonitoringRecord) > 0 {
  9128. mds = append(mds, item)
  9129. }
  9130. }
  9131. }
  9132. if pat_type == 12 {
  9133. for _, item := range monitor {
  9134. if len(item.MonitoringRecord) > 0 {
  9135. mds = append(mds, item)
  9136. }
  9137. }
  9138. }
  9139. if err == nil {
  9140. c.ServeSuccessJSON(map[string]interface{}{
  9141. "monitor": mds,
  9142. "patients": patients,
  9143. })
  9144. } else {
  9145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9146. }
  9147. }
  9148. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9149. admin_user_id, _ := c.GetInt64("admin_user_id")
  9150. timeStr := time.Now().Format("2006-01-02")
  9151. timeLayout := "2006-01-02 15:04:05"
  9152. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9153. timenow := timeStringToTime.Unix()
  9154. orgId := c.GetMobileAdminUserInfo().Org.Id
  9155. //查询当前护士的患者
  9156. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9157. var patientIds []int64
  9158. for _, item := range orderList {
  9159. patientIds = append(patientIds, item.PatientId)
  9160. }
  9161. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9162. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9163. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9164. //药品管理信息
  9165. _, drugStockConfig := service.FindHisConfig(orgId)
  9166. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9167. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9168. c.ServeSuccessJSON(map[string]interface{}{
  9169. "adviceList": adviceList,
  9170. "hisAdviceList": hisAdviceList,
  9171. "projectList": projectList,
  9172. "drugStockConfig": drugStockConfig,
  9173. "patientList": patientList,
  9174. "projectConfig": projectConfig,
  9175. })
  9176. }
  9177. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9178. patient_id, _ := c.GetInt64("patient_id")
  9179. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9180. c.ServeSuccessJSON(map[string]interface{}{
  9181. "recrods": recrods,
  9182. })
  9183. }
  9184. func (c *DialysisAPIController) ExMobileChangeSch() {
  9185. id_one, _ := c.GetInt64("id_one")
  9186. id_two, _ := c.GetInt64("id_two")
  9187. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9188. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9189. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9190. //if order2.ID > 0 {
  9191. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9192. // return
  9193. //}
  9194. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9195. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9196. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9197. if count > 0 {
  9198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9199. return
  9200. }
  9201. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9202. if count1 > 0 {
  9203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9204. return
  9205. }
  9206. }
  9207. err := service.UpdateScheduleThree(sch, sch_two)
  9208. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9209. if order.ID > 0 {
  9210. //查询该患者的排班机位
  9211. pSchedule, _ := service.GetPscheduleDate(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9212. service.UpdateDialysiOrderByPatientId(id_two, pSchedule.ScheduleType, pSchedule.PartitionId, pSchedule.BedId)
  9213. redis := service.RedisClient()
  9214. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9215. redis.Set(key, "", time.Second)
  9216. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9217. //清空key 值
  9218. redis.Set(keyOne, "", time.Second)
  9219. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  9220. //return
  9221. }
  9222. if err == nil {
  9223. //去除当天患者排班中重复数据,保留最后一条数据
  9224. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9225. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9226. c.ServeSuccessJSON(map[string]interface{}{
  9227. "msg": "交换成功",
  9228. })
  9229. } else {
  9230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9231. return
  9232. }
  9233. }
  9234. func (c *DialysisAPIController) MobileCoverSch() {
  9235. id_one, _ := c.GetInt64("id_one")
  9236. id_two, _ := c.GetInt64("id_two")
  9237. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9238. //针对凤凰医院
  9239. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  9240. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9241. if len(advice) > 0 {
  9242. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9243. }
  9244. }
  9245. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  9246. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9247. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9248. if len(hisAdvice) > 0 {
  9249. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9250. }
  9251. if len(project) > 0 {
  9252. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9253. }
  9254. }
  9255. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9256. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9257. if order.ID > 0 {
  9258. service.UpdateDialysiOrderByPatientId(id_two, sch_two.ScheduleType, sch_two.PartitionId, sch_two.BedId)
  9259. redis := service.RedisClient()
  9260. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9261. redis.Set(key, "", time.Second)
  9262. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9263. //清空key 值
  9264. redis.Set(keyOne, "", time.Second)
  9265. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9266. //return
  9267. }
  9268. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9269. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9270. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9271. if count > 0 {
  9272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9273. return
  9274. }
  9275. }
  9276. var new_sch models.Schedule
  9277. new_sch = sch
  9278. new_sch.BedId = sch_two.BedId
  9279. new_sch.ScheduleDate = sch_two.ScheduleDate
  9280. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  9281. new_sch.PartitionId = sch_two.PartitionId
  9282. new_sch.ScheduleType = sch_two.ScheduleType
  9283. new_sch.ID = 0
  9284. //删除原来的排班
  9285. err := service.SaveSchTwo(sch, sch_two)
  9286. //生成新的排班
  9287. if err == nil {
  9288. err2 := service.SaveSch(&new_sch)
  9289. if err2 == nil {
  9290. //去除当天患者排班中重复数据,保留最后一条数据
  9291. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9292. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9293. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  9294. c.ServeSuccessJSON(map[string]interface{}{
  9295. "msg": "覆盖成功",
  9296. "new_sch": new_sch,
  9297. })
  9298. } else {
  9299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9300. return
  9301. }
  9302. } else {
  9303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9304. return
  9305. }
  9306. }
  9307. //func BatchExectime() {
  9308. //
  9309. //}