dialysis_api_controller.go 478KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429
  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 projectsOne []*models.HisPrescriptionProject
  342. var stockType []*models.GoodsTypeOne
  343. var prepare []*models.XtDialysisBeforePrepare
  344. var lastAssessment models.XtPatientVascularAccess
  345. var lastDryWeightDislysis *models.SgjPatientDryweight
  346. var gobalConfig models.GobalConfig
  347. var operators []*models.SgjUserAdminRoles
  348. // 先走redis,没有走数据库
  349. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  350. go func() {
  351. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  352. ch <- struct{}{}
  353. }()
  354. go func() {
  355. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  356. ch <- struct{}{}
  357. }()
  358. go func() {
  359. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  360. ch <- struct{}{}
  361. }()
  362. go func() {
  363. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  364. ch <- struct{}{}
  365. }()
  366. go func() {
  367. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  368. ch <- struct{}{}
  369. }()
  370. go func() {
  371. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  372. ch <- struct{}{}
  373. }()
  374. go func() {
  375. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  376. ch <- struct{}{}
  377. }()
  378. go func() {
  379. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  380. ch <- struct{}{}
  381. }()
  382. go func() {
  383. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  384. ch <- struct{}{}
  385. }()
  386. go func() {
  387. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  388. ch <- struct{}{}
  389. }()
  390. go func() {
  391. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  392. ch <- struct{}{}
  393. }()
  394. go func() {
  395. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  396. ch <- struct{}{}
  397. }()
  398. go func() {
  399. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  400. ch <- struct{}{}
  401. }()
  402. go func() {
  403. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  404. ch <- struct{}{}
  405. }()
  406. go func() {
  407. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  408. ch <- struct{}{}
  409. }()
  410. go func() {
  411. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  412. ch <- struct{}{}
  413. }()
  414. go func() {
  415. // 先走redis,没有走数据库
  416. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  417. ch <- struct{}{}
  418. }()
  419. go func() {
  420. // 先走redis,没有走数据库
  421. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  422. ch <- struct{}{}
  423. }()
  424. go func() {
  425. // // 先走redis,没有走数据库
  426. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  427. ch <- struct{}{}
  428. }()
  429. go func() {
  430. // 先走redis,没有走数据库
  431. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  432. ch <- struct{}{}
  433. }()
  434. go func() {
  435. // //获取最后一次血管通路
  436. // 先走redis,没有走数据库
  437. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  438. ch <- struct{}{}
  439. }()
  440. go func() {
  441. // 先走redis,没有走数据库
  442. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  443. ch <- struct{}{}
  444. }()
  445. go func() {
  446. // 先走redis,没有走数据库
  447. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  448. ch <- struct{}{}
  449. }()
  450. go func() {
  451. // 先走redis,没有走数据库
  452. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  453. ch <- struct{}{}
  454. }()
  455. for range ch {
  456. // 每次从ch中接收数据,表明一个活动的协程结束
  457. count--
  458. // 当所有活动的协程都结束时,关闭管道
  459. if count == 0 {
  460. close(ch)
  461. }
  462. }
  463. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  464. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  465. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  466. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  467. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  468. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  469. var team_projects []*models.HisPrescriptionProject
  470. //var index int64 = 0
  471. for _, item := range temp_team_projects {
  472. //组套里面非检验项目的
  473. if item.HisProject.CostClassify != 3 && item.HisProject.CostClassify != 104 {
  474. projects = append(projects, item)
  475. }
  476. //组套里面检验项目的
  477. if item.HisProject.CostClassify == 3 || item.HisProject.CostClassify == 104 {
  478. team_projects = append(team_projects, item)
  479. }
  480. }
  481. //针对茂名舒和
  482. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  483. if len(projects) > 0 {
  484. for _, item := range projects {
  485. if item.Type == 2 {
  486. if item.HisProject.IsShow == 1 {
  487. projectsOne = append(projectsOne, item)
  488. }
  489. }
  490. if item.Type == 3 {
  491. if item.GoodInfo.IsShow == 1 {
  492. projectsOne = append(projectsOne, item)
  493. }
  494. }
  495. }
  496. }
  497. } else {
  498. for _, item := range projects {
  499. projectsOne = append(projectsOne, item)
  500. }
  501. }
  502. team_projects = RemoveRepeatedCheckRecod(team_projects)
  503. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  504. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  505. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  506. var his_advices []*models.HisDoctorAdviceInfo
  507. var his_advices_one []*models.HisDoctorAdviceInfo
  508. if is_open_config.IsOpen == 1 {
  509. // 先走redis,没有走数据库
  510. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  511. }
  512. //针对茂名舒和
  513. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  514. if len(his_advices) > 0 {
  515. for _, item := range his_advices {
  516. drug, _ := service.GetDrugIsShow(item.DrugId, adminInfo.Org.Id)
  517. if drug.IsShow == 1 {
  518. his_advices_one = append(his_advices_one, item)
  519. }
  520. }
  521. }
  522. } else {
  523. if len(his_advices) > 0 {
  524. for _, item := range his_advices {
  525. his_advices_one = append(his_advices_one, item)
  526. }
  527. }
  528. }
  529. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  530. if is_advice_open.IsAdviceOpen == 1 {
  531. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  532. }
  533. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  534. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  535. var remind_lists []models.XtCheckRemind
  536. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  537. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  538. }
  539. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  540. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  541. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  542. lastMonitor, _ := service.GetLastMonitor(patientID, date.Unix(), adminInfo.Org.Id)
  543. firstMonitor, _ := service.GetFirstMonitorOne(patientID, date.Unix(), adminInfo.Org.Id)
  544. returnData := map[string]interface{}{
  545. "patient": patient,
  546. "schedual": schedual,
  547. "prescription": dialysisPrescribe,
  548. "solution": dialysisSolution,
  549. "last_prescription": lastDialysisPrescribe,
  550. "receiver_treatment_access": receiverTreatmentAccess,
  551. "predialysis_evaluation": predialysisEvaluation,
  552. "doctor_advices": doctorAdvices,
  553. "double_check": doubleCheck,
  554. "assessment_after_dislysis": assessmentAfterDislysis,
  555. "treatment_summary": treatmentSummary,
  556. "monitor_records": monitorRecords,
  557. "dialysis_order": dialysisOrder,
  558. "operators": operators,
  559. "last_predialysis_evaluation": lastPredialysisEvaluation,
  560. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  561. "last_monitor_record": lastMonitorRecord,
  562. "config": gobalConfig,
  563. "dry_weight": lastDryWeightDislysis,
  564. "system_prescription": systemDialysisPrescribe,
  565. "his_advices": his_advices_one,
  566. "is_open_config": is_open_config,
  567. "stockType": stockType,
  568. "prepare": prepare,
  569. "lastAssessment": lastAssessment,
  570. "prescribeOne": prescribeOne,
  571. "is_project_open_config": is_project_open_config,
  572. "project": projectsOne,
  573. "team_projects": team_projects,
  574. "is_advice_open": is_advice_open,
  575. "prescription_open": prescriptionConfig.IsOpen,
  576. "lastOrder": lastOrder,
  577. "remind_lists": remind_lists,
  578. "lastDialysisPrescription": lastDialysisPrescription,
  579. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  580. "dryWeightList": dryWeightList,
  581. "firstMonitor": firstMonitor,
  582. "lastMonitor": lastMonitor,
  583. }
  584. this.ServeSuccessJSON(returnData)
  585. }
  586. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  587. adminInfo := c.GetMobileAdminUserInfo()
  588. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  589. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  590. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  591. returnData := map[string]interface{}{
  592. "admin_users": adminUsers,
  593. "devices": devices,
  594. "device_numbers": device_numbers,
  595. }
  596. c.ServeSuccessJSON(returnData)
  597. }
  598. func (c *DialysisAPIController) PostAtreatmentInfo() {
  599. id, _ := c.GetInt64("patient", 0)
  600. recordDateStr := c.GetString("record_date")
  601. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  602. summaryContent := c.GetString("summaryContent")
  603. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  604. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  605. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  606. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  607. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  608. nursingRecord := c.GetString("nursing_record")
  609. fmt.Println("护理记录", nursingRecord)
  610. specialRecord := c.GetString("special_record")
  611. fmt.Println("特殊记录", specialRecord)
  612. adminUserInfo := c.GetMobileAdminUserInfo()
  613. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  614. checkStaffId = adminUserInfo.AdminUser.Id
  615. deboardNurseId = adminUserInfo.AdminUser.Id
  616. treatDoctor = adminUserInfo.AdminUser.Id
  617. if id <= 0 {
  618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  619. return
  620. }
  621. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  622. if patient.ID == 0 {
  623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  624. return
  625. }
  626. if len(recordDateStr) == 0 {
  627. recordDateStr = time.Now().Format("2006-01-02")
  628. }
  629. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  630. if parseDateErr != nil {
  631. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  633. return
  634. }
  635. summary := models.TreatmentSummary{
  636. UserOrgId: adminUserInfo.Org.Id,
  637. PatientId: id,
  638. AssessmentDate: recordDate.Unix(),
  639. Mission: propagandaAndEducationContent,
  640. DialysisSummary: summaryContent,
  641. SjNurse: changeMedicalNurseId,
  642. ZlNurse: treatNurseId,
  643. HdNurse: checkStaffId,
  644. XjNurse: deboardNurseId,
  645. ZlDoctor: treatDoctor,
  646. CreatedTime: time.Now().Unix(),
  647. Status: 1,
  648. NursingRecord: nursingRecord,
  649. SpecialRecord: specialRecord,
  650. }
  651. // 查询信息规挡的设置天数
  652. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  653. if infor.ID > 0 && infor.WeekDay > 0 {
  654. var cha_time int64
  655. timeNowStr := time.Now().Format("2006-01-02")
  656. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  657. //今日的日期减去设置的日期
  658. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  659. if cha_time >= recordDate.Unix() {
  660. //查询审核是否允许
  661. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  662. //申请状态不允许的情况 拒绝修改
  663. if infor.ApplicationStatus != 1 {
  664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  665. return
  666. }
  667. }
  668. }
  669. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  670. if treatmentSummary.ID == 0 { //新增
  671. summary.Creater = adminUserInfo.AdminUser.Id
  672. service.AddSigleSummaryRecord(&summary)
  673. finish := models.XtDialysisFinish{
  674. IsFinish: 1,
  675. UserOrgId: adminUserInfo.Org.Id,
  676. Status: 1,
  677. Ctime: time.Now().Unix(),
  678. Mtime: 0,
  679. Module: 10,
  680. RecordDate: recordDate.Unix(),
  681. Sourse: 1,
  682. PatientId: id,
  683. }
  684. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  685. if dialysisFinish.ID == 0 {
  686. service.CreateDialysisFinish(finish)
  687. }
  688. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  689. redis := service.RedisClient()
  690. //清空key 值
  691. redis.Set(key, "", time.Second)
  692. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  693. redis.Set(keyOne, "", time.Second)
  694. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  695. redis.Set(keyThree, "", time.Second)
  696. defer redis.Close()
  697. c.ServeSuccessJSON(map[string]interface{}{
  698. "summary": summary,
  699. })
  700. } else { //修改
  701. summary.Creater = treatmentSummary.Creater
  702. summary.CreatedTime = treatmentSummary.CreatedTime
  703. summary.Modifier = adminUserInfo.AdminUser.Id
  704. summary.ID = treatmentSummary.ID
  705. service.UpdateSummeRecord(&summary)
  706. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  707. redis := service.RedisClient()
  708. //清空key 值
  709. redis.Set(key, "", time.Second)
  710. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  711. redis.Set(keyOne, "", time.Second)
  712. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  713. redis.Set(keyThree, "", time.Second)
  714. defer redis.Close()
  715. c.ServeSuccessJSON(map[string]interface{}{
  716. "summary": summary,
  717. })
  718. }
  719. }
  720. func (c *DialysisAPIController) PostDoubleCheck() {
  721. id, _ := c.GetInt64("patient", 0)
  722. recordDateStr := c.GetString("record_date")
  723. checkTimeStr := c.GetString("check_time")
  724. firstCheckTimeStr := c.GetString("first_check_time")
  725. creater, _ := c.GetInt64("creater", 0)
  726. modifier, _ := c.GetInt64("modifier", 0)
  727. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  728. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  729. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  730. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  731. dialysis_item_desc := c.GetString("dialysis_item_desc")
  732. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  733. vascular_access_desc := c.GetString("vascular_access_desc")
  734. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  735. collator, _ := c.GetInt64("collator", 0)
  736. employee_number := c.GetString("employee_number")
  737. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  738. needle_batch_number := c.GetString("needle_batch_number")
  739. if id <= 0 {
  740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  741. return
  742. }
  743. adminUserInfo := c.GetMobileAdminUserInfo()
  744. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  745. if patient.ID == 0 {
  746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  747. return
  748. }
  749. if len(recordDateStr) == 0 {
  750. recordDateStr = time.Now().Format("2006-01-02")
  751. }
  752. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  753. if parseDateErr != nil {
  754. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  756. return
  757. }
  758. var checkDate int64
  759. if len(checkTimeStr) == 0 {
  760. checkDate = 0
  761. } else {
  762. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  763. checkDate = checkDateUnix.Unix()
  764. }
  765. var firstCheckDate int64
  766. if len(firstCheckTimeStr) == 0 {
  767. firstCheckDate = 0
  768. } else {
  769. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  770. firstCheckDate = firstCheckDateUnix.Unix()
  771. }
  772. if adminUserInfo.Org.Id == 10644 {
  773. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  774. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  775. if check.ID == 0 {
  776. if employee_number != list.JobNumber {
  777. c.ServeSuccessJSON(map[string]interface{}{
  778. "doubleCheck": check,
  779. "msg": "2",
  780. })
  781. return
  782. }
  783. }
  784. if check.ID > 0 {
  785. if employee_number != list.JobNumber {
  786. c.ServeSuccessJSON(map[string]interface{}{
  787. "doubleCheck": check,
  788. "msg": "2",
  789. })
  790. return
  791. }
  792. }
  793. }
  794. doubleCheck := models.DoubleCheck{
  795. UserOrgId: adminUserInfo.Org.Id,
  796. PatientId: id,
  797. DialysisItemCheck: dialysis_item_check,
  798. DialysisParameterCheck: dialysis_parameter_check,
  799. VascularAccessVerification: vascular_access_verification,
  800. PipelineConnectionCheck: pipeline_connection_check,
  801. DialysisItemDesc: dialysis_item_desc,
  802. DialysisParameterDesc: dialysis_parameter_desc,
  803. VascularAccessDesc: vascular_access_desc,
  804. PipelineConnectionDesc: pipeline_connection_desc,
  805. Collator: collator,
  806. Status: 1,
  807. CreatedTime: time.Now().Unix(),
  808. CheckDate: recordDate.Unix(),
  809. UpdatedTime: time.Now().Unix(),
  810. EmployeeNumber: employee_number,
  811. DialyzerBatchNumber: dialyzer_batch_number,
  812. NeedleBatchNumber: needle_batch_number,
  813. }
  814. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  815. if check.ID == 0 { //新增
  816. doubleCheck.FirstCheckTime = firstCheckDate
  817. doubleCheck.CheckTime = checkDate
  818. doubleCheck.Creater = creater
  819. doubleCheck.Modifier = modifier
  820. if adminUserInfo.Org.Id == 10340 {
  821. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  822. doubleCheck.Creater = order.StartNurse
  823. }
  824. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  825. //查询未核对的医嘱
  826. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  827. for _, advice := range doctorList {
  828. if advice.ExecutionStaff == modifier {
  829. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  830. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  831. return
  832. }
  833. }
  834. }
  835. // 查询信息规挡的设置天数
  836. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  837. if infor.ID > 0 && infor.WeekDay > 0 {
  838. var cha_time int64
  839. timeNowStr := time.Now().Format("2006-01-02")
  840. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  841. //今日的日期减去设置的日期
  842. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  843. if cha_time >= recordDate.Unix() {
  844. //查询审核是否允许
  845. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  846. //申请状态不允许的情况 拒绝修改
  847. if infor.ApplicationStatus != 1 {
  848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  849. return
  850. }
  851. }
  852. }
  853. err := service.AddSigleDoubleCheck(&doubleCheck)
  854. finish := models.XtDialysisFinish{
  855. IsFinish: 1,
  856. UserOrgId: adminUserInfo.Org.Id,
  857. Status: 1,
  858. Ctime: time.Now().Unix(),
  859. Mtime: 0,
  860. Module: 5,
  861. RecordDate: recordDate.Unix(),
  862. Sourse: 1,
  863. PatientId: id,
  864. }
  865. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  866. if dialysisFinish.ID == 0 {
  867. service.CreateDialysisFinish(finish)
  868. }
  869. //针对长沙南雅
  870. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  871. //查询未核对的医嘱
  872. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  873. if len(doctorList) > 0 && modifier > 0 {
  874. for _, advice := range doctorList {
  875. service.UpdateDoctorAdviceList(advice.ID, modifier)
  876. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  877. redis := service.RedisClient()
  878. //清空key 值
  879. redis.Set(key, "", time.Second)
  880. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  881. redis.Set(keyTwo, "", time.Second)
  882. theTime := time.Now()
  883. recordDate := theTime.Format("2006-01-02")
  884. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  885. redis.Set(keyFour, "", time.Second)
  886. defer redis.Close()
  887. }
  888. }
  889. }
  890. //针对溪康
  891. if adminUserInfo.Org.Id == 10721 {
  892. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  893. if len(adviceInfoList) > 0 {
  894. for _, item := range adviceInfoList {
  895. service.UpdateHisAdviceList(item.ID, creater)
  896. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  897. redis := service.RedisClient()
  898. //清空key 值
  899. redis.Set(key, "", time.Second)
  900. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  901. redis.Set(keyTwo, "", time.Second)
  902. theTime := time.Now()
  903. recordDate := theTime.Format("2006-01-02")
  904. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  905. redis.Set(keyFour, "", time.Second)
  906. defer redis.Close()
  907. }
  908. }
  909. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  910. if len(adviceList) > 0 {
  911. for _, item := range adviceList {
  912. service.UpdateAdviceList(item.ID, creater)
  913. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  914. redis := service.RedisClient()
  915. //清空key 值
  916. redis.Set(key, "", time.Second)
  917. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  918. redis.Set(keyTwo, "", time.Second)
  919. theTime := time.Now()
  920. recordDate := theTime.Format("2006-01-02")
  921. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  922. redis.Set(keyFour, "", time.Second)
  923. defer redis.Close()
  924. }
  925. }
  926. }
  927. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  928. redis := service.RedisClient()
  929. //清空key 值
  930. redis.Set(key, "", time.Second)
  931. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  932. redis.Set(keyOne, "", time.Second)
  933. defer redis.Close()
  934. if err == nil {
  935. c.ServeSuccessJSON(map[string]interface{}{
  936. "doubleCheck": &doubleCheck,
  937. })
  938. }
  939. } else { //修改
  940. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  941. if infor.ID > 0 {
  942. var cha_time int64
  943. timeNowStr := time.Now().Format("2006-01-02")
  944. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  945. //今日的日期减去设置的日期
  946. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  947. if cha_time >= recordDate.Unix() {
  948. //查询审核是否允许
  949. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  950. //申请状态不允许的情况 拒绝修改
  951. if infor.ApplicationStatus != 1 {
  952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  953. return
  954. }
  955. }
  956. }
  957. doubleCheck.FirstCheckTime = firstCheckDate
  958. doubleCheck.CheckTime = checkDate
  959. doubleCheck.Creater = creater
  960. doubleCheck.Modifier = modifier
  961. doubleCheck.CreatedTime = check.CreatedTime
  962. doubleCheck.ID = check.ID
  963. doubleCheck.EmployeeNumber = employee_number
  964. doubleCheck.NeedleBatchNumber = needle_batch_number
  965. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  966. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  967. //查询未核对的医嘱
  968. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  969. for _, advice := range doctorList {
  970. if advice.ExecutionStaff == modifier {
  971. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  972. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  973. return
  974. }
  975. }
  976. }
  977. //针对溪康
  978. if adminUserInfo.Org.Id == 10721 {
  979. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  980. if len(adviceInfoList) > 0 {
  981. for _, item := range adviceInfoList {
  982. service.UpdateHisAdviceList(item.ID, creater)
  983. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  984. redis := service.RedisClient()
  985. //清空key 值
  986. redis.Set(key, "", time.Second)
  987. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  988. redis.Set(keyTwo, "", time.Second)
  989. theTime := time.Now()
  990. recordDate := theTime.Format("2006-01-02")
  991. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  992. redis.Set(keyFour, "", time.Second)
  993. defer redis.Close()
  994. }
  995. }
  996. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  997. if len(adviceList) > 0 {
  998. for _, item := range adviceList {
  999. service.UpdateAdviceList(item.ID, creater)
  1000. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1001. redis := service.RedisClient()
  1002. //清空key 值
  1003. redis.Set(key, "", time.Second)
  1004. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1005. redis.Set(keyTwo, "", time.Second)
  1006. theTime := time.Now()
  1007. recordDate := theTime.Format("2006-01-02")
  1008. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1009. redis.Set(keyFour, "", time.Second)
  1010. defer redis.Close()
  1011. }
  1012. }
  1013. }
  1014. err := service.UpdateDoubleCheck(&doubleCheck)
  1015. //针对长沙南雅
  1016. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  1017. //查询未核对的医嘱
  1018. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1019. if len(doctorList) > 0 && modifier > 0 {
  1020. for _, advice := range doctorList {
  1021. service.UpdateDoctorAdviceList(advice.ID, modifier)
  1022. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1023. redis := service.RedisClient()
  1024. //清空key 值
  1025. redis.Set(key, "", time.Second)
  1026. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1027. redis.Set(keyTwo, "", time.Second)
  1028. theTime := time.Now()
  1029. recordDate := theTime.Format("2006-01-02")
  1030. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1031. redis.Set(keyFour, "", time.Second)
  1032. defer redis.Close()
  1033. }
  1034. }
  1035. }
  1036. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1037. redis := service.RedisClient()
  1038. //清空key 值
  1039. redis.Set(key, "", time.Second)
  1040. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1041. redis.Set(keyOne, "", time.Second)
  1042. defer redis.Close()
  1043. if err == nil {
  1044. c.ServeSuccessJSON(map[string]interface{}{
  1045. "doubleCheck": &doubleCheck,
  1046. "msg": "1",
  1047. })
  1048. }
  1049. }
  1050. }
  1051. func (c *DialysisAPIController) PostAcceptsAssessment() {
  1052. id, _ := c.GetInt64("patient", 0)
  1053. recordDateStr := c.GetString("record_date")
  1054. way, _ := c.GetInt64("way", 0)
  1055. consciousness, _ := c.GetInt64("consciousness", 0)
  1056. appetite, _ := c.GetInt64("appetite", 0)
  1057. condition, _ := c.GetInt64("condition", 0)
  1058. posture, _ := c.GetInt64("posture")
  1059. sick_condition, _ := c.GetInt64("sick_condition", 0)
  1060. danger_level, _ := c.GetInt64("danger_level", 0)
  1061. intake, _ := c.GetInt64("intake", 0)
  1062. nutrition, _ := c.GetInt64("nutrition", 0)
  1063. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  1064. psychological_assessment_other := c.GetString("psychological_assessment_other")
  1065. score := c.GetString("score")
  1066. sick_condition_other := c.GetString("sick_condition_other")
  1067. //precaution, _ := c.GetInt64("precaution", 0)
  1068. precaution := c.GetString("precaution")
  1069. precaution_other := c.GetString("precaution_other")
  1070. psychological_other := c.GetString("psychological_other")
  1071. admission_number := c.GetString("admission_number")
  1072. tumble, _ := c.GetInt64("tumble")
  1073. diacrisis := c.GetString("diacrisis")
  1074. his_department := c.GetString("his_department")
  1075. his_bed := c.GetString("his_bed")
  1076. if id <= 0 {
  1077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1078. return
  1079. }
  1080. adminUserInfo := c.GetMobileAdminUserInfo()
  1081. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1082. if patient.ID == 0 {
  1083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1084. return
  1085. }
  1086. //now := time.Now()
  1087. //year, month, day := now.Date()
  1088. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1089. //todayTimeStamp := today_time.Unix()
  1090. if len(recordDateStr) == 0 {
  1091. recordDateStr = time.Now().Format("2006-01-02")
  1092. }
  1093. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1094. if parseDateErr != nil {
  1095. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. // 查询信息规挡的设置天数
  1100. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1101. if infor.ID > 0 && infor.WeekDay > 0 {
  1102. var cha_time int64
  1103. timeNowStr := time.Now().Format("2006-01-02")
  1104. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1105. //今日的日期减去设置的日期
  1106. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1107. if cha_time >= recordDate.Unix() {
  1108. //查询审核是否允许
  1109. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1110. //申请状态不允许的情况 拒绝修改
  1111. if infor.ApplicationStatus != 1 {
  1112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1113. return
  1114. }
  1115. }
  1116. }
  1117. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1118. if adminUserInfo.Org.Id == 10340 {
  1119. if condition == 1 {
  1120. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1121. if admission_number == "" {
  1122. admission_number = lastAcceptTreatment.AdmissionNumber
  1123. his_bed = lastAcceptTreatment.HisBed
  1124. his_department = lastAcceptTreatment.HisDepartment
  1125. tumble = lastAcceptTreatment.Tumble
  1126. }
  1127. }
  1128. }
  1129. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1130. UserOrgId: adminUserInfo.Org.Id,
  1131. PatientId: id,
  1132. RecordDate: recordDate.Unix(),
  1133. Way: way,
  1134. Consciousness: consciousness,
  1135. Appetite: appetite,
  1136. Condition: condition,
  1137. SickCondition: sick_condition,
  1138. DangerLevel: danger_level,
  1139. Intake: intake,
  1140. Nutrition: nutrition,
  1141. PsychologicalAssessment: psychological_assessment,
  1142. PsychologicalAssessmentOther: psychological_assessment_other,
  1143. SickConditionOther: sick_condition_other,
  1144. Posture: posture,
  1145. CreatedTime: time.Now().Unix(),
  1146. UpdateTime: time.Now().Unix(),
  1147. Status: 1,
  1148. Score: score,
  1149. Precaution: precaution,
  1150. PrecautionOther: precaution_other,
  1151. PsychologicalOther: psychological_other,
  1152. AdmissionNumber: admission_number,
  1153. Tumble: tumble,
  1154. Diacrisis: diacrisis,
  1155. HisBed: his_bed,
  1156. HisDepartment: his_department,
  1157. }
  1158. if receiveTreatment.ID == 0 { //新增
  1159. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1160. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1161. finish := models.XtDialysisFinish{
  1162. IsFinish: 1,
  1163. UserOrgId: adminUserInfo.Org.Id,
  1164. Status: 1,
  1165. Ctime: time.Now().Unix(),
  1166. Mtime: 0,
  1167. Module: 2,
  1168. RecordDate: recordDate.Unix(),
  1169. Sourse: 1,
  1170. PatientId: id,
  1171. }
  1172. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1173. if dialysisFinish.ID == 0 {
  1174. service.CreateDialysisFinish(finish)
  1175. }
  1176. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1177. redis := service.RedisClient()
  1178. defer redis.Close()
  1179. //清空key 值
  1180. redis.Set(key, "", time.Second)
  1181. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1182. redis.Set(keyOne, "", time.Second)
  1183. if err == nil {
  1184. c.ServeSuccessJSON(map[string]interface{}{
  1185. "receiveTreatmentAsses": receiveTreatmentAsses,
  1186. })
  1187. }
  1188. } else { //修改
  1189. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1190. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1191. // if getPermissionErr != nil {
  1192. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1193. // return
  1194. // } else if headNursePermission == nil {
  1195. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1196. // return
  1197. // }
  1198. //}
  1199. // 查询信息规挡的设置天数
  1200. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1201. if infor.ID > 0 && infor.WeekDay > 0 {
  1202. var cha_time int64
  1203. timeNowStr := time.Now().Format("2006-01-02")
  1204. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1205. //今日的日期减去设置的日期
  1206. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1207. if cha_time >= recordDate.Unix() {
  1208. //查询审核是否允许
  1209. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1210. //申请状态不允许的情况 拒绝修改
  1211. if infor.ApplicationStatus != 1 {
  1212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1213. return
  1214. }
  1215. }
  1216. }
  1217. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1218. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1219. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1220. receiveTreatmentAsses.ID = receiveTreatment.ID
  1221. if adminUserInfo.Org.Id == 10340 {
  1222. if condition == 1 {
  1223. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1224. if receiveTreatmentAsses.AdmissionNumber == "" {
  1225. receiveTreatmentAsses.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  1226. }
  1227. }
  1228. }
  1229. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1230. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1231. redis := service.RedisClient()
  1232. defer redis.Close()
  1233. //清空key 值
  1234. redis.Set(key, "", time.Second)
  1235. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1236. redis.Set(keyOne, "", time.Second)
  1237. if err == nil {
  1238. c.ServeSuccessJSON(map[string]interface{}{
  1239. "receiveTreatmentAsses": receiveTreatmentAsses,
  1240. })
  1241. }
  1242. }
  1243. }
  1244. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1245. id, _ := c.GetInt64("patient", 0)
  1246. recordDateStr := c.GetString("record_date")
  1247. weightAfter, _ := c.GetFloat("weight_after", 0)
  1248. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1249. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1250. fmt.Println("weight_loss", weightReduce)
  1251. temperature, _ := c.GetFloat("temperature", 0)
  1252. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1253. breathing_rate := c.GetString("breathing_rate")
  1254. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1255. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1256. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1257. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1258. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1259. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1260. cruor := c.GetString("cruor")
  1261. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1262. internalFistula := c.GetString("internal_fistula")
  1263. catheter := c.GetString("catheter")
  1264. complications := c.GetString("complication")
  1265. remark := c.GetString("remark")
  1266. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1267. dialysis_intakes := c.GetString("dialysis_intakes")
  1268. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1269. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1270. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1271. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1272. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1273. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1274. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1275. patientGose, _ := c.GetInt64("patient_gose", 0)
  1276. inpatientDepartment := c.GetString("inpatient_department")
  1277. observationContent := c.GetString("observation_content")
  1278. observationContentOther := c.GetString("observation_content_other")
  1279. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1280. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1281. in_advance_reason := c.GetString("in_advance_reason")
  1282. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1283. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1284. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1285. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1286. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1287. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1288. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1289. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1290. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1291. is_eat, _ := c.GetInt64("is_eat", 0)
  1292. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1293. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1294. channels, _ := c.GetInt64("channel", 0)
  1295. return_blood, _ := c.GetInt64("return_blood", 0)
  1296. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1297. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1298. dialysis_during, _ := c.GetFloat("dialysis_during")
  1299. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1300. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1301. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1302. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1303. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1304. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1305. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1306. setting_pressure := c.GetString("setting_pressure")
  1307. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1308. diastolic_pressure := c.GetString("diastolic_pressure")
  1309. other_complication := c.GetString("other_complication")
  1310. ktv := c.GetString("ktv")
  1311. urr := c.GetString("urr")
  1312. hypertenison, _ := c.GetInt64("hypertenison")
  1313. hypopiesia, _ := c.GetInt64("hypopiesia")
  1314. leave_office_method, _ := c.GetInt64("leave_office_method")
  1315. lapse, _ := c.GetInt64("lapse")
  1316. consciousness, _ := c.GetInt64("consciousness")
  1317. fallrisk, _ := c.GetInt64("fallrisk")
  1318. machine_run := c.GetString("machine_run")
  1319. after_urea := c.GetString("after_urea")
  1320. pip_coagulation := c.GetString("pip_coagulation")
  1321. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1322. transfusion_volume := c.GetString("transfusion_volume")
  1323. last_after_weight := c.GetString("last_after_weight")
  1324. displace_liqui_value := c.GetString("displace_liqui_value")
  1325. start_time := c.GetString("start_time")
  1326. symptom_after_dialysis_remark := c.GetString("symptom_after_dialysis_remark")
  1327. if id <= 0 {
  1328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1329. return
  1330. }
  1331. adminUserInfo := c.GetMobileAdminUserInfo()
  1332. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1333. if patient.ID == 0 {
  1334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1335. return
  1336. }
  1337. if len(recordDateStr) == 0 {
  1338. recordDateStr = time.Now().Format("2006-01-02")
  1339. }
  1340. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1341. fmt.Println("parseDateErr", parseDateErr)
  1342. if parseDateErr != nil {
  1343. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1344. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1345. return
  1346. }
  1347. startDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  1348. //now := time.Now()
  1349. //year, month, day := now.Date()
  1350. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1351. //todayTimeStamp := today_time.Unix()
  1352. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1353. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1354. UserOrgId: adminUserInfo.Org.Id,
  1355. PatientId: id,
  1356. AssessmentDate: recordDate.Unix(),
  1357. Temperature: temperature,
  1358. PulseFrequency: pulse_frequency,
  1359. BreathingRate: breathing_rate,
  1360. SystolicBloodPressure: systolic_blood_pressure,
  1361. DiastolicBloodPressure: diastolic_blood_pressure,
  1362. ActualUltrafiltration: actual_ultrafiltration,
  1363. ActualDisplacement: actual_displacement,
  1364. ActualTreatmentHour: actualtreatHour,
  1365. ActualTreatmentMinute: actualtreatmin,
  1366. WeightAfter: weightAfter,
  1367. AdditionalWeight: additionalWeight,
  1368. WeightLoss: weightReduce,
  1369. Cruor: cruor,
  1370. SymptomAfterDialysis: symptomsAfterDialysi,
  1371. InternalFistula: internalFistula,
  1372. Catheter: catheter,
  1373. Complication: complications,
  1374. DialysisIntakes: dialysateVolume,
  1375. CreatedTime: time.Now().Unix(),
  1376. UpdatedTime: time.Now().Unix(),
  1377. Status: 1,
  1378. Remark: remark,
  1379. BloodAccessPartId: blood_access_part_id,
  1380. BloodAccessPartOperaId: blood_access_part_opera_id,
  1381. DialysisIntakesUnit: dialysis_intakes_unit,
  1382. PuncturePointOozingBlood: puncturePointOozingBlood,
  1383. PuncturePointHaematoma: puncturePointHaematoma,
  1384. InternalFistulaTremorAc: internalFistulaTremorAc,
  1385. PatientGose: patientGose,
  1386. InpatientDepartment: inpatientDepartment,
  1387. ObservationContent: observationContent,
  1388. ObservationContentOther: observationContentOther,
  1389. DialysisProcess: dialysis_process,
  1390. InAdvanceMinute: in_advance_minute,
  1391. InAdvanceReason: in_advance_reason,
  1392. HemostasisMinute: hemostasis_minute,
  1393. HemostasisOpera: hemostasis_opera,
  1394. TremorNoise: tremor_noise,
  1395. DisequilibriumSyndrome: disequilibrium_syndrome,
  1396. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1397. ArterialTube: arterial_tube,
  1398. IntravenousTube: intravenous_tube,
  1399. Dialyzer: dialyzer,
  1400. InAdvanceReasonOther: in_advance_reason_other,
  1401. IsEat: is_eat,
  1402. CvcA: cvc_a,
  1403. CvcV: cvc_v,
  1404. Channel: channels,
  1405. ReturnBlood: return_blood,
  1406. RehydrationVolume: rehydration_volume,
  1407. DialysisDuring: dialysis_during,
  1408. StrokeVolume: stroke_volume,
  1409. BloodFlow: blood_flow,
  1410. SealingFluidDispose: sealing_fluid_dispose,
  1411. SealingFluidSpecial: sealing_fluid_special,
  1412. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1413. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1414. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1415. SettingPressure: setting_pressure,
  1416. DiastolicPressure: diastolic_pressure,
  1417. OtherComplication: other_complication,
  1418. Ktv: ktv,
  1419. Urr: urr,
  1420. Hypopiesia: hypopiesia,
  1421. Hypertenison: hypertenison,
  1422. Lapse: lapse,
  1423. LeaveOfficeMethod: leave_office_method,
  1424. Consciousness: consciousness,
  1425. Fallrisk: fallrisk,
  1426. MachineRun: machine_run,
  1427. AfterUrea: after_urea,
  1428. PipCoagulation: pip_coagulation,
  1429. AccumulatedBloodVolume: accumulated_blood_volume,
  1430. TransfusionVolume: transfusion_volume,
  1431. LastAfterWeight: last_after_weight,
  1432. DisplaceLiquiValue: displace_liqui_value,
  1433. RecordTime: startDate.Unix(),
  1434. SymptomAfterDialysisRemark: symptom_after_dialysis_remark,
  1435. }
  1436. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1437. // 查询信息规挡的设置天数
  1438. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1439. if infor.ID > 0 && infor.WeekDay > 0 {
  1440. var cha_time int64
  1441. timeNowStr := time.Now().Format("2006-01-02")
  1442. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1443. //今日的日期减去设置的日期
  1444. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1445. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1446. if cha_time >= recordDate.Unix() {
  1447. //查询审核是否允许
  1448. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1449. //申请状态不允许的情况 拒绝修改
  1450. if infor.ApplicationStatus != 1 {
  1451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1452. return
  1453. }
  1454. }
  1455. }
  1456. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1457. if assessmentAfter.ID == 0 { //新增
  1458. if appRole.UserType == 2 || appRole.UserType == 1 {
  1459. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1460. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1461. } else {
  1462. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1463. }
  1464. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1465. if assessmentAfterDislysis.UserOrgId != 10340 {
  1466. if assessmentAfterDislysis.WeightAfter == 0 {
  1467. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1468. }
  1469. }
  1470. if adminUserInfo.Org.Id == 10693 {
  1471. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1472. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1473. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1474. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1475. }
  1476. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1477. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1478. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1479. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1480. }
  1481. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1482. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1483. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1484. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1485. }
  1486. if assessmentAfterDislysis.PulseFrequency == 0 {
  1487. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1488. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1489. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1490. }
  1491. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1492. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1493. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1494. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1495. }
  1496. }
  1497. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1498. //记录日志
  1499. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1500. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1501. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1502. PatientId: assessmentAfterDislysis.PatientId,
  1503. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1504. Status: 1,
  1505. ErrLog: string(byterequest),
  1506. AdminUserId: adminUserInfo.AdminUser.Id,
  1507. Ctime: 0,
  1508. Mtime: 0,
  1509. Source: "手机端保存透后评估",
  1510. }
  1511. service.CreateAfterDialysisLog(afterDialysisLog)
  1512. finish := models.XtDialysisFinish{
  1513. IsFinish: 1,
  1514. UserOrgId: adminUserInfo.Org.Id,
  1515. Status: 1,
  1516. Ctime: time.Now().Unix(),
  1517. Mtime: 0,
  1518. Module: 9,
  1519. RecordDate: recordDate.Unix(),
  1520. Sourse: 1,
  1521. PatientId: id,
  1522. }
  1523. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1524. if dialysisFinish.ID == 0 {
  1525. service.CreateDialysisFinish(finish)
  1526. }
  1527. redis := service.RedisClient()
  1528. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1529. redis.Set(keyTwo, "", time.Second)
  1530. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1531. //清空key 值
  1532. redis.Set(key, "", time.Second)
  1533. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1534. redis.Set(keyOne, "", time.Second)
  1535. defer redis.Close()
  1536. if err == nil {
  1537. c.ServeSuccessJSON(map[string]interface{}{
  1538. "assessmentAfterDislysis": assessmentAfterDislysis,
  1539. })
  1540. }
  1541. return
  1542. } else { //修改
  1543. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1544. if infor.ID > 0 && infor.WeekDay > 0 {
  1545. var cha_time int64
  1546. timeNowStr := time.Now().Format("2006-01-02")
  1547. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1548. //今日的日期减去设置的日期
  1549. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1550. if cha_time >= recordDate.Unix() {
  1551. //查询审核是否允许
  1552. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1553. //申请状态不允许的情况 拒绝修改
  1554. if infor.ApplicationStatus != 1 {
  1555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1556. return
  1557. }
  1558. }
  1559. }
  1560. if appRole.UserType == 2 || appRole.UserType == 1 {
  1561. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1562. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1563. } else {
  1564. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1565. if assessmentAfterDislysis.Creater == 0 {
  1566. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1567. }
  1568. }
  1569. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1570. assessmentAfterDislysis.ID = assessmentAfter.ID
  1571. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1572. if assessmentAfterDislysis.UserOrgId != 10340 {
  1573. if assessmentAfterDislysis.WeightAfter == 0 {
  1574. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1575. }
  1576. }
  1577. if adminUserInfo.Org.Id == 10693 {
  1578. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1579. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1580. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1581. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1582. }
  1583. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1584. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1585. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1586. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1587. }
  1588. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1589. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1590. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1591. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1592. }
  1593. if assessmentAfterDislysis.PulseFrequency == 0 {
  1594. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1595. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1596. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1597. }
  1598. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1599. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1600. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1601. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1602. }
  1603. }
  1604. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1605. //记录日志
  1606. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1607. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1608. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1609. PatientId: assessmentAfterDislysis.PatientId,
  1610. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1611. Status: 1,
  1612. ErrLog: string(byterequest),
  1613. AdminUserId: adminUserInfo.AdminUser.Id,
  1614. Ctime: time.Now().Unix(),
  1615. Mtime: 0,
  1616. Source: "手机端修改保存透后评估",
  1617. }
  1618. service.CreateAfterDialysisLog(afterDialysisLog)
  1619. redis := service.RedisClient()
  1620. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1621. redis.Set(keyTwo, "", time.Second)
  1622. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1623. //清空key 值
  1624. redis.Set(key, "", time.Second)
  1625. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1626. redis.Set(keyOne, "", time.Second)
  1627. if err == nil {
  1628. c.ServeSuccessJSON(map[string]interface{}{
  1629. "assessmentAfterDislysis": assessmentAfterDislysis,
  1630. })
  1631. return
  1632. }
  1633. }
  1634. return
  1635. }
  1636. func (c *DialysisAPIController) PostDialysisPrescription() {
  1637. id, _ := c.GetInt64("patient", 0)
  1638. recordDateStr := c.GetString("record_date")
  1639. if id <= 0 {
  1640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1641. return
  1642. }
  1643. adminUserInfo := c.GetMobileAdminUserInfo()
  1644. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1645. if patient.ID == 0 {
  1646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1647. return
  1648. }
  1649. if len(recordDateStr) == 0 {
  1650. recordDateStr = time.Now().Format("2006-01-02")
  1651. }
  1652. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1653. if parseDateErr != nil {
  1654. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1656. return
  1657. }
  1658. mode_id, _ := c.GetInt64("mode_id", 0)
  1659. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1660. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1661. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1662. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1663. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1664. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1665. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1666. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1667. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1668. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1669. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1670. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1671. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1672. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1673. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1674. kalium, _ := c.GetFloat("kalium", 0)
  1675. sodium, _ := c.GetFloat("sodium", 0)
  1676. calcium, _ := c.GetFloat("calcium", 0)
  1677. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1678. glucose, _ := c.GetFloat("glucose", 0)
  1679. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1680. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1681. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1682. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1683. conductivity, _ := c.GetFloat("conductivity", 0)
  1684. remark := c.GetString("remark")
  1685. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1686. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1687. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1688. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1689. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1690. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1691. special_medicine_other := c.GetString("special_medicine_other")
  1692. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1693. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1694. blood_access, _ := c.GetInt64("blood_access", 0)
  1695. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1696. body_fluid_other := c.GetString("body_fluid_other")
  1697. niprocart, _ := c.GetInt64("niprocart", 0)
  1698. jms, _ := c.GetInt64("jms", 0)
  1699. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1700. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1701. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1702. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1703. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1704. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1705. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1706. injector, _ := c.GetInt64("injector", 0)
  1707. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1708. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1709. safe_package, _ := c.GetInt64("package", 0)
  1710. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1711. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1712. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1713. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1714. blood := c.GetString("blood")
  1715. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1716. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1717. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1718. displace_speed := c.GetString("displace_speed")
  1719. illness, _ := c.GetInt64("illness")
  1720. amylaceum := c.GetString("amylaceum")
  1721. single_time := c.GetString("single_time")
  1722. single_water := c.GetString("single_water")
  1723. replacement_flow := c.GetString("replacement_flow")
  1724. plasma_separator := c.GetString("plasma_separator")
  1725. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1726. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1727. oxygen_flow := c.GetString("oxygen_flow")
  1728. oxygen_time := c.GetString("oxygen_time")
  1729. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1730. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1731. puncture_needle := c.GetString("puncture_needle")
  1732. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1733. epo := c.GetString("epo")
  1734. epo_count, _ := c.GetFloat("epo_count", 0)
  1735. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1736. admin_user_id, _ := c.GetInt64("admin_user_id")
  1737. is_water := c.GetString("is_water")
  1738. var is_war int64
  1739. if is_water == "是" {
  1740. is_war = 1
  1741. }
  1742. if is_water == "否" {
  1743. is_war = 2
  1744. }
  1745. if is_water == "请选择" {
  1746. is_war = 0
  1747. }
  1748. drhy_water := c.GetString("drhy_water")
  1749. dry_water_hour := c.GetString("dry_water_hour")
  1750. water_machine := c.GetString("water_machine")
  1751. add_amount, _ := c.GetFloat("add_amount")
  1752. reduce_amount, _ := c.GetFloat("reduce_amount")
  1753. dialysis_remark := c.GetString("dialysis_remark")
  1754. prescribing_number, _ := c.GetFloat("prescribing_number")
  1755. prescription_sodium := c.GetString("prescription_sodium")
  1756. start_sodium := c.GetString("start_sodium")
  1757. sodium_curve := c.GetString("sodium_curve")
  1758. treatment_remark := c.GetString("treatment_remark")
  1759. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1760. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1761. prescription_water, _ := c.GetFloat("prescription_water")
  1762. dialysis_strainer := c.GetString("dialysis_strainer")
  1763. chaptalization := c.GetString("chaptalization")
  1764. washing_time := c.GetString("washing_time")
  1765. warsh_count := c.GetString("warsh_count")
  1766. blood_access_part_id := c.GetString("blood_access_part_id")
  1767. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1768. dialyzate := c.GetString("dialyzate")
  1769. first_super := c.GetString("first_super")
  1770. sterilization_water := c.GetString("sterilization_water")
  1771. five_glucose := c.GetString("five_glucose")
  1772. fifty_glucose := c.GetString("fifty_glucose")
  1773. magnesium_sulfate_injection := c.GetString("magnesium_sulfate_injection")
  1774. calcium_gluconate := c.GetString("calcium_gluconate")
  1775. five_potassium_chloride_injection := c.GetString("five_potassium_chloride_injection")
  1776. ten_potassium_chloride_injection := c.GetString("ten_potassium_chloride_injection")
  1777. five_sodium_bicarbonate_injection := c.GetString("five_sodium_bicarbonate_injection")
  1778. new_sty := c.GetString("new_sty")
  1779. var first_sup int64
  1780. if first_super == "是" {
  1781. first_sup = 1
  1782. }
  1783. if first_super == "否" {
  1784. first_sup = 2
  1785. }
  1786. if first_super == "请选择" {
  1787. first_sup = 0
  1788. }
  1789. is_sequential := c.GetString("is_sequential")
  1790. var is_sequent int64
  1791. if is_sequential == "是" {
  1792. is_sequent = 1
  1793. }
  1794. if is_sequential == "否" {
  1795. is_sequent = 2
  1796. }
  1797. if is_sequential == "请选择" {
  1798. is_sequent = 0
  1799. }
  1800. conduct := c.GetString("conduct")
  1801. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1802. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1803. //
  1804. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1805. // if appRole.UserType == 3 {
  1806. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1807. // if getPermissionErr != nil {
  1808. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1809. // return
  1810. // } else if headNursePermission == nil {
  1811. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1812. // return
  1813. // }
  1814. // }
  1815. //}
  1816. // 查询信息规挡的设置天数
  1817. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1818. if infor.ID > 0 && infor.WeekDay > 0 {
  1819. var cha_time int64
  1820. timeNowStr := time.Now().Format("2006-01-02")
  1821. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1822. //今日的日期减去设置的日期
  1823. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1824. if cha_time >= recordDate.Unix() {
  1825. //查询审核是否允许
  1826. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1827. //申请状态不允许的情况 拒绝修改
  1828. if infor.ApplicationStatus != 1 {
  1829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1830. return
  1831. }
  1832. }
  1833. }
  1834. if mode_id > 0 {
  1835. var str string
  1836. //查找该机构用的是什么透析器
  1837. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1838. if filedConfig.ID > 0 {
  1839. str = dialyzerPerfusionApparatus
  1840. } else {
  1841. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1842. }
  1843. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1844. }
  1845. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  1846. var dialysis_dialyszers_id int64
  1847. var dialysis_strainer_id int64
  1848. var dialysis_irrigation_id int64
  1849. if len(goodList) > 0 {
  1850. for _, item := range goodList {
  1851. if item.SpecificationName == dialysis_dialyszers {
  1852. dialysis_dialyszers_id = item.ID
  1853. }
  1854. if item.SpecificationName == dialysis_irrigation {
  1855. dialysis_irrigation_id = item.ID
  1856. }
  1857. if item.SpecificationName == dialysis_strainer {
  1858. dialysis_strainer_id = item.ID
  1859. }
  1860. }
  1861. }
  1862. //TODO 需要根据角色去判断
  1863. prescription := models.DialysisPrescription{
  1864. UserOrgId: adminUserInfo.Org.Id,
  1865. PatientId: id,
  1866. RecordDate: recordDate.Unix(),
  1867. ModeId: mode_id,
  1868. DialysisDuration: dialysis_duration,
  1869. Dialyzer: dialyzer,
  1870. PerfusionApparatus: perfusion_apparatus,
  1871. BloodFlowVolume: blood_flow_volume,
  1872. DewaterAmount: dewater_amount,
  1873. DisplaceLiqui: displace_liqui,
  1874. ReplacementWay: replacement_way,
  1875. Anticoagulant: anticoagulant,
  1876. AnticoagulantShouji: anticoagulant_shouji,
  1877. AnticoagulantWeichi: anticoagulant_weichi,
  1878. AnticoagulantZongliang: anticoagulant_zongliang,
  1879. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1880. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1881. Kalium: kalium,
  1882. Sodium: sodium,
  1883. Calcium: calcium,
  1884. Bicarbonate: bicarbonate,
  1885. Glucose: glucose,
  1886. // DryWeight: dry_weight,
  1887. DialysateFlow: dialysate_flow,
  1888. DialysateTemperature: dialysate_temperature,
  1889. // PrescriptionDoctor: prescription_doctor,
  1890. ReplacementTotal: replacement_total,
  1891. Conductivity: conductivity,
  1892. Remark: remark,
  1893. Status: 1,
  1894. CreatedTime: time.Now().Unix(),
  1895. UpdatedTime: time.Now().Unix(),
  1896. DialysisDurationMinute: dialysisDurationMinute,
  1897. DialysisDurationHour: dialysisDurationHour,
  1898. TargetUltrafiltration: targetUltrafiltration,
  1899. DialysateFormulation: dialysateFormulation,
  1900. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1901. BodyFluid: body_fluid,
  1902. SpecialMedicine: special_medicine,
  1903. SpecialMedicineOther: special_medicine_other,
  1904. DisplaceLiquiPart: displace_liqui_part,
  1905. DisplaceLiquiValue: displace_liqui_value,
  1906. BloodAccess: blood_access,
  1907. Ultrafiltration: ultrafiltration,
  1908. BodyFluidOther: body_fluid_other,
  1909. Niprocart: niprocart,
  1910. Jms: jms,
  1911. FistulaNeedleSet: fistula_needle_set,
  1912. FistulaNeedleSet16: fistula_needle_set_16,
  1913. Hemoperfusion: hemoperfusion,
  1914. DialyserSterilised: dialyser_sterilised,
  1915. Filtryzer: filtryzer,
  1916. Dialyzers: dialyzers,
  1917. Injector: injector,
  1918. Bloodlines: bloodlines,
  1919. TubingHemodialysis: tubing_hemodialysis,
  1920. Package: safe_package,
  1921. ALiquid: a_liquid,
  1922. TargetKtv: target_ktv,
  1923. PreImpulse: pre_impulse,
  1924. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1925. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1926. Blood: blood,
  1927. DialysisDialyszers: dialysis_dialyszers,
  1928. DialysisIrrigation: dialysis_irrigation,
  1929. AntioxidantCommodityName: antioxidant_commodity_name,
  1930. DisplaceSpeed: displace_speed,
  1931. Illness: illness,
  1932. Amylaceum: amylaceum,
  1933. SingleTime: single_time,
  1934. SingleWater: single_water,
  1935. ReplacementFlow: replacement_flow,
  1936. PlasmaSeparator: plasma_separator,
  1937. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1938. OxygenUptake: oxygen_uptake,
  1939. OxygenFlow: oxygen_flow,
  1940. OxygenTime: oxygen_time,
  1941. HemodialysisPipelines: hemodialysis_pipelines,
  1942. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1943. PunctureNeedle: puncture_needle,
  1944. PunctureNeedleCount: puncture_needle_count,
  1945. Epo: epo,
  1946. EpoCount: epo_count,
  1947. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1948. AdminUserId: admin_user_id,
  1949. IsWater: is_war,
  1950. DrhyWater: drhy_water,
  1951. DryWaterHour: dry_water_hour,
  1952. WaterMachine: water_machine,
  1953. AddAmount: add_amount,
  1954. ReduceAmount: reduce_amount,
  1955. DialysisRemark: dialysis_remark,
  1956. PrescribingNumber: prescribing_number,
  1957. StartSodium: start_sodium,
  1958. SodiumCurve: sodium_curve,
  1959. TreatmentRemark: treatment_remark,
  1960. PrescriptionSodium: prescription_sodium,
  1961. DialysisFluidFlow: dialysis_fluid_flow,
  1962. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1963. PrescriptionWater: prescription_water,
  1964. DialysisStrainer: dialysis_strainer,
  1965. Chaptalization: chaptalization,
  1966. WashingTime: washing_time,
  1967. WarshCount: warsh_count,
  1968. BloodAccessPartId: blood_access_part_id,
  1969. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1970. Dialyzate: dialyzate,
  1971. DialysisDialyszersId: dialysis_dialyszers_id,
  1972. DialysisIrrigationId: dialysis_irrigation_id,
  1973. DialysisStrainerId: dialysis_strainer_id,
  1974. FirstSuper: first_sup,
  1975. IsSequential: is_sequent,
  1976. Conduct: conduct,
  1977. SterilizationWater: sterilization_water,
  1978. FiveGlucose: five_glucose,
  1979. FiftyGlucose: fifty_glucose,
  1980. MagnesiumSulfateInjection: magnesium_sulfate_injection,
  1981. CalciumGluconate: calcium_gluconate,
  1982. FivePotassiumChlorideInjection: five_potassium_chloride_injection,
  1983. TenPotassiumChlorideInjection: ten_potassium_chloride_injection,
  1984. FiveSodiumBicarbonateInjection: five_sodium_bicarbonate_injection,
  1985. NewSty: new_sty,
  1986. }
  1987. if prescription.ModeId != 13 {
  1988. prescription.SterilizationWater = ""
  1989. prescription.FiveGlucose = ""
  1990. prescription.FiftyGlucose = ""
  1991. prescription.MagnesiumSulfateInjection = ""
  1992. prescription.CalciumGluconate = ""
  1993. prescription.FivePotassiumChlorideInjection = ""
  1994. prescription.TenPotassiumChlorideInjection = ""
  1995. prescription.FiveSodiumBicarbonateInjection = ""
  1996. prescription.NewSty = ""
  1997. }
  1998. if adminUserInfo.Org.Id == 10721 {
  1999. if prescription.ModeId == 2 {
  2000. if prescription.ReplacementTotal == 0 {
  2001. prescription.ReplacementTotal = 15
  2002. }
  2003. }
  2004. }
  2005. //查询最近透析准备表里是否存在 透析器 灌流器
  2006. //
  2007. //splitStr := strings.Split(dialysis_dialyszers, ",")
  2008. //
  2009. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  2010. //
  2011. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  2012. //if len(mation)>0{
  2013. // for _, item := range splitStr {
  2014. // for _,it := range mation{
  2015. // if(item == it.SpecificationName){
  2016. //
  2017. // //查询最近一次的透析器
  2018. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2019. //
  2020. // if errcode == gorm.ErrRecordNotFound{
  2021. // //插入数据
  2022. // prepare := models.DialysisBeforePrepare{
  2023. // UserOrgId: adminUserInfo.Org.Id,
  2024. // PatientId: id,
  2025. // RecordDate: recordDate.Unix(),
  2026. // GoodTypeId: it.GoodTypeId,
  2027. // GoodId: it.ID,
  2028. // Count: 1,
  2029. // Ctime: time.Now().Unix(),
  2030. // Creater: adminUserInfo.AdminUser.Id,
  2031. // Status:1,
  2032. //
  2033. // }
  2034. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2035. // fmt.Println("",errcode)
  2036. // }
  2037. // }
  2038. // }
  2039. //
  2040. // }
  2041. //
  2042. // for _, item := range splitIrrigation {
  2043. // for _,it := range mation{
  2044. // if(item == it.SpecificationName){
  2045. // //查询最近一次的透析器
  2046. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2047. // if errcode == gorm.ErrRecordNotFound{
  2048. // //插入数据
  2049. // prepare := models.DialysisBeforePrepare{
  2050. // UserOrgId: adminUserInfo.Org.Id,
  2051. // PatientId: id,
  2052. // RecordDate: recordDate.Unix(),
  2053. // GoodTypeId: it.GoodTypeId,
  2054. // GoodId: it.ID,
  2055. // Count: 1,
  2056. // Ctime: time.Now().Unix(),
  2057. // Creater: adminUserInfo.AdminUser.Id,
  2058. // Status:1,
  2059. //
  2060. // }
  2061. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2062. // fmt.Println(errcode)
  2063. // }
  2064. // }
  2065. // }
  2066. // }
  2067. //}
  2068. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2069. if dialysisPrescription.ID == 0 { //新增
  2070. if appRole.UserType == 2 || appRole.UserType == 1 {
  2071. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2072. }
  2073. prescription.Creater = adminUserInfo.AdminUser.Id
  2074. //针对河间咸得
  2075. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  2076. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  2077. prescription.DisplaceLiquiPart = 0
  2078. prescription.DisplaceLiquiValue = 0
  2079. }
  2080. }
  2081. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  2082. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  2083. }
  2084. err := service.AddSigleRecord(&prescription)
  2085. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2086. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9478 {
  2087. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2088. if len(monitorList) > 0 {
  2089. var ultrafiltration_rate float64
  2090. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2091. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2092. var replacement_rate float64
  2093. if adminUserInfo.Org.Id == 10721 {
  2094. //乘10 除10是为了保留一位小数
  2095. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2096. }
  2097. if adminUserInfo.Org.Id == 9478 {
  2098. //乘10 除10是为了保留一位小数
  2099. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  2100. }
  2101. if adminUserInfo.Org.Id == 10766 {
  2102. //乘10 除10是为了保留一位小数
  2103. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  2104. }
  2105. var firstOpeateTime = monitorList[0].OperateTime
  2106. for _, item := range monitorList {
  2107. //超滤率
  2108. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2109. //置换率
  2110. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2111. //超滤量
  2112. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2113. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2114. //置换量
  2115. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2116. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2117. }
  2118. }
  2119. }
  2120. //记录日志
  2121. byterequest, _ := json.Marshal(prescription)
  2122. prescriptionLog := models.XtDialysisPrescriptionLog{
  2123. UserOrgId: prescription.UserOrgId,
  2124. Ctime: time.Now().Unix(),
  2125. Mtime: 0,
  2126. ErrLog: string(byterequest),
  2127. AdminUserId: adminUserInfo.AdminUser.Id,
  2128. RecordDate: prescription.RecordDate,
  2129. PatientId: prescription.PatientId,
  2130. Source: "手机端新增保存处方",
  2131. Status: 1,
  2132. }
  2133. service.CreatePrescriptionLog(prescriptionLog)
  2134. finish := models.XtDialysisFinish{
  2135. IsFinish: 1,
  2136. UserOrgId: adminUserInfo.Org.Id,
  2137. Status: 1,
  2138. Ctime: time.Now().Unix(),
  2139. Mtime: 0,
  2140. Module: 1,
  2141. RecordDate: recordDate.Unix(),
  2142. Sourse: 1,
  2143. PatientId: id,
  2144. }
  2145. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2146. if dialysisFinish.ID == 0 {
  2147. service.CreateDialysisFinish(finish)
  2148. }
  2149. //长沙南雅医院,自动生成抗凝剂的临时处方
  2150. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2151. if prescribing_number == 0 {
  2152. prescribing_number = 1
  2153. }
  2154. if prescribing_number == 0 && id == 14682 {
  2155. prescribing_number = 2
  2156. }
  2157. if prescribing_number == 0 && id == 18560 {
  2158. prescribing_number = 2
  2159. }
  2160. advice := models.DoctorAdvice{
  2161. UserOrgId: adminUserInfo.Org.Id,
  2162. PatientId: id,
  2163. GroupNo: 0,
  2164. AdviceType: 2,
  2165. RecordDate: recordDate.Unix(),
  2166. AdviceDate: recordDate.Unix(),
  2167. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  2168. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  2169. AdviceDesc: "",
  2170. ReminderDate: 0,
  2171. SingleDose: anticoagulant_zongliang,
  2172. SingleDoseUnit: "iu",
  2173. DrugSpec: 0,
  2174. DrugSpecUnit: "",
  2175. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  2176. PrescribingNumberUnit: "支",
  2177. DeliveryWay: "静脉注射",
  2178. ExecutionFrequency: "上机前",
  2179. AdviceDoctor: 0,
  2180. Status: 1,
  2181. CreatedTime: time.Now().Unix(),
  2182. UpdatedTime: time.Now().Unix(),
  2183. IsPrescription: 1,
  2184. ExecutionState: 2,
  2185. StopState: 2,
  2186. IsSettle: 2,
  2187. }
  2188. // 查询排班信息
  2189. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2190. if schedulePatient.ID > 0 {
  2191. if schedulePatient.ScheduleType == 1 {
  2192. advice.StartTime = recordDate.Unix() + 6.5*60*60
  2193. }
  2194. if schedulePatient.ScheduleType == 2 {
  2195. advice.StartTime = recordDate.Unix() + 9*60*60
  2196. }
  2197. }
  2198. // 抗凝剂名称
  2199. switch anticoagulant {
  2200. case 1:
  2201. advice.AdviceName = "无肝素"
  2202. break
  2203. case 2:
  2204. advice.AdviceName = "普通肝素"
  2205. break
  2206. case 3:
  2207. advice.AdviceName = "低分子肝素"
  2208. break
  2209. case 4:
  2210. advice.AdviceName = "阿加曲班"
  2211. break
  2212. case 5:
  2213. advice.AdviceName = "枸橼酸钠"
  2214. break
  2215. case 6:
  2216. advice.AdviceName = "低分子肝素钙"
  2217. break
  2218. case 7:
  2219. advice.AdviceName = "低分子肝素钠"
  2220. break
  2221. case 8:
  2222. advice.AdviceName = "依诺肝素"
  2223. break
  2224. case 9:
  2225. advice.AdviceName = "达肝素"
  2226. break
  2227. case 10:
  2228. advice.AdviceName = "体外抗凝"
  2229. break
  2230. case 11:
  2231. advice.AdviceName = "那曲肝素"
  2232. break
  2233. case 12:
  2234. advice.AdviceName = "无抗凝剂"
  2235. break
  2236. }
  2237. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2238. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2239. advice.AdviceDoctor = appRole.AdminUserId
  2240. }
  2241. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2242. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2243. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2244. advice.AdviceName = "低分子肝素钠注射液"
  2245. // 修改患者临时医嘱里的抗凝剂医嘱
  2246. advice.ID = advicePrescription.ID
  2247. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2248. } else {
  2249. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2250. advice.AdviceName = "低分子肝素钠注射液"
  2251. // 新增患者临时医嘱里的抗凝剂医嘱
  2252. service.CreateDoctorAdvice(&advice)
  2253. }
  2254. }
  2255. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2256. redis := service.RedisClient()
  2257. defer redis.Close()
  2258. //清空key 值
  2259. redis.Set(key, "", time.Second)
  2260. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2261. redis.Set(keyOne, "", time.Second)
  2262. }
  2263. //获取key,清空redis
  2264. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2265. redis := service.RedisClient()
  2266. //清空key 值
  2267. redis.Set(key, "", time.Second)
  2268. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2269. //清空key 值
  2270. redis.Set(keyOne, "", time.Second)
  2271. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2272. //清空key 值
  2273. redis.Set(keyTwo, "", time.Second)
  2274. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2275. redis.Set(keySix, "", time.Second)
  2276. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2277. redis.Set(keySeven, "", time.Second)
  2278. if err == nil {
  2279. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2280. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2281. //清空key 值
  2282. redis.Set(keyThree, "", time.Second)
  2283. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2284. //清空key 值
  2285. redis.Set(keyFour, "", time.Second)
  2286. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2287. redis.Set(keyFive, "", time.Second)
  2288. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2289. redis.Set(keySix, "", time.Second)
  2290. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2291. redis.Set(keySeven, "", time.Second)
  2292. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2293. //清空key 值
  2294. redis.Set(keyOne, "", time.Second)
  2295. if updateErr != nil {
  2296. utils.ErrorLog("%v", updateErr)
  2297. }
  2298. defer redis.Close()
  2299. c.ServeSuccessJSON(map[string]interface{}{
  2300. "prescription": prescription,
  2301. })
  2302. }
  2303. } else { //修改
  2304. //if mode_id > 0 {
  2305. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2306. //}
  2307. //if template.TemplateId == 1 {
  2308. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2309. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2310. // if getPermissionErr != nil {
  2311. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2312. // return
  2313. // } else if headNursePermission == nil {
  2314. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2315. // return
  2316. // }
  2317. // }
  2318. //}
  2319. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2320. prescription.Modifier = adminUserInfo.AdminUser.Id
  2321. if appRole.UserType == 2 || appRole.UserType == 1 {
  2322. prescription_doctor := adminUserInfo.AdminUser.Id
  2323. prescription.PrescriptionDoctor = prescription_doctor
  2324. } else {
  2325. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2326. }
  2327. if dialysisPrescription.Creater == 0 { //体重称
  2328. prescription.Creater = adminUserInfo.AdminUser.Id
  2329. } else {
  2330. prescription.Creater = dialysisPrescription.Creater
  2331. if adminUserInfo.Org.Id == 9882 {
  2332. if appRole.UserType == 2 || appRole.UserType == 1 {
  2333. prescription_doctor := adminUserInfo.AdminUser.Id
  2334. prescription.PrescriptionDoctor = prescription_doctor
  2335. prescription.Creater = prescription_doctor
  2336. }
  2337. }
  2338. }
  2339. prescription.ID = dialysisPrescription.ID
  2340. if adminUserInfo.Org.Id == 10721 {
  2341. if prescription.ModeId == 2 {
  2342. if prescription.ReplacementTotal == 0 {
  2343. prescription.ReplacementTotal = 15
  2344. }
  2345. }
  2346. }
  2347. service.UpDateDialysisPrescription(&prescription)
  2348. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2349. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9478 {
  2350. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2351. if len(monitorList) > 0 {
  2352. var ultrafiltration_rate float64
  2353. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2354. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2355. var replacement_rate float64
  2356. if adminUserInfo.Org.Id == 10721 {
  2357. //乘10 除10是为了保留一位小数
  2358. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2359. }
  2360. if adminUserInfo.Org.Id == 9478 || adminUserInfo.Org.Id == 10766 {
  2361. //乘10 除10是为了保留一位小数
  2362. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  2363. }
  2364. var firstOpeateTime = monitorList[0].OperateTime
  2365. for _, item := range monitorList {
  2366. //超滤率
  2367. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2368. //置换率
  2369. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2370. //超滤量
  2371. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2372. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2373. //置换量
  2374. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2375. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2376. }
  2377. }
  2378. }
  2379. //记录日志
  2380. byterequest, _ := json.Marshal(prescription)
  2381. prescriptionLog := models.XtDialysisPrescriptionLog{
  2382. UserOrgId: prescription.UserOrgId,
  2383. Ctime: time.Now().Unix(),
  2384. Mtime: 0,
  2385. ErrLog: string(byterequest),
  2386. AdminUserId: adminUserInfo.AdminUser.Id,
  2387. RecordDate: prescription.RecordDate,
  2388. PatientId: prescription.PatientId,
  2389. Source: "手机端修改处方",
  2390. Status: 1,
  2391. }
  2392. service.CreatePrescriptionLog(prescriptionLog)
  2393. finish := models.XtDialysisFinish{
  2394. IsFinish: 1,
  2395. UserOrgId: adminUserInfo.Org.Id,
  2396. Status: 1,
  2397. Ctime: time.Now().Unix(),
  2398. Mtime: 0,
  2399. Module: 1,
  2400. RecordDate: recordDate.Unix(),
  2401. Sourse: 1,
  2402. PatientId: id,
  2403. }
  2404. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2405. if dialysisFinish.ID == 0 {
  2406. service.CreateDialysisFinish(finish)
  2407. }
  2408. //修改处方
  2409. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2410. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2411. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2412. if advicePrescription.ID > 0 {
  2413. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2414. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2415. redis := service.RedisClient()
  2416. defer redis.Close()
  2417. //清空key 值
  2418. redis.Set(key, "", time.Second)
  2419. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2420. redis.Set(keyOne, "", time.Second)
  2421. }
  2422. }
  2423. //获取key,清空redis
  2424. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2425. redis := service.RedisClient()
  2426. //清空key 值
  2427. redis.Set(key, "", time.Second)
  2428. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2429. //清空key 值
  2430. redis.Set(keyOne, "", time.Second)
  2431. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2432. redis.Set(keySix, "", time.Second)
  2433. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2434. redis.Set(keySeven, "", time.Second)
  2435. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2436. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2437. //清空key 值
  2438. redis.Set(keyTwoOne, "", time.Second)
  2439. defer redis.Close()
  2440. if updateErr != nil {
  2441. utils.ErrorLog("%v", updateErr)
  2442. }
  2443. c.ServeSuccessJSON(map[string]interface{}{
  2444. "prescription": prescription,
  2445. })
  2446. }
  2447. }
  2448. func (c *DialysisAPIController) Finish() {
  2449. id, _ := c.GetInt64("patient", 0)
  2450. recordDateStr := c.GetString("record_date")
  2451. nurseID, _ := c.GetInt64("nurse")
  2452. end_time := c.GetString("end_time")
  2453. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2454. internal_fistula := c.GetString("blood_access_internal_fistula")
  2455. catheter := c.GetString("catheter")
  2456. cruor := c.GetString("cruor")
  2457. mission := c.GetString("mission")
  2458. condenser := c.GetString("condenser")
  2459. if id <= 0 || nurseID <= 0 {
  2460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2461. return
  2462. }
  2463. adminUserInfo := c.GetMobileAdminUserInfo()
  2464. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2465. if patient.ID == 0 {
  2466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2467. return
  2468. }
  2469. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2470. if getNurseErr != nil {
  2471. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2473. return
  2474. } else if nurse == nil {
  2475. c.ErrorLog("护士不存在")
  2476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2477. return
  2478. }
  2479. if len(recordDateStr) == 0 {
  2480. recordDateStr = time.Now().Format("2006-01-02")
  2481. }
  2482. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2483. if parseDateErr != nil {
  2484. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2486. return
  2487. }
  2488. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2489. if parseEndDateErr != nil {
  2490. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2492. return
  2493. }
  2494. // 查询信息规挡的设置天数
  2495. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2496. if infor.ID > 0 && infor.WeekDay > 0 {
  2497. var cha_time int64
  2498. timeNowStr := time.Now().Format("2006-01-02")
  2499. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2500. //今日的日期减去设置的日期
  2501. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2502. if cha_time >= recordDate.Unix() {
  2503. //查询审核是否允许
  2504. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2505. //申请状态不允许的情况 拒绝修改
  2506. if infor.ApplicationStatus != 1 {
  2507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2508. return
  2509. }
  2510. }
  2511. }
  2512. //now := time.Now()
  2513. //year, month, day := now.Date()
  2514. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2515. //todayTimeStamp := today_time.Unix()
  2516. // 获取当天的第一条透析纪录
  2517. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2518. if getMonitorRecordsErr != nil {
  2519. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2521. return
  2522. }
  2523. // 获取当前的最后一条透析纪录
  2524. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2525. if getMonitorRecordsErr != nil {
  2526. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2528. return
  2529. }
  2530. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2531. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2532. if getAADErr != nil {
  2533. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2535. return
  2536. }
  2537. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2538. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2539. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2540. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2541. if assessmentAfterDislysis != nil {
  2542. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2543. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2544. } else {
  2545. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2546. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2547. tempassessmentAfterDislysis.Status = 1
  2548. tempassessmentAfterDislysis.PatientId = id
  2549. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2550. }
  2551. //长沙南雅
  2552. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2553. //获取最后一条透析处方数据
  2554. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2555. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2556. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2557. }
  2558. if dialysisOrder.Stage == 1 {
  2559. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2560. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2561. fmt.Println(value)
  2562. a, b := math.Modf(value)
  2563. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2564. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2565. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2566. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2567. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2568. }
  2569. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2570. //var num1 int64
  2571. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2572. //fmt.Println(num1)
  2573. //sub := float64(num1 / 3600)
  2574. //fmt.Println(sub)
  2575. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2576. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2577. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2578. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2579. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2580. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2581. if adminUserInfo.Org.Id != 10375 {
  2582. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2583. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2584. }
  2585. if adminUserInfo.Org.Id == 10766 {
  2586. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2587. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2588. }
  2589. if adminUserInfo.Org.Id != 10445 {
  2590. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2591. }
  2592. //北方营口医院
  2593. if adminUserInfo.Org.Id == 10445 {
  2594. //获取最后一条透析处方数据
  2595. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2596. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2597. } else {
  2598. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2599. }
  2600. //新化博翔
  2601. if adminUserInfo.Org.Id == 10447 {
  2602. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2603. }
  2604. //阳春
  2605. if adminUserInfo.Org.Id == 10485 {
  2606. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2607. }
  2608. if adminUserInfo.Org.Id == 10551 {
  2609. //获取最后一条透析处方数据
  2610. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2611. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2612. }
  2613. if adminUserInfo.Org.Id == 10580 {
  2614. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2615. }
  2616. if adminUserInfo.Org.Id == 10612 {
  2617. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2618. }
  2619. //孝康
  2620. if adminUserInfo.Org.Id == 10693 {
  2621. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2622. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2623. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2624. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2625. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2626. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2627. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2628. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2629. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2630. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2631. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2632. }
  2633. if adminUserInfo.Org.Id == 10721 {
  2634. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2635. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2636. }
  2637. if adminUserInfo.Org.Id == 10697 {
  2638. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2639. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2640. lastWeightAfter.LastAfterWeight = floatAfeter
  2641. }
  2642. if adminUserInfo.Org.Id == 10624 {
  2643. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2644. }
  2645. }
  2646. 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 || adminUserInfo.Org.Id == 10693 || adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10735 || adminUserInfo.Org.Id == 10742 || adminUserInfo.Org.Id == 10766 {
  2647. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2648. if adminUserInfo.Org.Id != 10702 {
  2649. if evaluation.SystolicBloodPressure == 0 {
  2650. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2651. if adminUserInfo.Org.Id == 10693 {
  2652. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2653. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2654. }
  2655. pre := models.PredialysisEvaluation{
  2656. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2657. }
  2658. fmt.Println("prew", pre)
  2659. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2660. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2661. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2662. redis := service.RedisClient()
  2663. redis.Set(key, "", time.Second)
  2664. redis.Set(keyOne, "", time.Second)
  2665. defer redis.Close()
  2666. fmt.Println(getNurseErr)
  2667. }
  2668. }
  2669. if adminUserInfo.Org.Id != 10702 {
  2670. if evaluation.DiastolicBloodPressure == 0 {
  2671. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2672. if adminUserInfo.Org.Id == 10693 {
  2673. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2674. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2675. }
  2676. pres := models.PredialysisEvaluation{
  2677. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2678. }
  2679. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2680. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2681. redis := service.RedisClient()
  2682. redis.Set(key, "", time.Second)
  2683. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2684. redis.Set(keyOne, "", time.Second)
  2685. defer redis.Close()
  2686. fmt.Println(getNurseErr)
  2687. }
  2688. }
  2689. if adminUserInfo.Org.Id != 10702 {
  2690. if evaluation.PulseFrequency == 0 {
  2691. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2692. if adminUserInfo.Org.Id == 10693 {
  2693. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2694. evaluation.PulseFrequency = pulseFrequency
  2695. }
  2696. press := models.PredialysisEvaluation{
  2697. PulseFrequency: evaluation.PulseFrequency,
  2698. }
  2699. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2700. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2701. redis := service.RedisClient()
  2702. redis.Set(key, "", time.Second)
  2703. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2704. redis.Set(keyOne, "", time.Second)
  2705. defer redis.Close()
  2706. fmt.Println(getNurseErr)
  2707. }
  2708. }
  2709. if evaluation.Temperature == 0 {
  2710. evaluation.Temperature = fmonitorRecords.Temperature
  2711. press := models.PredialysisEvaluation{
  2712. Temperature: evaluation.Temperature,
  2713. }
  2714. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2715. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2716. redis := service.RedisClient()
  2717. redis.Set(key, "", time.Second)
  2718. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2719. redis.Set(keyOne, "", time.Second)
  2720. defer redis.Close()
  2721. fmt.Println(getNurseErr)
  2722. }
  2723. }
  2724. if adminUserInfo.Org.Id == 9583 {
  2725. //获取透析处方的最后一条数据
  2726. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2727. if diaerr != nil {
  2728. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2730. return
  2731. }
  2732. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2733. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2734. }
  2735. }
  2736. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2737. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2738. }
  2739. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2740. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2741. }
  2742. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2743. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2744. }
  2745. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10766 {
  2746. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2747. }
  2748. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2749. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2750. }
  2751. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2752. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2753. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2754. }
  2755. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2756. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2757. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2758. }
  2759. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2760. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2761. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2762. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2763. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2764. }
  2765. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10735 {
  2766. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2767. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2768. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2769. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2770. }
  2771. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10766 {
  2772. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2773. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2774. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2775. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2776. }
  2777. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2778. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2779. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2780. }
  2781. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2782. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2783. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2784. }
  2785. if lastAssessmentAfterDislysis != nil {
  2786. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2787. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2788. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2789. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2790. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2791. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2792. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2793. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2794. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2795. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2796. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2797. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2798. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2799. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2800. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2801. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2802. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2803. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2804. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2805. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2806. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2807. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2808. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2809. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2810. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2811. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2812. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2813. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2814. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2815. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2816. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2817. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2818. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2819. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2820. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2821. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2822. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2823. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2824. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2825. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2826. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2827. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2828. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2829. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2830. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2831. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2832. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2833. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2834. if tempassessmentAfterDislysis.PatientId == 18695 {
  2835. tempassessmentAfterDislysis.ActualDisplacement = 0
  2836. }
  2837. if adminUserInfo.Org.Id != 10375 {
  2838. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2839. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2840. }
  2841. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2842. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2843. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2844. }
  2845. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2846. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2847. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2848. }
  2849. }
  2850. finish := models.XtDialysisFinish{
  2851. IsFinish: 1,
  2852. UserOrgId: adminUserInfo.Org.Id,
  2853. Status: 1,
  2854. Ctime: time.Now().Unix(),
  2855. Mtime: 0,
  2856. Module: 9,
  2857. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2858. Sourse: 1,
  2859. PatientId: tempassessmentAfterDislysis.PatientId,
  2860. }
  2861. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2862. if dialysisFinish.ID == 0 {
  2863. service.CreateDialysisFinish(finish)
  2864. }
  2865. //孝康
  2866. if adminUserInfo.Org.Id == 10693 {
  2867. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2868. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2869. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2870. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2871. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2872. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2873. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2874. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2875. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2876. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2877. }
  2878. if adminUserInfo.Org.Id == 10697 {
  2879. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2880. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2881. lastWeightAfter.LastAfterWeight = floatAfeter
  2882. }
  2883. if adminUserInfo.Org.Id == 10721 {
  2884. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2885. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2886. }
  2887. tempassessmentAfterDislysis.RecordTime = dialysisOrder.EndTime
  2888. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2889. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2890. redis := service.RedisClient()
  2891. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2892. redis.Set(keyOne, "", time.Second)
  2893. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2894. redis.Set(keyTwo, "", time.Second)
  2895. defer redis.Close()
  2896. //清空key 值
  2897. redis.Set(key, "", time.Second)
  2898. if err != nil {
  2899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2900. return
  2901. }
  2902. if dialysisOrder == nil {
  2903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2904. return
  2905. }
  2906. if dialysisOrder.Stage == 2 {
  2907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2908. return
  2909. }
  2910. if dialysisOrder.Stage == 1 {
  2911. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2912. finish := models.XtDialysisFinish{
  2913. IsFinish: 1,
  2914. UserOrgId: adminUserInfo.Org.Id,
  2915. Status: 1,
  2916. Ctime: time.Now().Unix(),
  2917. Mtime: 0,
  2918. Module: 8,
  2919. RecordDate: recordDate.Unix(),
  2920. Sourse: 1,
  2921. PatientId: id,
  2922. }
  2923. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2924. if dialysisFinish.ID == 0 {
  2925. service.CreateDialysisFinish(finish)
  2926. }
  2927. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2928. redis := service.RedisClient()
  2929. defer redis.Close()
  2930. //清空key 值
  2931. redis.Set(key, "", time.Second)
  2932. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2933. redis.Set(keyOne, "", time.Second)
  2934. //结束时候透析次数加1
  2935. service.UpdateSolutionByPatientId(id)
  2936. //下机完自动消毒,针对长沙南雅
  2937. if dialysisOrder.Stage == 1 {
  2938. 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 {
  2939. //根据床位号获取设备型号
  2940. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2941. //查询使用消毒最后一条消毒记录
  2942. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2943. fmt.Println("err", err)
  2944. if err == gorm.ErrRecordNotFound {
  2945. //查找排班
  2946. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2947. //查询改设备是否有消毒计划
  2948. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2949. //根据床位号获取设备id
  2950. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2951. //查询病人信息
  2952. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2953. var con = ""
  2954. if patients.IsInfectious == 0 {
  2955. con = ""
  2956. }
  2957. if patients.IsInfectious == 1 {
  2958. con = "无"
  2959. }
  2960. if patients.IsInfectious == 2 {
  2961. con = "有"
  2962. }
  2963. if errcode == nil {
  2964. var end_time int64
  2965. end_time = endDate.Unix() + plan.DisinfecTime*60
  2966. //新增消毒
  2967. information := models.DeviceInformation{
  2968. Date: dialysisOrder.DialysisDate,
  2969. Zone: dialysisOrder.ZoneId,
  2970. Class: dialysisOrder.SchedualType,
  2971. BedNumber: dialysisOrder.BedID,
  2972. PatientId: dialysisOrder.PatientId,
  2973. DialysisMode: scheduleByPatient.ModeId,
  2974. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2975. Disinfection: 1,
  2976. DialysisConcentration: 1,
  2977. DisinfectionStatus: 1,
  2978. Move: 1,
  2979. UserOrgId: dialysisOrder.UserOrgId,
  2980. DisinfectType: plan.Way,
  2981. DisinfectantType: plan.MachineDisinfectant,
  2982. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2983. Disinfectant: plan.Disinfectant,
  2984. Ctime: time.Now().Unix(),
  2985. Status: 1,
  2986. SignName: nurseID,
  2987. EquimentId: addmacher.ID,
  2988. DisinfectionResidue: 2,
  2989. Bed: addmacher.BedNumber,
  2990. StartTime: dialysisOrder.StartTime,
  2991. EndTime: dialysisOrder.EndTime,
  2992. Contagion: con,
  2993. WeightLoss: 0,
  2994. Hyperfiltratio: 0,
  2995. DialysisHour: "",
  2996. MachineRun: 1,
  2997. DisinfecStartime: endDate.Unix(),
  2998. DisinfecEndtime: end_time,
  2999. }
  3000. err := service.CreateInformationTwo(&information)
  3001. fmt.Println("报错", err)
  3002. }
  3003. }
  3004. }
  3005. }
  3006. dialysisOrder.Stage = 2
  3007. dialysisOrder.FinishNurse = nurseID
  3008. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  3009. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  3010. dialysisOrder.EndTime = endDate.Unix()
  3011. // 长沙南雅需求
  3012. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  3013. //获取最后1条监测的数据
  3014. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  3015. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  3016. var accumulatedBloodVolume float64
  3017. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  3018. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  3019. fmt.Println(err)
  3020. // 查询未执行的医嘱
  3021. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  3022. for _, item := range doctorAdvice {
  3023. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  3024. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  3025. redis := service.RedisClient()
  3026. //清空key 值
  3027. redis.Set(key, "", time.Second)
  3028. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  3029. redis.Set(keyTwo, "", time.Second)
  3030. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3031. redis.Set(keyThree, "", time.Second)
  3032. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  3033. theTime := toTime.Format("2006-01-02")
  3034. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3035. redis.Set(keyFour, "", time.Second)
  3036. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3037. redis.Set(keyFive, "", time.Second)
  3038. defer redis.Close()
  3039. }
  3040. }
  3041. go func() {
  3042. ssoDomain := beego.AppConfig.String("call_domain")
  3043. api := ssoDomain + "/index/downpatient"
  3044. values := make(url.Values)
  3045. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  3046. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3047. values.Set("patient_id", strconv.FormatInt(id, 10))
  3048. http.PostForm(api, values)
  3049. }()
  3050. if err == nil {
  3051. c.ServeSuccessJSON(map[string]interface{}{
  3052. "dialysisOrder": dialysisOrder,
  3053. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  3054. })
  3055. } else {
  3056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3057. }
  3058. }
  3059. //查找是否开启配置
  3060. //orderSetting, _ := service.GetDialysisOrderSetting(adminUserInfo.Org.Id)
  3061. ////开启下机扣减
  3062. //if orderSetting.IsOpen == 1 {
  3063. //
  3064. // //查询今日患者排班的模式
  3065. // db := service.XTWriteDB()
  3066. // // 开始外部循环的事务
  3067. // tx := db.Begin()
  3068. // // 在函数结束时处理事务回滚
  3069. // defer func() {
  3070. // if r := recover(); r != nil {
  3071. // tx.Rollback()
  3072. // }
  3073. // }()
  3074. //
  3075. // schedule, _ := service.GetDialysisOrderSchedule(id, recordDate.Unix(), adminUserInfo.Org.Id, tx)
  3076. //
  3077. // if schedule.ModeId == 1 {
  3078. // //扣减库存
  3079. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3080. //
  3081. // patient, _ := service.GetSfPatientById(tx, id)
  3082. // var over_count int64
  3083. // if schedule.ModeId == 1 {
  3084. // over_count = patient.HdCount
  3085. // }
  3086. // if schedule.ModeId == 2 {
  3087. // over_count = patient.HdfCount
  3088. // }
  3089. //
  3090. // if schedule.ModeId == 3 {
  3091. // over_count = patient.HdhpCount
  3092. // }
  3093. // if schedule.ModeId == 4 {
  3094. // over_count = patient.HpCount
  3095. // }
  3096. // if schedule.ModeId == 5 {
  3097. // over_count = patient.OtherCount
  3098. // }
  3099. // patientCountFlow := models.SfPatientCountFlow{
  3100. // PatientId: id,
  3101. // ModeId: schedule.ModeId,
  3102. // Count: 1,
  3103. // Status: 1,
  3104. // Ctime: time.Now().Unix(),
  3105. // Mtime: time.Now().Unix(),
  3106. // RecordDate: recordDate.Unix(),
  3107. // UserOrgId: adminUserInfo.Org.Id,
  3108. // Creater: adminUserInfo.AdminUser.Id,
  3109. // IsType: 1,
  3110. // OverCount: over_count,
  3111. // WarehouseOutId: 0,
  3112. // }
  3113. //
  3114. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3115. // }
  3116. //
  3117. // if schedule.ModeId == 2 {
  3118. //
  3119. // //扣减库存
  3120. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3121. //
  3122. // patient, _ := service.GetSfPatientById(tx, id)
  3123. // var over_count int64
  3124. // if schedule.ModeId == 1 {
  3125. // over_count = patient.HdCount
  3126. // }
  3127. // if schedule.ModeId == 2 {
  3128. // over_count = patient.HdfCount
  3129. // }
  3130. //
  3131. // if schedule.ModeId == 3 {
  3132. // over_count = patient.HdhpCount
  3133. // }
  3134. // if schedule.ModeId == 4 {
  3135. // over_count = patient.HpCount
  3136. // }
  3137. // if schedule.ModeId == 5 {
  3138. // over_count = patient.OtherCount
  3139. // }
  3140. // patientCountFlow := models.SfPatientCountFlow{
  3141. // PatientId: id,
  3142. // ModeId: schedule.ModeId,
  3143. // Count: 1,
  3144. // Status: 1,
  3145. // Ctime: time.Now().Unix(),
  3146. // Mtime: time.Now().Unix(),
  3147. // RecordDate: recordDate.Unix(),
  3148. // UserOrgId: adminUserInfo.Org.Id,
  3149. // Creater: adminUserInfo.AdminUser.Id,
  3150. // IsType: 2,
  3151. // OverCount: over_count,
  3152. // WarehouseOutId: 0,
  3153. // }
  3154. //
  3155. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3156. // }
  3157. //
  3158. // if schedule.ModeId == 3 {
  3159. //
  3160. // //扣减库存
  3161. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3162. //
  3163. // patient, _ := service.GetSfPatientById(tx, id)
  3164. // var over_count int64
  3165. // if schedule.ModeId == 1 {
  3166. // over_count = patient.HdCount
  3167. // }
  3168. // if schedule.ModeId == 2 {
  3169. // over_count = patient.HdfCount
  3170. // }
  3171. //
  3172. // if schedule.ModeId == 3 {
  3173. // over_count = patient.HdhpCount
  3174. // }
  3175. // if schedule.ModeId == 4 {
  3176. // over_count = patient.HpCount
  3177. // }
  3178. // if schedule.ModeId == 5 {
  3179. // over_count = patient.OtherCount
  3180. // }
  3181. // patientCountFlow := models.SfPatientCountFlow{
  3182. // PatientId: id,
  3183. // ModeId: schedule.ModeId,
  3184. // Count: 1,
  3185. // Status: 1,
  3186. // Ctime: time.Now().Unix(),
  3187. // Mtime: time.Now().Unix(),
  3188. // RecordDate: recordDate.Unix(),
  3189. // UserOrgId: adminUserInfo.Org.Id,
  3190. // Creater: adminUserInfo.AdminUser.Id,
  3191. // IsType: 3,
  3192. // OverCount: over_count,
  3193. // WarehouseOutId: 0,
  3194. // }
  3195. //
  3196. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3197. // }
  3198. // if schedule.ModeId == 4 {
  3199. //
  3200. // //扣减库存
  3201. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3202. //
  3203. // patient, _ := service.GetSfPatientById(tx, id)
  3204. // var over_count int64
  3205. // if schedule.ModeId == 1 {
  3206. // over_count = patient.HdCount
  3207. // }
  3208. // if schedule.ModeId == 2 {
  3209. // over_count = patient.HdfCount
  3210. // }
  3211. //
  3212. // if schedule.ModeId == 3 {
  3213. // over_count = patient.HdhpCount
  3214. // }
  3215. // if schedule.ModeId == 4 {
  3216. // over_count = patient.HpCount
  3217. // }
  3218. // if schedule.ModeId == 5 {
  3219. // over_count = patient.OtherCount
  3220. // }
  3221. // patientCountFlow := models.SfPatientCountFlow{
  3222. // PatientId: id,
  3223. // ModeId: schedule.ModeId,
  3224. // Count: 1,
  3225. // Status: 1,
  3226. // Ctime: time.Now().Unix(),
  3227. // Mtime: time.Now().Unix(),
  3228. // RecordDate: recordDate.Unix(),
  3229. // UserOrgId: adminUserInfo.Org.Id,
  3230. // Creater: adminUserInfo.AdminUser.Id,
  3231. // IsType: 4,
  3232. // OverCount: over_count,
  3233. // WarehouseOutId: 0,
  3234. // }
  3235. //
  3236. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3237. // }
  3238. // if schedule.ModeId != 1 && schedule.ModeId != 2 && schedule.ModeId != 3 && schedule.ModeId != 4 {
  3239. //
  3240. // //扣减库存
  3241. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3242. //
  3243. // patient, _ := service.GetSfPatientById(tx, id)
  3244. // var over_count int64
  3245. // if schedule.ModeId == 1 {
  3246. // over_count = patient.HdCount
  3247. // }
  3248. // if schedule.ModeId == 2 {
  3249. // over_count = patient.HdfCount
  3250. // }
  3251. //
  3252. // if schedule.ModeId == 3 {
  3253. // over_count = patient.HdhpCount
  3254. // }
  3255. // if schedule.ModeId == 4 {
  3256. // over_count = patient.HpCount
  3257. // }
  3258. // if schedule.ModeId == 5 {
  3259. // over_count = patient.OtherCount
  3260. // }
  3261. // patientCountFlow := models.SfPatientCountFlow{
  3262. // PatientId: id,
  3263. // ModeId: schedule.ModeId,
  3264. // Count: 1,
  3265. // Status: 1,
  3266. // Ctime: time.Now().Unix(),
  3267. // Mtime: time.Now().Unix(),
  3268. // RecordDate: recordDate.Unix(),
  3269. // UserOrgId: adminUserInfo.Org.Id,
  3270. // Creater: adminUserInfo.AdminUser.Id,
  3271. // IsType: 5,
  3272. // OverCount: over_count,
  3273. // WarehouseOutId: 0,
  3274. // }
  3275. //
  3276. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3277. // }
  3278. //
  3279. // tx.Commit()
  3280. // return
  3281. //}
  3282. }
  3283. func (c *DialysisAPIController) GetAllZone() {
  3284. adminUserInfo := c.GetMobileAdminUserInfo()
  3285. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  3286. if err == nil {
  3287. c.ServeSuccessJSON(map[string]interface{}{
  3288. "zone": zone,
  3289. })
  3290. }
  3291. }
  3292. func (c *DialysisAPIController) GetSchedualPatientsList() {
  3293. adminUserInfo := c.GetMobileAdminUserInfo()
  3294. page, _ := c.GetInt64("page", 1)
  3295. limit, _ := c.GetInt64("limit", 10)
  3296. schedulType, _ := c.GetInt64("schedul_type", 0)
  3297. startTime, _ := c.GetInt64("schedul_time", 0)
  3298. partitionType, _ := c.GetInt64("partition_type", 0)
  3299. keywords := c.GetString("keywords")
  3300. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  3301. if err == nil {
  3302. c.ServeSuccessJSON(map[string]interface{}{
  3303. "schedule": dialysisSchedule,
  3304. })
  3305. }
  3306. return
  3307. }
  3308. // /m/api/dialysis/start [post]
  3309. // @param patient_id:int
  3310. // @param record_date:string 排班时间 (yyyy-mm-dd)
  3311. // @param nurse:int 上机护士
  3312. // @param bed:int 床位号
  3313. func (this *DialysisAPIController) StartDialysis() {
  3314. patientID, _ := this.GetInt64("patient_id")
  3315. recordDateStr := this.GetString("record_date")
  3316. nurseID, _ := this.GetInt64("start_nurse")
  3317. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3318. blood_drawing, _ := this.GetInt64("blood_drawing")
  3319. schedual_type, _ := this.GetInt64("schedual_type")
  3320. bedID, _ := this.GetInt64("bed")
  3321. start_time := this.GetString("start_time")
  3322. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3323. change_nurse, _ := this.GetInt64("change_nurse")
  3324. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3325. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3326. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3327. puncture_needle := this.GetString("puncture_needle")
  3328. puncture_way := this.GetString("puncture_way")
  3329. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3330. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3331. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3332. zone_id, _ := this.GetInt64("zone_id")
  3333. elecsign := this.GetString("url")
  3334. nuclein_date_str := this.GetString("nuclein_date_str")
  3335. schedule_remark := this.GetString("schedule_remark")
  3336. order_remark := this.GetString("order_remark")
  3337. catheter_operation := this.GetString("catheter_operation")
  3338. blood_flow_volume := this.GetString("blood_flow_volume")
  3339. dialysis_strainer := this.GetString("dialysis_strainer")
  3340. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  3341. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3342. return
  3343. }
  3344. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3345. if parseStartDateErr != nil {
  3346. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3347. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3348. return
  3349. }
  3350. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3351. if parseErr != nil {
  3352. this.ErrorLog("时间解析失败:%v", parseErr)
  3353. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3354. return
  3355. }
  3356. adminUserInfo := this.GetMobileAdminUserInfo()
  3357. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  3358. if getPatientErr != nil {
  3359. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3360. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3361. return
  3362. } else if patient == nil {
  3363. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3364. return
  3365. }
  3366. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3367. if getNurseErr != nil {
  3368. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3369. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3370. return
  3371. } else if nurse == nil {
  3372. this.ErrorLog("护士不存在")
  3373. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3374. return
  3375. }
  3376. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3377. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3378. if getDeviceNumberErr != nil {
  3379. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3380. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3381. return
  3382. } else if deviceNumber == nil {
  3383. this.ErrorLog("床位号不存在")
  3384. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3385. return
  3386. }
  3387. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3388. if getRecordErr != nil {
  3389. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  3390. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3391. return
  3392. } else if dialysisRecord != nil {
  3393. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  3394. return
  3395. }
  3396. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  3397. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  3398. timeLayout := "2006-01-02 15:04:05"
  3399. loc, _ := time.LoadLocation("Local")
  3400. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3401. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  3402. schedulestartTime := theStartTime.Unix()
  3403. scheduleendTime := theEndTime.Unix()
  3404. var theNucleinDate int64
  3405. timeLayoutOne := "2006-01-02"
  3406. if len(nuclein_date_str) > 0 {
  3407. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  3408. if err != nil {
  3409. utils.ErrorLog(err.Error())
  3410. }
  3411. theNucleinDate = theTime.Unix()
  3412. }
  3413. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3414. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  3415. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  3416. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3417. if adminUserInfo.Org.Id == 10679 || adminUserInfo.Org.Id == 10164 {
  3418. record, _ := service.GetDialysisPrescriptionByRecord(adminUserInfo.Org.Id, patientID, schedulestartTime)
  3419. if record.ID == 0 {
  3420. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescription)
  3421. return
  3422. }
  3423. }
  3424. //查询该床位是否有人用了
  3425. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3426. if err == gorm.ErrRecordNotFound { //空床位
  3427. // 修改了床位逻辑
  3428. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3429. if daySchedule.ID > 0 {
  3430. daySchedule.PartitionId = deviceNumber.ZoneID
  3431. daySchedule.BedId = bedID
  3432. daySchedule.ScheduleType = schedual_type
  3433. daySchedule.UpdatedTime = time.Now().Unix()
  3434. xtSchedule := models.Schedule{
  3435. PartitionId: deviceNumber.ZoneID,
  3436. BedId: bedID,
  3437. ScheduleType: schedual_type,
  3438. UpdatedTime: time.Now().Unix(),
  3439. }
  3440. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3441. if err != nil {
  3442. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3443. return
  3444. }
  3445. }
  3446. } else if err == nil {
  3447. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  3448. if order.ID > 0 { //该机位被其他人占用了
  3449. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3450. return
  3451. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  3452. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3453. if daySchedule.ID > 0 {
  3454. err := service.UpdateScheduleTwo(daySchedule, schedule)
  3455. if err != nil {
  3456. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3457. return
  3458. }
  3459. }
  3460. }
  3461. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  3462. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3463. return
  3464. }
  3465. //else if order.ID == 0 { //该床位没被占用
  3466. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3467. // if daySchedule.ID > 0 {
  3468. // //daySchedule.PartitionId = deviceNumber.ZoneID
  3469. // //daySchedule.BedId = bedID
  3470. // //daySchedule.ScheduleType = schedual_type
  3471. // //daySchedule.UpdatedTime = time.Now().Unix()
  3472. // //err := service.UpdateSchedule(&daySchedule)
  3473. // xtSchedule := models.Schedule{
  3474. // PartitionId: deviceNumber.ZoneID,
  3475. // BedId: bedID,
  3476. // ScheduleType: schedual_type,
  3477. // UpdatedTime: time.Now().Unix(),
  3478. // }
  3479. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3480. // if err != nil {
  3481. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3482. // return
  3483. // }
  3484. // }
  3485. //}
  3486. //}
  3487. } else if err != nil {
  3488. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3489. return
  3490. }
  3491. // 查询信息规挡的设置天数
  3492. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3493. if infor.ID > 0 && infor.WeekDay > 0 {
  3494. var cha_time int64
  3495. timeNowStr := time.Now().Format("2006-01-02")
  3496. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3497. //今日的日期减去设置的日期
  3498. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3499. if cha_time >= recordDate.Unix() {
  3500. //查询审核是否允许
  3501. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  3502. //申请状态不允许的情况 拒绝修改
  3503. if infor.ApplicationStatus != 1 {
  3504. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3505. return
  3506. }
  3507. }
  3508. }
  3509. dialysisRecord = &models.DialysisOrder{
  3510. DialysisDate: recordDate.Unix(),
  3511. UserOrgId: adminUserInfo.Org.Id,
  3512. PatientId: patientID,
  3513. Stage: 1,
  3514. BedID: bedID,
  3515. StartNurse: nurseID,
  3516. Status: 1,
  3517. StartTime: startDate.Unix(),
  3518. CreatedTime: time.Now().Unix(),
  3519. UpdatedTime: time.Now().Unix(),
  3520. PunctureNurse: puncture_nurse,
  3521. Creator: adminUserInfo.AdminUser.Id,
  3522. Modifier: adminUserInfo.AdminUser.Id,
  3523. SchedualType: schedual_type,
  3524. WashpipeNurse: washpipe_nurse,
  3525. ChangeNurse: change_nurse,
  3526. DifficultPunctureNurse: difficult_puncture_nurse,
  3527. NewFistulaNurse: new_fistula_nurse,
  3528. ZoneId: zone_id,
  3529. QualityNurseId: quality_nurse_id,
  3530. PunctureNeedle: puncture_needle,
  3531. PunctureWay: puncture_way,
  3532. DialysisIrrigation: dialysis_irrigation,
  3533. DialysisDialyszers: dialysis_dialyszers,
  3534. BloodAccessId: blood_access_id,
  3535. Url: elecsign,
  3536. NucleinDate: theNucleinDate,
  3537. ScheduleRemark: schedule_remark,
  3538. OrderRemark: order_remark,
  3539. CatheterOperation: catheter_operation,
  3540. BloodFlowVolume: blood_flow_volume,
  3541. BloodDrawing: blood_drawing,
  3542. DialysisStrainer: dialysis_strainer,
  3543. }
  3544. //查询该床位是否有人用了
  3545. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3546. if errorscode == gorm.ErrRecordNotFound {
  3547. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3548. finish := models.XtDialysisFinish{
  3549. IsFinish: 1,
  3550. UserOrgId: adminUserInfo.Org.Id,
  3551. Status: 1,
  3552. Ctime: time.Now().Unix(),
  3553. Mtime: 0,
  3554. Module: 6,
  3555. RecordDate: schedulestartTime,
  3556. Sourse: 1,
  3557. PatientId: patientID,
  3558. }
  3559. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3560. if dialysisFinish.ID == 0 {
  3561. service.CreateDialysisFinish(finish)
  3562. }
  3563. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3564. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3565. //统计该患者总次数
  3566. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3567. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3568. }
  3569. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3570. //统计该患者总次数
  3571. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3572. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3573. }
  3574. redis := service.RedisClient()
  3575. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3576. redis.Set(key, "", time.Second)
  3577. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3578. //清空key 值
  3579. redis.Set(keyOne, "", time.Second)
  3580. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3581. //清空key 值
  3582. redis.Set(keyTwo, "", time.Second)
  3583. if createErr != nil {
  3584. this.ErrorLog("上机失败:%v", createErr)
  3585. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3586. return
  3587. }
  3588. }
  3589. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3590. var tempdispose string
  3591. // 只针对中能建
  3592. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3593. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3594. }
  3595. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3596. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3597. }
  3598. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3599. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3600. //}
  3601. var ultrafiltration_rate float64
  3602. var ultrafiltration_rate_one string
  3603. var replacement_rate float64
  3604. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3605. //后期预增脱水量
  3606. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3607. if prescription.ID > 0 {
  3608. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3609. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3610. 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
  3611. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3612. }
  3613. if adminUserInfo.Org.Id == 10742 || adminUserInfo.Org.Id == 10740 || adminUserInfo.Org.Id == 10745 || adminUserInfo.Org.Id == 9478 {
  3614. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3615. }
  3616. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3617. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3618. }
  3619. //针对医师汇
  3620. if adminUserInfo.Org.Id == 10121 {
  3621. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3622. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3623. }
  3624. //针对通道
  3625. if adminUserInfo.Org.Id == 10234 {
  3626. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3627. }
  3628. //针对监利大垸医院
  3629. if template.TemplateId == 41 {
  3630. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3631. }
  3632. //针对肇庆三鹤血液透析中心
  3633. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3634. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3635. }
  3636. if adminUserInfo.Org.Id == 10469 {
  3637. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3638. }
  3639. if adminUserInfo.Org.Id == 10667 {
  3640. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3641. }
  3642. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3643. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3644. }
  3645. // 只针对方济医院
  3646. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3647. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3648. ultrafiltration_rate = value
  3649. }
  3650. //针对
  3651. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3652. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3653. ultrafiltration_rate = ultrafiltration_rate / 1000
  3654. }
  3655. if adminUserInfo.Org.Id == 10551 {
  3656. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3657. ultrafiltration_rate = ultrafiltration_rate / 1000
  3658. }
  3659. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3660. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3661. ultrafiltration_rate = ultrafiltration_rate / 1000
  3662. }
  3663. if adminUserInfo.Org.Id == 10580 {
  3664. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3665. ultrafiltration_rate = ultrafiltration_rate / 1000
  3666. }
  3667. if adminUserInfo.Org.Id == 10629 {
  3668. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3669. ultrafiltration_rate = ultrafiltration_rate / 1000
  3670. }
  3671. if adminUserInfo.Org.Id == 10644 || adminUserInfo.Org.Id == 10751 {
  3672. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3673. ultrafiltration_rate = ultrafiltration_rate / 1000
  3674. }
  3675. if adminUserInfo.Org.Id == 10751 {
  3676. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3677. ultrafiltration_rate = ultrafiltration_rate / 1000
  3678. }
  3679. if adminUserInfo.Org.Id == 10667 {
  3680. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3681. ultrafiltration_rate = ultrafiltration_rate / 1000
  3682. }
  3683. if adminUserInfo.Org.Id == 10693 {
  3684. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3685. ultrafiltration_rate = ultrafiltration_rate
  3686. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3687. }
  3688. if adminUserInfo.Org.Id == 10727 || adminUserInfo.Org.Id == 10731 {
  3689. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3690. ultrafiltration_rate = ultrafiltration_rate
  3691. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3692. }
  3693. if adminUserInfo.Org.Id == 10206 {
  3694. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60)
  3695. ultrafiltration_rate = ultrafiltration_rate
  3696. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3697. }
  3698. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3699. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3700. ultrafiltration_rate = ultrafiltration_rate
  3701. }
  3702. if adminUserInfo.Org.Id == 10702 {
  3703. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3704. ultrafiltration_rate = ultrafiltration_rate / 1000
  3705. }
  3706. if adminUserInfo.Org.Id == 10752 {
  3707. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3708. ultrafiltration_rate = ultrafiltration_rate / 1000
  3709. }
  3710. if adminUserInfo.Org.Id == 10723 {
  3711. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3712. ultrafiltration_rate = ultrafiltration_rate / 1000
  3713. }
  3714. if adminUserInfo.Org.Id == 10721 {
  3715. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3716. ultrafiltration_rate = ultrafiltration_rate / 1000
  3717. }
  3718. if adminUserInfo.Org.Id == 10766 {
  3719. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3720. ultrafiltration_rate = ultrafiltration_rate / 1000
  3721. }
  3722. if adminUserInfo.Org.Id == 10757 {
  3723. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3724. ultrafiltration_rate = ultrafiltration_rate / 1000
  3725. }
  3726. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10757 {
  3727. if prescription.ModeId == 2 {
  3728. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3729. if totalMin == 0 {
  3730. totalMin = 240
  3731. }
  3732. if prescription.ReplacementTotal == 0 {
  3733. prescription.ReplacementTotal = 15
  3734. }
  3735. //乘10 除10是为了保留一位小数
  3736. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3737. }
  3738. }
  3739. if adminUserInfo.Org.Id == 10766 {
  3740. if prescription.ModeId == 2 || prescription.ModeId == 13 {
  3741. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3742. if totalMin == 0 {
  3743. totalMin = 240
  3744. }
  3745. if prescription.DisplaceLiquiValue == 0 {
  3746. prescription.DisplaceLiquiValue = 15
  3747. }
  3748. //乘10 除10是为了保留一位小数
  3749. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3750. }
  3751. }
  3752. if adminUserInfo.Org.Id == 10752 {
  3753. if prescription.ModeId == 2 {
  3754. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3755. if totalMin == 0 {
  3756. totalMin = 240
  3757. }
  3758. if prescription.ReplacementTotal == 0 {
  3759. prescription.ReplacementTotal = 15
  3760. }
  3761. //乘10 除10是为了保留一位小数
  3762. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3763. }
  3764. }
  3765. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10731 || adminUserInfo.Org.Id == 10727 || adminUserInfo.Org.Id == 10744 {
  3766. if prescription.ModeId == 2 {
  3767. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3768. if totalMin == 0 {
  3769. totalMin = 240
  3770. }
  3771. if prescription.DisplaceLiquiValue == 0 {
  3772. prescription.ReplacementTotal = 32
  3773. }
  3774. //乘10 除10是为了保留一位小数
  3775. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3776. }
  3777. }
  3778. }
  3779. }
  3780. if adminUserInfo.Org.Id == 10172 {
  3781. if prescription.ID == 0 {
  3782. if prescription.ModeId == 2 {
  3783. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3784. if totalMin == 0 {
  3785. totalMin = 240
  3786. }
  3787. if prescription.ReplacementTotal == 0 {
  3788. prescription.ReplacementTotal = 15
  3789. }
  3790. //乘10 除10是为了保留一位小数
  3791. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3792. }
  3793. }
  3794. }
  3795. record := models.MonitoringRecord{
  3796. UserOrgId: adminUserInfo.Org.Id,
  3797. PatientId: patientID,
  3798. DialysisOrderId: dialysisRecord.ID,
  3799. MonitoringDate: schedulestartTime,
  3800. OperateTime: startDate.Unix(),
  3801. // MonitoringTime: recordTime,
  3802. MonitoringNurse: nurseID,
  3803. Dispose: tempdispose,
  3804. UltrafiltrationRate: ultrafiltration_rate,
  3805. UltrafiltrationVolume: 0,
  3806. Status: 1,
  3807. CreatedTime: time.Now().Unix(),
  3808. UpdatedTime: time.Now().Unix(),
  3809. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3810. ReplacementRate: replacement_rate,
  3811. }
  3812. //只针对广慈医院
  3813. 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 || adminUserInfo.Org.Id == 10742 || adminUserInfo.Org.Id == 10757 || adminUserInfo.Org.Id == 9478 || adminUserInfo.Org.Id == 10766 {
  3814. // 查询病人是否有透前评估数据
  3815. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3816. //如果有数据就插入
  3817. if errcode == nil {
  3818. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3819. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3820. record.BreathingRate = befor.BreathingRate
  3821. record.PulseFrequency = befor.PulseFrequency
  3822. record.Temperature = befor.Temperature
  3823. }
  3824. }
  3825. //孝昌
  3826. if adminUserInfo.Org.Id == 10693 {
  3827. // 查询病人是否有透前评估数据
  3828. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3829. //如果有数据就插入
  3830. if errcode == nil {
  3831. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3832. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3833. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3834. record.BreathingRate = befor.BreathingRate
  3835. }
  3836. }
  3837. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3838. if newdialysisRecord.ID > 0 {
  3839. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3840. record.Temperature = 36.5
  3841. record.ArterialPressure = -100
  3842. record.DialysateTemperature = 36.5
  3843. record.Conductivity = 14
  3844. record.BreathingRate = "20"
  3845. record.VenousPressure = 80
  3846. record.TransmembranePressure = 60
  3847. record.Dispose = catheter_operation
  3848. }
  3849. //针对新化博翔
  3850. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3851. record.BloodOxygenSaturation = "99"
  3852. record.Conductivity = 14
  3853. record.DialysateTemperature = 36.5
  3854. record.BreathingRate = "20"
  3855. }
  3856. //针对兰溪人民医院的需求
  3857. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3858. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3859. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3860. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3861. record.Temperature = befor.Temperature
  3862. record.PulseFrequency = befor.PulseFrequency
  3863. record.BreathingRate = befor.BreathingRate
  3864. }
  3865. //针对乐山友谊医院的需求
  3866. if adminUserInfo.Org.Id == 10677 {
  3867. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3868. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3869. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3870. record.Temperature = befor.Temperature
  3871. record.PulseFrequency = befor.PulseFrequency
  3872. record.BreathingRate = befor.BreathingRate
  3873. }
  3874. //新化博翔
  3875. if adminUserInfo.Org.Id == 10447 {
  3876. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3877. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3878. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3879. record.BreathingRate = befor.BreathingRate
  3880. }
  3881. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3882. record.PulseFrequency = 80
  3883. record.Temperature = 36.5
  3884. }
  3885. //诊断灵山圣康
  3886. if adminUserInfo.Org.Id == 10375 {
  3887. record.Conductivity = 13.8
  3888. record.DialysateTemperature = 37
  3889. record.DialysateFlow = 500
  3890. record.BloodFlowVolume = 200
  3891. record.BreathingRate = "18"
  3892. record.SodiumConcentration = 140
  3893. }
  3894. //江成肾病医院
  3895. if adminUserInfo.Org.Id == 10517 {
  3896. record.SodiumConcentration = 138
  3897. record.DialysateTemperature = 36.5
  3898. }
  3899. //濉溪杏康血液透析中心
  3900. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3901. record.BloodFlowVolume = prescription.BloodFlowVolume
  3902. }
  3903. //胶州少海医院
  3904. if adminUserInfo.Org.Id == 10735 || adminUserInfo.Org.Id == 9478 {
  3905. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3906. dialysisPrescription, _ := service.GetDialysisPrescription(patientID, adminUserInfo.Org.Id, recordDate.Unix())
  3907. record.BreathingRate = befor.BreathingRate
  3908. record.BloodFlowVolume = dialysisPrescription.BloodFlowVolume
  3909. record.Temperature = befor.Temperature
  3910. record.PulseFrequency = befor.PulseFrequency
  3911. }
  3912. if adminUserInfo.Org.Id != 10683 {
  3913. err = service.CreateMonitor(&record)
  3914. }
  3915. //记录日志
  3916. byterequest, _ := json.Marshal(record)
  3917. monitorRecordLog := models.XtMonitorRecordLog{
  3918. RecordDate: record.MonitoringDate,
  3919. PatientId: record.PatientId,
  3920. Module: 1,
  3921. AdminUserId: adminUserInfo.AdminUser.Id,
  3922. Ctime: time.Now().Unix(),
  3923. Mtime: 0,
  3924. Status: 1,
  3925. UserOrgId: record.UserOrgId,
  3926. ErrLog: string(byterequest),
  3927. Source: "执行上机时新增监测",
  3928. }
  3929. service.CreateMonitorRecordLog(monitorRecordLog)
  3930. finish := models.XtDialysisFinish{
  3931. IsFinish: 1,
  3932. UserOrgId: adminUserInfo.Org.Id,
  3933. Status: 1,
  3934. Ctime: time.Now().Unix(),
  3935. Mtime: 0,
  3936. Module: 7,
  3937. RecordDate: schedulestartTime,
  3938. Sourse: 1,
  3939. PatientId: patientID,
  3940. }
  3941. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3942. if dialysisFinish.ID == 0 {
  3943. service.CreateDialysisFinish(finish)
  3944. }
  3945. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3946. redis := service.RedisClient()
  3947. //清空key 值
  3948. redis.Set(key, "", time.Second)
  3949. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3950. redis.Set(keyOne, "", time.Second)
  3951. defer redis.Close()
  3952. if err != nil {
  3953. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3954. return
  3955. }
  3956. }
  3957. go func() {
  3958. ssoDomain := beego.AppConfig.String("call_domain")
  3959. api := ssoDomain + "/index/uppatient"
  3960. values := make(url.Values)
  3961. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3962. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3963. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3964. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3965. http.PostForm(api, values)
  3966. }()
  3967. this.ServeSuccessJSON(map[string]interface{}{
  3968. "dialysis_order": newdialysisRecord,
  3969. "monitor": record,
  3970. })
  3971. return
  3972. }
  3973. func (c *DialysisAPIController) PostSolution() {
  3974. id, _ := c.GetInt64("patient", 0)
  3975. recordDateStr := c.GetString("record_date")
  3976. if id <= 0 {
  3977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3978. return
  3979. }
  3980. adminUserInfo := c.GetMobileAdminUserInfo()
  3981. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3982. if patient.ID == 0 {
  3983. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3984. return
  3985. }
  3986. if len(recordDateStr) == 0 {
  3987. recordDateStr = time.Now().Format("2006-01-02")
  3988. }
  3989. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3990. if parseDateErr != nil {
  3991. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3993. return
  3994. }
  3995. mode_id, _ := c.GetInt64("mode_id", 0)
  3996. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3997. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3998. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3999. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  4000. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  4001. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  4002. replacement_way, _ := c.GetInt64("replacement_way", 0)
  4003. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  4004. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  4005. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  4006. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  4007. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  4008. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  4009. kalium, _ := c.GetFloat("kalium", 0)
  4010. sodium, _ := c.GetFloat("sodium", 0)
  4011. calcium, _ := c.GetFloat("calcium", 0)
  4012. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  4013. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  4014. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  4015. glucose, _ := c.GetFloat("glucose", 0)
  4016. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  4017. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  4018. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  4019. conductivity, _ := c.GetFloat("conductivity", 0)
  4020. remark := c.GetString("remark")
  4021. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  4022. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  4023. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  4024. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  4025. body_fluid, _ := c.GetInt64("body_fluid", 0)
  4026. special_medicine, _ := c.GetInt64("special_medicine", 0)
  4027. special_medicine_other := c.GetString("special_medicine_other")
  4028. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  4029. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  4030. blood_access, _ := c.GetInt64("blood_access", 0)
  4031. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  4032. body_fluid_other := c.GetString("body_fluid_other")
  4033. replacement_total, _ := c.GetFloat("replacement_total", 0)
  4034. niprocart, _ := c.GetInt64("niprocart", 0)
  4035. jms, _ := c.GetInt64("jms", 0)
  4036. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  4037. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  4038. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  4039. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  4040. filtryzer, _ := c.GetInt64("filtryzer", 0)
  4041. target_ktv, _ := c.GetFloat("target_ktv", 0)
  4042. dialyzers, _ := c.GetInt64("dialyzers", 0)
  4043. injector, _ := c.GetInt64("injector", 0)
  4044. bloodlines, _ := c.GetInt64("bloodlines", 0)
  4045. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  4046. safe_package, _ := c.GetInt64("package", 0)
  4047. a_liquid, _ := c.GetInt64("a_liquid", 0)
  4048. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  4049. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  4050. blood := c.GetString("blood")
  4051. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  4052. dialysis_irrigation := c.GetString("dialysis_irrigation")
  4053. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  4054. displace_speed := c.GetString("displace_speed")
  4055. illness, _ := c.GetInt64("illness")
  4056. amylaceum := c.GetString("amylaceum")
  4057. single_time := c.GetString("single_time")
  4058. single_water := c.GetString("single_water")
  4059. replacement_flow := c.GetString("replacement_flow")
  4060. plasma_separator := c.GetString("plasma_separator")
  4061. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  4062. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  4063. oxygen_flow := c.GetString("oxygen_flow")
  4064. oxygen_time := c.GetString("oxygen_time")
  4065. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  4066. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  4067. puncture_needle := c.GetString("puncture_needle")
  4068. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  4069. epo := c.GetString("epo")
  4070. epo_count, _ := c.GetFloat("epo_count", 0)
  4071. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  4072. pre_impulse := c.GetString("pre_impulse")
  4073. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  4074. admin_user_id, _ := c.GetInt64("admin_user_id")
  4075. is_water := c.GetString("is_water")
  4076. add_amount, _ := c.GetFloat("add_amount")
  4077. reduce_amount, _ := c.GetFloat("reduce_amount")
  4078. prescribing_number, _ := c.GetFloat("prescribing_number")
  4079. treatment_remark := c.GetString("treatment_remark")
  4080. prescription_sodium := c.GetString("prescription_sodium")
  4081. start_sodium := c.GetString("start_sodium")
  4082. sodium_curve := c.GetString("sodium_curve")
  4083. var is_war int64
  4084. if is_water == "是" {
  4085. is_war = 1
  4086. }
  4087. if is_water == "否" {
  4088. is_war = 2
  4089. }
  4090. if is_water == "请选择" {
  4091. is_war = 0
  4092. }
  4093. drhy_water := c.GetString("drhy_water")
  4094. dry_water_hour := c.GetString("dry_water_hour")
  4095. water_machine := c.GetString("water_machine")
  4096. dialysis_remark := c.GetString("dialysis_remark")
  4097. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  4098. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  4099. prescription_water, _ := c.GetFloat("prescription_water")
  4100. dialysis_strainer := c.GetString("dialysis_strainer")
  4101. chaptalization := c.GetString("chaptalization")
  4102. washing_time := c.GetString("washing_time")
  4103. warsh_count := c.GetString("warsh_count")
  4104. blood_access_part_id := c.GetString("blood_access_part_id")
  4105. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  4106. dialyzate := c.GetString("dialyzate")
  4107. first_super := c.GetString("first_super")
  4108. is_sequential := c.GetString("is_sequential")
  4109. sterilization_water := c.GetString("sterilization_water")
  4110. five_glucose := c.GetString("five_glucose")
  4111. fifty_glucose := c.GetString("fifty_glucose")
  4112. magnesium_sulfate_injection := c.GetString("magnesium_sulfate_injection")
  4113. calcium_gluconate := c.GetString("calcium_gluconate")
  4114. five_potassium_chloride_injection := c.GetString("five_potassium_chloride_injection")
  4115. ten_potassium_chloride_injection := c.GetString("ten_potassium_chloride_injection")
  4116. five_sodium_bicarbonate_injection := c.GetString("five_sodium_bicarbonate_injection")
  4117. new_sty := c.GetString("new_sty")
  4118. var fisrt_sup int64
  4119. if first_super == "是" {
  4120. fisrt_sup = 1
  4121. }
  4122. if first_super == "否" {
  4123. fisrt_sup = 2
  4124. }
  4125. if first_super == "请选择" {
  4126. fisrt_sup = 0
  4127. }
  4128. var is_sequen int64
  4129. if is_sequential == "是" {
  4130. is_sequen = 1
  4131. }
  4132. if is_sequential == "否" {
  4133. is_sequen = 2
  4134. }
  4135. if is_sequential == "请选择" {
  4136. is_sequen = 0
  4137. }
  4138. conduct := c.GetString("conduct")
  4139. if mode_id > 0 {
  4140. var str string
  4141. //查找该机构用的是什么透析器
  4142. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  4143. if filedConfig.ID > 0 {
  4144. str = dialyzerPerfusionApparatus
  4145. } else {
  4146. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  4147. }
  4148. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  4149. }
  4150. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4151. //
  4152. //if template.TemplateId == 2 || template.TemplateId == 6 {
  4153. // if appRole.UserType == 3 {
  4154. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4155. // if getPermissionErr != nil {
  4156. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4157. // return
  4158. // } else if headNursePermission == nil {
  4159. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4160. // return
  4161. // }
  4162. // }
  4163. //}
  4164. // 查询信息规挡的设置天数
  4165. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4166. if infor.ID > 0 && infor.WeekDay > 0 {
  4167. var cha_time int64
  4168. timeNowStr := time.Now().Format("2006-01-02")
  4169. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4170. //今日的日期减去设置的日期
  4171. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4172. if cha_time >= recordDate.Unix() {
  4173. //查询审核是否允许
  4174. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  4175. //申请状态不允许的情况 拒绝修改
  4176. if infor.ApplicationStatus != 1 {
  4177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4178. return
  4179. }
  4180. }
  4181. }
  4182. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  4183. var dialysis_dialyszers_id int64
  4184. var dialysis_strainer_id int64
  4185. var dialysis_irrigation_id int64
  4186. if len(goodList) > 0 {
  4187. for _, item := range goodList {
  4188. if item.SpecificationName == dialysis_dialyszers {
  4189. dialysis_dialyszers_id = item.ID
  4190. }
  4191. if item.SpecificationName == dialysis_irrigation {
  4192. dialysis_irrigation_id = item.ID
  4193. }
  4194. if item.SpecificationName == dialysis_strainer {
  4195. dialysis_strainer_id = item.ID
  4196. }
  4197. }
  4198. }
  4199. prescription := models.DialysisPrescription{
  4200. UserOrgId: adminUserInfo.Org.Id,
  4201. PatientId: id,
  4202. RecordDate: recordDate.Unix(),
  4203. ModeId: mode_id,
  4204. DialysisDuration: dialysis_duration,
  4205. Dialyzer: dialyzer,
  4206. PerfusionApparatus: perfusion_apparatus,
  4207. BloodFlowVolume: blood_flow_volume,
  4208. DewaterAmount: dewater_amount,
  4209. DisplaceLiqui: displace_liqui,
  4210. ReplacementWay: replacement_way,
  4211. Anticoagulant: anticoagulant,
  4212. AnticoagulantShouji: anticoagulant_shouji,
  4213. AnticoagulantWeichi: anticoagulant_weichi,
  4214. AnticoagulantZongliang: anticoagulant_zongliang,
  4215. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4216. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4217. Kalium: kalium,
  4218. Sodium: sodium,
  4219. Calcium: calcium,
  4220. Bicarbonate: bicarbonate,
  4221. Glucose: glucose,
  4222. // DryWeight: dry_weight,
  4223. DialysateFlow: dialysate_flow,
  4224. DialysateTemperature: dialysate_temperature,
  4225. Conductivity: conductivity,
  4226. Remark: remark,
  4227. Status: 1,
  4228. CreatedTime: time.Now().Unix(),
  4229. UpdatedTime: time.Now().Unix(),
  4230. DialysisDurationMinute: dialysisDurationMinute,
  4231. DialysisDurationHour: dialysisDurationHour,
  4232. TargetUltrafiltration: targetUltrafiltration,
  4233. DialysateFormulation: dialysateFormulation,
  4234. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  4235. BodyFluid: body_fluid,
  4236. SpecialMedicine: special_medicine,
  4237. SpecialMedicineOther: special_medicine_other,
  4238. DisplaceLiquiPart: displace_liqui_part,
  4239. DisplaceLiquiValue: displace_liqui_value,
  4240. BloodAccess: blood_access,
  4241. Ultrafiltration: ultrafiltration,
  4242. BodyFluidOther: body_fluid_other,
  4243. ReplacementTotal: replacement_total,
  4244. Niprocart: niprocart,
  4245. Jms: jms,
  4246. FistulaNeedleSet: fistula_needle_set,
  4247. FistulaNeedleSet16: fistula_needle_set_16,
  4248. Hemoperfusion: hemoperfusion,
  4249. DialyserSterilised: dialyser_sterilised,
  4250. Filtryzer: filtryzer,
  4251. TargetKtv: target_ktv,
  4252. Dialyzers: dialyzers,
  4253. Injector: injector,
  4254. Bloodlines: bloodlines,
  4255. TubingHemodialysis: tubing_hemodialysis,
  4256. Package: safe_package,
  4257. ALiquid: a_liquid,
  4258. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  4259. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  4260. Blood: blood,
  4261. DialysisDialyszers: dialysis_dialyszers,
  4262. DialysisIrrigation: dialysis_irrigation,
  4263. AntioxidantCommodityName: antioxidant_commodity_name,
  4264. DisplaceSpeed: displace_speed,
  4265. Illness: illness,
  4266. Amylaceum: amylaceum,
  4267. SingleWater: single_water,
  4268. SingleTime: single_time,
  4269. ReplacementFlow: replacement_flow,
  4270. PlasmaSeparator: plasma_separator,
  4271. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  4272. OxygenUptake: oxygen_uptake,
  4273. OxygenTime: oxygen_time,
  4274. OxygenFlow: oxygen_flow,
  4275. HemodialysisPipelines: hemodialysis_pipelines,
  4276. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  4277. PunctureNeedle: puncture_needle,
  4278. PunctureNeedleCount: puncture_needle_count,
  4279. Epo: epo,
  4280. EpoCount: epo_count,
  4281. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  4282. PreImpulse: impulse,
  4283. AdminUserId: admin_user_id,
  4284. IsWater: is_war,
  4285. DrhyWater: drhy_water,
  4286. DryWaterHour: dry_water_hour,
  4287. WaterMachine: water_machine,
  4288. AddAmount: add_amount,
  4289. ReduceAmount: reduce_amount,
  4290. DialysisRemark: dialysis_remark,
  4291. PrescribingNumber: prescribing_number,
  4292. PrescriptionSodium: prescription_sodium,
  4293. StartSodium: start_sodium,
  4294. SodiumCurve: sodium_curve,
  4295. TreatmentRemark: treatment_remark,
  4296. DialysisFluidFlow: dialysis_fluid_flow,
  4297. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  4298. PrescriptionWater: prescription_water,
  4299. DialysisStrainer: dialysis_strainer,
  4300. Chaptalization: chaptalization,
  4301. WashingTime: washing_time,
  4302. WarshCount: warsh_count,
  4303. BloodAccessPartId: blood_access_part_id,
  4304. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  4305. Dialyzate: dialyzate,
  4306. DialysisDialyszersId: dialysis_dialyszers_id,
  4307. DialysisIrrigationId: dialysis_irrigation_id,
  4308. DialysisStrainerId: dialysis_strainer_id,
  4309. FirstSuper: fisrt_sup,
  4310. IsSequential: is_sequen,
  4311. Conduct: conduct,
  4312. SterilizationWater: sterilization_water,
  4313. FiveGlucose: five_glucose,
  4314. FiftyGlucose: fifty_glucose,
  4315. MagnesiumSulfateInjection: magnesium_sulfate_injection,
  4316. CalciumGluconate: calcium_gluconate,
  4317. FivePotassiumChlorideInjection: five_potassium_chloride_injection,
  4318. TenPotassiumChlorideInjection: ten_potassium_chloride_injection,
  4319. FiveSodiumBicarbonateInjection: five_sodium_bicarbonate_injection,
  4320. NewSty: new_sty,
  4321. }
  4322. if prescription.ModeId != 13 {
  4323. prescription.SterilizationWater = ""
  4324. prescription.FiveGlucose = ""
  4325. prescription.FiftyGlucose = ""
  4326. prescription.MagnesiumSulfateInjection = ""
  4327. prescription.CalciumGluconate = ""
  4328. prescription.FivePotassiumChlorideInjection = ""
  4329. prescription.TenPotassiumChlorideInjection = ""
  4330. prescription.FiveSodiumBicarbonateInjection = ""
  4331. prescription.NewSty = ""
  4332. }
  4333. if adminUserInfo.Org.Id == 10721 {
  4334. if prescription.ModeId == 2 {
  4335. if prescription.ReplacementTotal == 0 {
  4336. prescription.ReplacementTotal = 15
  4337. }
  4338. }
  4339. }
  4340. if adminUserInfo.Org.Id == 10766 || adminUserInfo.Org.Id == 9478 {
  4341. if prescription.ModeId == 2 || prescription.ModeId == 13 {
  4342. if prescription.ReplacementTotal == 0 {
  4343. prescription.ReplacementTotal = 15
  4344. }
  4345. }
  4346. }
  4347. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4348. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  4349. //
  4350. if appRole.UserType == 2 || appRole.UserType == 1 {
  4351. prescription_doctor = adminUserInfo.AdminUser.Id
  4352. prescription.PrescriptionDoctor = prescription_doctor
  4353. }
  4354. if dialysisPrescription.ID == 0 { //新增
  4355. prescription.Creater = adminUserInfo.AdminUser.Id
  4356. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  4357. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  4358. }
  4359. } else { //修改
  4360. if dialysisPrescription.Creater == 0 {
  4361. prescription.Creater = adminUserInfo.AdminUser.Id
  4362. } else {
  4363. prescription.Creater = dialysisPrescription.Creater
  4364. if adminUserInfo.Org.Id == 9882 {
  4365. if appRole.UserType == 2 || appRole.UserType == 1 {
  4366. prescription.Creater = adminUserInfo.AdminUser.Id
  4367. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  4368. }
  4369. }
  4370. }
  4371. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  4372. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  4373. }
  4374. //if/**/
  4375. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4376. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  4377. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4378. // if getPermissionErr != nil {
  4379. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4380. // return
  4381. // } else if headNursePermission == nil {
  4382. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4383. // return
  4384. // }
  4385. //}
  4386. //prescription.Creater = dialysisPrescription.Creater
  4387. prescription.CreatedTime = dialysisPrescription.CreatedTime
  4388. prescription.Modifier = adminUserInfo.AdminUser.Id
  4389. prescription.ID = dialysisPrescription.ID
  4390. }
  4391. solution := models.DialysisSolution{
  4392. RegistrarsId: adminUserInfo.AdminUser.Id,
  4393. UserOrgId: adminUserInfo.Org.Id,
  4394. Doctor: prescription_doctor,
  4395. PatientId: id,
  4396. ModeId: mode_id,
  4397. DialysisDuration: dialysis_duration,
  4398. PerfusionApparatus: perfusion_apparatus,
  4399. BloodFlowVolume: blood_flow_volume,
  4400. Dewater: dewater_amount,
  4401. DisplaceLiqui: displace_liqui,
  4402. ReplacementWay: replacement_way,
  4403. Anticoagulant: anticoagulant,
  4404. AnticoagulantShouji: anticoagulant_shouji,
  4405. AnticoagulantWeichi: anticoagulant_weichi,
  4406. AnticoagulantZongliang: anticoagulant_zongliang,
  4407. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4408. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4409. Kalium: kalium,
  4410. Sodium: sodium,
  4411. Calcium: calcium,
  4412. Bicarbonate: bicarbonate,
  4413. Glucose: glucose,
  4414. // DryWeight: dry_weight,
  4415. DialysateFlow: dialysate_flow,
  4416. DialysateTemperature: dialysate_temperature,
  4417. Conductivity: conductivity,
  4418. Remark: remark,
  4419. Status: 1,
  4420. CreatedTime: time.Now().Unix(),
  4421. UpdatedTime: time.Now().Unix(),
  4422. DialysisDurationMinute: dialysisDurationMinute,
  4423. DialysisDurationHour: dialysisDurationHour,
  4424. TargetUltrafiltration: targetUltrafiltration,
  4425. DialysateFormulation: dialysateFormulation,
  4426. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  4427. BodyFluid: body_fluid,
  4428. SpecialMedicine: special_medicine,
  4429. SpecialMedicineOther: special_medicine_other,
  4430. DisplaceLiquiPart: displace_liqui_part,
  4431. DisplaceLiquiValue: displace_liqui_value,
  4432. BloodAccess: blood_access,
  4433. Ultrafiltration: ultrafiltration,
  4434. BodyFluidOther: body_fluid_other,
  4435. ReplacementTotal: replacement_total,
  4436. TargetKtv: target_ktv,
  4437. DialysisDialyszers: dialysis_dialyszers,
  4438. DialysisIrrigation: dialysis_irrigation,
  4439. HemodialysisPipelines: hemodialysis_pipelines,
  4440. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  4441. PunctureNeedle: puncture_needle,
  4442. PunctureNeedleCount: puncture_needle_count,
  4443. Epo: epo,
  4444. EpoCount: epo_count,
  4445. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  4446. PreImpulse: impulse,
  4447. SolutionStatus: 1,
  4448. DialysisRemark: dialysis_remark,
  4449. PrescribingNumber: prescribing_number,
  4450. PrescriptionSodium: prescription_sodium,
  4451. StartSodium: start_sodium,
  4452. SodiumCurve: sodium_curve,
  4453. TreatmentRemark: treatment_remark,
  4454. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  4455. DialysisFluidFlow: dialysis_fluid_flow,
  4456. PrescriptionWater: prescription_water,
  4457. DialysisStrainer: dialysis_strainer,
  4458. Chaptalization: chaptalization,
  4459. WashingTime: washing_time,
  4460. WarshCount: warsh_count,
  4461. BloodAccessPartId: blood_access_part_id,
  4462. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  4463. Dialyzate: dialyzate,
  4464. DialysisDialyszersId: dialysis_dialyszers_id,
  4465. DialysisIrrigationId: dialysis_irrigation_id,
  4466. DialysisStrainerId: dialysis_strainer_id,
  4467. FirstSuper: fisrt_sup,
  4468. IsSequential: is_sequen,
  4469. Conduct: conduct,
  4470. SterilizationWater: sterilization_water,
  4471. FiveGlucose: five_glucose,
  4472. FiftyGlucose: fifty_glucose,
  4473. MagnesiumSulfateInjection: magnesium_sulfate_injection,
  4474. CalciumGluconate: calcium_gluconate,
  4475. FivePotassiumChlorideInjection: five_potassium_chloride_injection,
  4476. TenPotassiumChlorideInjection: ten_potassium_chloride_injection,
  4477. FiveSodiumBicarbonateInjection: five_sodium_bicarbonate_injection,
  4478. NewSty: new_sty,
  4479. }
  4480. if prescription.ModeId != 13 {
  4481. prescription.SterilizationWater = ""
  4482. prescription.FiveGlucose = ""
  4483. prescription.FiftyGlucose = ""
  4484. prescription.MagnesiumSulfateInjection = ""
  4485. prescription.CalciumGluconate = ""
  4486. prescription.FivePotassiumChlorideInjection = ""
  4487. prescription.TenPotassiumChlorideInjection = ""
  4488. prescription.FiveSodiumBicarbonateInjection = ""
  4489. prescription.NewSty = ""
  4490. }
  4491. //针对河间咸的
  4492. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  4493. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  4494. solution.DisplaceLiquiPart = 0
  4495. solution.DisplaceLiquiValue = 0
  4496. }
  4497. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  4498. prescription.DisplaceLiquiPart = 0
  4499. prescription.DisplaceLiquiValue = 0
  4500. }
  4501. }
  4502. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  4503. if solution.PrescribingNumber == 0 {
  4504. solution.PrescribingNumber = 1
  4505. }
  4506. if prescription.PrescribingNumber == 0 {
  4507. prescription.PrescribingNumber = 1
  4508. }
  4509. if solution.PrescribingNumber == 0 && id == 14682 {
  4510. solution.PrescribingNumber = 2
  4511. }
  4512. if solution.PrescribingNumber == 0 && id == 18560 {
  4513. solution.PrescribingNumber = 2
  4514. }
  4515. if prescription.PrescribingNumber == 0 && id == 14682 {
  4516. prescription.PrescribingNumber = 2
  4517. }
  4518. if prescription.PrescribingNumber == 0 && id == 18560 {
  4519. prescription.PrescribingNumber = 2
  4520. }
  4521. }
  4522. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  4523. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9478 {
  4524. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  4525. if len(monitorList) > 0 {
  4526. var ultrafiltration_rate float64
  4527. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4528. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  4529. var replacement_rate float64
  4530. if adminUserInfo.Org.Id == 10721 {
  4531. //乘10 除10是为了保留一位小数
  4532. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  4533. }
  4534. if adminUserInfo.Org.Id == 9478 {
  4535. //乘10 除10是为了保留一位小数
  4536. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  4537. }
  4538. if adminUserInfo.Org.Id == 10766 {
  4539. //乘10 除10是为了保留一位小数
  4540. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  4541. }
  4542. var firstOpeateTime = monitorList[0].OperateTime
  4543. for _, item := range monitorList {
  4544. //超滤率
  4545. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  4546. //置换率
  4547. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  4548. //超滤量
  4549. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  4550. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  4551. //置换量
  4552. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  4553. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  4554. }
  4555. }
  4556. }
  4557. //记录日志
  4558. byterequest, _ := json.Marshal(prescription)
  4559. prescriptionLog := models.XtDialysisPrescriptionLog{
  4560. UserOrgId: prescription.UserOrgId,
  4561. Ctime: time.Now().Unix(),
  4562. Mtime: 0,
  4563. ErrLog: string(byterequest),
  4564. AdminUserId: adminUserInfo.AdminUser.Id,
  4565. RecordDate: prescription.RecordDate,
  4566. PatientId: prescription.PatientId,
  4567. Source: "手机端新增长期处方",
  4568. Status: 1,
  4569. }
  4570. service.CreatePrescriptionLog(prescriptionLog)
  4571. finish := models.XtDialysisFinish{
  4572. IsFinish: 1,
  4573. UserOrgId: adminUserInfo.Org.Id,
  4574. Status: 1,
  4575. Ctime: time.Now().Unix(),
  4576. Mtime: 0,
  4577. Module: 1,
  4578. RecordDate: recordDate.Unix(),
  4579. Sourse: 1,
  4580. PatientId: id,
  4581. }
  4582. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  4583. if dialysisFinish.ID == 0 {
  4584. service.CreateDialysisFinish(finish)
  4585. }
  4586. //获取最新1条
  4587. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  4588. //更新状态
  4589. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  4590. //长沙南雅医院,自动生成抗凝剂的临时处方
  4591. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  4592. if prescribing_number == 0 {
  4593. prescribing_number = 1
  4594. }
  4595. advice := models.DoctorAdvice{
  4596. UserOrgId: adminUserInfo.Org.Id,
  4597. PatientId: id,
  4598. GroupNo: 0,
  4599. AdviceType: 2,
  4600. RecordDate: recordDate.Unix(),
  4601. AdviceDate: recordDate.Unix(),
  4602. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  4603. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  4604. AdviceDesc: "",
  4605. ReminderDate: 0,
  4606. SingleDose: prescription.AnticoagulantZongliang,
  4607. SingleDoseUnit: "iu",
  4608. DrugSpec: 0,
  4609. DrugSpecUnit: "",
  4610. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  4611. PrescribingNumberUnit: "支",
  4612. DeliveryWay: "静脉注射",
  4613. ExecutionFrequency: "上机前",
  4614. AdviceDoctor: 0,
  4615. Status: 1,
  4616. CreatedTime: time.Now().Unix(),
  4617. UpdatedTime: time.Now().Unix(),
  4618. IsPrescription: 1,
  4619. ExecutionState: 2,
  4620. StopState: 2,
  4621. IsSettle: 2,
  4622. }
  4623. // 查询排班信息
  4624. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4625. if schedulePatient.ID > 0 {
  4626. if schedulePatient.ScheduleType == 1 {
  4627. advice.StartTime = recordDate.Unix() + 6.5*60*60
  4628. }
  4629. if schedulePatient.ScheduleType == 2 {
  4630. advice.StartTime = recordDate.Unix() + 9*60*60
  4631. }
  4632. }
  4633. // 抗凝剂名称
  4634. switch anticoagulant {
  4635. case 1:
  4636. advice.AdviceName = "无肝素"
  4637. break
  4638. case 2:
  4639. advice.AdviceName = "普通肝素"
  4640. break
  4641. case 3:
  4642. advice.AdviceName = "低分子肝素"
  4643. break
  4644. case 4:
  4645. advice.AdviceName = "阿加曲班"
  4646. break
  4647. case 5:
  4648. advice.AdviceName = "枸橼酸钠"
  4649. break
  4650. case 6:
  4651. advice.AdviceName = "低分子肝素钙"
  4652. break
  4653. case 7:
  4654. advice.AdviceName = "低分子肝素钠"
  4655. break
  4656. case 8:
  4657. advice.AdviceName = "依诺肝素"
  4658. break
  4659. case 9:
  4660. advice.AdviceName = "达肝素"
  4661. break
  4662. case 10:
  4663. advice.AdviceName = "体外抗凝"
  4664. break
  4665. case 11:
  4666. advice.AdviceName = "那曲肝素"
  4667. break
  4668. case 12:
  4669. advice.AdviceName = "无抗凝剂"
  4670. break
  4671. }
  4672. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  4673. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  4674. advice.AdviceDoctor = appRole.AdminUserId
  4675. }
  4676. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  4677. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  4678. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  4679. advice.AdviceName = "低分子肝素钠注射液"
  4680. // 修改患者临时医嘱里的抗凝剂医嘱
  4681. advice.ID = advicePrescription.ID
  4682. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  4683. } else {
  4684. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  4685. advice.AdviceName = "低分子肝素钠注射液"
  4686. service.CreateDoctorAdvice(&advice)
  4687. }
  4688. }
  4689. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  4690. redis := service.RedisClient()
  4691. defer redis.Close()
  4692. //清空key 值
  4693. redis.Set(key, "", time.Second)
  4694. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  4695. redis.Set(keyOne, "", time.Second)
  4696. }
  4697. //获取key,清空redis
  4698. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  4699. redis := service.RedisClient()
  4700. defer redis.Close()
  4701. //清空key 值
  4702. redis.Set(key, "", time.Second)
  4703. //清空长期医嘱的key
  4704. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  4705. redis.Set(soulution_key, "", time.Second)
  4706. //查询最近透析准备表里是否存在 透析器 灌流器
  4707. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4708. redis.Set(keyOne, "", time.Second)
  4709. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  4710. redis.Set(keyTwo, "", time.Second)
  4711. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  4712. redis.Set(keyThree, "", time.Second)
  4713. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  4714. redis.Set(keyFour, "", time.Second)
  4715. //splitStr := strings.Split(dialysis_dialyszers, ",")
  4716. //
  4717. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  4718. //
  4719. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  4720. //if len(mation)>0{
  4721. // for _, item := range splitStr {
  4722. // for _,it := range mation{
  4723. // if(item == it.SpecificationName){
  4724. //
  4725. // //查询最近一次的透析器
  4726. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4727. //
  4728. // if errcode == gorm.ErrRecordNotFound{
  4729. // //插入数据
  4730. // prepare := models.DialysisBeforePrepare{
  4731. // UserOrgId: adminUserInfo.Org.Id,
  4732. // PatientId: id,
  4733. // RecordDate: recordDate.Unix(),
  4734. // GoodTypeId: it.GoodTypeId,
  4735. // GoodId: it.ID,
  4736. // Count: 1,
  4737. // Ctime: time.Now().Unix(),
  4738. // Creater: adminUserInfo.AdminUser.Id,
  4739. // Status:1,
  4740. //
  4741. // }
  4742. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4743. // fmt.Println("",errcode)
  4744. // }
  4745. // }
  4746. // }
  4747. //
  4748. // }
  4749. //
  4750. // for _, item := range splitIrrigation {
  4751. // for _,it := range mation{
  4752. // if(item == it.SpecificationName){
  4753. // //查询最近一次的透析器
  4754. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4755. // if errcode == gorm.ErrRecordNotFound{
  4756. // //插入数据
  4757. // prepare := models.DialysisBeforePrepare{
  4758. // UserOrgId: adminUserInfo.Org.Id,
  4759. // PatientId: id,
  4760. // RecordDate: recordDate.Unix(),
  4761. // GoodTypeId: it.GoodTypeId,
  4762. // GoodId: it.ID,
  4763. // Count: 1,
  4764. // Ctime: time.Now().Unix(),
  4765. // Creater: adminUserInfo.AdminUser.Id,
  4766. // Status:1,
  4767. //
  4768. // }
  4769. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4770. // fmt.Println(errcode)
  4771. // }
  4772. // }
  4773. // }
  4774. // }
  4775. //}
  4776. c.ServeSuccessJSON(map[string]interface{}{
  4777. "solution": &solution,
  4778. "prescription": &prescription,
  4779. })
  4780. }
  4781. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4782. patient, _ := c.GetInt64("patient", 0)
  4783. adminUserInfo := c.GetMobileAdminUserInfo()
  4784. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4785. c.ServeSuccessJSON(map[string]interface{}{
  4786. "receiveTreatmentAsses": receiveTreatmentAsses,
  4787. })
  4788. }
  4789. func (this *DialysisAPIController) PostSignInfo() {
  4790. patientID, _ := this.GetInt64("patient_id")
  4791. recordDateStr := this.GetString("date")
  4792. if patientID <= 0 {
  4793. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4794. return
  4795. }
  4796. if len(recordDateStr) == 0 {
  4797. recordDateStr = time.Now().Format("2006-01-02")
  4798. }
  4799. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4800. if parseDateErr != nil {
  4801. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4802. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4803. return
  4804. }
  4805. adminInfo := this.GetMobileAdminUserInfo()
  4806. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4807. if err != nil {
  4808. this.ErrorLog("签名失败:%v", err)
  4809. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4810. return
  4811. }
  4812. this.ServeSuccessJSON(map[string]interface{}{
  4813. "doctor_id": adminInfo.AdminUser.Id,
  4814. })
  4815. }
  4816. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4817. patientID, _ := this.GetInt64("patient_id")
  4818. adminInfo := this.GetMobileAdminUserInfo()
  4819. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4820. this.ServeSuccessJSON(map[string]interface{}{
  4821. "monitor": record,
  4822. })
  4823. }
  4824. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4825. thisTime := time.Now()
  4826. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4827. timeLayout := "2006-01-02 15:04:05"
  4828. loc, _ := time.LoadLocation("Local")
  4829. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4830. theAssessmentDateTime := theStartTime.Unix()
  4831. patientID, _ := this.GetInt64("patient_id")
  4832. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4833. adminInfo := this.GetMobileAdminUserInfo()
  4834. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4835. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4836. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4837. var ultrafiltration_rate float64
  4838. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4839. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4840. fmt.Println(evaluation)
  4841. fmt.Println("prescription.ID", prescription.ID)
  4842. if prescription.ID > 0 {
  4843. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4844. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4845. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4846. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4847. record.UltrafiltrationRate = ultrafiltration_rate
  4848. }
  4849. //重庆塘坝卫生院
  4850. if adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10745 || adminInfo.Org.Id == 9478 {
  4851. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4852. record.UltrafiltrationRate = ultrafiltration_rate
  4853. }
  4854. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4855. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4856. record.UltrafiltrationRate = ultrafiltration_rate
  4857. }
  4858. if adminInfo.Org.Id == 10510 {
  4859. record.UltrafiltrationRate = 0
  4860. }
  4861. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4862. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4863. record.UltrafiltrationRate = ultrafiltration_rate
  4864. }
  4865. if template.TemplateId == 20 || template.TemplateId == 22 || adminInfo.Org.Id == 10731 {
  4866. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4867. record.UltrafiltrationRate = ultrafiltration_rate
  4868. }
  4869. // 只针对方济医院
  4870. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4871. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4872. ultrafiltration_rate = value
  4873. record.UltrafiltrationRate = ultrafiltration_rate
  4874. }
  4875. if template.TemplateId == 41 || template.TemplateId == 47 {
  4876. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4877. record.UltrafiltrationRate = ultrafiltration_rate
  4878. }
  4879. if template.TemplateId == 43 {
  4880. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4881. record.UltrafiltrationRate = ultrafiltration_rate
  4882. }
  4883. if template.TemplateId == 46 || template.TemplateId == 54 {
  4884. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4885. record.UltrafiltrationRate = ultrafiltration_rate
  4886. }
  4887. 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 {
  4888. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4889. record.UltrafiltrationRate = ultrafiltration_rate
  4890. }
  4891. if adminInfo.Org.Id == 10469 {
  4892. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4893. record.UltrafiltrationRate = ultrafiltration_rate
  4894. }
  4895. if adminInfo.Org.Id == 10667 {
  4896. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4897. record.UltrafiltrationRate = ultrafiltration_rate
  4898. }
  4899. if adminInfo.Org.Id == 10471 {
  4900. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4901. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4902. }
  4903. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4904. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4905. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4906. }
  4907. if adminInfo.Org.Id == 10751 {
  4908. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4909. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4910. }
  4911. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4912. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4913. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4914. }
  4915. if adminInfo.Org.Id == 10721 {
  4916. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4917. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4918. }
  4919. if adminInfo.Org.Id == 10766 {
  4920. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4921. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4922. }
  4923. if adminInfo.Org.Id == 10757 {
  4924. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4925. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4926. }
  4927. if adminInfo.Org.Id == 10752 {
  4928. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4929. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4930. }
  4931. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4932. record.UltrafiltrationRate = 0
  4933. }
  4934. if adminInfo.Org.Id == 10727 || adminInfo.Org.Id == 10731 {
  4935. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4936. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4937. }
  4938. if adminInfo.Org.Id == 10206 {
  4939. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4940. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4941. }
  4942. //湘潭爱心美白石
  4943. if adminInfo.Org.Id == 9850 {
  4944. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4945. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4946. }
  4947. if adminInfo.Org.Id == 9919 {
  4948. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4949. record.UltrafiltrationRate = math.Floor(ultrafiltration_rate / 1000)
  4950. }
  4951. //if template.TemplateId == 47 {
  4952. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4953. // record.UltrafiltrationRate = ultrafiltration_rate
  4954. //}
  4955. }
  4956. }
  4957. // record.UltrafiltrationRate = ultrafiltration_rate
  4958. record.UltrafiltrationVolume = 0
  4959. 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
  4960. if ultrafiltration_rate > 0 {
  4961. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4962. record.UltrafiltrationVolume = value
  4963. }
  4964. }
  4965. 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
  4966. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4967. if adminInfo.Org.Id != 10735 {
  4968. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4969. record.UltrafiltrationVolume = ultrafiltration_volume
  4970. }
  4971. //胶州少海医院
  4972. if adminInfo.Org.Id == 10735 {
  4973. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4974. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4975. var ultrafiltration_rate_one = math.Floor(prescription.TargetUltrafiltration*1000/float64(totalMin)*60*1000) / 1000
  4976. if lastMonitorRecordList.ID > 0 {
  4977. record.UltrafiltrationRate = ultrafiltration_rate_one
  4978. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  4979. record.UltrafiltrationVolume = ultrafiltration_volume
  4980. } else {
  4981. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  4982. record.UltrafiltrationVolume = ultrafiltration_volume
  4983. }
  4984. }
  4985. }
  4986. }
  4987. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4988. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4989. record.UltrafiltrationVolume = ultrafiltration_volume
  4990. }
  4991. //长沙南雅
  4992. 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 || adminInfo.Org.Id == 9478 || adminInfo.Org.Id == 10766 {
  4993. if ultrafiltration_rate > 0 {
  4994. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4995. record.UltrafiltrationVolume = ultrafiltration_volume
  4996. }
  4997. }
  4998. if adminInfo.Org.Id == 10471 {
  4999. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5000. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5001. }
  5002. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  5003. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5004. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5005. }
  5006. if adminInfo.Org.Id == 10751 {
  5007. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5008. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5009. }
  5010. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  5011. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5012. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5013. }
  5014. //长沙南雅累计血容量自动计算
  5015. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  5016. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  5017. //}
  5018. if template.TemplateId == 47 || template.TemplateId == 54 {
  5019. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  5020. }
  5021. if adminInfo.Org.Id == 10510 {
  5022. record.UltrafiltrationVolume = 0
  5023. }
  5024. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10164 || adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10752 || adminInfo.Org.Id == 10757 || adminInfo.Org.Id == 10766 {
  5025. if ultrafiltration_rate > 0 {
  5026. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5027. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5028. }
  5029. }
  5030. //古镇乐生
  5031. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  5032. if ultrafiltration_rate > 0 {
  5033. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5034. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5035. }
  5036. }
  5037. if adminInfo.Org.Id == 9919 {
  5038. if ultrafiltration_rate > 0 {
  5039. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5040. record.UltrafiltrationVolume = math.Floor(ultrafiltration_volume / 1000)
  5041. }
  5042. }
  5043. if adminInfo.Org.Id == 10206 {
  5044. if ultrafiltration_rate > 0 {
  5045. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5046. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5047. }
  5048. }
  5049. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10757 || adminInfo.Org.Id == 10290 {
  5050. var replacement_rate float64
  5051. var displacement_quantity float64
  5052. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5053. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*60) / 1000
  5054. record.ReplacementRate = replacement_rate
  5055. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  5056. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5057. record.DisplacementQuantity = displacement_quantity
  5058. }
  5059. if adminInfo.Org.Id == 10766 || adminInfo.Org.Id == 10164 {
  5060. var replacement_rate float64
  5061. var displacement_quantity float64
  5062. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5063. //replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  5064. ////乘10 除10是为了保留一位小数
  5065. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  5066. fmt.Println("replacement_rate", replacement_rate)
  5067. record.ReplacementRate = replacement_rate
  5068. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5069. record.DisplacementQuantity = displacement_quantity
  5070. //fmt.Println("totalMin", totalMin)
  5071. //fmt.Println("math.Floor(prescription", math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60))
  5072. //fmt.Println("replacement_rate", replacement_rate)
  5073. //fmt.Println("math.Floor", math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600))
  5074. //fmt.Println("displacement_quantity===================", displacement_quantity)
  5075. }
  5076. if adminInfo.Org.Id == 9478 {
  5077. var replacement_rate float64
  5078. var displacement_quantity float64
  5079. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5080. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  5081. record.ReplacementRate = replacement_rate
  5082. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5083. record.DisplacementQuantity = displacement_quantity
  5084. }
  5085. if adminInfo.Org.Id == 10752 {
  5086. var replacement_rate float64
  5087. var displacement_quantity float64
  5088. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5089. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  5090. record.ReplacementRate = replacement_rate
  5091. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5092. record.DisplacementQuantity = displacement_quantity
  5093. }
  5094. if adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10745 || adminInfo.Org.Id == 9478 || adminInfo.Org.Id == 10766 {
  5095. var replacement_rate float64
  5096. var displacement_quantity float64
  5097. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5098. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  5099. record.ReplacementRate = replacement_rate
  5100. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5101. record.DisplacementQuantity = displacement_quantity
  5102. }
  5103. if adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10745 {
  5104. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5105. record.UltrafiltrationVolume = ultrafiltration_volume
  5106. }
  5107. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 || adminInfo.Org.Id == 10744 {
  5108. var replacement_rate float64
  5109. var displacement_quantity float64
  5110. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5111. if totalMin == 0 {
  5112. totalMin = 240
  5113. }
  5114. if prescription.DisplaceLiquiValue == 0 {
  5115. prescription.ReplacementTotal = 32
  5116. }
  5117. //乘10 除10是为了保留一位小数
  5118. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  5119. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  5120. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5121. record.DisplacementQuantity = displacement_quantity
  5122. }
  5123. if adminInfo.Org.Id == 9850 {
  5124. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5125. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5126. }
  5127. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  5128. fisrtMonitorRecordList, _ := service.GetFisrtMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  5129. this.ServeSuccessJSON(map[string]interface{}{
  5130. "monitor": record,
  5131. "lastMonitorRecordList": lastMonitorRecordList,
  5132. "fisrtMonitorRecordList": fisrtMonitorRecordList,
  5133. })
  5134. }
  5135. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  5136. record_id, _ := this.GetInt64("id")
  5137. nurseID, _ := this.GetInt64("start_nurse")
  5138. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  5139. bedID, _ := this.GetInt64("bed")
  5140. start_time := this.GetString("start_time")
  5141. schedual_type, _ := this.GetInt64("schedual_type")
  5142. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  5143. change_nurse, _ := this.GetInt64("change_nurse")
  5144. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  5145. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  5146. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  5147. patient_id, _ := this.GetInt64("patient_id")
  5148. record_date, _ := this.GetInt64("record_date")
  5149. puncture_needle := this.GetString("puncture_needle")
  5150. puncture_way := this.GetString("puncture_way")
  5151. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  5152. dialysis_irrigation := this.GetString("dialysis_irrigation")
  5153. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  5154. nuclein_date_str := this.GetString("nuclein_date_str")
  5155. order_remark := this.GetString("order_remark")
  5156. schedule_remark := this.GetString("schedule_remark")
  5157. catheter_operation := this.GetString("catheter_operation")
  5158. blood_flow_volume := this.GetString("blood_flow_volume")
  5159. blood_drawing, _ := this.GetInt64("blood_drawing")
  5160. dialysis_strainer := this.GetString("dialysis_strainer")
  5161. if record_id == 0 {
  5162. this.ErrorLog("id:%v", record_id)
  5163. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5164. return
  5165. }
  5166. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5167. if parseStartDateErr != nil {
  5168. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  5169. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5170. return
  5171. }
  5172. adminUserInfo := this.GetMobileAdminUserInfo()
  5173. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5174. if getNurseErr != nil {
  5175. this.ErrorLog("获取护士失败:%v", getNurseErr)
  5176. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5177. return
  5178. } else if nurse == nil {
  5179. this.ErrorLog("护士不存在")
  5180. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5181. return
  5182. }
  5183. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  5184. //if getNurseErr != nil {
  5185. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  5186. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5187. // return
  5188. //} else if nurse == nil {
  5189. // this.ErrorLog("护士不存在")
  5190. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5191. // return
  5192. //}
  5193. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  5194. if getDeviceNumberErr != nil {
  5195. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  5196. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5197. return
  5198. } else if deviceNumber == nil {
  5199. this.ErrorLog("床位号不存在")
  5200. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5201. return
  5202. }
  5203. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  5204. //
  5205. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  5206. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5207. // if getPermissionErr != nil {
  5208. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5209. // return
  5210. // } else if headNursePermission == nil {
  5211. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5212. // return
  5213. // }
  5214. //}
  5215. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  5216. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  5217. timeLayout := "2006-01-02 15:04:05"
  5218. loc, _ := time.LoadLocation("Local")
  5219. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  5220. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  5221. schedulestartTime := theStartTime.Unix()
  5222. scheduleendTime := theEndTime.Unix()
  5223. var theNucleinDate int64
  5224. timeLayoutOne := "2006-01-02"
  5225. if len(nuclein_date_str) > 0 {
  5226. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  5227. if err != nil {
  5228. utils.ErrorLog(err.Error())
  5229. }
  5230. theNucleinDate = theTime.Unix()
  5231. }
  5232. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  5233. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  5234. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5235. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  5236. if err == gorm.ErrRecordNotFound { //空床位
  5237. // 修改了床位逻辑
  5238. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5239. if daySchedule.ID > 0 {
  5240. //daySchedule.BedId = bedID
  5241. //daySchedule.PartitionId = deviceNumber.ZoneID
  5242. //daySchedule.ScheduleType = schedual_type
  5243. //daySchedule.UpdatedTime = time.Now().Unix()
  5244. //err := service.UpdateSchedule(&daySchedule)
  5245. xtSchedule := models.Schedule{
  5246. PartitionId: deviceNumber.ZoneID,
  5247. BedId: bedID,
  5248. ScheduleType: schedual_type,
  5249. UpdatedTime: time.Now().Unix(),
  5250. }
  5251. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  5252. if err != nil {
  5253. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5254. return
  5255. }
  5256. }
  5257. } else if err == nil {
  5258. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  5259. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5260. if daySchedule.ID > 0 {
  5261. //daySchedule.BedId = bedID
  5262. //daySchedule.PartitionId = deviceNumber.ZoneID
  5263. //
  5264. //daySchedule.ScheduleType = schedual_type
  5265. //daySchedule.UpdatedTime = time.Now().Unix()
  5266. //err := service.UpdateSchedule(&daySchedule)
  5267. xtSchedule := models.Schedule{
  5268. PartitionId: deviceNumber.ZoneID,
  5269. BedId: bedID,
  5270. ScheduleType: schedual_type,
  5271. UpdatedTime: time.Now().Unix(),
  5272. }
  5273. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  5274. if err != nil {
  5275. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5276. return
  5277. }
  5278. }
  5279. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  5280. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  5281. return
  5282. }
  5283. } else if err != nil {
  5284. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5285. return
  5286. }
  5287. }
  5288. dialysisRecord := &models.DialysisOrder{
  5289. ID: record_id,
  5290. UserOrgId: adminUserInfo.Org.Id,
  5291. BedID: bedID,
  5292. StartNurse: nurseID,
  5293. StartTime: startDate.Unix(),
  5294. PunctureNurse: puncture_nurse,
  5295. Creator: adminUserInfo.AdminUser.Id,
  5296. Modifier: adminUserInfo.AdminUser.Id,
  5297. WashpipeNurse: washpipe_nurse,
  5298. SchedualType: schedual_type,
  5299. ChangeNurse: change_nurse,
  5300. DifficultPunctureNurse: difficult_puncture_nurse,
  5301. NewFistulaNurse: new_fistula_nurse,
  5302. QualityNurseId: quality_nurse_id,
  5303. PunctureNeedle: puncture_needle,
  5304. PunctureWay: puncture_way,
  5305. DialysisDialyszers: dialysis_dialyszers,
  5306. DialysisIrrigation: dialysis_irrigation,
  5307. BloodAccessId: blood_access_id,
  5308. NucleinDate: theNucleinDate,
  5309. OrderRemark: order_remark,
  5310. ScheduleRemark: schedule_remark,
  5311. CatheterOperation: catheter_operation,
  5312. BloodFlowVolume: blood_flow_volume,
  5313. BloodDrawing: blood_drawing,
  5314. DialysisStrainer: dialysis_strainer,
  5315. }
  5316. _, prescription := service.FindDialysisPrescriptionByReordDate(patient_id, record_date, adminUserInfo.Org.Id)
  5317. if prescription.ID > 0 {
  5318. var endTime int64
  5319. endTime = dialysisRecord.StartTime + prescription.DialysisDurationHour*3600 + prescription.DialysisDurationMinute*60
  5320. dialysisRecord.EndTime = endTime
  5321. }
  5322. if adminUserInfo.Org.Id == 10766 || adminUserInfo.Org.Id == 10164 {
  5323. //查询第一条监测
  5324. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  5325. service.UpdateFirstMoitorById(firstMonitor.ID, dialysisRecord.StartTime)
  5326. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  5327. redis := service.RedisClient()
  5328. //清空key 值
  5329. redis.Set(key, "", time.Second)
  5330. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  5331. redis.Set(keyOne, "", time.Second)
  5332. defer redis.Close()
  5333. }
  5334. //修改床位号需要重新消毒
  5335. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  5336. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  5337. //查询第一条监测
  5338. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  5339. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  5340. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  5341. redis := service.RedisClient()
  5342. //清空key 值
  5343. redis.Set(key, "", time.Second)
  5344. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  5345. redis.Set(keyOne, "", time.Second)
  5346. defer redis.Close()
  5347. }
  5348. // 查询信息规挡的设置天数
  5349. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5350. if infor.ID > 0 && infor.WeekDay > 0 {
  5351. var cha_time int64
  5352. timeNowStr := time.Now().Format("2006-01-02")
  5353. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5354. //今日的日期减去设置的日期
  5355. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5356. if cha_time >= record_date {
  5357. //查询审核是否允许
  5358. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  5359. //申请状态不允许的情况 拒绝修改
  5360. if infor.ApplicationStatus != 1 {
  5361. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5362. return
  5363. }
  5364. }
  5365. }
  5366. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  5367. //修改床位后重新生成消毒计划
  5368. if adminUserInfo.Org.Id == 10340 {
  5369. //根据床位号获取设备型号
  5370. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  5371. //查询使用消毒最后一条消毒记录
  5372. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  5373. fmt.Println("err", err)
  5374. if err == gorm.ErrRecordNotFound {
  5375. //查找排班
  5376. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  5377. //查询改设备是否有消毒计划
  5378. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  5379. //根据床位号获取设备id
  5380. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  5381. //查询病人信息
  5382. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  5383. var con = ""
  5384. if patients.IsInfectious == 0 {
  5385. con = ""
  5386. }
  5387. if patients.IsInfectious == 1 {
  5388. con = "无"
  5389. }
  5390. if patients.IsInfectious == 2 {
  5391. con = "有"
  5392. }
  5393. if errcode == nil {
  5394. var end_time int64
  5395. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  5396. //新增消毒
  5397. information := models.DeviceInformation{
  5398. Date: dialysisRecord.DialysisDate,
  5399. Zone: dialysisRecord.ZoneId,
  5400. Class: dialysisRecord.SchedualType,
  5401. BedNumber: dialysisRecord.BedID,
  5402. PatientId: dialysisRecord.PatientId,
  5403. DialysisMode: scheduleByPatient.ModeId,
  5404. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  5405. Disinfection: 1,
  5406. DialysisConcentration: 1,
  5407. DisinfectionStatus: 1,
  5408. Move: 1,
  5409. UserOrgId: dialysisRecord.UserOrgId,
  5410. DisinfectType: plan.Way,
  5411. DisinfectantType: plan.MachineDisinfectant,
  5412. FluidPath: plan.DisinfectanWay, //液路消毒方式
  5413. Disinfectant: plan.Disinfectant,
  5414. Ctime: time.Now().Unix(),
  5415. Status: 1,
  5416. SignName: nurseID,
  5417. EquimentId: addmacher.ID,
  5418. DisinfectionResidue: 2,
  5419. Bed: addmacher.BedNumber,
  5420. StartTime: dialysisRecord.StartTime,
  5421. EndTime: dialysisRecord.EndTime,
  5422. Contagion: con,
  5423. WeightLoss: 0,
  5424. Hyperfiltratio: 0,
  5425. DialysisHour: "",
  5426. MachineRun: 1,
  5427. DisinfecStartime: dialysisRecord.EndTime,
  5428. DisinfecEndtime: end_time,
  5429. }
  5430. err := service.CreateInformationTwo(&information)
  5431. fmt.Println("报错", err)
  5432. }
  5433. }
  5434. }
  5435. order, _ := service.GetLastPatientOrder(record_id)
  5436. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  5437. redis := service.RedisClient()
  5438. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  5439. redis.Set(key, "", time.Second)
  5440. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  5441. //清空key 值
  5442. redis.Set(keyOne, "", time.Second)
  5443. scheduleDateStartOne := startDate.Format("2006-01-02")
  5444. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5445. redis.Set(keyTwo, "", time.Second)
  5446. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  5447. redis.Set(keyThree, "", time.Second)
  5448. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  5449. redis.Set(keyFour, "", time.Second)
  5450. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  5451. redis.Set(keyFive, "", time.Second)
  5452. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  5453. redis.Set(keySix, "", time.Second)
  5454. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  5455. redis.Set(keySeven, "", time.Second)
  5456. if updateErr != nil {
  5457. this.ErrorLog("修改上机失败:%v", updateErr)
  5458. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5459. return
  5460. }
  5461. if updateErr == nil {
  5462. if tempDialysisRecord.Stage == 2 {
  5463. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  5464. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5465. fmt.Println(value)
  5466. a, b := math.Modf(value)
  5467. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5468. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5469. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5470. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  5471. redis := service.RedisClient()
  5472. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  5473. redis.Set(key, "", time.Second)
  5474. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  5475. redis.Set(keyOne, "", time.Second)
  5476. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  5477. //清空key 值
  5478. redis.Set(keySix, "", time.Second)
  5479. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  5480. redis.Set(keySeven, "", time.Second)
  5481. redis.Close()
  5482. if updateAssessmentErr != nil {
  5483. utils.ErrorLog("%v", updateAssessmentErr)
  5484. }
  5485. }
  5486. }
  5487. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5488. this.ServeSuccessJSON(map[string]interface{}{
  5489. "dialysis_order": dialysisRecords,
  5490. })
  5491. }
  5492. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  5493. record_id, _ := c.GetInt64("id")
  5494. nurseID, _ := c.GetInt64("nurse")
  5495. end_time := c.GetString("end_time")
  5496. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  5497. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  5498. catheter := c.GetString("catheter")
  5499. cruor := c.GetString("cruor")
  5500. mission := c.GetString("mission")
  5501. condenser := c.GetString("condenser")
  5502. if record_id <= 0 || nurseID <= 0 {
  5503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5504. return
  5505. }
  5506. adminUserInfo := c.GetMobileAdminUserInfo()
  5507. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5508. if getNurseErr != nil {
  5509. c.ErrorLog("获取护士失败:%v", getNurseErr)
  5510. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5511. return
  5512. } else if nurse == nil {
  5513. c.ErrorLog("护士不存在")
  5514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5515. return
  5516. }
  5517. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  5518. if parseEndDateErr != nil {
  5519. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  5520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5521. return
  5522. }
  5523. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  5524. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  5525. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5526. // if getPermissionErr != nil {
  5527. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5528. // return
  5529. // } else if headNursePermission == nil {
  5530. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5531. // return
  5532. // }
  5533. //}
  5534. // 查询信息规挡的设置天数
  5535. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5536. if infor.ID > 0 {
  5537. var cha_time int64
  5538. timeNowStr := time.Now().Format("2006-01-02")
  5539. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5540. //今日的日期减去设置的日期
  5541. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5542. if cha_time >= tempDialysisRecords.DialysisDate {
  5543. //查询审核是否允许
  5544. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  5545. //申请状态不允许的情况 拒绝修改
  5546. if infor.ApplicationStatus != 1 {
  5547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5548. return
  5549. }
  5550. }
  5551. }
  5552. dialysisRecord := &models.DialysisOrder{
  5553. ID: record_id,
  5554. UserOrgId: adminUserInfo.Org.Id,
  5555. EndTime: endDate.Unix(),
  5556. FinishNurse: nurseID,
  5557. FinishModifier: adminUserInfo.AdminUser.Id,
  5558. PuncturePointHaematoma: puncture_point_haematoma,
  5559. BloodAccessInternalFistula: blood_access_internal_fistula,
  5560. Catheter: catheter,
  5561. Cruor: cruor,
  5562. Mission: mission,
  5563. Condenser: condenser,
  5564. }
  5565. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  5566. redis := service.RedisClient()
  5567. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  5568. //清空key 值
  5569. redis.Set(key, "", time.Second)
  5570. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5571. //清空key 值
  5572. redis.Set(keyOne, "", time.Second)
  5573. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5574. redis.Set(keySeven, "", time.Second)
  5575. redis.Close()
  5576. if updateErr != nil {
  5577. c.ErrorLog("修改下机失败:%v", updateErr)
  5578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5579. return
  5580. }
  5581. if updateErr == nil {
  5582. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  5583. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5584. a, b := math.Modf(value)
  5585. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5586. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5587. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5588. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  5589. redis := service.RedisClient()
  5590. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  5591. redis.Set(keyTen, "", time.Second)
  5592. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  5593. redis.Set(keyTwo, "", time.Second)
  5594. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  5595. redis.Set(key, "", time.Second)
  5596. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5597. redis.Set(keyThree, "", time.Second)
  5598. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5599. redis.Set(keySeven, "", time.Second)
  5600. defer redis.Close()
  5601. if updateAssessmentErr != nil {
  5602. utils.ErrorLog("%v", updateAssessmentErr)
  5603. }
  5604. }
  5605. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5606. c.ServeSuccessJSON(map[string]interface{}{
  5607. "dialysis_order": dialysisRecords,
  5608. })
  5609. }
  5610. func (c *DialysisAPIController) GetLongAdvice() {
  5611. patient_id, _ := c.GetInt64("id")
  5612. adminUserInfo := c.GetMobileAdminUserInfo()
  5613. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5614. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5615. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5616. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5617. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5618. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5619. c.ServeSuccessJSON(map[string]interface{}{
  5620. "status": "1",
  5621. })
  5622. return
  5623. } else { //开启推送提醒
  5624. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5625. var advice_three []*models.DoctorAdvice
  5626. recordDateStr := time.Now().Format("2006-01-02")
  5627. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5628. nowtime := recordDate.Unix()
  5629. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  5630. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  5631. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  5632. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  5633. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  5634. for _, advice := range advices {
  5635. if advice.FrequencyType == 3 {
  5636. t := time.Now()
  5637. week := int(t.Weekday())
  5638. fmt.Println(t.Weekday())
  5639. fmt.Println(week)
  5640. switch week {
  5641. case 1:
  5642. if strings.Index(advice.WeekDay, "周一") == -1 {
  5643. advice_three = append(advice_three, advice)
  5644. }
  5645. break
  5646. case 2:
  5647. if strings.Index(advice.WeekDay, "周二") == -1 {
  5648. advice_three = append(advice_three, advice)
  5649. }
  5650. break
  5651. case 3:
  5652. if strings.Index(advice.WeekDay, "周三") == -1 {
  5653. advice_three = append(advice_three, advice)
  5654. }
  5655. break
  5656. case 4:
  5657. if strings.Index(advice.WeekDay, "周四") == -1 {
  5658. advice_three = append(advice_three, advice)
  5659. }
  5660. break
  5661. case 5:
  5662. if strings.Index(advice.WeekDay, "周五") == -1 {
  5663. advice_three = append(advice_three, advice)
  5664. }
  5665. break
  5666. case 6:
  5667. if strings.Index(advice.WeekDay, "周六") == -1 {
  5668. advice_three = append(advice_three, advice)
  5669. }
  5670. break
  5671. case 0:
  5672. if strings.Index(advice.WeekDay, "周日") == -1 {
  5673. advice_three = append(advice_three, advice)
  5674. }
  5675. break
  5676. }
  5677. }
  5678. }
  5679. for _, advice := range advices_two {
  5680. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5681. now := p.Unix()
  5682. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5683. dayStr2 := "-" + dayStr
  5684. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5685. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5686. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5687. for _, ad := range advices {
  5688. advice_three = append(advice_three, ad)
  5689. }
  5690. }
  5691. if err == nil {
  5692. c.ServeSuccessJSON(map[string]interface{}{
  5693. "status": "2",
  5694. "advices": advices,
  5695. "advices_two": RemoveRepeatedElement(advice_three),
  5696. "is_open_remind": config.IsOpenRemind,
  5697. "his_config_open": hisConfig.IsOpen,
  5698. "is_advice_open": is_advice_open.IsAdviceOpen,
  5699. "prescription_open": prescription_open.IsOpen,
  5700. })
  5701. }
  5702. }
  5703. }
  5704. func (c *DialysisAPIController) GetLongAdviceOne() {
  5705. patient_id, _ := c.GetInt64("id")
  5706. startTime := c.GetString("schedule_date")
  5707. timeLayout := "2006-01-02"
  5708. loc, _ := time.LoadLocation("Local")
  5709. var theStartTime int64
  5710. if len(startTime) > 0 {
  5711. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  5712. if err != nil {
  5713. utils.ErrorLog(err.Error())
  5714. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5715. return
  5716. }
  5717. theStartTime = theTime.Unix()
  5718. }
  5719. adminUserInfo := c.GetMobileAdminUserInfo()
  5720. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5721. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5722. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5723. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5724. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5725. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5726. c.ServeSuccessJSON(map[string]interface{}{
  5727. "status": "1",
  5728. })
  5729. return
  5730. } else { //开启推送提醒
  5731. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5732. var advice_three []*models.DoctorAdvice
  5733. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  5734. fmt.Println("theStartTime-----------------------", theStartTime)
  5735. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  5736. for _, advice := range advices {
  5737. if advice.FrequencyType == 3 {
  5738. t := time.Now()
  5739. week := int(t.Weekday())
  5740. fmt.Println(t.Weekday())
  5741. fmt.Println(week)
  5742. switch week {
  5743. case 1:
  5744. if strings.Index(advice.WeekDay, "周一") == -1 {
  5745. advice_three = append(advice_three, advice)
  5746. }
  5747. break
  5748. case 2:
  5749. if strings.Index(advice.WeekDay, "周二") == -1 {
  5750. advice_three = append(advice_three, advice)
  5751. }
  5752. break
  5753. case 3:
  5754. if strings.Index(advice.WeekDay, "周三") == -1 {
  5755. advice_three = append(advice_three, advice)
  5756. }
  5757. break
  5758. case 4:
  5759. if strings.Index(advice.WeekDay, "周四") == -1 {
  5760. advice_three = append(advice_three, advice)
  5761. }
  5762. break
  5763. case 5:
  5764. if strings.Index(advice.WeekDay, "周五") == -1 {
  5765. advice_three = append(advice_three, advice)
  5766. }
  5767. break
  5768. case 6:
  5769. if strings.Index(advice.WeekDay, "周六") == -1 {
  5770. advice_three = append(advice_three, advice)
  5771. }
  5772. break
  5773. case 0:
  5774. if strings.Index(advice.WeekDay, "周日") == -1 {
  5775. advice_three = append(advice_three, advice)
  5776. }
  5777. break
  5778. }
  5779. }
  5780. }
  5781. for _, advice := range advices_two {
  5782. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5783. now := p.Unix()
  5784. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5785. dayStr2 := "-" + dayStr
  5786. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5787. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5788. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5789. fmt.Println("advices-==---------------", advices)
  5790. for _, ad := range advices {
  5791. advice_three = append(advice_three, ad)
  5792. }
  5793. }
  5794. if err == nil {
  5795. c.ServeSuccessJSON(map[string]interface{}{
  5796. "status": "2",
  5797. "advices": advices,
  5798. "advices_two": RemoveRepeatedElement(advice_three),
  5799. "is_open_remind": config.IsOpenRemind,
  5800. "his_config_open": hisConfig.IsOpen,
  5801. "is_advice_open": is_advice_open.IsAdviceOpen,
  5802. "prescription_open": prescription_open.IsOpen,
  5803. })
  5804. }
  5805. }
  5806. }
  5807. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5808. newArr = make([]*models.DoctorAdvice, 0)
  5809. for i := 0; i < len(arr); i++ {
  5810. repeat := false
  5811. for j := i + 1; j < len(arr); j++ {
  5812. if arr[i].ID == arr[j].ID {
  5813. repeat = true
  5814. break
  5815. }
  5816. }
  5817. if !repeat {
  5818. newArr = append(newArr, arr[i])
  5819. }
  5820. }
  5821. return
  5822. }
  5823. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5824. patient, _ := c.GetInt64("id", 0)
  5825. groupNo, _ := c.GetInt64("groupno", 0)
  5826. if patient <= 0 {
  5827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5828. return
  5829. }
  5830. adminUserInfo := c.GetMobileAdminUserInfo()
  5831. dataBody := make(map[string]interface{}, 0)
  5832. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5833. if err != nil {
  5834. utils.ErrorLog(err.Error())
  5835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5836. return
  5837. }
  5838. utils.ErrorLog("%v", dataBody)
  5839. timeLayout := "2006-01-02 15:04"
  5840. loc, _ := time.LoadLocation("Local")
  5841. timeLayout2 := "2006-01-02"
  5842. loc2, _ := time.LoadLocation("Local")
  5843. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5844. utils.ErrorLog("advice_type")
  5845. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5846. return
  5847. }
  5848. adviceType := int64(2)
  5849. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5850. utils.ErrorLog("advice_date")
  5851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5852. return
  5853. }
  5854. adviceDate, _ := dataBody["advice_date"].(string)
  5855. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5856. AdviceDate := theTime.Unix()
  5857. RecordDate := theTime.Unix()
  5858. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5859. utils.ErrorLog("start_time")
  5860. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5861. return
  5862. }
  5863. startTime, _ := dataBody["start_time"].(string)
  5864. if len(startTime) == 0 {
  5865. utils.ErrorLog("len(start_time) == 0")
  5866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5867. return
  5868. }
  5869. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5870. if err != nil {
  5871. utils.ErrorLog(err.Error())
  5872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5873. return
  5874. }
  5875. StartTime := theTime.Unix()
  5876. Remark := ""
  5877. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5878. remark, _ := dataBody["remark"].(string)
  5879. Remark = remark
  5880. }
  5881. var advices []*models.GroupAdvice
  5882. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5883. utils.ErrorLog("advices")
  5884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5885. return
  5886. }
  5887. adviceNames := dataBody["advices"].([]interface{})
  5888. for _, adviceNameMap := range adviceNames {
  5889. adviceNameM := adviceNameMap.(map[string]interface{})
  5890. var advice models.GroupAdvice
  5891. advice.Remark = Remark
  5892. advice.AdviceType = adviceType
  5893. advice.StartTime = StartTime
  5894. advice.AdviceDate = AdviceDate
  5895. advice.RecordDate = RecordDate
  5896. advice.Status = 1
  5897. advice.CreatedTime = time.Now().Unix()
  5898. advice.UpdatedTime = time.Now().Unix()
  5899. advice.StopState = 2
  5900. advice.ExecutionState = 2
  5901. advice.UserOrgId = adminUserInfo.Org.Id
  5902. advice.PatientId = patient
  5903. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5904. advice.IsSettle = 2
  5905. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5906. utils.ErrorLog("advice_name")
  5907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5908. return
  5909. }
  5910. adviceName, _ := adviceNameM["advice_name"].(string)
  5911. if len(adviceName) == 0 {
  5912. utils.ErrorLog("len(advice_name) == 0")
  5913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5914. return
  5915. }
  5916. advice.AdviceName = adviceName
  5917. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5918. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5919. advice.DrugSpec = drugSpec
  5920. }
  5921. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5922. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5923. advice.AdviceDesc = adviceDesc
  5924. }
  5925. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5926. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5927. advice.DrugSpecUnit = drugSpecUnit
  5928. }
  5929. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5930. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5931. // advice.SingleDose = singleDose
  5932. //}
  5933. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5934. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5935. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5936. }
  5937. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5938. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5939. advice.SingleDoseUnit = singleDoseUnit
  5940. }
  5941. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5942. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5943. // advice.PrescribingNumber = prescribingNumber
  5944. //}
  5945. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5946. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5947. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5948. }
  5949. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5950. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5951. advice.PrescribingNumberUnit = prescribingNumberUnit
  5952. }
  5953. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5954. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5955. advice.DeliveryWay = deliveryWay
  5956. }
  5957. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5958. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5959. advice.ExecutionFrequency = executionFrequency
  5960. }
  5961. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5962. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5963. advice.FrequencyType = frequency_type
  5964. }
  5965. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5966. day_count := int64(adviceNameM["day_count"].(float64))
  5967. advice.DayCount = day_count
  5968. }
  5969. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5970. week_day, _ := adviceNameM["week_day"].(string)
  5971. advice.WeekDay = week_day
  5972. }
  5973. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5974. way := int64(adviceNameM["way"].(float64))
  5975. advice.Way = way
  5976. }
  5977. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5978. drug_id := int64(adviceNameM["drug_id"].(float64))
  5979. advice.DrugId = drug_id
  5980. }
  5981. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5982. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5983. advice.DrugNameId = drug_name_id
  5984. }
  5985. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  5986. remark, _ := adviceNameM["remark"].(string)
  5987. advice.Remark = remark
  5988. }
  5989. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  5990. groupno := int64(adviceNameM["groupno"].(float64))
  5991. advice.GroupNo = groupno
  5992. }
  5993. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5994. template_id, _ := adviceNameM["template_id"].(string)
  5995. advice.TemplateId = template_id
  5996. }
  5997. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5998. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5999. advice.ExecutionFrequency = executionFrequency
  6000. }
  6001. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  6002. children := adviceNameM["child"].([]interface{})
  6003. if len(children) > 0 {
  6004. for _, childrenMap := range children {
  6005. childMap := childrenMap.(map[string]interface{})
  6006. var child models.GroupAdvice
  6007. child.Remark = Remark
  6008. child.AdviceType = adviceType
  6009. child.StartTime = StartTime
  6010. child.AdviceDate = AdviceDate
  6011. child.RecordDate = RecordDate
  6012. child.Status = 1
  6013. child.CreatedTime = time.Now().Unix()
  6014. child.UpdatedTime = time.Now().Unix()
  6015. child.StopState = 2
  6016. child.ExecutionState = 2
  6017. child.UserOrgId = adminUserInfo.Org.Id
  6018. child.PatientId = patient
  6019. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  6020. child.IsSettle = 1
  6021. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  6022. utils.ErrorLog("child advice_name")
  6023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6024. return
  6025. }
  6026. childAdviceName, _ := childMap["advice_name"].(string)
  6027. if len(childAdviceName) == 0 {
  6028. utils.ErrorLog("len(child advice_name) == 0")
  6029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6030. return
  6031. }
  6032. child.AdviceName = childAdviceName
  6033. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  6034. childAdviceDesc, _ := childMap["advice_desc"].(string)
  6035. child.AdviceDesc = childAdviceDesc
  6036. }
  6037. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  6038. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  6039. child.DrugSpec = childDrugSpec
  6040. }
  6041. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  6042. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  6043. child.DrugSpecUnit = childDrugSpecUnit
  6044. }
  6045. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  6046. child.SingleDose = childMap["single_dose"].(float64)
  6047. }
  6048. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  6049. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  6050. child.SingleDoseUnit = childSingleDoseUnit
  6051. }
  6052. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  6053. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  6054. }
  6055. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  6056. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  6057. child.PrescribingNumberUnit = childPrescribingNumberUnit
  6058. }
  6059. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  6060. groupno := int64(childMap["groupno"].(float64))
  6061. advice.GroupNo = groupno
  6062. }
  6063. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  6064. remark, _ := childMap["remark"].(string)
  6065. child.Remark = remark
  6066. }
  6067. child.DeliveryWay = advice.DeliveryWay
  6068. child.ExecutionFrequency = advice.ExecutionFrequency
  6069. advice.Children = append(advice.Children, &child)
  6070. }
  6071. }
  6072. }
  6073. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  6074. if temp_advice.ID == 0 {
  6075. advices = append(advices, &advice)
  6076. }
  6077. }
  6078. if len(advices) > 0 {
  6079. finish := models.XtDialysisFinish{
  6080. IsFinish: 1,
  6081. UserOrgId: adminUserInfo.Org.Id,
  6082. Status: 1,
  6083. Ctime: time.Now().Unix(),
  6084. Mtime: 0,
  6085. Module: 4,
  6086. RecordDate: AdviceDate,
  6087. Sourse: 1,
  6088. PatientId: patient,
  6089. }
  6090. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  6091. if dialysisFinish.ID == 0 {
  6092. service.CreateDialysisFinish(finish)
  6093. }
  6094. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  6095. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  6096. for _, item := range advices {
  6097. byterequest, _ := json.Marshal(item)
  6098. adviceLog := models.XtDoctorAdviceLog{
  6099. UserOrgId: adminUserInfo.Org.Id,
  6100. PatientId: patient,
  6101. AdminUserId: adminUserInfo.AdminUser.Id,
  6102. Module: 1,
  6103. ErrLog: string(byterequest),
  6104. Status: 1,
  6105. Ctime: time.Now().Unix(),
  6106. Mtime: 0,
  6107. Source: "手机端医嘱推送",
  6108. RecordDate: item.AdviceDate,
  6109. }
  6110. service.CreateDoctorAdviceLog(adviceLog)
  6111. }
  6112. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  6113. redis := service.RedisClient()
  6114. //清空key 值
  6115. redis.Set(key, "", time.Second)
  6116. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  6117. redis.Set(keyOne, "", time.Second)
  6118. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  6119. defer redis.Close()
  6120. redis.Set(keyThree, "", time.Second)
  6121. if err != nil {
  6122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  6123. return
  6124. }
  6125. c.ServeSuccessJSON(map[string]interface{}{
  6126. "msg": "ok",
  6127. "advices": list,
  6128. })
  6129. } else {
  6130. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  6131. for _, item := range advices {
  6132. byterequest, _ := json.Marshal(item)
  6133. adviceLog := models.XtDoctorAdviceLog{
  6134. UserOrgId: adminUserInfo.Org.Id,
  6135. PatientId: patient,
  6136. AdminUserId: adminUserInfo.AdminUser.Id,
  6137. Module: 1,
  6138. ErrLog: string(byterequest),
  6139. Status: 1,
  6140. Ctime: time.Now().Unix(),
  6141. Mtime: 0,
  6142. Source: "手机端医嘱推送",
  6143. RecordDate: item.AdviceDate,
  6144. }
  6145. service.CreateDoctorAdviceLog(adviceLog)
  6146. }
  6147. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  6148. redis := service.RedisClient()
  6149. //清空key 值
  6150. redis.Set(key, "", time.Second)
  6151. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  6152. redis.Set(keyOne, "", time.Second)
  6153. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  6154. defer redis.Close()
  6155. redis.Set(keyThree, "", time.Second)
  6156. if err != nil {
  6157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  6158. return
  6159. }
  6160. c.ServeSuccessJSON(map[string]interface{}{
  6161. "msg": "ok",
  6162. "advices": list,
  6163. })
  6164. }
  6165. } else {
  6166. c.ServeSuccessJSON(map[string]interface{}{
  6167. "msg": "ok",
  6168. })
  6169. }
  6170. return
  6171. }
  6172. func (c *DialysisAPIController) UploadDryWeight() {
  6173. patient_id, _ := c.GetInt64("id")
  6174. dry_weight, _ := c.GetFloat("dry_weight")
  6175. doctor_id, _ := c.GetInt64("doctor_id")
  6176. remark := c.GetString("remark")
  6177. adminUserInfo := c.GetMobileAdminUserInfo()
  6178. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  6179. if err == gorm.ErrRecordNotFound {
  6180. dryWeight := &models.SgjPatientDryweight{
  6181. PatientId: patient_id,
  6182. DryWeight: dry_weight,
  6183. Remakes: remark,
  6184. Ctime: time.Now().Unix(),
  6185. Mtime: time.Now().Unix(),
  6186. Creator: doctor_id,
  6187. Status: 1,
  6188. UserOrgId: adminUserInfo.Org.Id,
  6189. AdjustedValue: "/",
  6190. UserId: adminUserInfo.AdminUser.Id,
  6191. }
  6192. createErr := service.CreatePatientWeightAdjust(dryWeight)
  6193. redis := service.RedisClient()
  6194. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  6195. redis.Set(keyOne, "", time.Second)
  6196. loc, _ := time.LoadLocation("Local")
  6197. nowTime := time.Now()
  6198. nowDay := nowTime.Format("2006-01-02")
  6199. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  6200. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  6201. redis.Set(key, "", time.Second)
  6202. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  6203. redis.Set(keyTwo, "", time.Second)
  6204. redis.Close()
  6205. if createErr == nil {
  6206. c.ServeSuccessJSON(map[string]interface{}{
  6207. "msg": "提交成功",
  6208. "weight": dryWeight,
  6209. })
  6210. }
  6211. } else {
  6212. dryWeight := &models.SgjPatientDryweight{
  6213. PatientId: patient_id,
  6214. DryWeight: dry_weight,
  6215. Remakes: remark,
  6216. Ctime: time.Now().Unix(),
  6217. Mtime: time.Now().Unix(),
  6218. Creator: doctor_id,
  6219. Status: 1,
  6220. UserOrgId: adminUserInfo.Org.Id,
  6221. AdjustedValue: "/",
  6222. UserId: adminUserInfo.AdminUser.Id,
  6223. }
  6224. var value float64
  6225. value = dry_weight - weightAdjust.DryWeight
  6226. if value < 0 {
  6227. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  6228. } else if value == 0 {
  6229. dryWeight.AdjustedValue = "/"
  6230. } else if value > 0 {
  6231. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  6232. }
  6233. createErr := service.CreatePatientWeightAdjust(dryWeight)
  6234. //康桥
  6235. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10721 {
  6236. timeNowStr := time.Now().Format("2006-01-02")
  6237. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6238. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  6239. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  6240. if beforAssesment.ID > 0 {
  6241. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  6242. var dewater_amount float64
  6243. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  6244. if adminUserInfo.Org.Id != 10702 {
  6245. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  6246. }
  6247. if adminUserInfo.Org.Id == 10702 {
  6248. service.UpdatePatientDialysisPrscriptionOne(dialysisPrescription.ID, dewater_amount)
  6249. }
  6250. //获取key,清空redis
  6251. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  6252. redis := service.RedisClient()
  6253. //清空key 值
  6254. redis.Set(key, "", time.Second)
  6255. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  6256. //清空key 值
  6257. redis.Set(keyOne, "", time.Second)
  6258. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  6259. //清空key 值
  6260. redis.Set(keyTwo, "", time.Second)
  6261. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  6262. redis.Set(keySix, "", time.Second)
  6263. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  6264. redis.Set(keySeven, "", time.Second)
  6265. }
  6266. }
  6267. redis := service.RedisClient()
  6268. loc, _ := time.LoadLocation("Local")
  6269. nowTime := time.Now()
  6270. nowDay := nowTime.Format("2006-01-02")
  6271. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  6272. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  6273. redis.Set(keyOne, "", time.Second)
  6274. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  6275. redis.Set(key, "", time.Second)
  6276. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  6277. redis.Set(keyTwo, "", time.Second)
  6278. redis.Close()
  6279. if createErr == nil {
  6280. c.ServeSuccessJSON(map[string]interface{}{
  6281. "msg": "提交成功",
  6282. "weight": dryWeight,
  6283. })
  6284. }
  6285. }
  6286. }
  6287. func (c *DialysisAPIController) GetSolution() {
  6288. patient_id, _ := c.GetInt64("patient_id")
  6289. mode_id, _ := c.GetInt64("mode_id")
  6290. adminUserInfo := c.GetMobileAdminUserInfo()
  6291. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  6292. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  6293. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  6294. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  6295. if err != nil {
  6296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6297. return
  6298. }
  6299. c.ServeSuccessJSON(map[string]interface{}{
  6300. "solution": solution,
  6301. "prescription": prescription,
  6302. "system_prescription": system_prescription,
  6303. "dialysisPrescription": dialysisPrescription,
  6304. })
  6305. }
  6306. func (c *DialysisAPIController) GetSchedule() {
  6307. schedual_type, _ := c.GetInt64("schedual_type")
  6308. adminUserInfo := c.GetMobileAdminUserInfo()
  6309. scheduleTime, _ := c.GetInt64("record_date")
  6310. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  6311. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  6312. c.ServeSuccessJSON(map[string]interface{}{
  6313. "number": deviceNumber,
  6314. "list": list,
  6315. })
  6316. }
  6317. func (c *DialysisAPIController) GetPatientId() {
  6318. id, _ := c.GetInt64("id")
  6319. //orgid := c.GetMobileAdminUserInfo().Org.Id
  6320. patientId, _ := service.GetPatientId(id)
  6321. //获取该患者的所有传染病
  6322. list, _ := service.GetPatientInfectious(id)
  6323. c.ServeSuccessJSON(map[string]interface{}{
  6324. "patient": patientId,
  6325. "infectioulist": list,
  6326. })
  6327. }
  6328. func (this *DialysisAPIController) GetDialysisSchedule() {
  6329. schedualDate := this.GetString("date")
  6330. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  6331. if parseDateErr != nil {
  6332. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6333. return
  6334. }
  6335. adminInfo := this.GetMobileAdminUserInfo()
  6336. orgID := adminInfo.Org.Id
  6337. redis := service.RedisClient()
  6338. defer redis.Close()
  6339. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  6340. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  6341. if len(scheduals) > 0 {
  6342. //缓存数据
  6343. scheduals_json, err := json.Marshal(scheduals)
  6344. if err == nil {
  6345. redis.Set(key, scheduals_json, time.Second*30)
  6346. }
  6347. }
  6348. this.ServeSuccessJSON(map[string]interface{}{
  6349. "scheduals": scheduals,
  6350. })
  6351. }
  6352. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  6353. change_type, _ := this.GetInt64("type", 0)
  6354. record_date := this.GetString("record_time")
  6355. patient_id, _ := this.GetInt64("patient_id", 0)
  6356. timeLayout := "2006-01-02"
  6357. loc, _ := time.LoadLocation("Local")
  6358. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6359. record_time := theAdviceRecordTime.Unix()
  6360. adminUserInfo := this.GetMobileAdminUserInfo()
  6361. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  6362. if err == nil {
  6363. if len(advices) == 0 {
  6364. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6365. return
  6366. } else {
  6367. this.ServeSuccessJSON(map[string]interface{}{
  6368. "advices": advices,
  6369. "schedule": sch,
  6370. })
  6371. return
  6372. }
  6373. } else {
  6374. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6375. return
  6376. }
  6377. }
  6378. func (c *DialysisAPIController) CreateConsumables() {
  6379. record_date := c.GetString("record_time")
  6380. patient_id, _ := c.GetInt64("patient_id", 0)
  6381. active, _ := c.GetInt64("active")
  6382. adminUser := c.GetMobileAdminUserInfo()
  6383. timeLayout := "2006-01-02"
  6384. loc, _ := time.LoadLocation("Local")
  6385. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6386. record_time := theRecordTime.Unix()
  6387. // 查询信息规挡的设置天数
  6388. orgid := c.GetMobileAdminUserInfo().Org.Id
  6389. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  6390. if infor.ID > 0 {
  6391. var cha_time int64
  6392. timeNowStr := time.Now().Format("2006-01-02")
  6393. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6394. //今日的日期减去设置的日期
  6395. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6396. if cha_time >= record_time {
  6397. //查询审核是否允许
  6398. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  6399. //申请状态不允许的情况 拒绝修改
  6400. if infor.ApplicationStatus != 1 {
  6401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6402. return
  6403. }
  6404. }
  6405. }
  6406. dataBody := make(map[string]interface{}, 0)
  6407. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6408. if err != nil {
  6409. utils.ErrorLog(err.Error())
  6410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6411. return
  6412. }
  6413. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6414. var beforePrepares []*models.DialysisBeforePrepareGoods
  6415. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6416. var dialysisBefor []*models.DialysisBeforePrepare
  6417. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6418. goods, _ := dataBody["goods"].([]interface{})
  6419. if len(goods) > 0 {
  6420. for _, item := range goods {
  6421. items := item.(map[string]interface{})
  6422. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6423. utils.ErrorLog("good_id")
  6424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6425. return
  6426. }
  6427. good_id := int64(items["good_id"].(float64))
  6428. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6429. utils.ErrorLog("good_type_id")
  6430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6431. return
  6432. }
  6433. good_type_id := int64(items["good_type_id"].(float64))
  6434. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6435. utils.ErrorLog("count")
  6436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6437. return
  6438. }
  6439. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6440. commdity_code := items["commdity_code"].(string)
  6441. fmt.Println("commdity", commdity_code)
  6442. prepareGoods := &models.DialysisBeforePrepareGoods{
  6443. GoodTypeId: good_type_id,
  6444. GoodId: good_id,
  6445. Count: count,
  6446. StorehouseId: houseConfig.StorehouseOutInfo,
  6447. }
  6448. beforePrepares = append(beforePrepares, prepareGoods)
  6449. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6450. GoodTypeId: good_type_id,
  6451. GoodId: good_id,
  6452. Count: count,
  6453. StorehouseId: houseConfig.StorehouseOutInfo,
  6454. }
  6455. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6456. prepare := &models.DialysisBeforePrepare{
  6457. GoodTypeId: good_type_id,
  6458. GoodId: good_id,
  6459. Count: count,
  6460. PatientId: patient_id,
  6461. RecordDate: record_time,
  6462. UserOrgId: adminUser.Org.Id,
  6463. Status: 1,
  6464. Ctime: time.Now().Unix(),
  6465. Creater: adminUser.AdminUser.Id,
  6466. CommdityCode: commdity_code,
  6467. StorehouseId: houseConfig.StorehouseOutInfo,
  6468. }
  6469. dialysisBefor = append(dialysisBefor, prepare)
  6470. }
  6471. }
  6472. //查询是否有库存
  6473. for _, item := range dialysisBefor {
  6474. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6475. if err == gorm.ErrRecordNotFound {
  6476. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6477. c.ServeSuccessJSON(map[string]interface{}{
  6478. "message": "1",
  6479. "good_name": goodObj.GoodName,
  6480. "specification_name": goodObj.SpecificationName,
  6481. })
  6482. return
  6483. }
  6484. if err != nil {
  6485. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6486. c.ServeSuccessJSON(map[string]interface{}{
  6487. "message": "1",
  6488. "good_name": goodObj.GoodName,
  6489. "specification_name": goodObj.SpecificationName,
  6490. })
  6491. return
  6492. }
  6493. }
  6494. fmt.Println("active-----------------------", active)
  6495. fmt.Println("len(goods)-----------------------", len(goods))
  6496. //新增
  6497. if active == 1 && len(goods) > 0 {
  6498. for _, item := range dialysisBefor {
  6499. dialyPrepareOne := models.DialysisBeforePrepare{
  6500. GoodTypeId: item.GoodTypeId,
  6501. GoodId: item.GoodId,
  6502. PatientId: item.PatientId,
  6503. RecordDate: item.RecordDate,
  6504. UserOrgId: item.UserOrgId,
  6505. Count: item.Count,
  6506. Ctime: time.Now().Unix(),
  6507. Creater: item.Creater,
  6508. CommdityCode: item.CommdityCode,
  6509. Status: 1,
  6510. StorehouseId: houseConfig.StorehouseOutInfo,
  6511. }
  6512. //先清除再插入
  6513. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6514. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  6515. //查询默认仓库
  6516. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6517. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6518. var total_count int64
  6519. for _, it := range stockList {
  6520. total_count += it.StockCount
  6521. }
  6522. //基础库插入数据
  6523. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6524. //更新库存
  6525. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6526. var flush_count int64
  6527. for _, it := range goodList {
  6528. flush_count += it.StockCount
  6529. }
  6530. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6531. }
  6532. if err == nil {
  6533. c.ServeSuccessJSON(map[string]interface{}{
  6534. "msg": "保存成功",
  6535. "message": "2",
  6536. })
  6537. return
  6538. } else {
  6539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6540. return
  6541. }
  6542. }
  6543. if len(beforePrepares) > 0 && active == 2 {
  6544. for _, item := range beforePrepares {
  6545. //1.查看该患者该耗材型号最后一次出库数量
  6546. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6547. //判断当前出库数量和最后一次出库数量的大小
  6548. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  6549. if item.Count <= goodInfo.Count {
  6550. //退库
  6551. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  6552. //查询今日出库数据
  6553. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6554. for _, it := range list {
  6555. prepare := models.DialysisBeforePrepare{
  6556. UserOrgId: it.OrgId,
  6557. PatientId: patient_id,
  6558. RecordDate: it.RecordTime,
  6559. GoodId: it.GoodId,
  6560. GoodTypeId: it.GoodTypeId,
  6561. Count: it.Count,
  6562. Ctime: time.Now().Unix(),
  6563. Creater: adminUser.AdminUser.Id,
  6564. Status: 1,
  6565. StorehouseId: houseConfig.StorehouseOutInfo,
  6566. }
  6567. //删除准备表数据
  6568. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6569. service.CreateDialysisBeforePrepareOne(&prepare)
  6570. }
  6571. }
  6572. var last_total int64
  6573. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6574. if item.Count >= goodInfo.Count {
  6575. //查询当前批次当前耗材最后一条出库数据
  6576. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6577. //计算当前出库和最后一次出库数据相差数据
  6578. last_total = item.Count - lastOutInfo.Count
  6579. //查询该批次剩余库存
  6580. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  6581. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  6582. if lastInfo.StockCount >= last_total {
  6583. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6584. //查询今日出库数据
  6585. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6586. for _, it := range list {
  6587. prepare := models.DialysisBeforePrepare{
  6588. UserOrgId: it.OrgId,
  6589. PatientId: patient_id,
  6590. RecordDate: it.RecordTime,
  6591. GoodId: it.GoodId,
  6592. GoodTypeId: it.GoodTypeId,
  6593. Count: it.Count,
  6594. Ctime: time.Now().Unix(),
  6595. Creater: adminUser.AdminUser.Id,
  6596. Status: 1,
  6597. StorehouseId: houseConfig.StorehouseOutInfo,
  6598. }
  6599. //删除准备表数据
  6600. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6601. service.CreateDialysisBeforePrepareOne(&prepare)
  6602. //查询默认仓库
  6603. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6604. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6605. var total_count int64
  6606. for _, it := range stockList {
  6607. total_count += it.StockCount
  6608. }
  6609. //基础库插入数据
  6610. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6611. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6612. var flush_count int64
  6613. for _, it := range goodList {
  6614. flush_count += it.StockCount
  6615. }
  6616. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6617. }
  6618. }
  6619. //如果库存不够,则出库到下一个批次
  6620. if lastInfo.StockCount < last_total {
  6621. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6622. //查询今日出库数据
  6623. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6624. for _, it := range list {
  6625. prepare := models.DialysisBeforePrepare{
  6626. UserOrgId: it.OrgId,
  6627. PatientId: patient_id,
  6628. RecordDate: it.RecordTime,
  6629. GoodId: it.GoodId,
  6630. GoodTypeId: it.GoodTypeId,
  6631. Count: it.Count,
  6632. Ctime: time.Now().Unix(),
  6633. Creater: adminUser.AdminUser.Id,
  6634. Status: 1,
  6635. StorehouseId: houseConfig.StorehouseOutInfo,
  6636. }
  6637. //删除准备表数据
  6638. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6639. service.CreateDialysisBeforePrepareOne(&prepare)
  6640. //查询默认仓库
  6641. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6642. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6643. var total_count int64
  6644. for _, it := range stockList {
  6645. total_count += it.StockCount
  6646. }
  6647. //基础库插入数据
  6648. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6649. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6650. var flush_count int64
  6651. for _, it := range goodList {
  6652. flush_count += it.StockCount
  6653. }
  6654. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6655. }
  6656. if err != nil {
  6657. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6658. c.ServeSuccessJSON(map[string]interface{}{
  6659. "message": "1",
  6660. "good_name": goodObj.GoodName,
  6661. "specification_name": goodObj.SpecificationName,
  6662. })
  6663. return
  6664. }
  6665. }
  6666. }
  6667. if err != nil {
  6668. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6669. c.ServeSuccessJSON(map[string]interface{}{
  6670. "message": "1",
  6671. "good_name": goodObj.GoodName,
  6672. "specification_name": goodObj.SpecificationName,
  6673. })
  6674. return
  6675. }
  6676. }
  6677. }
  6678. }
  6679. var errs error
  6680. if errs == nil {
  6681. c.ServeSuccessJSON(map[string]interface{}{
  6682. "msg": "提交成功",
  6683. "message": "2",
  6684. "good_name": "",
  6685. "specification_name": "",
  6686. })
  6687. return
  6688. } else {
  6689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6690. return
  6691. }
  6692. }
  6693. func (c *DialysisAPIController) CreateStockOutInfo() {
  6694. patient_id, _ := c.GetInt64("patient_id", 0)
  6695. record_date := c.GetString("record_time")
  6696. if patient_id <= 0 {
  6697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6698. return
  6699. }
  6700. adminInfo := c.GetMobileAdminUserInfo()
  6701. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  6702. timeLayout := "2006-01-02"
  6703. loc, _ := time.LoadLocation("Local")
  6704. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6705. record_time := theRecordTime.Unix()
  6706. // 查询信息规挡的设置天数
  6707. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6708. if infor.ID > 0 && infor.WeekDay > 0 {
  6709. var cha_time int64
  6710. timeNowStr := time.Now().Format("2006-01-02")
  6711. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6712. //今日的日期减去设置的日期
  6713. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6714. if cha_time >= record_time {
  6715. //查询审核是否允许
  6716. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6717. //申请状态不允许的情况 拒绝修改
  6718. if infor.ApplicationStatus != 1 {
  6719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6720. return
  6721. }
  6722. }
  6723. }
  6724. //创建步骤表
  6725. finish := models.XtDialysisFinish{
  6726. IsFinish: 1,
  6727. UserOrgId: adminInfo.Org.Id,
  6728. Status: 1,
  6729. Ctime: time.Now().Unix(),
  6730. Mtime: 0,
  6731. Module: 11,
  6732. RecordDate: record_time,
  6733. Sourse: 1,
  6734. PatientId: patient_id,
  6735. }
  6736. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6737. if dialysisFinish.ID == 0 {
  6738. service.CreateDialysisFinish(finish)
  6739. }
  6740. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  6741. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6742. //去重
  6743. consumables = RemoveRepeatedGood(consumables)
  6744. if adminInfo.Org.Id == 9919 {
  6745. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6746. //查询是否有库存
  6747. for _, item := range consumables {
  6748. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6749. if item.Count > warehouse.Count {
  6750. goodErrcode := models.XtGoodErrcode{
  6751. UserOrgId: item.UserOrgId,
  6752. Errcode: "自动出库库存不足",
  6753. GoodId: item.GoodId,
  6754. Status: 1,
  6755. Ctime: time.Now().Unix(),
  6756. Mtime: 0,
  6757. Count: 0,
  6758. StockCount: 0,
  6759. Creater: creator,
  6760. BatchNumberId: warehouse.ID,
  6761. WarehouseOutId: 0,
  6762. }
  6763. service.CreateGoodErrcode(goodErrcode)
  6764. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6765. c.ServeSuccessJSON(map[string]interface{}{
  6766. "message": "1",
  6767. "good_name": goodObj.GoodName,
  6768. "specification_name": goodObj.SpecificationName,
  6769. })
  6770. return
  6771. }
  6772. }
  6773. //查询是否有出库单
  6774. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6775. if err == gorm.ErrRecordNotFound {
  6776. //没有记录,则创建出库单
  6777. timeStr := time.Now().Format("2006-01-02")
  6778. timeArr := strings.Split(timeStr, "-")
  6779. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6780. total = total + 1
  6781. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6782. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6783. number = number + total
  6784. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6785. creater := adminInfo.AdminUser.Id
  6786. warehouseOut := models.WarehouseOut{
  6787. WarehouseOutOrderNumber: warehousing_out_order,
  6788. OperationTime: time.Now().Unix(),
  6789. OrgId: adminInfo.Org.Id,
  6790. Creater: creater,
  6791. Ctime: time.Now().Unix(),
  6792. Status: 1,
  6793. WarehouseOutTime: record_time,
  6794. Dealer: 0,
  6795. Manufacturer: 0,
  6796. Type: 1,
  6797. IsSys: 1,
  6798. StorehouseId: houseConfig.StorehouseOutInfo,
  6799. IsCheck: 1,
  6800. }
  6801. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  6802. if err != nil {
  6803. goodErrcode := models.XtGoodErrcode{
  6804. UserOrgId: adminInfo.Org.Id,
  6805. Errcode: "创建出库单失败",
  6806. GoodId: 0,
  6807. Status: 1,
  6808. Ctime: time.Now().Unix(),
  6809. Mtime: 0,
  6810. Count: 0,
  6811. StockCount: 0,
  6812. Creater: creator,
  6813. BatchNumberId: 0,
  6814. WarehouseOutId: 0,
  6815. }
  6816. service.CreateGoodErrcode(goodErrcode)
  6817. utils.TraceLog("创建出库单失败 err = %v", err)
  6818. } else {
  6819. for _, item := range consumables {
  6820. //出库
  6821. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6822. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6823. if err == nil {
  6824. goodErrcode := models.XtGoodErrcode{
  6825. UserOrgId: adminInfo.Org.Id,
  6826. Errcode: "自动出库接口报错",
  6827. GoodId: 0,
  6828. Status: 1,
  6829. Ctime: time.Now().Unix(),
  6830. Mtime: 0,
  6831. Count: 0,
  6832. StockCount: 0,
  6833. Creater: creator,
  6834. BatchNumberId: 0,
  6835. WarehouseOutId: 0,
  6836. }
  6837. service.CreateGoodErrcode(goodErrcode)
  6838. utils.TraceLog("创建出库单失败 err = %v", err)
  6839. }
  6840. //查询
  6841. //出库数量相加
  6842. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6843. if errs != nil {
  6844. goodErrcode := models.XtGoodErrcode{
  6845. UserOrgId: item.UserOrgId,
  6846. Errcode: "创建剩余库存字段报错",
  6847. GoodId: item.GoodId,
  6848. Status: 1,
  6849. Ctime: time.Now().Unix(),
  6850. Mtime: 0,
  6851. Count: 0,
  6852. StockCount: 0,
  6853. Creater: creater,
  6854. BatchNumberId: 0,
  6855. WarehouseOutId: 0,
  6856. }
  6857. service.CreateGoodErrcode(goodErrcode)
  6858. }
  6859. }
  6860. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6861. if len(list) == 0 {
  6862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6863. return
  6864. }
  6865. for _, item := range list {
  6866. prepare := models.DialysisBeforePrepare{
  6867. UserOrgId: adminInfo.Org.Id,
  6868. PatientId: patient_id,
  6869. RecordDate: record_time,
  6870. GoodId: item.GoodId,
  6871. GoodTypeId: item.GoodTypeId,
  6872. Count: item.Count,
  6873. Creater: adminInfo.AdminUser.Id,
  6874. Status: 1,
  6875. Ctime: time.Now().Unix(),
  6876. StorehouseId: houseConfig.StorehouseOutInfo,
  6877. }
  6878. //清空准备表数据
  6879. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6880. if err != nil {
  6881. goodErrcode := models.XtGoodErrcode{
  6882. UserOrgId: item.OrgId,
  6883. Errcode: "自动出库清空准备表数据报错",
  6884. GoodId: item.GoodId,
  6885. Status: 1,
  6886. Ctime: time.Now().Unix(),
  6887. Mtime: 0,
  6888. Count: 0,
  6889. StockCount: 0,
  6890. Creater: creater,
  6891. BatchNumberId: 0,
  6892. WarehouseOutId: 0,
  6893. }
  6894. service.CreateGoodErrcode(goodErrcode)
  6895. }
  6896. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6897. if errs != nil {
  6898. goodErrcode := models.XtGoodErrcode{
  6899. UserOrgId: item.OrgId,
  6900. Errcode: "自动出库创建准备表数据报错",
  6901. GoodId: item.GoodId,
  6902. Status: 1,
  6903. Ctime: time.Now().Unix(),
  6904. Mtime: 0,
  6905. Count: 0,
  6906. StockCount: 0,
  6907. Creater: creater,
  6908. BatchNumberId: 0,
  6909. WarehouseOutId: 0,
  6910. }
  6911. service.CreateGoodErrcode(goodErrcode)
  6912. }
  6913. //查询默认仓库
  6914. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6915. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6916. var total_count int64
  6917. for _, it := range stockList {
  6918. total_count += it.StockCount
  6919. }
  6920. //基础库插入数据
  6921. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6922. if errcodes != nil {
  6923. goodErrcode := models.XtGoodErrcode{
  6924. UserOrgId: item.OrgId,
  6925. Errcode: "自动出库基础库插入数据",
  6926. GoodId: item.GoodId,
  6927. Status: 1,
  6928. Ctime: time.Now().Unix(),
  6929. Mtime: 0,
  6930. Count: 0,
  6931. StockCount: 0,
  6932. Creater: creater,
  6933. BatchNumberId: 0,
  6934. WarehouseOutId: 0,
  6935. }
  6936. service.CreateGoodErrcode(goodErrcode)
  6937. }
  6938. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6939. var flush_count int64
  6940. for _, it := range goodList {
  6941. flush_count += it.StockCount
  6942. }
  6943. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6944. if errsss != nil {
  6945. goodErrcode := models.XtGoodErrcode{
  6946. UserOrgId: item.OrgId,
  6947. Errcode: "自动出库剩余库存更新数据",
  6948. GoodId: item.GoodId,
  6949. Status: 1,
  6950. Ctime: time.Now().Unix(),
  6951. Mtime: 0,
  6952. Count: 0,
  6953. StockCount: 0,
  6954. Creater: creater,
  6955. BatchNumberId: 0,
  6956. WarehouseOutId: 0,
  6957. }
  6958. service.CreateGoodErrcode(goodErrcode)
  6959. }
  6960. }
  6961. }
  6962. //
  6963. } else if err == nil {
  6964. for _, item := range consumables {
  6965. //出库
  6966. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6967. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6968. if err != nil {
  6969. goodErrcode := models.XtGoodErrcode{
  6970. UserOrgId: adminInfo.Org.Id,
  6971. Errcode: "自动出库接口报错",
  6972. GoodId: 0,
  6973. Status: 1,
  6974. Ctime: time.Now().Unix(),
  6975. Mtime: 0,
  6976. Count: 0,
  6977. StockCount: 0,
  6978. Creater: creator,
  6979. BatchNumberId: 0,
  6980. WarehouseOutId: 0,
  6981. }
  6982. service.CreateGoodErrcode(goodErrcode)
  6983. }
  6984. //出库数量相加
  6985. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6986. if errss != nil {
  6987. goodErrcode := models.XtGoodErrcode{
  6988. UserOrgId: item.UserOrgId,
  6989. Errcode: "创建剩余库存字段报错",
  6990. GoodId: item.GoodId,
  6991. Status: 1,
  6992. Ctime: time.Now().Unix(),
  6993. Mtime: time.Now().Unix(),
  6994. Count: 0,
  6995. StockCount: 0,
  6996. Creater: item.Creater,
  6997. BatchNumberId: 0,
  6998. WarehouseOutId: 0,
  6999. }
  7000. service.CreateGoodErrcode(goodErrcode)
  7001. }
  7002. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7003. if len(list) == 0 {
  7004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7005. return
  7006. }
  7007. for _, item := range list {
  7008. prepare := models.DialysisBeforePrepare{
  7009. UserOrgId: adminInfo.Org.Id,
  7010. PatientId: patient_id,
  7011. RecordDate: record_time,
  7012. GoodId: item.GoodId,
  7013. GoodTypeId: item.GoodTypeId,
  7014. Count: item.Count,
  7015. Creater: adminInfo.AdminUser.Id,
  7016. Status: 1,
  7017. Ctime: time.Now().Unix(),
  7018. StorehouseId: houseConfig.StorehouseOutInfo,
  7019. }
  7020. //清空准备表数据
  7021. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7022. if errs != nil {
  7023. goodErrcode := models.XtGoodErrcode{
  7024. UserOrgId: adminInfo.Org.Id,
  7025. Errcode: "自动出库清空准备表数据报错",
  7026. GoodId: 0,
  7027. Status: 1,
  7028. Ctime: time.Now().Unix(),
  7029. Mtime: 0,
  7030. Count: 0,
  7031. StockCount: 0,
  7032. Creater: creator,
  7033. BatchNumberId: 0,
  7034. WarehouseOutId: 0,
  7035. }
  7036. service.CreateGoodErrcode(goodErrcode)
  7037. }
  7038. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  7039. if errcodes != nil {
  7040. goodErrcode := models.XtGoodErrcode{
  7041. UserOrgId: adminInfo.Org.Id,
  7042. Errcode: "自动出库创建准备表数据报错",
  7043. GoodId: 0,
  7044. Status: 1,
  7045. Ctime: time.Now().Unix(),
  7046. Mtime: 0,
  7047. Count: 0,
  7048. StockCount: 0,
  7049. Creater: creator,
  7050. BatchNumberId: 0,
  7051. WarehouseOutId: 0,
  7052. }
  7053. service.CreateGoodErrcode(goodErrcode)
  7054. }
  7055. //查询默认仓库
  7056. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7057. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7058. var total_count int64
  7059. for _, it := range stockList {
  7060. total_count += it.StockCount
  7061. }
  7062. //基础库插入数据
  7063. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7064. if errcodes != nil {
  7065. goodErrcode := models.XtGoodErrcode{
  7066. UserOrgId: adminInfo.Org.Id,
  7067. Errcode: "自动出库基础库插入数据报错",
  7068. GoodId: 0,
  7069. Status: 1,
  7070. Ctime: time.Now().Unix(),
  7071. Mtime: 0,
  7072. Count: 0,
  7073. StockCount: 0,
  7074. Creater: creator,
  7075. BatchNumberId: 0,
  7076. WarehouseOutId: 0,
  7077. }
  7078. service.CreateGoodErrcode(goodErrcode)
  7079. }
  7080. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7081. var flush_count int64
  7082. for _, it := range goodList {
  7083. flush_count += it.StockCount
  7084. }
  7085. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7086. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  7087. if errss != nil {
  7088. goodErrcode := models.XtGoodErrcode{
  7089. UserOrgId: item.OrgId,
  7090. Errcode: "自动出库剩余库存更新数据",
  7091. GoodId: item.GoodId,
  7092. Status: 1,
  7093. Ctime: time.Now().Unix(),
  7094. Mtime: 0,
  7095. Count: 0,
  7096. StockCount: 0,
  7097. Creater: creater,
  7098. BatchNumberId: 0,
  7099. WarehouseOutId: 0,
  7100. }
  7101. service.CreateGoodErrcode(goodErrcode)
  7102. }
  7103. }
  7104. }
  7105. }
  7106. c.ServeSuccessJSON(map[string]interface{}{
  7107. "msg": "提交成功",
  7108. "message": "2",
  7109. "good_name": "",
  7110. "specification_name": "",
  7111. })
  7112. return
  7113. }
  7114. if record.IsOpen == 1 {
  7115. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7116. //查询是否有库存
  7117. for _, item := range consumables {
  7118. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  7119. if item.Count > warehouse.Count {
  7120. goodErrcode := models.XtGoodErrcode{
  7121. UserOrgId: item.UserOrgId,
  7122. Errcode: "自动出库库存不足",
  7123. GoodId: item.GoodId,
  7124. Status: 1,
  7125. Ctime: time.Now().Unix(),
  7126. Mtime: 0,
  7127. Count: 0,
  7128. StockCount: 0,
  7129. Creater: creator,
  7130. BatchNumberId: warehouse.ID,
  7131. WarehouseOutId: 0,
  7132. }
  7133. service.CreateGoodErrcode(goodErrcode)
  7134. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7135. c.ServeSuccessJSON(map[string]interface{}{
  7136. "message": "1",
  7137. "good_name": goodObj.GoodName,
  7138. "specification_name": goodObj.SpecificationName,
  7139. })
  7140. return
  7141. }
  7142. }
  7143. //查询是否有出库单
  7144. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7145. if err == gorm.ErrRecordNotFound {
  7146. //没有记录,则创建出库单
  7147. timeStr := time.Now().Format("2006-01-02")
  7148. timeArr := strings.Split(timeStr, "-")
  7149. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7150. total = total + 1
  7151. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7152. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7153. number = number + total
  7154. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7155. creater := adminInfo.AdminUser.Id
  7156. warehouseOut := models.WarehouseOut{
  7157. WarehouseOutOrderNumber: warehousing_out_order,
  7158. OperationTime: time.Now().Unix(),
  7159. OrgId: adminInfo.Org.Id,
  7160. Creater: creater,
  7161. Ctime: time.Now().Unix(),
  7162. Status: 1,
  7163. WarehouseOutTime: record_time,
  7164. Dealer: 0,
  7165. Manufacturer: 0,
  7166. Type: 1,
  7167. IsSys: 1,
  7168. StorehouseId: houseConfig.StorehouseOutInfo,
  7169. IsCheck: 1,
  7170. }
  7171. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  7172. if err != nil {
  7173. goodErrcode := models.XtGoodErrcode{
  7174. UserOrgId: adminInfo.Org.Id,
  7175. Errcode: "创建出库单失败",
  7176. GoodId: 0,
  7177. Status: 1,
  7178. Ctime: time.Now().Unix(),
  7179. Mtime: 0,
  7180. Count: 0,
  7181. StockCount: 0,
  7182. Creater: creator,
  7183. BatchNumberId: 0,
  7184. WarehouseOutId: 0,
  7185. }
  7186. service.CreateGoodErrcode(goodErrcode)
  7187. utils.TraceLog("创建出库单失败 err = %v", err)
  7188. } else {
  7189. for _, item := range consumables {
  7190. //出库
  7191. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  7192. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  7193. if err == nil {
  7194. goodErrcode := models.XtGoodErrcode{
  7195. UserOrgId: adminInfo.Org.Id,
  7196. Errcode: "自动出库接口报错",
  7197. GoodId: 0,
  7198. Status: 1,
  7199. Ctime: time.Now().Unix(),
  7200. Mtime: 0,
  7201. Count: 0,
  7202. StockCount: 0,
  7203. Creater: creator,
  7204. BatchNumberId: 0,
  7205. WarehouseOutId: 0,
  7206. }
  7207. service.CreateGoodErrcode(goodErrcode)
  7208. utils.TraceLog("创建出库单失败 err = %v", err)
  7209. }
  7210. //查询
  7211. //出库数量相加
  7212. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  7213. if errs != nil {
  7214. goodErrcode := models.XtGoodErrcode{
  7215. UserOrgId: item.UserOrgId,
  7216. Errcode: "创建剩余库存字段报错",
  7217. GoodId: item.GoodId,
  7218. Status: 1,
  7219. Ctime: time.Now().Unix(),
  7220. Mtime: 0,
  7221. Count: 0,
  7222. StockCount: 0,
  7223. Creater: creater,
  7224. BatchNumberId: 0,
  7225. WarehouseOutId: 0,
  7226. }
  7227. service.CreateGoodErrcode(goodErrcode)
  7228. }
  7229. }
  7230. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7231. if len(list) == 0 {
  7232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7233. return
  7234. }
  7235. for _, item := range list {
  7236. prepare := models.DialysisBeforePrepare{
  7237. UserOrgId: adminInfo.Org.Id,
  7238. PatientId: patient_id,
  7239. RecordDate: record_time,
  7240. GoodId: item.GoodId,
  7241. GoodTypeId: item.GoodTypeId,
  7242. Count: item.Count,
  7243. Creater: adminInfo.AdminUser.Id,
  7244. Status: 1,
  7245. Ctime: time.Now().Unix(),
  7246. StorehouseId: houseConfig.StorehouseOutInfo,
  7247. }
  7248. //清空准备表数据
  7249. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7250. if err != nil {
  7251. goodErrcode := models.XtGoodErrcode{
  7252. UserOrgId: item.OrgId,
  7253. Errcode: "自动出库清空准备表数据报错",
  7254. GoodId: item.GoodId,
  7255. Status: 1,
  7256. Ctime: time.Now().Unix(),
  7257. Mtime: 0,
  7258. Count: 0,
  7259. StockCount: 0,
  7260. Creater: creater,
  7261. BatchNumberId: 0,
  7262. WarehouseOutId: 0,
  7263. }
  7264. service.CreateGoodErrcode(goodErrcode)
  7265. }
  7266. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  7267. if errs != nil {
  7268. goodErrcode := models.XtGoodErrcode{
  7269. UserOrgId: item.OrgId,
  7270. Errcode: "自动出库创建准备表数据报错",
  7271. GoodId: item.GoodId,
  7272. Status: 1,
  7273. Ctime: time.Now().Unix(),
  7274. Mtime: 0,
  7275. Count: 0,
  7276. StockCount: 0,
  7277. Creater: creater,
  7278. BatchNumberId: 0,
  7279. WarehouseOutId: 0,
  7280. }
  7281. service.CreateGoodErrcode(goodErrcode)
  7282. }
  7283. //查询默认仓库
  7284. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7285. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7286. var total_count int64
  7287. for _, it := range stockList {
  7288. total_count += it.StockCount
  7289. }
  7290. //基础库插入数据
  7291. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7292. if errcodes != nil {
  7293. goodErrcode := models.XtGoodErrcode{
  7294. UserOrgId: item.OrgId,
  7295. Errcode: "自动出库基础库插入数据",
  7296. GoodId: item.GoodId,
  7297. Status: 1,
  7298. Ctime: time.Now().Unix(),
  7299. Mtime: 0,
  7300. Count: 0,
  7301. StockCount: 0,
  7302. Creater: creater,
  7303. BatchNumberId: 0,
  7304. WarehouseOutId: 0,
  7305. }
  7306. service.CreateGoodErrcode(goodErrcode)
  7307. }
  7308. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7309. var flush_count int64
  7310. for _, it := range goodList {
  7311. flush_count += it.StockCount
  7312. }
  7313. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7314. if errsss != nil {
  7315. goodErrcode := models.XtGoodErrcode{
  7316. UserOrgId: item.OrgId,
  7317. Errcode: "自动出库剩余库存更新数据",
  7318. GoodId: item.GoodId,
  7319. Status: 1,
  7320. Ctime: time.Now().Unix(),
  7321. Mtime: 0,
  7322. Count: 0,
  7323. StockCount: 0,
  7324. Creater: creater,
  7325. BatchNumberId: 0,
  7326. WarehouseOutId: 0,
  7327. }
  7328. service.CreateGoodErrcode(goodErrcode)
  7329. }
  7330. }
  7331. }
  7332. //
  7333. } else if err == nil {
  7334. for _, item := range consumables {
  7335. //出库
  7336. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  7337. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  7338. if err != nil {
  7339. goodErrcode := models.XtGoodErrcode{
  7340. UserOrgId: adminInfo.Org.Id,
  7341. Errcode: "自动出库接口报错",
  7342. GoodId: 0,
  7343. Status: 1,
  7344. Ctime: time.Now().Unix(),
  7345. Mtime: 0,
  7346. Count: 0,
  7347. StockCount: 0,
  7348. Creater: creator,
  7349. BatchNumberId: 0,
  7350. WarehouseOutId: 0,
  7351. }
  7352. service.CreateGoodErrcode(goodErrcode)
  7353. }
  7354. //出库数量相加
  7355. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  7356. if errss != nil {
  7357. goodErrcode := models.XtGoodErrcode{
  7358. UserOrgId: item.UserOrgId,
  7359. Errcode: "创建剩余库存字段报错",
  7360. GoodId: item.GoodId,
  7361. Status: 1,
  7362. Ctime: time.Now().Unix(),
  7363. Mtime: time.Now().Unix(),
  7364. Count: 0,
  7365. StockCount: 0,
  7366. Creater: item.Creater,
  7367. BatchNumberId: 0,
  7368. WarehouseOutId: 0,
  7369. }
  7370. service.CreateGoodErrcode(goodErrcode)
  7371. }
  7372. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7373. if len(list) == 0 {
  7374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7375. return
  7376. }
  7377. for _, item := range list {
  7378. prepare := models.DialysisBeforePrepare{
  7379. UserOrgId: adminInfo.Org.Id,
  7380. PatientId: patient_id,
  7381. RecordDate: record_time,
  7382. GoodId: item.GoodId,
  7383. GoodTypeId: item.GoodTypeId,
  7384. Count: item.Count,
  7385. Creater: adminInfo.AdminUser.Id,
  7386. Status: 1,
  7387. Ctime: time.Now().Unix(),
  7388. StorehouseId: houseConfig.StorehouseOutInfo,
  7389. }
  7390. //清空准备表数据
  7391. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7392. if errs != nil {
  7393. goodErrcode := models.XtGoodErrcode{
  7394. UserOrgId: adminInfo.Org.Id,
  7395. Errcode: "自动出库清空准备表数据报错",
  7396. GoodId: 0,
  7397. Status: 1,
  7398. Ctime: time.Now().Unix(),
  7399. Mtime: 0,
  7400. Count: 0,
  7401. StockCount: 0,
  7402. Creater: creator,
  7403. BatchNumberId: 0,
  7404. WarehouseOutId: 0,
  7405. }
  7406. service.CreateGoodErrcode(goodErrcode)
  7407. }
  7408. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  7409. if errcodes != nil {
  7410. goodErrcode := models.XtGoodErrcode{
  7411. UserOrgId: adminInfo.Org.Id,
  7412. Errcode: "自动出库创建准备表数据报错",
  7413. GoodId: 0,
  7414. Status: 1,
  7415. Ctime: time.Now().Unix(),
  7416. Mtime: 0,
  7417. Count: 0,
  7418. StockCount: 0,
  7419. Creater: creator,
  7420. BatchNumberId: 0,
  7421. WarehouseOutId: 0,
  7422. }
  7423. service.CreateGoodErrcode(goodErrcode)
  7424. }
  7425. //查询默认仓库
  7426. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7427. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7428. var total_count int64
  7429. for _, it := range stockList {
  7430. total_count += it.StockCount
  7431. }
  7432. //基础库插入数据
  7433. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7434. if errcodes != nil {
  7435. goodErrcode := models.XtGoodErrcode{
  7436. UserOrgId: adminInfo.Org.Id,
  7437. Errcode: "自动出库基础库插入数据报错",
  7438. GoodId: 0,
  7439. Status: 1,
  7440. Ctime: time.Now().Unix(),
  7441. Mtime: 0,
  7442. Count: 0,
  7443. StockCount: 0,
  7444. Creater: creator,
  7445. BatchNumberId: 0,
  7446. WarehouseOutId: 0,
  7447. }
  7448. service.CreateGoodErrcode(goodErrcode)
  7449. }
  7450. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7451. var flush_count int64
  7452. for _, it := range goodList {
  7453. flush_count += it.StockCount
  7454. }
  7455. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7456. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  7457. if errss != nil {
  7458. goodErrcode := models.XtGoodErrcode{
  7459. UserOrgId: item.OrgId,
  7460. Errcode: "自动出库剩余库存更新数据",
  7461. GoodId: item.GoodId,
  7462. Status: 1,
  7463. Ctime: time.Now().Unix(),
  7464. Mtime: 0,
  7465. Count: 0,
  7466. StockCount: 0,
  7467. Creater: creater,
  7468. BatchNumberId: 0,
  7469. WarehouseOutId: 0,
  7470. }
  7471. service.CreateGoodErrcode(goodErrcode)
  7472. }
  7473. }
  7474. }
  7475. }
  7476. c.ServeSuccessJSON(map[string]interface{}{
  7477. "msg": "提交成功",
  7478. "message": "2",
  7479. "good_name": "",
  7480. "specification_name": "",
  7481. })
  7482. return
  7483. } else {
  7484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  7485. return
  7486. }
  7487. }
  7488. func (c *DialysisAPIController) EditConsumables() {
  7489. patient_id, _ := c.GetInt64("patient_id", 0)
  7490. record_date := c.GetString("record_time")
  7491. if patient_id <= 0 {
  7492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7493. return
  7494. }
  7495. adminInfo := c.GetMobileAdminUserInfo()
  7496. timeLayout := "2006-01-02"
  7497. loc, _ := time.LoadLocation("Local")
  7498. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7499. record_time := theRecordTime.Unix()
  7500. // 查询信息规挡的设置天数
  7501. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7502. if infor.ID > 0 && infor.WeekDay > 0 {
  7503. var cha_time int64
  7504. timeNowStr := time.Now().Format("2006-01-02")
  7505. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7506. //今日的日期减去设置的日期
  7507. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7508. if cha_time >= record_time {
  7509. //查询审核是否允许
  7510. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7511. //申请状态不允许的情况 拒绝修改
  7512. if infor.ApplicationStatus != 1 {
  7513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7514. return
  7515. }
  7516. }
  7517. }
  7518. dataBody := make(map[string]interface{}, 0)
  7519. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7520. if err != nil {
  7521. utils.ErrorLog(err.Error())
  7522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7523. return
  7524. }
  7525. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7526. var beforePrepares []*models.DialysisBeforePrepareGoods
  7527. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7528. var cancelbefor []*models.DialysisBeforePrepareGoods
  7529. var outbefor []*models.DialysisBeforePrepareGoods
  7530. //判断是否开启自动出库
  7531. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7532. if record.IsOpen == 1 {
  7533. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7534. goods, _ := dataBody["goods"].([]interface{})
  7535. if len(goods) > 0 {
  7536. for _, item := range goods {
  7537. items := item.(map[string]interface{})
  7538. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7539. utils.ErrorLog("good_id")
  7540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7541. return
  7542. }
  7543. good_id := int64(items["good_id"].(float64))
  7544. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7545. utils.ErrorLog("good_type_id")
  7546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7547. return
  7548. }
  7549. good_type_id := int64(items["good_type_id"].(float64))
  7550. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7551. utils.ErrorLog("count")
  7552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7553. return
  7554. }
  7555. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7556. commdity_code := items["commdity_code"].(string)
  7557. fmt.Println(commdity_code)
  7558. prepareGoods := &models.DialysisBeforePrepareGoods{
  7559. GoodTypeId: good_type_id,
  7560. GoodId: good_id,
  7561. Count: count,
  7562. StorehouseId: houseConfig.StorehouseOutInfo,
  7563. }
  7564. beforePrepares = append(beforePrepares, prepareGoods)
  7565. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  7566. GoodTypeId: good_type_id,
  7567. GoodId: good_id,
  7568. Count: count,
  7569. StorehouseId: houseConfig.StorehouseOutInfo,
  7570. }
  7571. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  7572. }
  7573. for _, item := range beforePrepares {
  7574. //1.查看该患者该耗材型号最后一次出库数量
  7575. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7576. //判断当前出库数量和最后一次出库数量的大小
  7577. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  7578. if item.Count < goodInfo.Count {
  7579. cancelbefor = append(cancelbefor, item)
  7580. }
  7581. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  7582. if item.Count > goodInfo.Count {
  7583. outbefor = append(outbefor, item)
  7584. }
  7585. //处理编辑耗材新增不了的问题
  7586. if goodInfo.Count == item.Count {
  7587. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  7588. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  7589. }
  7590. }
  7591. if len(cancelbefor) > 0 {
  7592. //退库
  7593. for _, item := range cancelbefor {
  7594. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7595. creater := adminInfo.AdminUser.Id
  7596. //查询该患者当天已经出库的耗材信息
  7597. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  7598. var delete_count int64 = 0
  7599. delete_count = warehouseOutInfos.Count - item.Count
  7600. //增加库存数量
  7601. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  7602. //减少实际出库库存数量
  7603. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  7604. // 删除出库完成后,要增加对应批次的库存数量
  7605. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  7606. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7607. //更新剩余库存
  7608. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7609. var flush_count int64
  7610. for _, it := range goodListOne {
  7611. flush_count += it.StockCount
  7612. }
  7613. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7614. //查询剩余库存
  7615. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7616. var sum_count int64
  7617. for _, item := range goodList {
  7618. sum_count += item.StockCount
  7619. }
  7620. // 在出库记录表里记录退库详情
  7621. warehouseOutInfo := &models.WarehouseOutInfo{
  7622. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7623. WarehouseOutId: warehouseOut.ID,
  7624. Status: 1,
  7625. Ctime: time.Now().Unix(),
  7626. OrgId: adminInfo.Org.Id,
  7627. Type: 1,
  7628. IsSys: 1,
  7629. SysRecordTime: record_time,
  7630. GoodTypeId: item.GoodTypeId,
  7631. GoodId: item.GoodId,
  7632. PatientId: patient_id,
  7633. ConsumableType: 2,
  7634. StorehouseId: houseConfig.StorehouseOutInfo,
  7635. IsCheck: 1,
  7636. OverCount: sum_count,
  7637. }
  7638. warehouseOutInfo.Count = item.Count
  7639. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  7640. warehouseOutInfo.Price = stockInInfo.Price
  7641. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7642. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7643. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7644. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7645. warehouseOutInfo.Number = warehouseOutInfos.Number
  7646. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7647. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7648. //查找当天是否存在出库记录
  7649. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  7650. if errcod == gorm.ErrRecordNotFound {
  7651. service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  7652. //插入详情明细表
  7653. stockFlow := models.VmStockFlow{
  7654. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7655. WarehouseOutId: warehouseOut.ID,
  7656. GoodId: item.GoodId,
  7657. Number: warehouseOutInfos.Number,
  7658. ProductDate: stockInInfo.ProductDate,
  7659. ExpireDate: stockInInfo.ExpiryDate,
  7660. Count: item.Count,
  7661. Price: stockInInfo.Price,
  7662. Status: 1,
  7663. Ctime: record_time,
  7664. UserOrgId: adminInfo.Org.Id,
  7665. Manufacturer: stockInInfo.Manufacturer,
  7666. Dealer: stockInInfo.Dealer,
  7667. LicenseNumber: stockInInfo.LicenseNumber,
  7668. IsEdit: 2,
  7669. Creator: creater,
  7670. SystemTime: record_time,
  7671. ConsumableType: 3,
  7672. WarehousingDetailId: 0,
  7673. IsSys: 1,
  7674. UpdateCreator: creater,
  7675. PatientId: patient_id,
  7676. StorehouseId: houseConfig.StorehouseOutInfo,
  7677. }
  7678. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  7679. if errflow == gorm.ErrRecordNotFound {
  7680. //创建流水表
  7681. err := service.CreateStockFlowOne(stockFlow)
  7682. fmt.Println("err", err)
  7683. } else if errflow == nil {
  7684. //插入详情明细表
  7685. stockFlow := models.VmStockFlow{
  7686. ID: exsit.ID,
  7687. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7688. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7689. WarehouseOutId: warehouseOut.ID,
  7690. GoodId: item.GoodId,
  7691. Number: warehouseOutInfos.Number,
  7692. ProductDate: stockInInfo.ProductDate,
  7693. ExpireDate: stockInInfo.ExpiryDate,
  7694. Count: exsit.Count - delete_count,
  7695. Price: stockInInfo.Price,
  7696. Status: 1,
  7697. Ctime: record_time,
  7698. UserOrgId: adminInfo.Org.Id,
  7699. Manufacturer: stockInInfo.Manufacturer,
  7700. Dealer: stockInInfo.Dealer,
  7701. LicenseNumber: stockInInfo.LicenseNumber,
  7702. IsEdit: 2,
  7703. Creator: creater,
  7704. SystemTime: record_time,
  7705. ConsumableType: 3,
  7706. WarehousingDetailId: 0,
  7707. IsSys: 1,
  7708. UpdateCreator: creater,
  7709. PatientId: patient_id,
  7710. StorehouseId: houseConfig.StorehouseOutInfo,
  7711. }
  7712. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  7713. }
  7714. } else if errcod == nil {
  7715. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  7716. //查询剩余库存
  7717. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7718. var sum_count int64
  7719. for _, item := range goodList {
  7720. sum_count += item.StockCount
  7721. }
  7722. //创建退库单,生成退库数据
  7723. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7724. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  7725. operation_time := time.Now().Unix()
  7726. creater := adminInfo.AdminUser.Id
  7727. //创建退库单
  7728. timeStr := time.Now().Format("2006-01-02")
  7729. timeArr := strings.Split(timeStr, "-")
  7730. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  7731. total = total + 1
  7732. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7733. cancelStock := models.CancelStock{
  7734. OrderNumber: orderNumber,
  7735. OperaTime: operation_time,
  7736. OrgId: adminInfo.Org.Id,
  7737. Creater: creater,
  7738. Ctime: time.Now().Unix(),
  7739. Status: 1,
  7740. ReturnTime: record_time,
  7741. Type: 1,
  7742. StorehouseId: houseConfig.StorehouseOutInfo,
  7743. IsCheck: 1,
  7744. }
  7745. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  7746. if msgerrkonde == gorm.ErrRecordNotFound {
  7747. service.AddSigleCancelStock(&cancelStock)
  7748. }
  7749. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  7750. //查询是否有出库
  7751. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  7752. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7753. deaerler, _ := service.GetDealerById(info.Dealer)
  7754. if info.ID > 0 {
  7755. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  7756. cancelStockInfo := models.CancelStockInfo{
  7757. GoodId: item.GoodId,
  7758. CancelStockId: cancel.ID,
  7759. GoodTypeId: good.GoodTypeId,
  7760. Count: delete_count,
  7761. Price: info.Price,
  7762. Total: 0,
  7763. ProductDate: info.ProductDate,
  7764. ExpiryDate: info.ExpiryDate,
  7765. Ctime: time.Now().Unix(),
  7766. Status: 1,
  7767. OrgId: adminInfo.Org.Id,
  7768. OrderNumber: cancel.OrderNumber,
  7769. Type: 0,
  7770. Dealer: deaerler.DealerName,
  7771. Manufacturer: manufacturer.ManufacturerName,
  7772. Number: info.Number,
  7773. RegisterAccount: "",
  7774. Remark: "",
  7775. WarehouseInfoId: info.WarehouseInfotId,
  7776. PatientId: info.PatientId,
  7777. RecordDate: info.SysRecordTime,
  7778. StorehouseId: houseConfig.StorehouseOutInfo,
  7779. IsCheck: 1,
  7780. }
  7781. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7782. //退库数量增加
  7783. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7784. //查询剩余库存
  7785. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7786. var over_count int64
  7787. for _, it := range goodList {
  7788. over_count += it.StockCount
  7789. }
  7790. flow := models.VmStockFlow{
  7791. WarehousingId: info.WarehouseInfotId,
  7792. GoodId: item.GoodId,
  7793. Number: info.Number,
  7794. LicenseNumber: info.LicenseNumber,
  7795. Count: delete_count,
  7796. UserOrgId: adminInfo.Org.Id,
  7797. PatientId: patient_id,
  7798. SystemTime: info.SysRecordTime,
  7799. ConsumableType: 7,
  7800. IsSys: 0,
  7801. WarehousingOrder: "",
  7802. WarehouseOutId: info.WarehouseOutId,
  7803. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7804. IsEdit: 0,
  7805. CancelStockId: cancel.ID,
  7806. CancelOrderNumber: cancel.OrderNumber,
  7807. Manufacturer: manufacturer.ID,
  7808. Dealer: 0,
  7809. Creator: adminInfo.AdminUser.Id,
  7810. UpdateCreator: 0,
  7811. Status: 1,
  7812. Ctime: record_time,
  7813. Mtime: 0,
  7814. Price: info.Price,
  7815. WarehousingDetailId: info.WarehouseInfotId,
  7816. WarehouseOutDetailId: info.ID,
  7817. CancelOutDetailId: cancelInfo.ID,
  7818. ProductDate: info.ProductDate,
  7819. ExpireDate: info.ExpiryDate,
  7820. StorehouseId: houseConfig.StorehouseOutInfo,
  7821. OverCount: over_count,
  7822. }
  7823. service.CreateStockFlowOne(flow)
  7824. }
  7825. }
  7826. //更改自动出库的表格
  7827. details := models.BloodAutomaticReduceDetail{
  7828. WarehouseOutId: warehouseOutInfo.ID,
  7829. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7830. PatientId: patient_id,
  7831. Ctime: time.Now().Unix(),
  7832. Mtime: time.Now().Unix(),
  7833. Status: 1,
  7834. RecordTime: record_time,
  7835. OrgId: adminInfo.Org.Id,
  7836. GoodId: item.GoodId,
  7837. GoodTypeId: item.GoodTypeId,
  7838. Count: item.Count,
  7839. StorehouseId: houseConfig.StorehouseOutInfo,
  7840. }
  7841. //查询当天耗材是否已经存在数据
  7842. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7843. if errcode == gorm.ErrRecordNotFound {
  7844. service.CreateAutoReduceRecord(&details)
  7845. } else if errcode == nil {
  7846. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7847. service.CreateAutoReduceRecord(&details)
  7848. }
  7849. //查询默认仓库
  7850. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7851. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7852. var total_count int64
  7853. for _, it := range stockList {
  7854. total_count += it.StockCount
  7855. }
  7856. //基础库插入数据
  7857. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7858. }
  7859. }
  7860. if len(outbefor) > 0 {
  7861. //出库
  7862. for _, item := range outbefor {
  7863. var last_total int64
  7864. //1.查看该患者该耗材型号最后一次出库数量
  7865. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7866. //计算当前出库和最后一次出库数据相差数据
  7867. last_total = item.Count - goodInfoOne.Count
  7868. //查询该耗材的总库存
  7869. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  7870. // 如果库存差大于剩余库存则提示库存不足
  7871. if last_total > wareinfo.StockCount {
  7872. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7873. c.ServeSuccessJSON(map[string]interface{}{
  7874. "message": "1",
  7875. "good_name": goodObj.GoodName,
  7876. "specification_name": goodObj.SpecificationName,
  7877. })
  7878. return
  7879. } else {
  7880. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7881. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7882. if err == gorm.ErrRecordNotFound {
  7883. //没有记录,则创建出库单
  7884. timeStr := time.Now().Format("2006-01-02")
  7885. timeArr := strings.Split(timeStr, "-")
  7886. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7887. total = total + 1
  7888. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7889. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7890. number = number + total
  7891. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7892. warehouseOut := models.WarehouseOut{
  7893. WarehouseOutOrderNumber: warehousing_out_order,
  7894. OperationTime: time.Now().Unix(),
  7895. OrgId: adminInfo.Org.Id,
  7896. Creater: adminInfo.AdminUser.Id,
  7897. Ctime: time.Now().Unix(),
  7898. Status: 1,
  7899. WarehouseOutTime: record_time,
  7900. Dealer: 0,
  7901. Manufacturer: 0,
  7902. Type: 1,
  7903. IsSys: 1,
  7904. StorehouseId: houseConfig.StorehouseOutInfo,
  7905. IsCheck: 1,
  7906. }
  7907. service.AddSigleWarehouseOutOne(&warehouseOut)
  7908. }
  7909. //出库
  7910. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  7911. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7912. //1.查看该患者该耗材型号最后一次出库数量
  7913. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7914. prepare := models.DialysisBeforePrepare{
  7915. UserOrgId: adminInfo.Org.Id,
  7916. PatientId: patient_id,
  7917. RecordDate: record_time,
  7918. GoodId: item.GoodId,
  7919. GoodTypeId: item.GoodTypeId,
  7920. Count: item.Count - goodInfoTwo.Count,
  7921. Ctime: time.Now().Unix(),
  7922. Mtime: 0,
  7923. Creater: adminInfo.AdminUser.Id,
  7924. Modifier: adminInfo.AdminUser.Id,
  7925. Status: 1,
  7926. CommdityCode: "",
  7927. NewCount: 0,
  7928. ProjectId: 0,
  7929. StorehouseId: houseConfig.StorehouseOutInfo,
  7930. }
  7931. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  7932. //增加出库数量
  7933. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  7934. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7935. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7936. var total_count int64
  7937. for _, it := range stockList {
  7938. total_count += it.StockCount
  7939. }
  7940. //基础库插入数据
  7941. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7942. //剩余库存
  7943. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7944. var flush_count int64
  7945. for _, it := range goodList {
  7946. flush_count += it.StockCount
  7947. }
  7948. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7949. }
  7950. }
  7951. }
  7952. //查询今日出库数据
  7953. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7954. for _, it := range list {
  7955. prepare := models.DialysisBeforePrepare{
  7956. UserOrgId: it.OrgId,
  7957. PatientId: patient_id,
  7958. RecordDate: it.RecordTime,
  7959. GoodId: it.GoodId,
  7960. GoodTypeId: it.GoodTypeId,
  7961. Count: it.Count,
  7962. Ctime: time.Now().Unix(),
  7963. Creater: adminInfo.AdminUser.Id,
  7964. Status: 1,
  7965. StorehouseId: houseConfig.StorehouseOutInfo,
  7966. ProjectId: it.ProjectId,
  7967. }
  7968. //删除准备表数据
  7969. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  7970. service.CreateDialysisBeforePrepareOne(&prepare)
  7971. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7972. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7973. var total_count int64
  7974. for _, it := range stockList {
  7975. total_count += it.StockCount
  7976. }
  7977. //基础库插入数据
  7978. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  7979. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  7980. var flush_count int64
  7981. for _, it := range goodList {
  7982. flush_count += it.StockCount
  7983. }
  7984. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  7985. }
  7986. }
  7987. }
  7988. //更新自动出库的地方
  7989. var errs error
  7990. if errs == nil {
  7991. c.ServeSuccessJSON(map[string]interface{}{
  7992. "msg": "修改成功",
  7993. "message": "2",
  7994. "good_name": "",
  7995. "specification_name": "",
  7996. })
  7997. return
  7998. } else {
  7999. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8000. return
  8001. }
  8002. }
  8003. }
  8004. func (c *DialysisAPIController) GetDialysisGoods() {
  8005. schedualDate := c.GetString("schedule_date")
  8006. schedule_type, _ := c.GetInt64("schedule_type")
  8007. partition_id, _ := c.GetInt64("partition_id")
  8008. page, _ := c.GetInt("page")
  8009. patient_id, _ := c.GetInt64("patient_id")
  8010. schedualEndDate := int64(0)
  8011. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  8012. if parseDateErr != nil && len(schedualDate) != 0 {
  8013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8014. return
  8015. }
  8016. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  8017. if parseDateErr != nil && len(schedualDate) != 0 {
  8018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8019. return
  8020. }
  8021. schedualEndDate = endDate.Unix()
  8022. adminUser := c.GetMobileAdminUserInfo()
  8023. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  8024. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  8025. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  8026. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  8027. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  8028. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  8029. //获取当天该病人的透析处方
  8030. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  8031. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  8032. if err == gorm.ErrRecordNotFound {
  8033. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  8034. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  8035. if patient_id != 0 {
  8036. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  8037. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  8038. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  8039. //获取患者总的出库数据
  8040. item.LastAutomaticReduceDetail = goodUser
  8041. item.LastDialysisBeforePrepare = lastGoodUserDetial
  8042. item.Project = project
  8043. for _, it := range item.AutomaticReduceDetail {
  8044. var total int64
  8045. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  8046. for _, its := range auto {
  8047. total += its.Count
  8048. }
  8049. it.Count = total
  8050. }
  8051. }
  8052. }
  8053. c.ServeSuccessJSON(map[string]interface{}{
  8054. "dialysis_goods": dialysisGoods,
  8055. "good_type": goodTypes,
  8056. "total": total,
  8057. "prescribe": prescribe,
  8058. "good_info": good_info,
  8059. "warehouseOutList": warehouseOutList,
  8060. "config": config,
  8061. "outConfig": outConfig,
  8062. "settleConfig": settleConfig,
  8063. })
  8064. return
  8065. } else if err == nil {
  8066. //获取当天排班的每个患者的库存使用情况
  8067. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  8068. //获取患者总的出库数据
  8069. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  8070. if patient_id != 0 {
  8071. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  8072. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  8073. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  8074. item.Project = project
  8075. item.LastAutomaticReduceDetail = goodUser
  8076. item.LastDialysisBeforePrepare = lastGoodUserDetial
  8077. for _, it := range item.AutomaticReduceDetail {
  8078. var total int64
  8079. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  8080. for _, its := range auto {
  8081. total += its.Count
  8082. }
  8083. it.Count = total
  8084. }
  8085. }
  8086. }
  8087. if err == nil {
  8088. c.ServeSuccessJSON(map[string]interface{}{
  8089. "dialysis_goods": dialysisGoods,
  8090. "good_type": goodTypes,
  8091. "total": total,
  8092. "prescribe": prescribe,
  8093. "good_info": good_info,
  8094. "project": project,
  8095. "warehouseOutList": warehouseOutList,
  8096. "config": config,
  8097. "outConfig": outConfig,
  8098. "settleConfig": settleConfig,
  8099. })
  8100. return
  8101. } else {
  8102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8103. return
  8104. }
  8105. } else if err != nil {
  8106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8107. return
  8108. }
  8109. }
  8110. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  8111. start_time := c.GetString("start_time")
  8112. end_time := c.GetString("end_time")
  8113. timeLayout := "2006-01-02"
  8114. loc, _ := time.LoadLocation("Local")
  8115. var theStartTime int64
  8116. if len(start_time) > 0 {
  8117. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8118. if err != nil {
  8119. utils.ErrorLog(err.Error())
  8120. }
  8121. theStartTime = theTime.Unix()
  8122. }
  8123. var theEndtTime int64
  8124. if len(end_time) > 0 {
  8125. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8126. if err != nil {
  8127. utils.ErrorLog(err.Error())
  8128. }
  8129. theEndtTime = theTime.Unix()
  8130. }
  8131. adminUser := c.GetMobileAdminUserInfo()
  8132. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  8133. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  8134. if err == nil {
  8135. c.ServeSuccessJSON(map[string]interface{}{
  8136. "stock_out": outInfo,
  8137. "stockCount": stockCount,
  8138. })
  8139. return
  8140. } else {
  8141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8142. return
  8143. }
  8144. }
  8145. func (c *DialysisAPIController) GetStockInGoodInfo() {
  8146. patient_id, _ := c.GetInt64("patient_id", 0)
  8147. record_time := c.GetString("record_time")
  8148. adminUser := c.GetMobileAdminUserInfo()
  8149. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  8150. if parseDateErr != nil && len(record_time) != 0 {
  8151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8152. return
  8153. }
  8154. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  8155. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  8156. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  8157. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  8158. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  8159. //获取今日患者的透析处方参数
  8160. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  8161. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  8162. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  8163. c.ServeSuccessJSON(map[string]interface{}{
  8164. "good_type": goodTypes,
  8165. "good_user": goodUser,
  8166. "good_info": good_info,
  8167. "last_good_user": lastGoodUserDetial,
  8168. "project": project,
  8169. "prescription": prescribe,
  8170. "outInfo": outInfo,
  8171. "configs": configs,
  8172. })
  8173. return
  8174. }
  8175. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  8176. patient_id, _ := c.GetInt64("patient_id", 0)
  8177. record_date := c.GetString("record_time")
  8178. timeLayout := "2006-01-02"
  8179. loc, _ := time.LoadLocation("Local")
  8180. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  8181. record_time := theRecordTime.Unix()
  8182. adminInfo := c.GetMobileAdminUserInfo()
  8183. dataBody := make(map[string]interface{}, 0)
  8184. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8185. if err != nil {
  8186. utils.ErrorLog(err.Error())
  8187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8188. return
  8189. }
  8190. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8191. var beforePrepares []*models.DialysisBeforePrepareGoods
  8192. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  8193. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  8194. goods, _ := dataBody["goods"].([]interface{})
  8195. if len(goods) > 0 {
  8196. for _, item := range goods {
  8197. items := item.(map[string]interface{})
  8198. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  8199. utils.ErrorLog("good_id")
  8200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8201. return
  8202. }
  8203. good_id := int64(items["good_id"].(float64))
  8204. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  8205. utils.ErrorLog("good_type_id")
  8206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8207. return
  8208. }
  8209. good_type_id := int64(items["good_type_id"].(float64))
  8210. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  8211. utils.ErrorLog("count")
  8212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8213. return
  8214. }
  8215. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  8216. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  8217. utils.ErrorLog("project_id")
  8218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8219. return
  8220. }
  8221. project_id := int64(items["project_id"].(float64))
  8222. new_count := int64(items["new_count"].(float64))
  8223. old_count := int64(items["old_count"].(float64))
  8224. prepare := &models.DialysisBeforePrepareGoods{
  8225. GoodId: good_id,
  8226. GoodTypeId: good_type_id,
  8227. Count: count,
  8228. ProjectId: project_id,
  8229. StorehouseId: houseConfig.StorehouseOutInfo,
  8230. NewCount: new_count,
  8231. OldCount: old_count,
  8232. }
  8233. beforePrepares = append(beforePrepares, prepare)
  8234. newPrepare := &models.NewDialysisBeforePrepareGoods{
  8235. GoodId: good_id,
  8236. GoodTypeId: good_type_id,
  8237. Count: count,
  8238. ProjectId: project_id,
  8239. StorehouseId: houseConfig.StorehouseOutInfo,
  8240. NewCount: new_count,
  8241. OldCount: old_count,
  8242. }
  8243. newBeforePrepares = append(newBeforePrepares, newPrepare)
  8244. }
  8245. }
  8246. }
  8247. //查询是否有库存
  8248. for _, item := range beforePrepares {
  8249. if item.NewCount > 0 {
  8250. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8251. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  8252. if item.Count > warehouse.Count {
  8253. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  8254. c.ServeSuccessJSON(map[string]interface{}{
  8255. "message": "1",
  8256. "good_name": goodObj.GoodName,
  8257. "specification_name": goodObj.SpecificationName,
  8258. })
  8259. return
  8260. }
  8261. }
  8262. }
  8263. // 查询信息规挡的设置天数
  8264. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  8265. if infor.ID > 0 && infor.WeekDay > 0 {
  8266. var cha_time int64
  8267. timeNowStr := time.Now().Format("2006-01-02")
  8268. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  8269. //今日的日期减去设置的日期
  8270. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  8271. if cha_time >= record_time {
  8272. //查询审核是否允许
  8273. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  8274. //申请状态不允许的情况 拒绝修改
  8275. if infor.ApplicationStatus != 1 {
  8276. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  8277. return
  8278. }
  8279. }
  8280. }
  8281. //出库逻辑
  8282. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  8283. if err != nil {
  8284. utils.ErrorLog(err.Error())
  8285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8286. return
  8287. }
  8288. finish := models.XtDialysisFinish{
  8289. IsFinish: 1,
  8290. UserOrgId: adminInfo.Org.Id,
  8291. Status: 1,
  8292. Ctime: time.Now().Unix(),
  8293. Mtime: 0,
  8294. Module: 11,
  8295. RecordDate: record_time,
  8296. Sourse: 1,
  8297. PatientId: patient_id,
  8298. }
  8299. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  8300. if dialysisFinish.ID == 0 {
  8301. service.CreateDialysisFinish(finish)
  8302. }
  8303. //查询当天出库的数据
  8304. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  8305. for _, item := range list {
  8306. prepare := models.DialysisBeforePrepare{
  8307. UserOrgId: item.OrgId,
  8308. PatientId: item.PatientId,
  8309. RecordDate: item.RecordTime,
  8310. GoodId: item.GoodId,
  8311. GoodTypeId: item.GoodTypeId,
  8312. Count: item.Count,
  8313. Creater: adminInfo.AdminUser.Id,
  8314. Status: 1,
  8315. Ctime: time.Now().Unix(),
  8316. ProjectId: item.ProjectId,
  8317. StorehouseId: houseConfig.StorehouseOutInfo,
  8318. }
  8319. //清空准备表的数据
  8320. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  8321. //插入准备表数据
  8322. service.CreateDialysisBeforePrepareOne(&prepare)
  8323. //查询默认仓库
  8324. //查询默认仓库
  8325. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8326. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  8327. var total_count int64
  8328. for _, it := range stockList {
  8329. total_count += it.StockCount
  8330. }
  8331. //基础库插入数据
  8332. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  8333. ////更新剩余库存
  8334. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  8335. var flush_count int64
  8336. for _, it := range goodList {
  8337. flush_count += it.StockCount
  8338. }
  8339. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  8340. if errs != nil {
  8341. goodErrcode := models.XtGoodErrcode{
  8342. UserOrgId: item.OrgId,
  8343. Errcode: "手动出库更新剩余出库失败",
  8344. GoodId: item.GoodId,
  8345. Status: 1,
  8346. Ctime: time.Now().Unix(),
  8347. Mtime: 0,
  8348. Count: 0,
  8349. StockCount: 0,
  8350. Creater: adminInfo.AdminUser.Id,
  8351. BatchNumberId: 0,
  8352. WarehouseOutId: 0,
  8353. }
  8354. service.CreateGoodErrcode(goodErrcode)
  8355. }
  8356. }
  8357. //更新自动出库的地方
  8358. var errs error
  8359. if errs == nil {
  8360. c.ServeSuccessJSON(map[string]interface{}{
  8361. "msg": "修改成功",
  8362. "message": "2",
  8363. "good_name": "",
  8364. "specification_name": "",
  8365. })
  8366. return
  8367. } else {
  8368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8369. return
  8370. }
  8371. }
  8372. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  8373. newArr = make([]*models.DialysisBeforePrepare, 0)
  8374. for i := 0; i < len(arr); i++ {
  8375. repeat := false
  8376. for j := i + 1; j < len(arr); j++ {
  8377. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  8378. repeat = true
  8379. break
  8380. }
  8381. }
  8382. if !repeat {
  8383. newArr = append(newArr, arr[i])
  8384. }
  8385. }
  8386. return
  8387. }
  8388. func (c *DialysisAPIController) GetAllDrug() {
  8389. patient_id, _ := c.GetInt64("patient_id", 0)
  8390. adminInfo := c.GetMobileAdminUserInfo()
  8391. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  8392. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  8393. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  8394. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  8395. c.ServeSuccessJSON(map[string]interface{}{
  8396. "base_drug_config": drugStockConfig,
  8397. "private_drug_config": privateDrugConfig,
  8398. "base_drug_list": drugList,
  8399. "private_drug_list": privateDrugList,
  8400. })
  8401. }
  8402. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  8403. newArr = make([]*models.DialysisBeforePrepare, 0)
  8404. for i := 0; i < len(arr); i++ {
  8405. repeat := false
  8406. for j := i + 1; j < len(arr); j++ {
  8407. if arr[i].GoodId == arr[j].GoodId {
  8408. repeat = true
  8409. break
  8410. }
  8411. }
  8412. if !repeat {
  8413. newArr = append(newArr, arr[i])
  8414. }
  8415. }
  8416. return
  8417. }
  8418. func (c *DialysisAPIController) GetDepartment() {
  8419. adminInfo := c.GetMobileAdminUserInfo()
  8420. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  8421. if err == nil {
  8422. c.ServeSuccessJSON(map[string]interface{}{
  8423. "departments": departments,
  8424. })
  8425. } else {
  8426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8427. return
  8428. }
  8429. }
  8430. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  8431. types, _ := c.GetInt("type", 0)
  8432. start_time := c.GetString("start_time")
  8433. end_time := c.GetString("end_time")
  8434. orgId := c.GetMobileAdminUserInfo().Org.Id
  8435. timeLayout := "2006-01-02"
  8436. loc, _ := time.LoadLocation("Local")
  8437. var startTime int64
  8438. if len(start_time) > 0 {
  8439. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8440. if err != nil {
  8441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8442. return
  8443. }
  8444. startTime = theTime.Unix()
  8445. }
  8446. var endTime int64
  8447. if len(end_time) > 0 {
  8448. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8449. if err != nil {
  8450. utils.ErrorLog(err.Error())
  8451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8452. return
  8453. }
  8454. endTime = theTime.Unix()
  8455. }
  8456. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  8457. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  8458. if err != nil {
  8459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8460. } else {
  8461. c.ServeSuccessJSON(map[string]interface{}{
  8462. "list": list,
  8463. "type": types,
  8464. "stockTotal": stockTotal,
  8465. })
  8466. }
  8467. }
  8468. func (c *DialysisAPIController) GetPrescriptionList() {
  8469. start_time := c.GetString("start_time")
  8470. end_time := c.GetString("end_time")
  8471. schedule_type, _ := c.GetInt64("schedule_type")
  8472. partion_id, _ := c.GetInt64("partion_id")
  8473. orgId := c.GetMobileAdminUserInfo().Org.Id
  8474. timeLayout := "2006-01-02"
  8475. loc, _ := time.LoadLocation("Local")
  8476. var startTime int64
  8477. if len(start_time) > 0 {
  8478. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8479. if err != nil {
  8480. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8481. return
  8482. }
  8483. startTime = theTime.Unix()
  8484. }
  8485. var endTime int64
  8486. if len(end_time) > 0 {
  8487. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8488. if err != nil {
  8489. utils.ErrorLog(err.Error())
  8490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8491. return
  8492. }
  8493. endTime = theTime.Unix()
  8494. }
  8495. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  8496. fmt.Println("schedulelist22222222", schedulelist)
  8497. c.ServeSuccessJSON(map[string]interface{}{
  8498. "list": schedulelist,
  8499. })
  8500. return
  8501. }
  8502. func (c *DialysisAPIController) BatchDeleteMonitor() {
  8503. ids := c.GetString("ids")
  8504. //patient_id, _ := c.GetInt64("patient_id")
  8505. //monitoring_date, _ := c.GetInt64("monitoring_date")
  8506. idArray := strings.Split(ids, ",")
  8507. err := service.BatchDeleteMonitor(idArray)
  8508. fmt.Print("err", err)
  8509. //orgid := c.GetMobileAdminUserInfo().Org.Id
  8510. //redis := service.RedisClient()
  8511. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  8512. //redis.Set(key, "", time.Second)
  8513. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  8514. //redis.Set(keyOne, "", time.Second)
  8515. //fmt.Println("keyo呢32332322332332232332",keyOne)
  8516. //redis.Close()
  8517. c.ServeSuccessJSON(map[string]interface{}{
  8518. "msg": "批量删除成功",
  8519. })
  8520. return
  8521. }
  8522. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  8523. id, _ := c.GetInt64("id")
  8524. timeLayout := "2006-01-02"
  8525. loc, _ := time.LoadLocation("Local")
  8526. //start_time := time.Now().Format("2006-01-02")
  8527. start_time := c.GetString("start_time")
  8528. end_time := c.GetString("end_time")
  8529. var startdateunix int64
  8530. if len(start_time) > 0 {
  8531. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8532. if err != nil {
  8533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8534. return
  8535. }
  8536. startdateunix = theTime.Unix()
  8537. }
  8538. var enddateunix int64
  8539. if len(end_time) > 0 {
  8540. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8541. if err != nil {
  8542. utils.ErrorLog(err.Error())
  8543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8544. return
  8545. }
  8546. enddateunix = theTime.Unix()
  8547. }
  8548. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8549. //nowTime := time.Now()
  8550. //endTime := nowTime.AddDate(-30, 0, 0)
  8551. //endTimes := endTime.Format("2006-01-02")
  8552. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8553. org_id := c.GetMobileAdminUserInfo().Org.Id
  8554. //if org_id == 10579 {
  8555. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8556. // c.ServeSuccessJSON(map[string]interface{}{
  8557. // "list": list,
  8558. // })
  8559. // return
  8560. //} else {
  8561. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8562. // c.ServeSuccessJSON(map[string]interface{}{
  8563. // "list": list,
  8564. // })
  8565. // return
  8566. //}
  8567. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  8568. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8569. c.ServeSuccessJSON(map[string]interface{}{
  8570. "list": list,
  8571. })
  8572. return
  8573. } else {
  8574. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8575. c.ServeSuccessJSON(map[string]interface{}{
  8576. "list": list,
  8577. })
  8578. }
  8579. return
  8580. }
  8581. func (c *DialysisAPIController) BathDeleteAdviceList() {
  8582. dataBody := make(map[string]interface{}, 0)
  8583. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8584. ids := c.GetString("ids")
  8585. idArray := strings.Split(ids, ",")
  8586. origin, _ := c.GetInt64("origin")
  8587. if origin == 1 {
  8588. err = service.BatchDeleteAdvice(idArray)
  8589. fmt.Print("err", err)
  8590. c.ServeSuccessJSON(map[string]interface{}{
  8591. "msg": "批量删除成功",
  8592. })
  8593. return
  8594. }
  8595. if origin == 2 {
  8596. service.BatchDeleteHisAdvice(idArray)
  8597. }
  8598. }
  8599. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  8600. good_id, _ := c.GetInt64("good_id")
  8601. count, _ := c.GetInt64("count")
  8602. record_time, _ := c.GetInt64("record_time")
  8603. patient_id, _ := c.GetInt64("patient_id")
  8604. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  8605. c.ServeSuccessJSON(map[string]interface{}{
  8606. "detail": detail,
  8607. })
  8608. return
  8609. }
  8610. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  8611. good_id, _ := c.GetInt64("good_id")
  8612. record_time, _ := c.GetInt64("record_time")
  8613. patient_id, _ := c.GetInt64("patient_id")
  8614. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  8615. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  8616. fmt.Print("err", err)
  8617. c.ServeSuccessJSON(map[string]interface{}{
  8618. "msg": "批量删除成功",
  8619. })
  8620. return
  8621. }
  8622. func (c *DialysisAPIController) BatchAdviceCheck() {
  8623. ids := c.GetString("ids")
  8624. idArray := strings.Split(ids, ",")
  8625. creator, _ := c.GetInt64("creator")
  8626. origin, _ := c.GetInt64("origin")
  8627. if origin == 1 {
  8628. err := service.BatchAdviceCheck(idArray, creator)
  8629. fmt.Println(err)
  8630. list, _ := service.GetAdviceExecutionById(idArray)
  8631. c.ServeSuccessJSON(map[string]interface{}{
  8632. "list": list,
  8633. })
  8634. return
  8635. }
  8636. if origin == 2 {
  8637. service.BatchHisAdviceCheck(idArray, creator)
  8638. list, _ := service.GetHisAdviceExecutionById(idArray)
  8639. c.ServeSuccessJSON(map[string]interface{}{
  8640. "list": list,
  8641. })
  8642. return
  8643. }
  8644. }
  8645. func (c *DialysisAPIController) BatchAdviceExecution() {
  8646. ids := c.GetString("ids")
  8647. idArray := strings.Split(ids, ",")
  8648. executionTime := c.GetString("execution_time")
  8649. creator, _ := c.GetInt64("creator")
  8650. timeLayout := "2006-01-02 15:04:05"
  8651. loc, _ := time.LoadLocation("Local")
  8652. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  8653. orgin, _ := c.GetInt64("origin")
  8654. if orgin == 1 {
  8655. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  8656. list, _ := service.GetAdviceExecutionById(idArray)
  8657. fmt.Println(err)
  8658. c.ServeSuccessJSON(map[string]interface{}{
  8659. "list": list,
  8660. })
  8661. return
  8662. }
  8663. if orgin == 2 {
  8664. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  8665. list, _ := service.GetHisAdviceExecutionById(idArray)
  8666. fmt.Println(err)
  8667. c.ServeSuccessJSON(map[string]interface{}{
  8668. "list": list,
  8669. })
  8670. return
  8671. }
  8672. }
  8673. func (c *DialysisAPIController) UpdateStockGoods() {
  8674. good_id, _ := c.GetInt64("good_id")
  8675. record_time, _ := c.GetInt64("record_time")
  8676. patient_id, _ := c.GetInt64("patient_id")
  8677. count, _ := c.GetInt64("count")
  8678. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  8679. fmt.Print("err", err)
  8680. c.ServeSuccessJSON(map[string]interface{}{
  8681. "msg": "更新成功",
  8682. })
  8683. return
  8684. }
  8685. // 当前数据比上一次出库数据少
  8686. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  8687. //查询该患者当天已经出库的耗材信息
  8688. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8689. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8690. for i := len(goods_yc) - 1; i >= 0; i-- {
  8691. goods_yc_temp := goods_yc[i]
  8692. for j := len(goods) - 1; j >= 0; j-- {
  8693. goods_temp := goods[j]
  8694. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8695. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8696. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8697. if goods_yc_temp.Count == goods_temp.Count {
  8698. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8699. goods = append(goods[:j], goods[j+1:]...)
  8700. break
  8701. }
  8702. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8703. if goods_yc_temp.Count > goods_temp.Count {
  8704. temp_count := goods_yc_temp.Count - goods_temp.Count
  8705. goods_yc[i].Count = temp_count
  8706. goods = append(goods[:j], goods[j+1:]...)
  8707. break
  8708. }
  8709. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8710. if goods_yc_temp.Count < goods_temp.Count {
  8711. temp_count := goods_temp.Count - goods_yc_temp.Count
  8712. goods[j].Count = temp_count
  8713. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8714. break
  8715. }
  8716. }
  8717. }
  8718. }
  8719. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8720. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8721. //退库
  8722. if len(goods_yc) > 0 {
  8723. for _, good_yc := range goods_yc {
  8724. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8725. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  8726. }
  8727. }
  8728. return nil
  8729. }
  8730. // 耗材出库删除
  8731. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8732. // 先根据相关信息查询当天该耗材的出库信息
  8733. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8734. if err != nil {
  8735. return err
  8736. }
  8737. var delete_count int64 = 0
  8738. delete_count = warehouseOutInfos.Count - count
  8739. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8740. // 在出库记录表里记录退库详情
  8741. warehouseOutInfo := &models.WarehouseOutInfo{
  8742. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8743. WarehouseOutId: warehouseOut.ID,
  8744. Status: 1,
  8745. Ctime: time.Now().Unix(),
  8746. OrgId: orgID,
  8747. Type: 1,
  8748. IsSys: 1,
  8749. SysRecordTime: record_time,
  8750. GoodTypeId: good_yc.GoodTypeId,
  8751. GoodId: good_yc.GoodId,
  8752. PatientId: good_yc.PatientId,
  8753. ConsumableType: 2,
  8754. StorehouseId: houseConfig.StorehouseOutInfo,
  8755. IsCheck: 1,
  8756. }
  8757. warehouseOutInfo.Count = count
  8758. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8759. warehouseOutInfo.Price = stockInInfo.Price
  8760. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8761. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8762. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8763. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8764. warehouseOutInfo.Number = warehouseOutInfos.Number
  8765. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8766. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8767. //查找当天是否存在出库记录
  8768. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8769. if errcod == gorm.ErrRecordNotFound {
  8770. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8771. //插入详情明细表
  8772. stockFlow := models.VmStockFlow{
  8773. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8774. WarehouseOutId: warehouseOut.ID,
  8775. GoodId: good_yc.GoodId,
  8776. Number: warehouseOutInfos.Number,
  8777. ProductDate: stockInInfo.ProductDate,
  8778. ExpireDate: stockInInfo.ExpiryDate,
  8779. Count: count,
  8780. Price: stockInInfo.Price,
  8781. Status: 1,
  8782. Ctime: time.Now().Unix(),
  8783. UserOrgId: good_yc.OrgId,
  8784. Manufacturer: stockInInfo.Manufacturer,
  8785. Dealer: stockInInfo.Dealer,
  8786. LicenseNumber: stockInInfo.LicenseNumber,
  8787. IsEdit: 2,
  8788. Creator: creater,
  8789. SystemTime: record_time,
  8790. ConsumableType: 3,
  8791. WarehousingDetailId: 0,
  8792. IsSys: 1,
  8793. UpdateCreator: creater,
  8794. PatientId: patient_id,
  8795. StorehouseId: houseConfig.StorehouseOutInfo,
  8796. }
  8797. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8798. if errflow == gorm.ErrRecordNotFound {
  8799. //创建流水表
  8800. err := service.CreateStockFlowOne(stockFlow)
  8801. fmt.Println("err", err)
  8802. } else if errflow == nil {
  8803. //插入详情明细表
  8804. stockFlow := models.VmStockFlow{
  8805. ID: exsit.ID,
  8806. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8807. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8808. WarehouseOutId: warehouseOut.ID,
  8809. GoodId: good_yc.GoodId,
  8810. Number: warehouseOutInfos.Number,
  8811. ProductDate: stockInInfo.ProductDate,
  8812. ExpireDate: stockInInfo.ExpiryDate,
  8813. Count: exsit.Count - delete_count,
  8814. Price: stockInInfo.Price,
  8815. Status: 1,
  8816. Ctime: time.Now().Unix(),
  8817. UserOrgId: good_yc.OrgId,
  8818. Manufacturer: stockInInfo.Manufacturer,
  8819. Dealer: stockInInfo.Dealer,
  8820. LicenseNumber: stockInInfo.LicenseNumber,
  8821. IsEdit: 2,
  8822. Creator: creater,
  8823. SystemTime: record_time,
  8824. ConsumableType: 3,
  8825. WarehousingDetailId: 0,
  8826. IsSys: 1,
  8827. UpdateCreator: creater,
  8828. PatientId: patient_id,
  8829. StorehouseId: houseConfig.StorehouseOutInfo,
  8830. }
  8831. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8832. }
  8833. if errOne != nil {
  8834. return errOne
  8835. }
  8836. } else if errcod == nil {
  8837. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8838. //插入详情明细表
  8839. stockFlow := models.VmStockFlow{
  8840. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8841. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8842. WarehouseOutId: warehouseOut.ID,
  8843. GoodId: good_yc.GoodId,
  8844. Number: warehouseOutInfos.Number,
  8845. ProductDate: stockInInfo.ProductDate,
  8846. ExpireDate: stockInInfo.ExpiryDate,
  8847. Count: count,
  8848. Price: stockInInfo.Price,
  8849. Status: 1,
  8850. Ctime: time.Now().Unix(),
  8851. UserOrgId: good_yc.OrgId,
  8852. Manufacturer: stockInInfo.Manufacturer,
  8853. Dealer: stockInInfo.Dealer,
  8854. LicenseNumber: stockInInfo.LicenseNumber,
  8855. IsEdit: 2,
  8856. Creator: creater,
  8857. SystemTime: record_time,
  8858. ConsumableType: 3,
  8859. WarehousingDetailId: 0,
  8860. IsSys: 1,
  8861. UpdateCreator: creater,
  8862. PatientId: patient_id,
  8863. ReturnCount: delete_count,
  8864. StorehouseId: houseConfig.StorehouseOutInfo,
  8865. }
  8866. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8867. if errflows == gorm.ErrRecordNotFound {
  8868. //创建流水表
  8869. service.CreateStockFlowOne(stockFlow)
  8870. } else if errflows == nil {
  8871. stockFlow := models.VmStockFlow{
  8872. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8873. ID: exsit.ID,
  8874. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8875. WarehouseOutId: warehouseOut.ID,
  8876. GoodId: good_yc.GoodId,
  8877. Number: warehouseOutInfos.Number,
  8878. ProductDate: stockInInfo.ProductDate,
  8879. ExpireDate: stockInInfo.ExpiryDate,
  8880. Count: exsit.Count - delete_count,
  8881. Price: stockInInfo.Price,
  8882. Status: 1,
  8883. Ctime: time.Now().Unix(),
  8884. UserOrgId: good_yc.OrgId,
  8885. Manufacturer: stockInInfo.Manufacturer,
  8886. Dealer: stockInInfo.Dealer,
  8887. LicenseNumber: stockInInfo.LicenseNumber,
  8888. IsEdit: 2,
  8889. Creator: creater,
  8890. SystemTime: record_time,
  8891. ConsumableType: 3,
  8892. WarehousingDetailId: 0,
  8893. IsSys: 1,
  8894. UpdateCreator: creater,
  8895. PatientId: patient_id,
  8896. ReturnCount: delete_count,
  8897. StorehouseId: houseConfig.StorehouseOutInfo,
  8898. }
  8899. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8900. }
  8901. }
  8902. //更改自动出库的表格
  8903. details := models.BloodAutomaticReduceDetail{
  8904. WarehouseOutId: warehouseOutInfo.ID,
  8905. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8906. PatientId: patient_id,
  8907. Ctime: time.Now().Unix(),
  8908. Mtime: time.Now().Unix(),
  8909. Status: 1,
  8910. RecordTime: record_time,
  8911. OrgId: orgID,
  8912. GoodId: good_yc.GoodId,
  8913. GoodTypeId: good_yc.GoodTypeId,
  8914. Count: count,
  8915. StorehouseId: houseConfig.StorehouseOutInfo,
  8916. }
  8917. //查询当天耗材是否已经存在数据
  8918. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8919. if errcode == gorm.ErrRecordNotFound {
  8920. errTwo := service.CreateAutoReduceRecord(&details)
  8921. if errTwo != nil {
  8922. return errTwo
  8923. }
  8924. } else if errcode == nil {
  8925. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8926. service.CreateAutoReduceRecord(&details)
  8927. }
  8928. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8929. //增加出库库存数量
  8930. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  8931. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8932. fmt.Println("errOne", errOne)
  8933. // 删除出库完成后,要增加对应批次的库存数量
  8934. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8935. if errThree != nil {
  8936. return errThree
  8937. }
  8938. if good_yc.Count == 0 {
  8939. return nil
  8940. } else {
  8941. return errors.New("退库和出库数据不匹配")
  8942. }
  8943. }
  8944. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  8945. //查询该患者当天已经出库的耗材信息
  8946. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8947. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8948. for i := len(goods_yc) - 1; i >= 0; i-- {
  8949. goods_yc_temp := goods_yc[i]
  8950. for j := len(goods) - 1; j >= 0; j-- {
  8951. goods_temp := goods[j]
  8952. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8953. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8954. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8955. if goods_yc_temp.Count == goods_temp.Count {
  8956. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8957. goods = append(goods[:j], goods[j+1:]...)
  8958. break
  8959. }
  8960. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8961. if goods_yc_temp.Count > goods_temp.Count {
  8962. temp_count := goods_yc_temp.Count - goods_temp.Count
  8963. goods_yc[i].Count = temp_count
  8964. goods = append(goods[:j], goods[j+1:]...)
  8965. break
  8966. }
  8967. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8968. if goods_yc_temp.Count < goods_temp.Count {
  8969. temp_count := goods_temp.Count - goods_yc_temp.Count
  8970. goods[j].Count = temp_count
  8971. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8972. break
  8973. }
  8974. }
  8975. }
  8976. }
  8977. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8978. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8979. fmt.Println("剩余需要出库的", len(goods))
  8980. if len(goods) > 0 {
  8981. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  8982. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8983. if err == gorm.ErrRecordNotFound {
  8984. //没有记录,则创建出库单
  8985. timeStr := time.Now().Format("2006-01-02")
  8986. timeArr := strings.Split(timeStr, "-")
  8987. total, _ := service.FindAllWarehouseOut(orgID)
  8988. total = total + 1
  8989. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8990. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8991. number = number + total
  8992. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8993. warehouseOut := models.WarehouseOut{
  8994. WarehouseOutOrderNumber: warehousing_out_order,
  8995. OperationTime: time.Now().Unix(),
  8996. OrgId: orgID,
  8997. Creater: creater,
  8998. Ctime: time.Now().Unix(),
  8999. Status: 1,
  9000. WarehouseOutTime: record_time,
  9001. Dealer: 0,
  9002. Manufacturer: 0,
  9003. Type: 1,
  9004. IsSys: 1,
  9005. StorehouseId: houseConfig.StorehouseOutInfo,
  9006. IsCheck: 1,
  9007. }
  9008. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  9009. if err != nil {
  9010. utils.TraceLog("创建出库单失败 err = %v", err)
  9011. return err
  9012. } else {
  9013. out = warehouseOut
  9014. }
  9015. }
  9016. for _, item := range goods {
  9017. var newCount int64 = 0
  9018. for _, it := range goodOne {
  9019. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  9020. newCount = it.Count
  9021. }
  9022. }
  9023. prepare := models.DialysisBeforePrepare{
  9024. GoodTypeId: item.GoodTypeId,
  9025. GoodId: item.GoodId,
  9026. Count: item.Count,
  9027. StorehouseId: houseConfig.StorehouseOutInfo,
  9028. }
  9029. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  9030. //增加出库数量
  9031. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  9032. }
  9033. }
  9034. if len(goods_yc) > 0 {
  9035. for _, good_yc := range goods_yc {
  9036. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  9037. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  9038. }
  9039. }
  9040. return nil
  9041. }
  9042. // 耗材出库删除
  9043. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  9044. // 先根据相关信息查询当天该耗材的出库信息
  9045. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  9046. if err != nil {
  9047. return err
  9048. }
  9049. var delete_count int64 = 0
  9050. for _, ware := range warehouseOutInfos {
  9051. // 判断当前出库的数据和删除出库数量
  9052. if good_yc.Count <= ware.Count {
  9053. delete_count = good_yc.Count
  9054. } else {
  9055. delete_count = ware.Count
  9056. }
  9057. warehouseOutInfo := &models.WarehouseOutInfo{
  9058. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  9059. WarehouseOutId: warehouseOut.ID,
  9060. Status: 1,
  9061. Ctime: time.Now().Unix(),
  9062. Remark: "",
  9063. OrgId: orgID,
  9064. Type: 1,
  9065. Manufacturer: 0,
  9066. Dealer: 0,
  9067. IsSys: 0,
  9068. SysRecordTime: record_time,
  9069. GoodTypeId: good_yc.GoodTypeId,
  9070. GoodId: good_yc.GoodId,
  9071. StorehouseId: warehouseOut.StorehouseId,
  9072. IsCheck: 1,
  9073. }
  9074. warehouseOutInfo.Count = delete_count
  9075. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  9076. warehouseOutInfo.Price = stockInInfo.Price
  9077. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  9078. if errOne != nil {
  9079. return errOne
  9080. }
  9081. // 删除出库完成后,要改变流水库存(有疑问)
  9082. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  9083. fmt.Println("errOne", errOne)
  9084. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  9085. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  9086. //扣减出库数量
  9087. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  9088. if errThree != nil {
  9089. return errThree
  9090. }
  9091. }
  9092. if good_yc.Count == 0 {
  9093. return nil
  9094. } else {
  9095. return errors.New("退库和出库数据不匹配")
  9096. }
  9097. }
  9098. func (this *DialysisAPIController) GetMobileScheduleList() {
  9099. limit, _ := this.GetInt64("limit")
  9100. page, _ := this.GetInt64("page")
  9101. type_options_visible, _ := this.GetInt64("type_options_visible")
  9102. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  9103. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  9104. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  9105. }
  9106. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  9107. newArr = make([]*models.HisPrescriptionProject, 0)
  9108. for i := 0; i < len(arr); i++ {
  9109. repeat := false
  9110. for j := i + 1; j < len(arr); j++ {
  9111. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  9112. repeat = true
  9113. break
  9114. }
  9115. }
  9116. if !repeat {
  9117. newArr = append(newArr, arr[i])
  9118. }
  9119. }
  9120. return
  9121. }
  9122. func (this *DialysisAPIController) GetRoleList() {
  9123. admin_user_id, _ := this.GetInt64("admin_user_id")
  9124. orgid := this.GetMobileAdminUserInfo().Org.Id
  9125. list, err := service.GetRoleList(orgid, admin_user_id)
  9126. fmt.Println(err)
  9127. this.ServeSuccessJSON(map[string]interface{}{
  9128. "list": list,
  9129. })
  9130. return
  9131. }
  9132. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  9133. // 先根据相关信息查询当天该耗材的出库信息
  9134. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  9135. if err != nil {
  9136. return err
  9137. }
  9138. var delete_count int64 = 0
  9139. delete_count = warehouseOutInfos.Count - count
  9140. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  9141. // 删除出库完成后,要增加对应批次的库存数量
  9142. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  9143. if errThree != nil {
  9144. return errThree
  9145. }
  9146. //增加退库数量
  9147. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  9148. //扣减出库数量
  9149. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  9150. //查询剩余库存
  9151. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  9152. var sum_count int64
  9153. for _, item := range goodList {
  9154. sum_count += item.StockCount
  9155. }
  9156. // 在出库记录表里记录退库详情
  9157. warehouseOutInfo := &models.WarehouseOutInfo{
  9158. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  9159. WarehouseOutId: warehouseOut.ID,
  9160. Status: 1,
  9161. Ctime: time.Now().Unix(),
  9162. OrgId: orgID,
  9163. Type: 1,
  9164. IsSys: 1,
  9165. SysRecordTime: record_time,
  9166. GoodTypeId: good_yc.GoodTypeId,
  9167. GoodId: good_yc.GoodId,
  9168. PatientId: good_yc.PatientId,
  9169. ConsumableType: 2,
  9170. StorehouseId: houseConfig.StorehouseOutInfo,
  9171. IsCheck: 1,
  9172. OverCount: sum_count,
  9173. }
  9174. warehouseOutInfo.Count = count
  9175. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  9176. warehouseOutInfo.Price = stockInInfo.Price
  9177. warehouseOutInfo.Dealer = stockInInfo.Dealer
  9178. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  9179. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  9180. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  9181. warehouseOutInfo.Number = warehouseOutInfos.Number
  9182. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  9183. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  9184. //查找当天是否存在出库记录
  9185. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  9186. if errcod == gorm.ErrRecordNotFound {
  9187. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  9188. //插入详情明细表
  9189. if errOne != nil {
  9190. return errOne
  9191. }
  9192. //插入详情明细表
  9193. stockFlow := models.VmStockFlow{
  9194. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  9195. WarehouseOutId: warehouseOut.ID,
  9196. GoodId: good_yc.GoodId,
  9197. Number: warehouseOutInfos.Number,
  9198. ProductDate: stockInInfo.ProductDate,
  9199. ExpireDate: stockInInfo.ExpiryDate,
  9200. Count: count,
  9201. Price: stockInInfo.Price,
  9202. Status: 1,
  9203. Ctime: record_time,
  9204. UserOrgId: good_yc.OrgId,
  9205. Manufacturer: stockInInfo.Manufacturer,
  9206. Dealer: stockInInfo.Dealer,
  9207. LicenseNumber: stockInInfo.LicenseNumber,
  9208. IsEdit: 2,
  9209. Creator: creater,
  9210. SystemTime: record_time,
  9211. ConsumableType: 3,
  9212. WarehousingDetailId: 0,
  9213. IsSys: 1,
  9214. UpdateCreator: creater,
  9215. PatientId: patient_id,
  9216. StorehouseId: houseConfig.StorehouseOutInfo,
  9217. OverCount: sum_count,
  9218. ProjectId: good_yc.ProjectId,
  9219. }
  9220. err := service.CreateStockFlowOne(stockFlow)
  9221. fmt.Println("err", err)
  9222. } else if errcod == nil {
  9223. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  9224. }
  9225. //创建退库单
  9226. operation_time := time.Now().Unix()
  9227. //创建退库单
  9228. timeStr := time.Now().Format("2006-01-02")
  9229. timeArr := strings.Split(timeStr, "-")
  9230. total, _ := service.FindAllCancelStockTotal(orgID)
  9231. total = total + 1
  9232. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9233. cancelStock := models.CancelStock{
  9234. OrderNumber: orderNumber,
  9235. OperaTime: operation_time,
  9236. OrgId: orgID,
  9237. Creater: warehouseOut.Creater,
  9238. Ctime: time.Now().Unix(),
  9239. Status: 1,
  9240. ReturnTime: record_time,
  9241. Type: 1,
  9242. StorehouseId: stockInInfo.StorehouseId,
  9243. IsCheck: 1,
  9244. }
  9245. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  9246. if msgerrkonde == gorm.ErrRecordNotFound {
  9247. service.AddSigleCancelStock(&cancelStock)
  9248. }
  9249. cancel, _ := service.GetLastCancelStockById(orgID)
  9250. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  9251. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  9252. cancelStockInfo := models.CancelStockInfo{
  9253. GoodId: stockInInfo.GoodId,
  9254. CancelStockId: cancel.ID,
  9255. GoodTypeId: stockInInfo.GoodTypeId,
  9256. Count: delete_count,
  9257. Price: stockInInfo.PackingPrice,
  9258. Total: 0,
  9259. ProductDate: stockInInfo.ProductDate,
  9260. ExpiryDate: stockInInfo.ExpiryDate,
  9261. Ctime: record_time,
  9262. Status: 1,
  9263. OrgId: orgID,
  9264. OrderNumber: cancel.OrderNumber,
  9265. Type: 0,
  9266. Dealer: deaerler.DealerName,
  9267. Manufacturer: manufacturer.ManufacturerName,
  9268. Number: stockInInfo.Number,
  9269. RegisterAccount: "",
  9270. Remark: "",
  9271. WarehouseInfoId: stockInInfo.ID,
  9272. PatientId: patient_id,
  9273. RecordDate: record_time,
  9274. StorehouseId: stockInInfo.StorehouseId,
  9275. IsCheck: 1,
  9276. }
  9277. service.CreateCancelStockInfoOne(&cancelStockInfo)
  9278. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  9279. flow := models.VmStockFlow{
  9280. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  9281. GoodId: good_yc.GoodId,
  9282. Number: warehouseOutInfos.Number,
  9283. LicenseNumber: stockInInfo.LicenseNumber,
  9284. Count: delete_count,
  9285. UserOrgId: orgID,
  9286. PatientId: patient_id,
  9287. SystemTime: record_time,
  9288. ConsumableType: 7,
  9289. IsSys: 0,
  9290. WarehousingOrder: "",
  9291. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  9292. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  9293. IsEdit: 0,
  9294. CancelStockId: cancel.ID,
  9295. CancelOrderNumber: cancel.OrderNumber,
  9296. Manufacturer: manufacturer.ID,
  9297. Dealer: 0,
  9298. Creator: warehouseOut.Creater,
  9299. UpdateCreator: 0,
  9300. Status: 1,
  9301. Ctime: record_time,
  9302. Mtime: 0,
  9303. Price: stockInInfo.Price,
  9304. WarehousingDetailId: stockInInfo.ID,
  9305. WarehouseOutDetailId: warehouseOutInfos.ID,
  9306. CancelOutDetailId: cancelInfo.ID,
  9307. ProductDate: stockInInfo.ProductDate,
  9308. ExpireDate: stockInInfo.ExpiryDate,
  9309. StorehouseId: houseConfig.StorehouseOutInfo,
  9310. OverCount: sum_count,
  9311. }
  9312. service.CreateStockFlowOne(flow)
  9313. //更改自动出库的表格
  9314. details := models.BloodAutomaticReduceDetail{
  9315. WarehouseOutId: warehouseOutInfo.ID,
  9316. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  9317. PatientId: patient_id,
  9318. Ctime: time.Now().Unix(),
  9319. Mtime: time.Now().Unix(),
  9320. Status: 1,
  9321. RecordTime: record_time,
  9322. OrgId: orgID,
  9323. GoodId: good_yc.GoodId,
  9324. GoodTypeId: good_yc.GoodTypeId,
  9325. Count: count,
  9326. StorehouseId: houseConfig.StorehouseOutInfo,
  9327. }
  9328. //查询当天耗材是否已经存在数据
  9329. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  9330. if errcode == gorm.ErrRecordNotFound {
  9331. errTwo := service.CreateAutoReduceRecord(&details)
  9332. if errTwo != nil {
  9333. return errTwo
  9334. }
  9335. } else if errcode == nil {
  9336. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  9337. service.CreateAutoReduceRecord(&details)
  9338. }
  9339. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  9340. //增加出库库存数量
  9341. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  9342. if good_yc.Count == 0 {
  9343. return nil
  9344. } else {
  9345. return errors.New("退库和出库数据不匹配")
  9346. }
  9347. }
  9348. func (this *DialysisAPIController) SavePatientSign() {
  9349. adminUserInfo := this.GetMobileAdminUserInfo()
  9350. patient_id, _ := this.GetInt64("patient_id")
  9351. dialysis_date, _ := this.GetInt64("dialysis_date")
  9352. orgid := adminUserInfo.Org.Id
  9353. var esdata models.DialysisOrder
  9354. var err error
  9355. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  9356. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9357. return
  9358. }
  9359. esdata.Hash = esdata.Hash
  9360. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  9361. order := models.DialysisOrder{
  9362. Hash: esdata.Hash,
  9363. Url: esdata.Url,
  9364. }
  9365. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  9366. redis := service.RedisClient()
  9367. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  9368. redis.Set(key, "", time.Second)
  9369. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  9370. //清空key 值
  9371. redis.Set(keyOne, "", time.Second)
  9372. //scheduleDateStartOne := startDate.Format("2006-01-02")
  9373. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  9374. //redis.Set(keyTwo, "", time.Second)
  9375. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  9376. redis.Set(keyThree, "", time.Second)
  9377. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  9378. redis.Set(keyFour, "", time.Second)
  9379. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  9380. redis.Set(keyFive, "", time.Second)
  9381. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  9382. redis.Set(keySix, "", time.Second)
  9383. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  9384. redis.Set(keySeven, "", time.Second)
  9385. if err != nil {
  9386. fmt.Println(err)
  9387. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9388. return
  9389. }
  9390. this.ServeSuccessJSON(map[string]interface{}{
  9391. "electronic_signature": esdata,
  9392. })
  9393. }
  9394. func (this *DialysisAPIController) GetPatientSign() {
  9395. patient_id, _ := this.GetInt64("patient_id")
  9396. dialysis_date, _ := this.GetInt64("dialysis_date")
  9397. adminUserInfo := this.GetMobileAdminUserInfo()
  9398. orgId := adminUserInfo.Org.Id
  9399. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  9400. if err != nil {
  9401. fmt.Println(err)
  9402. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9403. return
  9404. }
  9405. this.ServeSuccessJSON(map[string]interface{}{
  9406. "dialysisOrder": dialysisOrder,
  9407. })
  9408. }
  9409. func (this *DialysisAPIController) GetScheduleByPatient() {
  9410. patient_id, _ := this.GetInt64("patient_id")
  9411. schedule_date, _ := this.GetInt64("schedule_date")
  9412. orgid := this.GetMobileAdminUserInfo().Org.Id
  9413. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  9414. this.ServeSuccessJSON(map[string]interface{}{
  9415. "schedule": schedule,
  9416. })
  9417. }
  9418. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  9419. org_id := this.GetMobileAdminUserInfo().Org.Id
  9420. patient_id, _ := this.GetInt64("patient_id")
  9421. schedule_date, _ := this.GetInt64("schedule_date")
  9422. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  9423. this.ServeSuccessJSON(map[string]interface{}{
  9424. "order": order,
  9425. })
  9426. }
  9427. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  9428. org_id := this.GetMobileAdminUserInfo().Org.Id
  9429. schedule_date := this.GetString("schedule_date")
  9430. schedule_type, _ := this.GetInt64("schedule_type")
  9431. timeLayout := "2006-01-02"
  9432. loc, _ := time.LoadLocation("Local")
  9433. var startdateunix int64
  9434. if len(schedule_date) > 0 {
  9435. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  9436. if err != nil {
  9437. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9438. return
  9439. }
  9440. startdateunix = theTime.Unix()
  9441. }
  9442. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  9443. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  9444. devices, _ := service.GetAllDevicetByListSix(org_id)
  9445. for key, item := range scheduals {
  9446. // 床位信息
  9447. for _, device := range devices {
  9448. if item.BedId == device.ID {
  9449. scheduals[key].DeviceNumber = device
  9450. break
  9451. }
  9452. }
  9453. }
  9454. this.ServeSuccessJSON(map[string]interface{}{
  9455. "list": list,
  9456. "scheduals": scheduals,
  9457. })
  9458. }
  9459. func (this *DialysisAPIController) SavePatientPicture() {
  9460. patient_id, _ := this.GetInt64("patient_id")
  9461. dialysis_date, _ := this.GetInt64("schedule_date")
  9462. avatar := this.GetString("avatar")
  9463. fmt.Println("patient_id", patient_id)
  9464. orgId := this.GetMobileAdminUserInfo().Org.Id
  9465. order := models.DialysisOrder{
  9466. Url: avatar,
  9467. }
  9468. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  9469. redis := service.RedisClient()
  9470. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  9471. redis.Set(key, "", time.Second)
  9472. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  9473. //清空key 值
  9474. redis.Set(keyOne, "", time.Second)
  9475. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  9476. redis.Set(keyThree, "", time.Second)
  9477. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  9478. redis.Set(keyFour, "", time.Second)
  9479. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  9480. redis.Set(keyFive, "", time.Second)
  9481. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  9482. redis.Set(keySix, "", time.Second)
  9483. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  9484. redis.Set(keySeven, "", time.Second)
  9485. if err != nil {
  9486. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9487. return
  9488. }
  9489. this.ServeSuccessJSON(map[string]interface{}{
  9490. "order": order,
  9491. })
  9492. }
  9493. func (this *DialysisAPIController) ExectionMobileAdvice() {
  9494. ids := this.GetString("ids")
  9495. idSplit := strings.Split(ids, ",")
  9496. orgId := this.GetMobileAdminUserInfo().Org.Id
  9497. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9498. execution_time := this.GetString("exce_time")
  9499. timeLayout2 := "2006-01-02 15:04:05"
  9500. loc, _ := time.LoadLocation("Local")
  9501. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  9502. if errs != nil {
  9503. utils.ErrorLog(errs.Error())
  9504. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9505. return
  9506. }
  9507. //his客户
  9508. if config.IsOpen == 1 {
  9509. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  9510. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  9511. for _, item := range list {
  9512. for _, it := range adviceList {
  9513. if item.DrugId == it.DrugId {
  9514. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9515. }
  9516. }
  9517. }
  9518. for _, item := range list {
  9519. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9520. var sum_out_count int64
  9521. for _, itemThree := range item.ChildDoctorAdvice {
  9522. var prescribing_number int64
  9523. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9524. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9525. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9526. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9527. }
  9528. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9529. prescribing_number = parseIntPrescribingNumber
  9530. }
  9531. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9532. prescribing_number = parseIntPrescribingNumber
  9533. }
  9534. sum_out_count += prescribing_number
  9535. }
  9536. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9537. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9538. //库存不足
  9539. if sum_out_count > drugStockOut.FlushCount {
  9540. this.ServeSuccessJSON(map[string]interface{}{
  9541. "msg": "2",
  9542. "drug": medical,
  9543. "ids": ids,
  9544. })
  9545. return
  9546. }
  9547. }
  9548. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9549. //执行医嘱
  9550. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9551. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  9552. for _, item := range advices {
  9553. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9554. redis := service.RedisClient()
  9555. //清空key 值
  9556. redis.Set(key, "", time.Second)
  9557. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9558. redis.Set(keyTwo, "", time.Second)
  9559. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9560. redis.Set(keyThree, "", time.Second)
  9561. recordDate := theTime.Format("2006-01-02")
  9562. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9563. redis.Set(keyFour, "", time.Second)
  9564. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9565. redis.Set(keyFive, "", time.Second)
  9566. defer redis.Close()
  9567. }
  9568. if errs == nil {
  9569. //药品管理信息
  9570. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9571. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9572. if drugStockConfig.IsOpen == 1 {
  9573. for _, item := range advices {
  9574. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  9575. config, _ := service.GetDrugOpenConfigOne(orgId)
  9576. if config.IsOpen != 1 {
  9577. //查询该药品是否有库存
  9578. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9579. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  9580. if medical.IsUse == 2 {
  9581. if config.IsOpen != 1 {
  9582. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9583. service.HisDrugsDelivery(orgId, creater, &advice)
  9584. if orgId == 3877 || orgId == 10265 {
  9585. //查询该药品是否有出库记录
  9586. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9587. if len(flowMap) == 0 {
  9588. errs := service.UpdateHisAdviceById(advice.ID)
  9589. if errs != nil {
  9590. drugError := models.XtDrugError{
  9591. UserOrgId: orgId,
  9592. DrugId: item.DrugId,
  9593. RecordDate: item.AdviceDate,
  9594. PatientId: item.PatientId,
  9595. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9596. Status: 1,
  9597. Ctime: time.Now().Unix(),
  9598. Mtime: 0,
  9599. SumCount: 0,
  9600. Prescribingnumber: advice.PrescribingNumber,
  9601. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9602. }
  9603. service.CreateDrugError(drugError)
  9604. }
  9605. this.ServeSuccessJSON(map[string]interface{}{
  9606. "msg": "2",
  9607. "drug": medical,
  9608. "ids": ids,
  9609. })
  9610. return
  9611. }
  9612. }
  9613. }
  9614. if pharmacyConfig.IsOpen != 1 {
  9615. service.HisDrugsDelivery(orgId, creater, &advice)
  9616. if orgId == 3877 || orgId == 10265 {
  9617. //查询该药品是否有出库记录
  9618. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9619. if len(flowMap) == 0 {
  9620. errs := service.UpdateHisAdviceById(advice.ID)
  9621. if errs != nil {
  9622. drugError := models.XtDrugError{
  9623. UserOrgId: orgId,
  9624. DrugId: item.DrugId,
  9625. RecordDate: item.AdviceDate,
  9626. PatientId: item.PatientId,
  9627. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9628. Status: 1,
  9629. Ctime: time.Now().Unix(),
  9630. Mtime: 0,
  9631. SumCount: 0,
  9632. Prescribingnumber: advice.PrescribingNumber,
  9633. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9634. }
  9635. service.CreateDrugError(drugError)
  9636. }
  9637. this.ServeSuccessJSON(map[string]interface{}{
  9638. "msg": "2",
  9639. "drug": medical,
  9640. "ids": ids,
  9641. })
  9642. return
  9643. }
  9644. }
  9645. }
  9646. //更新字典里面的库存
  9647. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9648. var sum_count int64
  9649. for _, its := range stockInfo {
  9650. if its.MaxUnit == medical.MaxUnit {
  9651. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9652. }
  9653. sum_count += its.StockMaxNumber + its.StockMinNumber
  9654. }
  9655. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9656. //剩余库存
  9657. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9658. }
  9659. }
  9660. }
  9661. }
  9662. }
  9663. this.ServeSuccessJSON(map[string]interface{}{
  9664. "msg": "1",
  9665. "ids": ids,
  9666. })
  9667. return
  9668. } else {
  9669. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9670. }
  9671. }
  9672. //血透客户
  9673. if config.IsOpen == 2 || config.IsOpen == 0 {
  9674. //药品管理信息
  9675. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9676. if drugStockConfig.IsOpen == 1 {
  9677. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  9678. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  9679. for _, item := range list {
  9680. for _, it := range adviceList {
  9681. if item.DrugId == it.DrugId {
  9682. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9683. }
  9684. }
  9685. }
  9686. for _, item := range list {
  9687. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9688. var sum_out_count int64
  9689. for _, itemThree := range item.ChildDoctorAdvice {
  9690. var prescribing_number int64
  9691. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9692. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9693. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9694. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9695. }
  9696. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9697. prescribing_number = parseIntPrescribingNumber
  9698. }
  9699. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9700. prescribing_number = parseIntPrescribingNumber
  9701. }
  9702. sum_out_count += prescribing_number
  9703. }
  9704. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9705. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9706. //库存不足
  9707. if sum_out_count > drugStockOut.FlushCount {
  9708. this.ServeSuccessJSON(map[string]interface{}{
  9709. "msg": "2",
  9710. "drug": medical,
  9711. "ids": ids,
  9712. })
  9713. return
  9714. }
  9715. }
  9716. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9717. //执行医嘱
  9718. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9719. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9720. for _, item := range advices {
  9721. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9722. redis := service.RedisClient()
  9723. //清空key 值
  9724. redis.Set(key, "", time.Second)
  9725. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9726. redis.Set(keyTwo, "", time.Second)
  9727. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9728. redis.Set(keyThree, "", time.Second)
  9729. recordDate := theTime.Format("2006-01-02")
  9730. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9731. redis.Set(keyFour, "", time.Second)
  9732. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9733. redis.Set(keyFive, "", time.Second)
  9734. defer redis.Close()
  9735. }
  9736. if errs == nil {
  9737. for _, item := range advices {
  9738. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9739. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9740. //查询是否出库按钮开启
  9741. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  9742. if adviceSetting.IsAdviceOpen == 1 {
  9743. //查询是否出库按钮开启
  9744. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  9745. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9746. if prescriptionConfig.IsOpen == 1 {
  9747. if medical.IsUse == 2 {
  9748. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9749. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9750. }
  9751. if pharmacyConfig.IsOpen != 1 {
  9752. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9753. }
  9754. //更新字典里面的库存
  9755. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9756. var sum_count int64
  9757. for _, its := range stockInfo {
  9758. if its.MaxUnit == medical.MaxUnit {
  9759. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9760. }
  9761. sum_count += its.StockMaxNumber + its.StockMinNumber
  9762. }
  9763. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9764. //剩余库存
  9765. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9766. }
  9767. }
  9768. } else {
  9769. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9770. if medical.IsUse == 2 {
  9771. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9772. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9773. }
  9774. if pharmacyConfig.IsOpen != 1 {
  9775. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9776. }
  9777. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9778. var sum_count int64
  9779. for _, its := range stockInfo {
  9780. if its.MaxUnit == medical.MaxUnit {
  9781. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9782. }
  9783. sum_count += its.StockMaxNumber + its.StockMinNumber
  9784. }
  9785. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9786. //剩余库存
  9787. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9788. }
  9789. }
  9790. }
  9791. }
  9792. this.ServeSuccessJSON(map[string]interface{}{
  9793. "msg": "1",
  9794. "ids": ids,
  9795. })
  9796. return
  9797. } else {
  9798. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9799. //执行医嘱
  9800. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9801. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9802. for _, item := range advices {
  9803. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9804. redis := service.RedisClient()
  9805. //清空key 值
  9806. redis.Set(key, "", time.Second)
  9807. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9808. redis.Set(keyTwo, "", time.Second)
  9809. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9810. redis.Set(keyThree, "", time.Second)
  9811. recordDate := theTime.Format("2006-01-02")
  9812. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9813. redis.Set(keyFour, "", time.Second)
  9814. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9815. redis.Set(keyFive, "", time.Second)
  9816. defer redis.Close()
  9817. }
  9818. this.ServeSuccessJSON(map[string]interface{}{
  9819. "msg": "1",
  9820. "ids": ids,
  9821. })
  9822. return
  9823. }
  9824. }
  9825. }
  9826. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  9827. ids := this.GetString("ids")
  9828. idSplit := strings.Split(ids, ",")
  9829. orgId := this.GetMobileAdminUserInfo().Org.Id
  9830. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9831. if config.IsOpen == 1 {
  9832. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  9833. this.ServeSuccessJSON(map[string]interface{}{
  9834. "msg": "1",
  9835. "ids": ids,
  9836. })
  9837. return
  9838. }
  9839. if config.IsOpen == 0 || config.IsOpen == 2 {
  9840. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  9841. this.ServeSuccessJSON(map[string]interface{}{
  9842. "msg": "1",
  9843. "ids": ids,
  9844. })
  9845. return
  9846. }
  9847. }
  9848. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  9849. ids := this.GetString("ids")
  9850. idSplit := strings.Split(ids, ",")
  9851. orgId := this.GetMobileAdminUserInfo().Org.Id
  9852. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9853. //his
  9854. if config.IsOpen == 1 {
  9855. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9856. theTime := time.Now()
  9857. advices := models.HisDoctorAdviceThirty{
  9858. CheckTime: theTime.Unix(),
  9859. Checker: checker,
  9860. UpdatedTime: time.Now().Unix(),
  9861. }
  9862. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  9863. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9864. for _, item := range list {
  9865. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9866. redis := service.RedisClient()
  9867. //清空key 值
  9868. redis.Set(key, "", time.Second)
  9869. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9870. redis.Set(keyTwo, "", time.Second)
  9871. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9872. redis.Set(keyThree, "", time.Second)
  9873. recordDate := theTime.Format("2006-01-02")
  9874. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9875. redis.Set(keyFour, "", time.Second)
  9876. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9877. redis.Set(keyFive, "", time.Second)
  9878. defer redis.Close()
  9879. }
  9880. this.ServeSuccessJSON(map[string]interface{}{
  9881. "msg": "1",
  9882. "ids": ids,
  9883. })
  9884. return
  9885. }
  9886. //血透
  9887. if config.IsOpen == 0 || config.IsOpen == 2 {
  9888. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9889. theTime := time.Now()
  9890. advices := models.DoctorAdvice{
  9891. CheckTime: theTime.Unix(),
  9892. Checker: checker,
  9893. UpdatedTime: time.Now().Unix(),
  9894. }
  9895. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  9896. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9897. for _, item := range list {
  9898. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9899. redis := service.RedisClient()
  9900. //清空key 值
  9901. redis.Set(key, "", time.Second)
  9902. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9903. redis.Set(keyTwo, "", time.Second)
  9904. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9905. redis.Set(keyThree, "", time.Second)
  9906. recordDate := theTime.Format("2006-01-02")
  9907. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9908. redis.Set(keyFour, "", time.Second)
  9909. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9910. redis.Set(keyFive, "", time.Second)
  9911. defer redis.Close()
  9912. }
  9913. this.ServeSuccessJSON(map[string]interface{}{
  9914. "msg": "1",
  9915. "ids": ids,
  9916. })
  9917. return
  9918. }
  9919. }
  9920. func (this *DialysisAPIController) CheckSchedule() {
  9921. patientID, _ := this.GetInt64("patient_id")
  9922. recordDateStr := this.GetString("record_date")
  9923. nurseID, _ := this.GetInt64("start_nurse")
  9924. schedual_type, _ := this.GetInt64("schedual_type")
  9925. bedID, _ := this.GetInt64("bed")
  9926. start_time := this.GetString("start_time")
  9927. fmt.Println("patientID", patientID)
  9928. fmt.Println("recordDateStr", recordDateStr)
  9929. fmt.Println("nurseID", nurseID)
  9930. fmt.Println("schedual_type------", schedual_type)
  9931. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  9932. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9933. return
  9934. }
  9935. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  9936. if parseStartDateErr != nil {
  9937. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  9938. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9939. return
  9940. }
  9941. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9942. if parseErr != nil {
  9943. this.ErrorLog("时间解析失败:%v", parseErr)
  9944. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9945. return
  9946. }
  9947. adminUserInfo := this.GetMobileAdminUserInfo()
  9948. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  9949. if getPatientErr != nil {
  9950. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  9951. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9952. return
  9953. } else if patient == nil {
  9954. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9955. return
  9956. }
  9957. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  9958. if getNurseErr != nil {
  9959. this.ErrorLog("获取护士失败:%v", getNurseErr)
  9960. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9961. return
  9962. } else if nurse == nil {
  9963. this.ErrorLog("护士不存在")
  9964. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9965. return
  9966. }
  9967. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  9968. if getDeviceNumberErr != nil {
  9969. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  9970. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9971. return
  9972. } else if deviceNumber == nil {
  9973. this.ErrorLog("床位号不存在")
  9974. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9975. return
  9976. }
  9977. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  9978. if getRecordErr != nil {
  9979. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  9980. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9981. return
  9982. } else if dialysisRecord != nil {
  9983. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  9984. return
  9985. }
  9986. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  9987. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  9988. timeLayout := "2006-01-02 15:04:05"
  9989. loc, _ := time.LoadLocation("Local")
  9990. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  9991. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  9992. schedulestartTime := theStartTime.Unix()
  9993. scheduleendTime := theEndTime.Unix()
  9994. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  9995. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  9996. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9997. //查询该床位是否有人用了
  9998. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9999. if err == nil {
  10000. if schedule.ID == 0 {
  10001. this.ServeSuccessJSON(map[string]interface{}{
  10002. "status": 0,
  10003. "msg": "请求失败",
  10004. })
  10005. } else {
  10006. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  10007. if order.ID > 0 { //该机位被其他人占用了
  10008. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  10009. return
  10010. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  10011. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  10012. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  10013. this.ServeSuccessJSON(map[string]interface{}{
  10014. "status": 1,
  10015. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  10016. })
  10017. return
  10018. } else {
  10019. this.ServeSuccessJSON(map[string]interface{}{
  10020. "status": 0,
  10021. "msg": "",
  10022. })
  10023. }
  10024. }
  10025. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  10026. this.ServeSuccessJSON(map[string]interface{}{
  10027. "status": 2,
  10028. "msg": "当前机位已有患者在使用,请重新选择!",
  10029. })
  10030. }
  10031. }
  10032. } else {
  10033. this.ServeSuccessJSON(map[string]interface{}{
  10034. "status": 0,
  10035. "msg": "",
  10036. })
  10037. }
  10038. }
  10039. func (this *DialysisAPIController) GetNewDoctorListToday() {
  10040. orgId := this.GetMobileAdminUserInfo().Org.Id
  10041. schedule_type, _ := this.GetInt64("schedule_type")
  10042. partion_type, _ := this.GetInt64("partion_type")
  10043. start_time := this.GetString("start_time")
  10044. timeLayout := "2006-01-02"
  10045. loc, _ := time.LoadLocation("Local")
  10046. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10047. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  10048. _, config := service.FindXTHisRecordByOrgId(orgId)
  10049. appId := this.GetMobileAdminUserInfo().App.Id
  10050. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  10051. if err == nil {
  10052. this.ServeSuccessJSON(map[string]interface{}{
  10053. "list": list,
  10054. "config": config,
  10055. "doctorList": doctorList,
  10056. })
  10057. return
  10058. } else {
  10059. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10060. return
  10061. }
  10062. }
  10063. func (this *DialysisAPIController) SaveMobileInformation() {
  10064. patient_id, _ := this.GetInt64("patient_id")
  10065. record_date, _ := this.GetInt64("record_date")
  10066. startTime := this.GetString("start_time")
  10067. module, _ := this.GetInt64("module")
  10068. remark := this.GetString("remark")
  10069. timeLayout := "2006-01-02 15:04"
  10070. loc, _ := time.LoadLocation("Local")
  10071. if len(startTime) == 0 {
  10072. utils.ErrorLog("len(start_time) == 0")
  10073. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10074. return
  10075. }
  10076. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  10077. if err != nil {
  10078. utils.ErrorLog(err.Error())
  10079. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10080. return
  10081. }
  10082. StartTime := theTime.Unix()
  10083. fmt.Println("startime-------------", StartTime)
  10084. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  10085. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  10086. information := models.XtDialysisInformation{
  10087. Module: module,
  10088. PatientId: patient_id,
  10089. RecordDate: record_date,
  10090. ApplicationDate: StartTime,
  10091. Creater: creater,
  10092. ApplicationStatus: 2,
  10093. Checker: 0,
  10094. CheckTime: 0,
  10095. Remark: remark,
  10096. UserOrgId: user_org_id,
  10097. Ctime: time.Now().Unix(),
  10098. Status: 1,
  10099. Mtime: 0,
  10100. }
  10101. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  10102. if infor.ID == 0 {
  10103. service.SaveDialysisInformation(information)
  10104. }
  10105. if infor.ID > 0 {
  10106. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  10107. }
  10108. this.ServeSuccessJSON(map[string]interface{}{
  10109. "information": information,
  10110. })
  10111. return
  10112. }
  10113. func (this *DialysisAPIController) GetMobileInformation() {
  10114. limit, _ := this.GetInt64("limit")
  10115. page, _ := this.GetInt64("page")
  10116. orgid := this.GetMobileAdminUserInfo().Org.Id
  10117. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  10118. appid := this.GetMobileAdminUserInfo().App.Id
  10119. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  10120. patients, _ := service.GetAllpatientThirty(orgid)
  10121. this.ServeSuccessJSON(map[string]interface{}{
  10122. "information": information,
  10123. "total": total,
  10124. "doclist": doclist,
  10125. "patients": patients,
  10126. })
  10127. return
  10128. }
  10129. func (this *DialysisAPIController) GetMobileInformationOne() {
  10130. limit, _ := this.GetInt64("limit")
  10131. page, _ := this.GetInt64("page")
  10132. orgid := this.GetMobileAdminUserInfo().Org.Id
  10133. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  10134. appid := this.GetMobileAdminUserInfo().App.Id
  10135. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  10136. patients, _ := service.GetAllpatientThirty(orgid)
  10137. this.ServeSuccessJSON(map[string]interface{}{
  10138. "information": information,
  10139. "total": total,
  10140. "doclist": doclist,
  10141. "patients": patients,
  10142. })
  10143. return
  10144. }
  10145. func (this *DialysisAPIController) CheckMobileInformation() {
  10146. id, _ := this.GetInt64("id")
  10147. application_status, _ := this.GetInt64("application_status")
  10148. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  10149. checktime := time.Now().Unix()
  10150. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  10151. if err == nil {
  10152. this.ServeSuccessJSON(map[string]interface{}{
  10153. "msg": "ok",
  10154. })
  10155. return
  10156. }
  10157. }
  10158. func (c *DialysisAPIController) GetControlMonitorList() {
  10159. partition, _ := c.GetInt64("partition")
  10160. monitorDate := c.GetString("date")
  10161. patient_id, _ := c.GetInt64("patient_id")
  10162. pat_type, _ := c.GetInt64("pat_type")
  10163. timeLayout := "2006-01-02"
  10164. loc, _ := time.LoadLocation("Local")
  10165. var theStartTime int64
  10166. if len(monitorDate) > 0 {
  10167. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  10168. if err != nil {
  10169. theStartTime = 0
  10170. }
  10171. theStartTime = theTime.Unix()
  10172. }
  10173. adminInfo := c.GetMobileAdminUserInfo()
  10174. orgID := adminInfo.Org.Id
  10175. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  10176. if err != nil {
  10177. c.ErrorLog("获取排班信息失败:%v", err)
  10178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10179. } else {
  10180. if len(monitor) > 0 {
  10181. //获取所有床位
  10182. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  10183. //获取所有分区
  10184. zoneList, _ := service.GetAllZoneByList(orgID)
  10185. //获取透析处方
  10186. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  10187. //获取透前评估
  10188. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  10189. //获取上机
  10190. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  10191. //获取透后
  10192. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  10193. //获取透后监测
  10194. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  10195. //获取所有的患者
  10196. patients, _ := service.GetAllPatientListByListOne(orgID)
  10197. //获取所有透析模式
  10198. treatments, _ := service.GetAllTreatModeByList(orgID)
  10199. //获取所有医嘱
  10200. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  10201. //获取双人核对
  10202. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  10203. //治疗小结
  10204. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  10205. //待消毒
  10206. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  10207. for key, item := range monitor {
  10208. // 获取床位信息
  10209. for _, it := range numberList {
  10210. if item.BedId == it.ID {
  10211. monitor[key].DeviceNumber = it
  10212. break
  10213. }
  10214. }
  10215. //获取分区信息
  10216. for _, it := range zoneList {
  10217. if item.PartitionId == it.ID {
  10218. monitor[key].DeviceZone = it
  10219. }
  10220. }
  10221. for _, prescription := range prescriptions {
  10222. if item.PatientId == prescription.PatientId {
  10223. monitor[key].Prescription = prescription
  10224. break
  10225. }
  10226. }
  10227. for _, it := range checkList {
  10228. if item.PatientId == it.PatientId {
  10229. monitor[key].DoubleCheck = it
  10230. break
  10231. }
  10232. }
  10233. for _, it := range summaryList {
  10234. if item.PatientId == it.PatientId {
  10235. monitor[key].TreatmentSummaryForList = it
  10236. break
  10237. }
  10238. }
  10239. // 透前评估
  10240. for _, assessmentBefore := range assessmentBefores {
  10241. if item.PatientId == assessmentBefore.PatientId {
  10242. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  10243. break
  10244. }
  10245. }
  10246. // 透析上下机
  10247. for _, dialysisOrder := range dialysisOrders {
  10248. if item.PatientId == dialysisOrder.PatientId {
  10249. monitor[key].DialysisOrder = dialysisOrder
  10250. break
  10251. }
  10252. }
  10253. // 治疗小节
  10254. for _, afterDislysis := range AssessmentAfterDislysis {
  10255. if item.PatientId == afterDislysis.PatientId {
  10256. monitor[key].AssessmentAfterDislysis = afterDislysis
  10257. break
  10258. }
  10259. }
  10260. for _, it := range monitorlist {
  10261. if item.PatientId == it.PatientId {
  10262. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  10263. }
  10264. }
  10265. for _, it := range adviceList {
  10266. if item.PatientId == it.PatientId {
  10267. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  10268. }
  10269. }
  10270. for _, patient := range patients {
  10271. if item.PatientId == patient.ID {
  10272. monitor[key].MonitorPatients = patient
  10273. break
  10274. }
  10275. }
  10276. for _, treatment := range treatments {
  10277. if item.ModeId == treatment.ID {
  10278. monitor[key].TreatmentMode = treatment
  10279. break
  10280. }
  10281. }
  10282. for _, infor := range informationList {
  10283. if item.PatientId == infor.PatientId {
  10284. monitor[key].NewDeviceInformation = infor
  10285. break
  10286. }
  10287. }
  10288. }
  10289. }
  10290. }
  10291. patients, err := service.GetAllpatientFourty(orgID)
  10292. var mds []*models.NewMonitorDialysisScheduleList
  10293. if pat_type == 0 {
  10294. for _, item := range monitor {
  10295. mds = append(mds, item)
  10296. }
  10297. }
  10298. //待医嘱核对
  10299. if pat_type == 1 {
  10300. for _, item := range monitor {
  10301. if len(item.AdviceList) > 0 {
  10302. mds = append(mds, item)
  10303. }
  10304. }
  10305. }
  10306. //待开小结
  10307. if pat_type == 2 {
  10308. for _, item := range monitor {
  10309. if item.TreatmentSummaryForList == nil {
  10310. mds = append(mds, item)
  10311. }
  10312. }
  10313. }
  10314. //待下机
  10315. if pat_type == 3 {
  10316. for _, item := range monitor {
  10317. if item.DialysisOrder != nil {
  10318. if item.DialysisOrder.ID > 0 {
  10319. mds = append(mds, item)
  10320. }
  10321. }
  10322. }
  10323. }
  10324. //待消毒
  10325. if pat_type == 4 {
  10326. for _, item := range monitor {
  10327. if item.NewDeviceInformation == nil {
  10328. mds = append(mds, item)
  10329. }
  10330. }
  10331. }
  10332. //待双人核对
  10333. if pat_type == 5 {
  10334. for _, item := range monitor {
  10335. if item.DoubleCheck == nil {
  10336. mds = append(mds, item)
  10337. }
  10338. }
  10339. }
  10340. //医嘱未执行
  10341. if pat_type == 6 {
  10342. for _, item := range monitor {
  10343. if len(item.AdviceList) > 0 {
  10344. mds = append(mds, item)
  10345. }
  10346. }
  10347. }
  10348. //患者未签名
  10349. if pat_type == 7 {
  10350. for _, item := range monitor {
  10351. if item.DialysisOrder != nil {
  10352. if item.DialysisOrder.ID > 0 {
  10353. mds = append(mds, item)
  10354. }
  10355. }
  10356. }
  10357. }
  10358. //目标超滤于实际超滤不同
  10359. if pat_type == 8 {
  10360. for _, item := range monitor {
  10361. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  10362. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  10363. mds = append(mds, item)
  10364. }
  10365. }
  10366. }
  10367. }
  10368. //血压少于5次
  10369. if pat_type == 9 {
  10370. for _, item := range monitor {
  10371. if len(item.MonitoringRecord) < 5 {
  10372. mds = append(mds, item)
  10373. }
  10374. }
  10375. }
  10376. if pat_type == 13 {
  10377. for _, item := range monitor {
  10378. if len(item.MonitoringRecord) < 3 {
  10379. mds = append(mds, item)
  10380. }
  10381. }
  10382. }
  10383. if pat_type == 10 {
  10384. for _, item := range monitor {
  10385. if len(item.MonitoringRecord) == 0 {
  10386. mds = append(mds, item)
  10387. }
  10388. }
  10389. }
  10390. if pat_type == 11 {
  10391. for _, item := range monitor {
  10392. if len(item.MonitoringRecord) > 0 {
  10393. mds = append(mds, item)
  10394. }
  10395. }
  10396. }
  10397. if pat_type == 12 {
  10398. for _, item := range monitor {
  10399. if len(item.MonitoringRecord) > 0 {
  10400. mds = append(mds, item)
  10401. }
  10402. }
  10403. }
  10404. if err == nil {
  10405. c.ServeSuccessJSON(map[string]interface{}{
  10406. "monitor": mds,
  10407. "patients": patients,
  10408. })
  10409. } else {
  10410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10411. }
  10412. }
  10413. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  10414. admin_user_id, _ := c.GetInt64("admin_user_id")
  10415. timeStr := time.Now().Format("2006-01-02")
  10416. timeLayout := "2006-01-02 15:04:05"
  10417. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  10418. timenow := timeStringToTime.Unix()
  10419. orgId := c.GetMobileAdminUserInfo().Org.Id
  10420. //查询当前护士的患者
  10421. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  10422. var patientIds []int64
  10423. for _, item := range orderList {
  10424. patientIds = append(patientIds, item.PatientId)
  10425. }
  10426. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  10427. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  10428. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  10429. //药品管理信息
  10430. _, drugStockConfig := service.FindHisConfig(orgId)
  10431. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  10432. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  10433. c.ServeSuccessJSON(map[string]interface{}{
  10434. "adviceList": adviceList,
  10435. "hisAdviceList": hisAdviceList,
  10436. "projectList": projectList,
  10437. "drugStockConfig": drugStockConfig,
  10438. "patientList": patientList,
  10439. "projectConfig": projectConfig,
  10440. })
  10441. }
  10442. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  10443. patient_id, _ := c.GetInt64("patient_id")
  10444. org_id := c.GetMobileAdminUserInfo().Org.Id
  10445. recrods, _ := service.GetLastAcceptRecrods(patient_id, org_id)
  10446. c.ServeSuccessJSON(map[string]interface{}{
  10447. "recrods": recrods,
  10448. })
  10449. }
  10450. func (c *DialysisAPIController) ExMobileChangeSch() {
  10451. id_one, _ := c.GetInt64("id_one")
  10452. id_two, _ := c.GetInt64("id_two")
  10453. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  10454. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  10455. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  10456. //if order2.ID > 0 {
  10457. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  10458. // return
  10459. //}
  10460. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  10461. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  10462. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  10463. if count > 0 {
  10464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10465. return
  10466. }
  10467. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  10468. if count1 > 0 {
  10469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10470. return
  10471. }
  10472. }
  10473. err := service.UpdateScheduleThree(sch, sch_two)
  10474. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  10475. if order.ID > 0 {
  10476. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10477. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10478. redis := service.RedisClient()
  10479. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10480. redis.Set(key, "", time.Second)
  10481. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10482. //清空key 值
  10483. redis.Set(keyOne, "", time.Second)
  10484. }
  10485. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10486. if orderOne.ID > 0 {
  10487. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10488. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10489. redis := service.RedisClient()
  10490. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10491. redis.Set(key, "", time.Second)
  10492. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10493. //清空key 值
  10494. redis.Set(keyOne, "", time.Second)
  10495. }
  10496. if err == nil {
  10497. //去除当天患者排班中重复数据,保留最后一条数据
  10498. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10499. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10500. c.ServeSuccessJSON(map[string]interface{}{
  10501. "msg": "交换成功",
  10502. })
  10503. } else {
  10504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10505. return
  10506. }
  10507. }
  10508. func (c *DialysisAPIController) MobileCoverSch() {
  10509. id_one, _ := c.GetInt64("id_one")
  10510. id_two, _ := c.GetInt64("id_two")
  10511. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  10512. //针对凤凰医院
  10513. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  10514. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10515. if len(advice) > 0 {
  10516. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10517. }
  10518. }
  10519. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  10520. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10521. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10522. if len(hisAdvice) > 0 {
  10523. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10524. }
  10525. if len(project) > 0 {
  10526. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10527. }
  10528. }
  10529. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  10530. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  10531. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  10532. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  10533. if count > 0 {
  10534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10535. return
  10536. }
  10537. }
  10538. var new_sch models.Schedule
  10539. new_sch = sch
  10540. new_sch.BedId = sch_two.BedId
  10541. new_sch.ScheduleDate = sch_two.ScheduleDate
  10542. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  10543. new_sch.PartitionId = sch_two.PartitionId
  10544. new_sch.ScheduleType = sch_two.ScheduleType
  10545. new_sch.ID = 0
  10546. //删除原来的排班
  10547. err := service.SaveSchTwo(sch, sch_two)
  10548. //生成新的排班
  10549. if err == nil {
  10550. err2 := service.SaveSch(&new_sch)
  10551. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  10552. if order.ID > 0 {
  10553. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10554. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10555. redis := service.RedisClient()
  10556. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10557. redis.Set(key, "", time.Second)
  10558. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10559. //清空key 值
  10560. redis.Set(keyOne, "", time.Second)
  10561. }
  10562. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10563. if orderOne.ID > 0 {
  10564. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10565. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10566. redis := service.RedisClient()
  10567. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10568. redis.Set(key, "", time.Second)
  10569. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10570. //清空key 值
  10571. redis.Set(keyOne, "", time.Second)
  10572. }
  10573. if err2 == nil {
  10574. //去除当天患者排班中重复数据,保留最后一条数据
  10575. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10576. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10577. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  10578. c.ServeSuccessJSON(map[string]interface{}{
  10579. "msg": "覆盖成功",
  10580. "new_sch": new_sch,
  10581. })
  10582. } else {
  10583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10584. return
  10585. }
  10586. } else {
  10587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10588. return
  10589. }
  10590. }
  10591. func (c *DialysisAPIController) BatchCheckAdvice() {
  10592. patient_id, _ := c.GetInt64("patient_id")
  10593. advice_date, _ := c.GetInt64("advice_date")
  10594. org_id := c.GetMobileAdminUserInfo().Org.Id
  10595. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  10596. //查询是his系统还是血透系统
  10597. _, configs := service.FindXTHisRecordByOrgId(org_id)
  10598. //his客户
  10599. if configs.IsOpen == 1 {
  10600. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  10601. for _, item := range adviceList {
  10602. service.BatchCheckHisAdvice(item.ID, creater)
  10603. }
  10604. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10605. for _, item := range projectList {
  10606. service.BatchCheckProject(item.ID, creater)
  10607. }
  10608. c.ServeSuccessJSON(map[string]interface{}{
  10609. "adviceList": adviceList,
  10610. "projectList": projectList,
  10611. })
  10612. }
  10613. if configs.IsOpen != 1 {
  10614. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  10615. for _, item := range adviceList {
  10616. service.BatchAdviceList(item.ID, creater)
  10617. }
  10618. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10619. for _, item := range projectList {
  10620. service.BatchCheckProject(item.ID, creater)
  10621. }
  10622. c.ServeSuccessJSON(map[string]interface{}{
  10623. "adviceList": adviceList,
  10624. "projectList": projectList,
  10625. })
  10626. }
  10627. return
  10628. }
  10629. func (c *DialysisAPIController) GetAllMobileDrugList() {
  10630. org_id := c.GetMobileAdminUserInfo().Org.Id
  10631. drugList, _ := service.GetAllDrugList(org_id)
  10632. c.ServeSuccessJSON(map[string]interface{}{
  10633. "drugList": drugList,
  10634. })
  10635. }
  10636. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  10637. org_id := c.GetMobileAdminUserInfo().Org.Id
  10638. dataBody := make(map[string]interface{}, 0)
  10639. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10640. if err != nil {
  10641. utils.ErrorLog(err.Error())
  10642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10643. return
  10644. }
  10645. timeLayout := "2006-01-02"
  10646. loc, _ := time.LoadLocation("Local")
  10647. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  10648. utils.ErrorLog("advice_type")
  10649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10650. return
  10651. }
  10652. adviceType := int64(dataBody["advice_type"].(float64))
  10653. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10654. utils.ErrorLog("start_time")
  10655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10656. return
  10657. }
  10658. startTime2, _ := dataBody["start_time"].(string)
  10659. time_arr := strings.Split(startTime2, " ")
  10660. if len(time_arr) > 0 {
  10661. startTime2 = time_arr[0]
  10662. }
  10663. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10664. utils.ErrorLog("advice_date")
  10665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10666. return
  10667. }
  10668. advice_date, _ := dataBody["advice_date"].(string)
  10669. var advicedateunix int64
  10670. if len(advice_date) > 0 {
  10671. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10672. if err != nil {
  10673. fmt.Println(err)
  10674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10675. return
  10676. }
  10677. advicedateunix = theTime.Unix()
  10678. }
  10679. adviceDate := startTime2
  10680. if len(adviceDate) == 0 {
  10681. utils.ErrorLog("len(adviceDate) == 0")
  10682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10683. return
  10684. }
  10685. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10686. if err != nil {
  10687. utils.ErrorLog(err.Error())
  10688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10689. return
  10690. }
  10691. AdviceDate := advicedateunix
  10692. RecordDate := advicedateunix
  10693. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10694. utils.ErrorLog("start_time")
  10695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10696. return
  10697. }
  10698. startTime, _ := dataBody["start_time"].(string)
  10699. if len(startTime) == 0 {
  10700. utils.ErrorLog("len(start_time) == 0")
  10701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10702. return
  10703. }
  10704. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10705. if err != nil {
  10706. utils.ErrorLog(err.Error())
  10707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10708. return
  10709. }
  10710. StartTime := theTime.Unix()
  10711. advice_name, _ := dataBody["advice_name"].(string)
  10712. advice_desc, _ := dataBody["advice_desc"].(string)
  10713. delivery_way, _ := dataBody["delivery_way"].(string)
  10714. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10715. frequency_type := int64(dataBody["frequency_type"].(float64))
  10716. frequency_week, _ := dataBody["frequency_week"].(string)
  10717. prescribing_number := dataBody["prescribing_number"].(float64)
  10718. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10719. remark := dataBody["remark"].(string)
  10720. single_dose := dataBody["single_dose"].(float64)
  10721. single_dose_unit := dataBody["single_dose_unit"].(string)
  10722. patient_id := int64(dataBody["patient_id"].(float64))
  10723. day_count := int64(dataBody["day_count"].(float64))
  10724. groupNo := int64(dataBody["group_no"].(float64))
  10725. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10726. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  10727. if groupNo <= 0 {
  10728. group := service.GetMaxAdviceGroupID(org_id)
  10729. groupNo = group + 1
  10730. }
  10731. var template_id = ""
  10732. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  10733. template_id = "M" + adviceLastId
  10734. advice := models.DoctorAdvice{
  10735. UserOrgId: org_id,
  10736. PatientId: patient_id,
  10737. AdviceType: adviceType,
  10738. AdviceDate: AdviceDate,
  10739. StartTime: StartTime,
  10740. AdviceName: advice_name,
  10741. AdviceDesc: advice_desc,
  10742. ReminderDate: 0,
  10743. SingleDose: single_dose,
  10744. SingleDoseUnit: single_dose_unit,
  10745. DrugSpec: 0,
  10746. DrugSpecUnit: "",
  10747. PrescribingNumber: prescribing_number,
  10748. PrescribingNumberUnit: prescribing_number_unit,
  10749. DeliveryWay: delivery_way,
  10750. ExecutionFrequency: execution_frequency,
  10751. AdviceDoctor: advice_doctor,
  10752. Status: 1,
  10753. CreatedTime: time.Now().Unix(),
  10754. UpdatedTime: 0,
  10755. AdviceAffirm: "",
  10756. Remark: remark,
  10757. StopTime: 0,
  10758. StopReason: "",
  10759. StopDoctor: 0,
  10760. StopState: 2,
  10761. ParentId: 0,
  10762. ExecutionTime: 0,
  10763. ExecutionStaff: 0,
  10764. ExecutionState: 0,
  10765. Checker: 0,
  10766. RecordDate: RecordDate,
  10767. DialysisOrderId: 0,
  10768. CheckTime: 0,
  10769. CheckState: 0,
  10770. AdviceId: 0,
  10771. RemindType: 0,
  10772. FrequencyType: frequency_type,
  10773. DayCount: day_count,
  10774. WeekDay: frequency_week,
  10775. ChildDoctorAdvice: nil,
  10776. TemplateId: template_id,
  10777. Modifier: 0,
  10778. IsCheck: 0,
  10779. Way: 0,
  10780. DrugId: 0,
  10781. DrugNameId: 0,
  10782. IsMedicine: 0,
  10783. PushStartTime: 0,
  10784. IsSettle: 0,
  10785. IsPrescription: 0,
  10786. GroupNo: groupNo,
  10787. }
  10788. service.CreateMobileAdivce(advice)
  10789. c.ServeSuccessJSON(map[string]interface{}{
  10790. "msg": "保存成功!",
  10791. })
  10792. }
  10793. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  10794. patient_id, _ := c.GetInt64("patient_id")
  10795. org_id := c.GetMobileAdminUserInfo().Org.Id
  10796. app_id := c.GetMobileAdminUserInfo().App.Id
  10797. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  10798. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  10799. c.ServeSuccessJSON(map[string]interface{}{
  10800. "adviceList": adviceList,
  10801. "adminRoles": adminRoles,
  10802. })
  10803. }
  10804. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  10805. org_id := c.GetMobileAdminUserInfo().Org.Id
  10806. dataBody := make(map[string]interface{}, 0)
  10807. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10808. if err != nil {
  10809. utils.ErrorLog(err.Error())
  10810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10811. return
  10812. }
  10813. timeLayout := "2006-01-02"
  10814. loc, _ := time.LoadLocation("Local")
  10815. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10816. utils.ErrorLog("start_time")
  10817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10818. return
  10819. }
  10820. startTime2, _ := dataBody["start_time"].(string)
  10821. time_arr := strings.Split(startTime2, " ")
  10822. if len(time_arr) > 0 {
  10823. startTime2 = time_arr[0]
  10824. }
  10825. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10826. utils.ErrorLog("advice_date")
  10827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10828. return
  10829. }
  10830. advice_date, _ := dataBody["advice_date"].(string)
  10831. var advicedateunix int64
  10832. if len(advice_date) > 0 {
  10833. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10834. if err != nil {
  10835. fmt.Println(err)
  10836. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10837. return
  10838. }
  10839. advicedateunix = theTime.Unix()
  10840. }
  10841. adviceDate := startTime2
  10842. if len(adviceDate) == 0 {
  10843. utils.ErrorLog("len(adviceDate) == 0")
  10844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10845. return
  10846. }
  10847. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10848. if err != nil {
  10849. utils.ErrorLog(err.Error())
  10850. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10851. return
  10852. }
  10853. AdviceDate := advicedateunix
  10854. RecordDate := advicedateunix
  10855. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10856. utils.ErrorLog("start_time")
  10857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10858. return
  10859. }
  10860. startTime, _ := dataBody["start_time"].(string)
  10861. if len(startTime) == 0 {
  10862. utils.ErrorLog("len(start_time) == 0")
  10863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10864. return
  10865. }
  10866. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10867. if err != nil {
  10868. utils.ErrorLog(err.Error())
  10869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10870. return
  10871. }
  10872. StartTime := theTime.Unix()
  10873. advice_name, _ := dataBody["advice_name"].(string)
  10874. advice_desc, _ := dataBody["advice_desc"].(string)
  10875. delivery_way, _ := dataBody["delivery_way"].(string)
  10876. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10877. prescribing_number := dataBody["prescribing_number"].(float64)
  10878. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10879. remark := dataBody["remark"].(string)
  10880. single_dose := dataBody["single_dose"].(float64)
  10881. single_dose_unit := dataBody["single_dose_unit"].(string)
  10882. patient_id := int64(dataBody["patient_id"].(float64))
  10883. groupNo := int64(dataBody["group_no"].(float64))
  10884. parent_id := int64(dataBody["parent_id"].(float64))
  10885. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10886. advice := models.XtDoctorAdviceOne{
  10887. UserOrgId: org_id,
  10888. PatientId: patient_id,
  10889. AdviceType: 1,
  10890. AdviceDate: AdviceDate,
  10891. StartTime: StartTime,
  10892. AdviceName: advice_name,
  10893. AdviceDesc: advice_desc,
  10894. ReminderDate: 0,
  10895. SingleDose: single_dose,
  10896. SingleDoseUnit: single_dose_unit,
  10897. PrescribingNumber: prescribing_number,
  10898. PrescribingNumberUnit: prescribing_number_unit,
  10899. DeliveryWay: delivery_way,
  10900. ExecutionFrequency: execution_frequency,
  10901. AdviceDoctor: advice_doctor,
  10902. Status: 1,
  10903. CreatedTime: time.Now().Unix(),
  10904. UpdatedTime: time.Now().Unix(),
  10905. AdviceAffirm: "",
  10906. Remark: remark,
  10907. StopTime: 0,
  10908. StopReason: "",
  10909. StopDoctor: 0,
  10910. StopState: 2,
  10911. ParentId: parent_id,
  10912. ExecutionTime: 0,
  10913. ExecutionStaff: 0,
  10914. ExecutionState: 0,
  10915. Checker: 0,
  10916. RecordDate: RecordDate,
  10917. DialysisOrderId: 0,
  10918. CheckTime: 0,
  10919. CheckState: 0,
  10920. DrugSpec: 0,
  10921. DrugSpecUnit: "",
  10922. Groupno: groupNo,
  10923. RemindType: 0,
  10924. FrequencyType: 0,
  10925. DayCount: 0,
  10926. WeekDay: "",
  10927. TemplateId: "",
  10928. Modifier: 0,
  10929. }
  10930. service.CreateMobileAdivceOne(advice)
  10931. c.ServeSuccessJSON(map[string]interface{}{
  10932. "msg": "保存成功!",
  10933. })
  10934. }
  10935. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  10936. id, _ := c.GetInt64("id")
  10937. service.DeleteSelfAdviceSubAdvice(id)
  10938. c.ServeSuccessJSON(map[string]interface{}{
  10939. "msg": "保存成功!",
  10940. })
  10941. }
  10942. func (c *DialysisAPIController) GetEditAdviceAction() {
  10943. id, _ := c.GetInt64("id")
  10944. org_id := c.GetMobileAdminUserInfo().Org.Id
  10945. advice, _ := service.GetEditAdviceActionList(id, org_id)
  10946. drugList, _ := service.GetAllDrugList(org_id)
  10947. c.ServeSuccessJSON(map[string]interface{}{
  10948. "advice": advice,
  10949. "drugList": drugList,
  10950. })
  10951. }
  10952. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  10953. dataBody := make(map[string]interface{}, 0)
  10954. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10955. if err != nil {
  10956. utils.ErrorLog(err.Error())
  10957. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10958. return
  10959. }
  10960. timeLayout := "2006-01-02"
  10961. loc, _ := time.LoadLocation("Local")
  10962. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10963. utils.ErrorLog("start_time")
  10964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10965. return
  10966. }
  10967. startTime2, _ := dataBody["start_time"].(string)
  10968. time_arr := strings.Split(startTime2, " ")
  10969. if len(time_arr) > 0 {
  10970. startTime2 = time_arr[0]
  10971. }
  10972. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10973. utils.ErrorLog("advice_date")
  10974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10975. return
  10976. }
  10977. advice_date, _ := dataBody["advice_date"].(string)
  10978. var advicedateunix int64
  10979. if len(advice_date) > 0 {
  10980. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10981. if err != nil {
  10982. fmt.Println(err)
  10983. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10984. return
  10985. }
  10986. advicedateunix = theTime.Unix()
  10987. }
  10988. adviceDate := startTime2
  10989. if len(adviceDate) == 0 {
  10990. utils.ErrorLog("len(adviceDate) == 0")
  10991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10992. return
  10993. }
  10994. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10995. if err != nil {
  10996. utils.ErrorLog(err.Error())
  10997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10998. return
  10999. }
  11000. AdviceDate := advicedateunix
  11001. RecordDate := advicedateunix
  11002. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11003. utils.ErrorLog("start_time")
  11004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11005. return
  11006. }
  11007. startTime, _ := dataBody["start_time"].(string)
  11008. if len(startTime) == 0 {
  11009. utils.ErrorLog("len(start_time) == 0")
  11010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11011. return
  11012. }
  11013. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  11014. if err != nil {
  11015. utils.ErrorLog(err.Error())
  11016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11017. return
  11018. }
  11019. StartTime := theTime.Unix()
  11020. advice_name, _ := dataBody["advice_name"].(string)
  11021. advice_desc, _ := dataBody["advice_desc"].(string)
  11022. delivery_way, _ := dataBody["delivery_way"].(string)
  11023. execution_frequency, _ := dataBody["execution_frequency"].(string)
  11024. prescribing_number := dataBody["prescribing_number"].(float64)
  11025. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  11026. remark := dataBody["remark"].(string)
  11027. single_dose := dataBody["single_dose"].(float64)
  11028. single_dose_unit := dataBody["single_dose_unit"].(string)
  11029. id := int64(dataBody["id"].(float64))
  11030. frequency_type := int64(dataBody["frequency_type"].(float64))
  11031. frequency_week, _ := dataBody["frequency_week"].(string)
  11032. day_count := int64(dataBody["day_count"].(float64))
  11033. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  11034. advice := models.XtDoctorAdviceOne{
  11035. AdviceDate: AdviceDate,
  11036. StartTime: StartTime,
  11037. AdviceName: advice_name,
  11038. AdviceDesc: advice_desc,
  11039. SingleDose: single_dose,
  11040. SingleDoseUnit: single_dose_unit,
  11041. PrescribingNumber: prescribing_number,
  11042. PrescribingNumberUnit: prescribing_number_unit,
  11043. DeliveryWay: delivery_way,
  11044. ExecutionFrequency: execution_frequency,
  11045. AdviceDoctor: advice_doctor,
  11046. Remark: remark,
  11047. RecordDate: RecordDate,
  11048. FrequencyType: frequency_type,
  11049. DayCount: day_count,
  11050. WeekDay: frequency_week,
  11051. }
  11052. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  11053. c.ServeSuccessJSON(map[string]interface{}{
  11054. "advice": advice,
  11055. })
  11056. }
  11057. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  11058. dataBody := make(map[string]interface{}, 0)
  11059. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11060. if err != nil {
  11061. utils.ErrorLog(err.Error())
  11062. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11063. return
  11064. }
  11065. timeLayout := "2006-01-02"
  11066. loc, _ := time.LoadLocation("Local")
  11067. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11068. utils.ErrorLog("start_time")
  11069. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11070. return
  11071. }
  11072. startTime2, _ := dataBody["start_time"].(string)
  11073. time_arr := strings.Split(startTime2, " ")
  11074. if len(time_arr) > 0 {
  11075. startTime2 = time_arr[0]
  11076. }
  11077. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  11078. utils.ErrorLog("advice_date")
  11079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11080. return
  11081. }
  11082. advice_date, _ := dataBody["advice_date"].(string)
  11083. var advicedateunix int64
  11084. if len(advice_date) > 0 {
  11085. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  11086. if err != nil {
  11087. fmt.Println(err)
  11088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11089. return
  11090. }
  11091. advicedateunix = theTime.Unix()
  11092. }
  11093. adviceDate := startTime2
  11094. if len(adviceDate) == 0 {
  11095. utils.ErrorLog("len(adviceDate) == 0")
  11096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11097. return
  11098. }
  11099. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  11100. if err != nil {
  11101. utils.ErrorLog(err.Error())
  11102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11103. return
  11104. }
  11105. AdviceDate := advicedateunix
  11106. RecordDate := advicedateunix
  11107. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11108. utils.ErrorLog("start_time")
  11109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11110. return
  11111. }
  11112. startTime, _ := dataBody["start_time"].(string)
  11113. if len(startTime) == 0 {
  11114. utils.ErrorLog("len(start_time) == 0")
  11115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11116. return
  11117. }
  11118. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  11119. if err != nil {
  11120. utils.ErrorLog(err.Error())
  11121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11122. return
  11123. }
  11124. StartTime := theTime.Unix()
  11125. advice_name, _ := dataBody["advice_name"].(string)
  11126. advice_desc, _ := dataBody["advice_desc"].(string)
  11127. delivery_way, _ := dataBody["delivery_way"].(string)
  11128. execution_frequency, _ := dataBody["execution_frequency"].(string)
  11129. prescribing_number := dataBody["prescribing_number"].(float64)
  11130. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  11131. remark := dataBody["remark"].(string)
  11132. single_dose := dataBody["single_dose"].(float64)
  11133. single_dose_unit := dataBody["single_dose_unit"].(string)
  11134. id := int64(dataBody["id"].(float64))
  11135. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  11136. advice := models.XtDoctorAdviceOne{
  11137. AdviceDate: AdviceDate,
  11138. StartTime: StartTime,
  11139. AdviceName: advice_name,
  11140. AdviceDesc: advice_desc,
  11141. SingleDose: single_dose,
  11142. SingleDoseUnit: single_dose_unit,
  11143. PrescribingNumber: prescribing_number,
  11144. PrescribingNumberUnit: prescribing_number_unit,
  11145. DeliveryWay: delivery_way,
  11146. ExecutionFrequency: execution_frequency,
  11147. AdviceDoctor: advice_doctor,
  11148. Remark: remark,
  11149. RecordDate: RecordDate,
  11150. }
  11151. service.UpdateMobileDoctorAdviceById(id, advice)
  11152. c.ServeSuccessJSON(map[string]interface{}{
  11153. "advice": advice,
  11154. })
  11155. }
  11156. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  11157. dataBody := make(map[string]interface{}, 0)
  11158. timeLayout := "2006-01-02"
  11159. loc, _ := time.LoadLocation("Local")
  11160. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11161. if err != nil {
  11162. utils.ErrorLog(err.Error())
  11163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11164. return
  11165. }
  11166. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11167. utils.ErrorLog("start_time")
  11168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11169. return
  11170. }
  11171. startTime2, _ := dataBody["start_time"].(string)
  11172. time_arr := strings.Split(startTime2, " ")
  11173. if len(time_arr) > 0 {
  11174. startTime2 = time_arr[0]
  11175. }
  11176. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  11177. utils.ErrorLog("advice_date")
  11178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11179. return
  11180. }
  11181. advice_date, _ := dataBody["advice_date"].(string)
  11182. var advicedateunix int64
  11183. if len(advice_date) > 0 {
  11184. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  11185. if err != nil {
  11186. fmt.Println(err)
  11187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11188. return
  11189. }
  11190. advicedateunix = theTime.Unix()
  11191. }
  11192. adviceDate := startTime2
  11193. if len(adviceDate) == 0 {
  11194. utils.ErrorLog("len(adviceDate) == 0")
  11195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11196. return
  11197. }
  11198. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  11199. if err != nil {
  11200. utils.ErrorLog(err.Error())
  11201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11202. return
  11203. }
  11204. RecordDate := advicedateunix
  11205. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11206. utils.ErrorLog("start_time")
  11207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11208. return
  11209. }
  11210. startTime, _ := dataBody["start_time"].(string)
  11211. if len(startTime) == 0 {
  11212. utils.ErrorLog("len(start_time) == 0")
  11213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11214. return
  11215. }
  11216. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  11217. if err != nil {
  11218. utils.ErrorLog(err.Error())
  11219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11220. return
  11221. }
  11222. StartTime := theTime.Unix()
  11223. patient_id := int64(dataBody["patient_id"].(float64))
  11224. group_no := int64(dataBody["group_no"].(float64))
  11225. org_id := c.GetMobileAdminUserInfo().Org.Id
  11226. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  11227. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  11228. utils.ErrorLog("advices")
  11229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11230. return
  11231. }
  11232. adviceNames := dataBody["advices"].([]interface{})
  11233. var advices []*models.GroupAdvice
  11234. for _, adviceNameMap := range adviceNames {
  11235. var advice models.GroupAdvice
  11236. adviceNameM := adviceNameMap.(map[string]interface{})
  11237. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  11238. utils.ErrorLog("advice_name")
  11239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11240. return
  11241. }
  11242. adviceName, _ := adviceNameM["advice_name"].(string)
  11243. if len(adviceName) == 0 {
  11244. utils.ErrorLog("len(advice_name) == 0")
  11245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11246. return
  11247. }
  11248. advice.AdviceName = adviceName
  11249. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  11250. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  11251. advice.DrugSpec = drugSpec
  11252. }
  11253. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  11254. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  11255. advice.AdviceDesc = adviceDesc
  11256. }
  11257. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  11258. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  11259. advice.DrugSpecUnit = drugSpecUnit
  11260. }
  11261. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  11262. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  11263. advice.SingleDose = singleDose
  11264. }
  11265. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  11266. singleDose := adviceNameM["single_dose"].(float64)
  11267. advice.SingleDose = singleDose
  11268. }
  11269. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  11270. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  11271. advice.SingleDoseUnit = singleDoseUnit
  11272. }
  11273. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  11274. tmp := adviceNameM["single_dose_unit"].(float64)
  11275. singleDoseUnit := service.TypeConversion(tmp)
  11276. advice.SingleDoseUnit = singleDoseUnit
  11277. }
  11278. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  11279. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  11280. advice.PrescribingNumber = prescribingNumber
  11281. }
  11282. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  11283. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  11284. advice.PrescribingNumber = prescribingNumber
  11285. }
  11286. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  11287. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  11288. advice.PrescribingNumberUnit = prescribingNumberUnit
  11289. }
  11290. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  11291. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  11292. advice.DeliveryWay = deliveryWay
  11293. }
  11294. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  11295. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  11296. advice.ExecutionFrequency = executionFrequency
  11297. }
  11298. remark, _ := adviceNameM["remark"].(string)
  11299. advice.Remark = remark
  11300. advice.AdviceType = 1
  11301. advice.StartTime = StartTime
  11302. advice.RecordDate = RecordDate
  11303. advice.PatientId = patient_id
  11304. advice.UserOrgId = org_id
  11305. advice.AdviceDoctor = advice_doctor
  11306. advice.StopState = 2
  11307. advices = append(advices, &advice)
  11308. }
  11309. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  11310. c.ServeSuccessJSON(map[string]interface{}{
  11311. "advice": newAdvices,
  11312. })
  11313. }
  11314. func (c *DialysisAPIController) StopLongAdvice() {
  11315. stop_time := c.GetString("execution_time")
  11316. id, _ := c.GetInt64("id")
  11317. if len(stop_time) <= 0 {
  11318. utils.ErrorLog("stop_time")
  11319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11320. return
  11321. }
  11322. timeLayout2 := "2006-01-02 15:04:05"
  11323. loc, _ := time.LoadLocation("Local")
  11324. theTime, errs := time.ParseInLocation(timeLayout2, stop_time, loc)
  11325. if errs != nil {
  11326. utils.ErrorLog(errs.Error())
  11327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11328. return
  11329. }
  11330. advice, _ := service.StopLongAdvice(id, theTime.Unix())
  11331. c.ServeSuccessJSON(map[string]interface{}{
  11332. "advice": advice,
  11333. })
  11334. }
  11335. func (c *DialysisAPIController) BatchAdviceCheckList() {
  11336. dataBody := make(map[string]interface{}, 0)
  11337. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11338. if err != nil {
  11339. utils.ErrorLog(err.Error())
  11340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11341. return
  11342. }
  11343. orgId := c.GetMobileAdminUserInfo().Org.Id
  11344. patient_id := int64(dataBody["patient_id"].(float64))
  11345. record_date := int64(dataBody["record_date"].(float64))
  11346. checker := int64(dataBody["checker"].(float64))
  11347. check_time := dataBody["check_time"].(string)
  11348. checkTime, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", check_time)
  11349. if parseStartDateErr != nil {
  11350. c.ErrorLog("时间解析失败:%v", parseStartDateErr)
  11351. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11352. return
  11353. }
  11354. var advice_id []int64
  11355. var his_advice_id []int64
  11356. var project_id []int64
  11357. var team_list []int64
  11358. if dataBody["new_advice_list"] != nil && reflect.TypeOf(dataBody["new_advice_list"]).String() == "[]interface {}" {
  11359. newAdviceList, _ := dataBody["new_advice_list"].([]interface{})
  11360. if len(newAdviceList) > 0 {
  11361. for _, item := range newAdviceList {
  11362. items := item.(map[string]interface{})
  11363. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11364. utils.ErrorLog("id")
  11365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11366. return
  11367. }
  11368. id := int64(items["id"].(float64))
  11369. if items["origin"] == nil || reflect.TypeOf(items["origin"]).String() != "float64" {
  11370. utils.ErrorLog("origin")
  11371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11372. return
  11373. }
  11374. origin := int64(items["origin"].(float64))
  11375. if items["team_id"] == nil || reflect.TypeOf(items["team_id"]).String() != "float64" {
  11376. utils.ErrorLog("team_id")
  11377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11378. return
  11379. }
  11380. team_id := int64(items["team_id"].(float64))
  11381. if team_id == 0 {
  11382. //临时医嘱
  11383. if origin == 1 {
  11384. service.BatchAdviceDoctorList(patient_id, record_date, id, orgId, checker, checkTime.Unix())
  11385. advice_id = append(advice_id, id)
  11386. }
  11387. //his医嘱
  11388. if origin == 2 {
  11389. service.BatchHisAdviceDoctorList(patient_id, record_date, id, orgId, checker, checkTime.Unix())
  11390. his_advice_id = append(his_advice_id, id)
  11391. }
  11392. //his医嘱
  11393. if origin == 3 {
  11394. service.BatchHisPrescriptionProject(patient_id, record_date, id, orgId, checker, checkTime.Unix())
  11395. project_id = append(project_id, id)
  11396. }
  11397. }
  11398. if team_id > 0 {
  11399. service.BatchCheckPrescriptionProject(patient_id, record_date, team_id, orgId, checker, checkTime.Unix())
  11400. team_list = append(team_list, team_id)
  11401. }
  11402. }
  11403. }
  11404. }
  11405. advice, _ := service.GetBatchAdviceList(advice_id)
  11406. hisadvice, _ := service.GetBatchHisAdviceList(his_advice_id)
  11407. hisproject, _ := service.GetBatchPrescriptionList(project_id)
  11408. teamlist, _ := service.GetBatchTeamList(team_list, patient_id, record_date, orgId)
  11409. c.ServeSuccessJSON(map[string]interface{}{
  11410. "advice": advice,
  11411. "hisadvice": hisadvice,
  11412. "hisproject": hisproject,
  11413. "teamlist": teamlist,
  11414. })
  11415. return
  11416. }
  11417. func (c *DialysisAPIController) BatchAdviceExeCutionList() {
  11418. dataBody := make(map[string]interface{}, 0)
  11419. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11420. if err != nil {
  11421. utils.ErrorLog(err.Error())
  11422. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11423. return
  11424. }
  11425. orgId := c.GetMobileAdminUserInfo().Org.Id
  11426. patient_id := int64(dataBody["patient_id"].(float64))
  11427. record_date := int64(dataBody["record_date"].(float64))
  11428. execution_staff := int64(dataBody["execution_staff"].(float64))
  11429. execution_time := dataBody["execution_time"].(string)
  11430. executionTime, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  11431. if parseStartDateErr != nil {
  11432. c.ErrorLog("时间解析失败:%v", parseStartDateErr)
  11433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11434. return
  11435. }
  11436. var advice_id []int64
  11437. var his_advice_id []int64
  11438. var project_id []int64
  11439. var team_list []int64
  11440. if dataBody["new_advice_list"] != nil && reflect.TypeOf(dataBody["new_advice_list"]).String() == "[]interface {}" {
  11441. newAdviceList, _ := dataBody["new_advice_list"].([]interface{})
  11442. if len(newAdviceList) > 0 {
  11443. for _, item := range newAdviceList {
  11444. items := item.(map[string]interface{})
  11445. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11446. utils.ErrorLog("id")
  11447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11448. return
  11449. }
  11450. id := int64(items["id"].(float64))
  11451. if items["origin"] == nil || reflect.TypeOf(items["origin"]).String() != "float64" {
  11452. utils.ErrorLog("origin")
  11453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11454. return
  11455. }
  11456. origin := int64(items["origin"].(float64))
  11457. if items["team_id"] == nil || reflect.TypeOf(items["team_id"]).String() != "float64" {
  11458. utils.ErrorLog("team_id")
  11459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11460. return
  11461. }
  11462. team_id := int64(items["team_id"].(float64))
  11463. if team_id == 0 {
  11464. //临时医嘱
  11465. if origin == 1 {
  11466. service.BatchExecutionAdviceDoctorList(patient_id, record_date, id, orgId, execution_staff, executionTime.Unix())
  11467. advice_id = append(advice_id, id)
  11468. }
  11469. //his医嘱
  11470. if origin == 2 {
  11471. service.BatchExecutionHisAdviceDoctorList(patient_id, record_date, id, orgId, execution_staff, executionTime.Unix())
  11472. his_advice_id = append(his_advice_id, id)
  11473. }
  11474. //his医嘱
  11475. if origin == 3 {
  11476. service.BatchExecutionHisPrescriptionProject(patient_id, record_date, id, orgId, execution_staff, executionTime.Unix())
  11477. project_id = append(project_id, id)
  11478. }
  11479. }
  11480. if team_id > 0 {
  11481. service.BatchExecutionPrescriptionProject(patient_id, record_date, team_id, orgId, execution_staff, executionTime.Unix())
  11482. team_list = append(team_list, team_id)
  11483. }
  11484. }
  11485. }
  11486. }
  11487. advice, _ := service.GetBatchAdviceList(advice_id)
  11488. hisadvice, _ := service.GetBatchHisAdviceList(his_advice_id)
  11489. hisproject, _ := service.GetBatchPrescriptionList(project_id)
  11490. teamlist, _ := service.GetBatchTeamList(team_list, patient_id, record_date, orgId)
  11491. c.ServeSuccessJSON(map[string]interface{}{
  11492. "advice": advice,
  11493. "hisadvice": hisadvice,
  11494. "hisproject": hisproject,
  11495. "teamlist": teamlist,
  11496. })
  11497. return
  11498. }