dialysis_api_controller.go 258KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935
  1. package controllers
  2. import (
  3. "XT_New/models"
  4. "XT_New/service"
  5. "XT_New/utils"
  6. "encoding/json"
  7. "fmt"
  8. "github.com/jinzhu/gorm"
  9. "math"
  10. "reflect"
  11. "strconv"
  12. "strings"
  13. //"strings"
  14. "time"
  15. "XT_New/enums"
  16. "github.com/astaxie/beego"
  17. )
  18. type DialysisApiController struct {
  19. BaseAuthAPIController
  20. }
  21. func DialysisApiRegistRouters() {
  22. beego.Router("/api/dialysis/device", &DialysisApiController{}, "get:GetDeviceList")
  23. beego.Router("/api/dialysis/patients", &DialysisApiController{}, "get:GetDialysisWatch")
  24. beego.Router("/api/dialysis/zone", &DialysisApiController{}, "get:GetAllDeviceZone")
  25. beego.Router("/api/dialysis/info", &DialysisApiController{}, "get:GetSchedualPatientsInfo")
  26. beego.Router("/api/dialysis/advice/create", &DialysisApiController{}, "Post:CreateDoctorAdvice")
  27. beego.Router("/api/dialysis/advice/get", &DialysisApiController{}, "Get:GetDoctorAdvice")
  28. beego.Router("/api/dialysis/advice/edit", &DialysisApiController{}, "put:EditDoctorAdvice")
  29. beego.Router("/api/dialysis/monitor/create", &DialysisApiController{}, "Post:CreateMonitor")
  30. beego.Router("/api/dialysis/monitor/del", &DialysisApiController{}, "Post:DelMonitor")
  31. beego.Router("/api/dialysis/dialysisorder", &DialysisApiController{}, "Get:GetDialysisOrder")
  32. beego.Router("/api/dialysis/prescription", &DialysisApiController{}, "Post:PostPrescription")
  33. beego.Router("/api/dialysis/soulution", &DialysisApiController{}, "Post:PostSoulution")
  34. beego.Router("/api/dialysis/dobule", &DialysisApiController{}, "Post:PostDouleCheck")
  35. beego.Router("/api/dialysis/accepts", &DialysisApiController{}, "Post:PostReceiveTreatmentAsses")
  36. beego.Router("/api/dialysis/assessmentbeforedislysis", &DialysisApiController{}, "Post:PostAssessmentBeforeDislysis")
  37. beego.Router("/api/dialysis/assessmentafterdislysis", &DialysisApiController{}, "Post:PostAssessmentAfterDislysis")
  38. beego.Router("/api/dialysis/treatmentsummary", &DialysisApiController{}, "Post:PostTreatmentSummary")
  39. beego.Router("/api/dialysis/advice_remind", &DialysisApiController{}, "Get:GetLongAdvice")
  40. beego.Router("/api/dialysis/advice_remind/one", &DialysisApiController{}, "Get:GetLongAdviceOne")
  41. beego.Router("/api/dialysis/advice_remind/two", &DialysisApiController{}, "Get:GetLongAdviceTwo")
  42. beego.Router("/api/advice_remind/create", &DialysisApiController{}, "Post:CreateRemindDoctorAdvice")
  43. beego.Router("/api/solution/get", &DialysisApiController{}, "Get:GetSolution")
  44. beego.Router("/api/schedule/get", &DialysisApiController{}, "Get:GetSchedule")
  45. beego.Router("/api/today_monitor/get", &DialysisApiController{}, "Get:GetTodayMonitor")
  46. beego.Router("/api/dryweight/commit", &DialysisApiController{}, "Post:UploadDryWeight")
  47. beego.Router("/api/func_per/get", &DialysisApiController{}, "Get:GetFuncPurview")
  48. beego.Router("/api/doctoradvice/get", &DialysisApiController{}, "Get:GetLastOrNextDoctorAdvice")
  49. beego.Router("/api/dialysisgoods/get", &DialysisApiController{}, "Get:GetDialysisGoods")
  50. beego.Router("/api/goodstatistics/get", &DialysisApiController{}, "Get:GetDialysisGoodsStatistics")
  51. beego.Router("/api/queue/get", &DialysisApiController{}, "Get:GetQueueCall")
  52. beego.Router("/api/queue/update", &DialysisApiController{}, "Get:UpdateQueueCall")
  53. beego.Router("/api/get/getrolelist", &DialysisApiController{}, "Get:GetRoleList")
  54. beego.Router("/api/getinitprintdata", &DialysisApiController{}, "Get:GetInitPrintData")
  55. beego.Router("/api/schedule/getorderdoctoradvice", &DialysisApiController{}, "Get:GetOrderDoctorAdvice")
  56. beego.Router("/api/getinitprintdateone", &DialysisApiController{}, "Get:GetInitPrintDataOne")
  57. //新接口
  58. beego.Router("/api/patient/getpatientdialysissolutiongrouplist", &DialysisApiController{}, "Get:GetPatientDialysisSolutionGroupList")
  59. beego.Router("/api/patient/getdialysisadvicetemplatelist", &DialysisApiController{}, "Get:GetDialysisAdviceTemplateList")
  60. beego.Router("/api/patient/savedialysissetting", &DialysisApiController{}, "Get:SaveDialysisSetting")
  61. beego.Router("/api/patient/getdialysissetting", &DialysisApiController{}, "Get:GetDialysisSetting")
  62. beego.Router("/api/patient/getdialysisparameter", &DialysisApiController{}, "Get:GetDialysisParameterList")
  63. beego.Router("/api/patient/getdialysisgoodtotalcount", &DialysisApiController{}, "Get:GetDialysisGoodTotalCount")
  64. beego.Router("/api/patient/getdialysisadvicescheduelist", &DialysisApiController{}, "Get:GetDialysisAdviceSchedulist")
  65. beego.Router("/api/patient/getdialysisparametergoodlist", &DialysisApiController{}, "Get:GetDialysisParameterGoodList")
  66. beego.Router("/api/patient/savehisdialysis", &DialysisApiController{}, "Get:SaveHisDialysis")
  67. beego.Router("/api/patient/gethisdialysisgoodcount", &DialysisApiController{}, "Get:GetHisDialysisGoodCount")
  68. beego.Router("/api/schedule/getpatientshedule", &DialysisApiController{}, "Get:GetPatientSchedule")
  69. beego.Router("/api/patient/getscheduleprintlist", &DialysisApiController{}, "Get:GetSchedulePrintList")
  70. beego.Router("/api/patient/getsolutionlistbyorgid", &DialysisApiController{}, "Get:GetSolutionListByOrgId")
  71. beego.Router("/api/schedule/excutiondoctoradvice", &DialysisApiController{}, "Get:ExcutionDoctorAdvice")
  72. beego.Router("/api/schedule/checknewdoctoradvice", &DialysisApiController{}, "Get:CheckNewDoctorAdvice")
  73. beego.Router("/api/schedule/settlenewdoctoradvice", &DialysisApiController{}, "Get:SettleNewDoctorAdvice")
  74. beego.Router("/api/schedule/excutiondoctoradvicebyid", &DialysisApiController{}, "Get:ExcutionDoctorAdviceById")
  75. beego.Router("/api/patient/getdialysisadvicetoday", &DialysisApiController{}, "Get:GetDialysisAdviceToday")
  76. beego.Router("/api/schedule/getmobileschedulelist", &DialysisApiController{}, "Get:GetMobileScheduleList")
  77. beego.Router("/api/patient/saveinformation", &DialysisApiController{}, "Get:SaveInformation")
  78. beego.Router("/api/patient/savedialysisInformationsetting", &DialysisApiController{}, "Get:SaveDialysisInformationSetting")
  79. beego.Router("/api/patient/getdialyisinformationsetting", &DialysisApiController{}, "Get:GetDialysisInformationSetting")
  80. beego.Router("/api/patient/checkdialysisinformation", &DialysisApiController{}, "Get:CheckDialysisInformation")
  81. beego.Router("/api/dialysis/patientsflow", &DialysisApiController{}, "Get:GetDialysisPatientsFlow")
  82. beego.Router("/api/patient/getlongdialysisadvicetoday", &DialysisApiController{}, "Get:GetLongDialysisAdviceToday")
  83. }
  84. func (c *DialysisApiController) GetQueueCall() {
  85. adminUserInfo := c.GetAdminUserInfo()
  86. queueConfig, _ := service.FindQueueCallInfo(adminUserInfo.CurrentOrgId)
  87. if queueConfig.ID <= 0 {
  88. queueConfig.OrgId = adminUserInfo.CurrentOrgId
  89. queueConfig.Qhsj = 10
  90. queueConfig.Jzdcbbcs = 3
  91. queueConfig.Jzbbsy = 1
  92. queueConfig.Jzjhyc = 0
  93. queueConfig.Sjdcbbcs = 3
  94. queueConfig.Sjbbsy = 0
  95. queueConfig.Sjjhyc = 0
  96. queueConfig.Txxqyxs = 0
  97. queueConfig.Txglsyxs = 0
  98. }
  99. c.ServeSuccessJSON(map[string]interface{}{
  100. "queue_config": queueConfig,
  101. })
  102. }
  103. func (c *DialysisApiController) UpdateQueueCall() {
  104. adminUserInfo := c.GetAdminUserInfo()
  105. queueConfig, _ := service.FindQueueCallInfo(adminUserInfo.CurrentOrgId)
  106. if queueConfig.ID <= 0 {
  107. queueConfig.OrgId = adminUserInfo.CurrentOrgId
  108. queueConfig.Qhsj = 10
  109. queueConfig.Jzdcbbcs = 3
  110. queueConfig.Jzbbsy = 1
  111. queueConfig.Jzjhyc = 0
  112. queueConfig.Sjdcbbcs = 3
  113. queueConfig.Sjbbsy = 0
  114. queueConfig.Sjjhyc = 0
  115. queueConfig.Txxqyxs = 0
  116. queueConfig.Txglsyxs = 0
  117. queueConfig.CreateTime = time.Now().Unix()
  118. queueConfig.UpdateTime = time.Now().Unix()
  119. }
  120. qhsj, _ := c.GetInt64("qhsj", 0)
  121. if qhsj > 0 {
  122. queueConfig.Qhsj = qhsj
  123. }
  124. jzdcbbcs, _ := c.GetInt64("jzdcbbcs", 0)
  125. if jzdcbbcs > 0 {
  126. queueConfig.Jzdcbbcs = jzdcbbcs
  127. }
  128. jzbbsy, _ := c.GetInt64("jzbbsy", 0)
  129. if jzbbsy > 0 {
  130. queueConfig.Jzbbsy = jzbbsy
  131. }
  132. jzjhyc, _ := c.GetInt64("jzjhyc", 0)
  133. queueConfig.Jzjhyc = jzjhyc
  134. sjdcbbcs, _ := c.GetInt64("sjdcbbcs", 0)
  135. if sjdcbbcs > 0 {
  136. queueConfig.Sjdcbbcs = sjdcbbcs
  137. }
  138. sjbbsy, _ := c.GetInt64("sjbbsy", 0)
  139. if sjbbsy > 0 {
  140. queueConfig.Sjbbsy = sjbbsy
  141. }
  142. sjjhyc, _ := c.GetInt64("sjjhyc", 0)
  143. queueConfig.Sjjhyc = sjjhyc
  144. txxqyxs, _ := c.GetInt64("txxqyxs", 0)
  145. queueConfig.Txxqyxs = txxqyxs
  146. txglsyxs, _ := c.GetInt64("txglsyxs", 0)
  147. queueConfig.Txglsyxs = txglsyxs
  148. queueConfig.UpdateTime = time.Now().Unix()
  149. service.UpDateQueueCallInfo(queueConfig)
  150. c.ServeSuccessJSON(map[string]interface{}{
  151. "queue_config": queueConfig,
  152. })
  153. }
  154. func (c *DialysisApiController) PostPrescription() {
  155. patient, _ := c.GetInt64("patient_id", 0)
  156. recordDateStr := c.GetString("record_date")
  157. if patient <= 0 {
  158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  159. return
  160. }
  161. adminUserInfo := c.GetAdminUserInfo()
  162. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  163. if patientInfo.ID == 0 {
  164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  165. return
  166. }
  167. if len(recordDateStr) == 0 {
  168. recordDateStr = time.Now().Format("2006-01-02")
  169. }
  170. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  171. if parseDateErr != nil {
  172. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  174. return
  175. }
  176. mode_id, _ := c.GetInt64("mode_id", 0)
  177. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  178. dialyzer, _ := c.GetInt64("dialyzer", 0)
  179. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  180. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  181. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  182. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  183. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  184. replacement_way, _ := c.GetInt64("replacement_way", 0)
  185. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  186. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  187. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  188. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  189. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  190. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  191. kalium, _ := c.GetFloat("kalium", 0)
  192. sodium, _ := c.GetFloat("sodium", 0)
  193. replacement_total, _ := c.GetFloat("replacement_total", 0)
  194. calcium, _ := c.GetFloat("calcium", 0)
  195. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  196. glucose, _ := c.GetFloat("glucose", 0)
  197. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  198. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  199. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  200. conductivity, _ := c.GetFloat("conductivity", 0)
  201. remark := c.GetString("remark")
  202. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  203. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  204. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  205. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  206. body_fluid, _ := c.GetInt64("body_fluid", 0)
  207. special_medicine, _ := c.GetInt64("special_medicine", 0)
  208. special_medicine_other := c.GetString("special_medicine_other")
  209. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  210. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  211. blood_access, _ := c.GetInt64("blood_access", 0)
  212. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  213. body_fluid_other := c.GetString("body_fluid_other")
  214. target_ktv, _ := c.GetFloat("target_ktv", 0)
  215. niprocart, _ := c.GetInt64("niprocart", 0)
  216. jms, _ := c.GetInt64("jms", 0)
  217. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  218. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  219. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  220. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  221. filtryzer, _ := c.GetInt64("filtryzer", 0)
  222. dialyzers, _ := c.GetInt64("dialyzers", 0)
  223. injector, _ := c.GetInt64("injector", 0)
  224. bloodlines, _ := c.GetInt64("bloodlines", 0)
  225. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  226. safe_package, _ := c.GetInt64("package", 0)
  227. a_liquid, _ := c.GetInt64("a_liquid", 0)
  228. preImpules, _ := c.GetFloat("pre_impulse", 0)
  229. fmt.Println("", preImpules)
  230. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  231. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  232. //heparin_sodium := c.GetString("heparin_sodium")
  233. //fmt.Println("肝素钠",heparin_sodium)
  234. //nucleoprotamine := c.GetString("nucleoprotamine")
  235. //fmt.Println("鱼精蛋白",nucleoprotamine)
  236. //push_the_protamine := c.GetString("push_the_protamine")
  237. //fmt.Println("下机前推注鱼精蛋白",push_the_protamine)
  238. // var prescription_doctor int64
  239. blood := c.GetString("blood")
  240. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  241. dialysis_irrigation := c.GetString("dialysis_irrigation")
  242. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  243. displace_speed := c.GetString("displace_speed")
  244. illness, _ := c.GetInt64("illness")
  245. amylaceum := c.GetString("amylaceum")
  246. single_time := c.GetString("single_time")
  247. single_water := c.GetString("single_water")
  248. replacement_flow := c.GetString("replacement_flow")
  249. plasma_separator := c.GetString("plasma_separator")
  250. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  251. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  252. oxygen_flow := c.GetString("oxygen_flow")
  253. oxygen_time := c.GetString("oxygen_time")
  254. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  255. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  256. puncture_needle := c.GetString("puncture_needle")
  257. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  258. epo := c.GetString("epo")
  259. epo_count, _ := c.GetFloat("epo_count", 0)
  260. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  261. admin_user_id, _ := c.GetInt64("admin_user_id")
  262. is_water, _ := c.GetInt64("is_water")
  263. drhy_water := c.GetString("drhy_water")
  264. dry_water_hour := c.GetString("dry_water_hour")
  265. water_machine := c.GetString("water_machine")
  266. add_amount, _ := c.GetFloat("add_amount")
  267. reduce_amount, _ := c.GetFloat("reduce_amount")
  268. dialysis_remark := c.GetString("dialysis_remark")
  269. prescribing_number, _ := c.GetFloat("prescribing_number")
  270. treatment_remark := c.GetString("treatment_remark")
  271. prescription_sodium := c.GetString("prescription_sodium")
  272. start_sodium := c.GetString("start_sodium")
  273. sodium_curve := c.GetString("sodium_curve")
  274. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  275. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  276. prescription_water, _ := c.GetFloat("prescription_water")
  277. dialysis_strainer := c.GetString("dialysis_strainer")
  278. chaptalization := c.GetString("chaptalization")
  279. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  280. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  281. //if template.TemplateId == 2 || template.TemplateId == 6 {
  282. // if appRole.UserType == 3 {
  283. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  284. // if getPermissionErr != nil {
  285. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  286. // return
  287. // } else if headNursePermission == nil {
  288. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  289. // return
  290. // }
  291. // }
  292. //}
  293. prescription := models.DialysisPrescription{
  294. UserOrgId: adminUserInfo.CurrentOrgId,
  295. PatientId: patient,
  296. RecordDate: recordDate.Unix(),
  297. ModeId: mode_id,
  298. DialysisDuration: dialysis_duration,
  299. Dialyzer: dialyzer,
  300. ReplacementTotal: replacement_total,
  301. PerfusionApparatus: perfusion_apparatus,
  302. BloodFlowVolume: blood_flow_volume,
  303. DewaterAmount: dewater_amount,
  304. DisplaceLiqui: displace_liqui,
  305. ReplacementWay: replacement_way,
  306. Anticoagulant: anticoagulant,
  307. AnticoagulantShouji: anticoagulant_shouji,
  308. AnticoagulantWeichi: anticoagulant_weichi,
  309. AnticoagulantZongliang: anticoagulant_zongliang,
  310. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  311. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  312. Kalium: kalium,
  313. Sodium: sodium,
  314. Calcium: calcium,
  315. Bicarbonate: bicarbonate,
  316. Glucose: glucose,
  317. // DryWeight: dry_weight,
  318. DialysateFlow: dialysate_flow,
  319. DialysateTemperature: dialysate_temperature,
  320. Conductivity: conductivity,
  321. Remark: remark,
  322. Status: 1,
  323. CreatedTime: time.Now().Unix(),
  324. UpdatedTime: time.Now().Unix(),
  325. DialysisDurationMinute: dialysisDurationMinute,
  326. DialysisDurationHour: dialysisDurationHour,
  327. TargetUltrafiltration: targetUltrafiltration,
  328. DialysateFormulation: dialysateFormulation,
  329. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  330. BodyFluid: body_fluid,
  331. SpecialMedicine: special_medicine,
  332. SpecialMedicineOther: special_medicine_other,
  333. DisplaceLiquiPart: displace_liqui_part,
  334. DisplaceLiquiValue: displace_liqui_value,
  335. BloodAccess: blood_access,
  336. Ultrafiltration: ultrafiltration,
  337. BodyFluidOther: body_fluid_other,
  338. TargetKtv: target_ktv,
  339. Niprocart: niprocart,
  340. Jms: jms,
  341. FistulaNeedleSet: fistula_needle_set,
  342. FistulaNeedleSet16: fistula_needle_set_16,
  343. Hemoperfusion: hemoperfusion,
  344. DialyserSterilised: dialyser_sterilised,
  345. Filtryzer: filtryzer,
  346. Dialyzers: dialyzers,
  347. Injector: injector,
  348. Bloodlines: bloodlines,
  349. TubingHemodialysis: tubing_hemodialysis,
  350. Package: safe_package,
  351. ALiquid: a_liquid,
  352. PreImpulse: preImpules,
  353. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  354. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  355. Blood: blood,
  356. DialysisDialyszers: dialysis_dialyszers,
  357. DialysisIrrigation: dialysis_irrigation,
  358. AntioxidantCommodityName: antioxidant_commodity_name,
  359. DisplaceSpeed: displace_speed,
  360. Illness: illness,
  361. Amylaceum: amylaceum,
  362. SingleTime: single_time,
  363. SingleWater: single_water,
  364. ReplacementFlow: replacement_flow,
  365. PlasmaSeparator: plasma_separator,
  366. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  367. OxygenFlow: oxygen_flow,
  368. OxygenUptake: oxygen_uptake,
  369. OxygenTime: oxygen_time,
  370. HemodialysisPipelines: hemodialysis_pipelines,
  371. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  372. PunctureNeedle: puncture_needle,
  373. PunctureNeedleCount: puncture_needle_count,
  374. Epo: epo,
  375. EpoCount: epo_count,
  376. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  377. AdminUserId: admin_user_id,
  378. IsWater: is_water,
  379. DrhyWater: drhy_water,
  380. DryWaterHour: dry_water_hour,
  381. WaterMachine: water_machine,
  382. AddAmount: add_amount,
  383. ReduceAmount: reduce_amount,
  384. DialysisRemark: dialysis_remark,
  385. PrescribingNumber: prescribing_number,
  386. TreatmentRemark: treatment_remark,
  387. PrescriptionSodium: prescription_sodium,
  388. StartSodium: start_sodium,
  389. SodiumCurve: sodium_curve,
  390. DialysisFluidFlow: dialysis_fluid_flow,
  391. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  392. PrescriptionWater: prescription_water,
  393. DialysisStrainer: dialysis_strainer,
  394. Chaptalization: chaptalization,
  395. }
  396. //长沙南雅医院,自动生成抗凝剂的临时处方
  397. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10340 {
  398. if prescribing_number == 0 {
  399. prescribing_number = 1
  400. }
  401. advice := models.DoctorAdvice{
  402. UserOrgId: adminUserInfo.CurrentOrgId,
  403. PatientId: patient,
  404. GroupNo: 0,
  405. AdviceType: 2,
  406. RecordDate: recordDate.Unix(),
  407. AdviceDate: recordDate.Unix(),
  408. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  409. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  410. AdviceDesc: "",
  411. ReminderDate: 0,
  412. SingleDose: anticoagulant_zongliang,
  413. SingleDoseUnit: "iu",
  414. DrugSpec: 0,
  415. DrugSpecUnit: "",
  416. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  417. PrescribingNumberUnit: "支",
  418. DeliveryWay: "静脉注射",
  419. ExecutionFrequency: "上机前",
  420. AdviceDoctor: 0,
  421. Status: 1,
  422. CreatedTime: time.Now().Unix(),
  423. UpdatedTime: time.Now().Unix(),
  424. IsPrescription: 1,
  425. ExecutionState: 2,
  426. StopState: 2,
  427. IsSettle: 2,
  428. }
  429. // 查询排班信息
  430. schedulePatient, _ := service.GetScheduleByPatient(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  431. if schedulePatient.ID > 0 {
  432. if schedulePatient.ScheduleType == 1 {
  433. advice.StartTime = recordDate.Unix() + 6.5*60*60
  434. }
  435. if schedulePatient.ScheduleType == 2 {
  436. advice.StartTime = recordDate.Unix() + 11*60*60
  437. }
  438. }
  439. // 抗凝剂名称
  440. switch anticoagulant {
  441. case 1:
  442. advice.AdviceName = "无肝素"
  443. break
  444. case 2:
  445. advice.AdviceName = "普通肝素"
  446. break
  447. case 3:
  448. advice.AdviceName = "低分子肝素"
  449. break
  450. case 4:
  451. advice.AdviceName = "阿加曲班"
  452. break
  453. case 5:
  454. advice.AdviceName = "枸橼酸钠"
  455. break
  456. case 6:
  457. advice.AdviceName = "低分子肝素钙"
  458. break
  459. case 7:
  460. advice.AdviceName = "低分子肝素钠"
  461. break
  462. case 8:
  463. advice.AdviceName = "依诺肝素"
  464. break
  465. case 9:
  466. advice.AdviceName = "达肝素"
  467. break
  468. case 10:
  469. advice.AdviceName = "体外抗凝"
  470. break
  471. case 11:
  472. advice.AdviceName = "那曲肝素"
  473. break
  474. case 12:
  475. advice.AdviceName = "无抗凝剂"
  476. break
  477. }
  478. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  479. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 {
  480. advice.AdviceDoctor = appRole.AdminUserId
  481. }
  482. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  483. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  484. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  485. advice.AdviceName = "低分子肝素钠注射液"
  486. // 修改患者临时医嘱里的抗凝剂医嘱
  487. advice.ID = advicePrescription.ID
  488. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  489. //service.UpdateDoctorAdvice(&advice)
  490. } else {
  491. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  492. advice.AdviceName = "低分子肝素钠注射液"
  493. // 新增患者临时医嘱里的抗凝剂医嘱
  494. service.CreateDoctorAdvice(&advice)
  495. }
  496. }
  497. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  498. redis := service.RedisClient()
  499. //清空key 值
  500. redis.Set(key, "", time.Second)
  501. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  502. redis.Set(keyOne, "", time.Second)
  503. }
  504. if appRole.UserType == 2 || appRole.UserType == 1 {
  505. prescription.PrescriptionDoctor = appRole.AdminUserId
  506. }
  507. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  508. if dialysisPrescription.ID == 0 { //新增
  509. if mode_id > 0 {
  510. var str string
  511. //查找该机构用的是什么透析器
  512. filedConfig, _ := service.GetFiledConfig(adminUserInfo.CurrentOrgId)
  513. if filedConfig.ID > 0 {
  514. str = dialyzerPerfusionApparatus
  515. } else {
  516. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  517. }
  518. if adminUserInfo.CurrentOrgId == 10346 {
  519. service.ModifyScheduleModeOne(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  520. } else {
  521. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  522. }
  523. }
  524. prescription.Creater = adminUserInfo.AdminUser.Id
  525. //针对河间咸得
  526. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 {
  527. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  528. prescription.DisplaceLiquiPart = 0
  529. prescription.DisplaceLiquiValue = 0
  530. }
  531. }
  532. if adminUserInfo.CurrentOrgId == 10340 && prescription.AdminUserId == 0 {
  533. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  534. }
  535. // 查询信息规挡的设置天数
  536. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  537. if infor.ID > 0 && infor.WeekDay > 0 {
  538. var cha_time int64
  539. timeNowStr := time.Now().Format("2006-01-02")
  540. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  541. //今日的日期减去设置的日期
  542. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  543. if cha_time >= recordDate.Unix() {
  544. //查询审核是否允许
  545. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  546. //申请状态不允许的情况 拒绝修改
  547. if infor.ApplicationStatus != 1 {
  548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  549. return
  550. }
  551. }
  552. }
  553. err := service.AddSigleRecord(&prescription)
  554. //创建步骤表
  555. finish := models.XtDialysisFinish{
  556. IsFinish: 1,
  557. UserOrgId: adminUserInfo.CurrentOrgId,
  558. Status: 1,
  559. Ctime: time.Now().Unix(),
  560. Mtime: 0,
  561. Module: 1,
  562. RecordDate: recordDate.Unix(),
  563. Sourse: 1,
  564. PatientId: patient,
  565. }
  566. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 1, patient)
  567. if dialysisFinish.ID == 0 {
  568. service.CreateDialysisFinish(finish)
  569. }
  570. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  571. redis := service.RedisClient()
  572. //清空key 值
  573. redis.Set(key, "", time.Second)
  574. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  575. redis.Set(keyTwo, "", time.Second)
  576. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  577. redis.Set(keyThree, "", time.Second)
  578. defer redis.Close()
  579. if err == nil {
  580. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  581. if updateErr != nil {
  582. utils.ErrorLog("%v", updateErr)
  583. }
  584. c.ServeSuccessJSON(map[string]interface{}{
  585. "prescription": &prescription,
  586. })
  587. } else {
  588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  589. }
  590. } else { //修改
  591. if mode_id > 0 {
  592. var str string
  593. //查找该机构用的是什么透析器
  594. filedConfig, _ := service.GetFiledConfig(adminUserInfo.CurrentOrgId)
  595. if filedConfig.ID > 0 {
  596. str = dialyzerPerfusionApparatus
  597. } else {
  598. str = dialysis_dialyszers + "/" + dialysis_irrigation
  599. }
  600. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  601. }
  602. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  603. //if template.TemplateId == 1 {
  604. // if dialysisPrescription.Creater > 0 && dialysisPrescription.Creater != adminUserInfo.AdminUser.Id {
  605. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  606. // if getPermissionErr != nil {
  607. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  608. // return
  609. // } else if headNursePermission == nil {
  610. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  611. // return
  612. // }
  613. // }
  614. //}
  615. if appRole.UserType == 2 || appRole.UserType == 1 {
  616. prescription_doctor := adminUserInfo.AdminUser.Id
  617. prescription.PrescriptionDoctor = prescription_doctor
  618. }
  619. if dialysisPrescription.Creater == 0 { //体重称
  620. prescription.Creater = adminUserInfo.AdminUser.Id
  621. } else {
  622. prescription.Creater = dialysisPrescription.Creater
  623. }
  624. prescription.CreatedTime = dialysisPrescription.CreatedTime
  625. prescription.UpdatedTime = time.Now().Unix()
  626. prescription.Modifier = adminUserInfo.AdminUser.Id
  627. prescription.ID = dialysisPrescription.ID
  628. // 查询信息规挡的设置天数
  629. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  630. if infor.ID > 0 && infor.WeekDay > 0 {
  631. var cha_time int64
  632. timeNowStr := time.Now().Format("2006-01-02")
  633. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  634. //今日的日期减去设置的日期
  635. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  636. if cha_time >= recordDate.Unix() {
  637. //查询审核是否允许
  638. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  639. //申请状态不允许的情况 拒绝修改
  640. if infor.ApplicationStatus != 1 {
  641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  642. return
  643. }
  644. }
  645. }
  646. updateErr := service.UpDateDialysisPrescription(&prescription)
  647. //创建步骤表
  648. finish := models.XtDialysisFinish{
  649. IsFinish: 1,
  650. UserOrgId: adminUserInfo.CurrentOrgId,
  651. Status: 1,
  652. Ctime: time.Now().Unix(),
  653. Mtime: 0,
  654. Module: 1,
  655. RecordDate: recordDate.Unix(),
  656. Sourse: 1,
  657. PatientId: patient,
  658. }
  659. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 1, patient)
  660. if dialysisFinish.ID == 0 {
  661. service.CreateDialysisFinish(finish)
  662. }
  663. //修改处方
  664. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10340 {
  665. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  666. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  667. if advicePrescription.ID > 0 {
  668. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  669. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  670. redis := service.RedisClient()
  671. defer redis.Close()
  672. //清空key 值
  673. redis.Set(key, "", time.Second)
  674. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  675. redis.Set(keyOne, "", time.Second)
  676. }
  677. }
  678. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  679. redis := service.RedisClient()
  680. defer redis.Close()
  681. //清空key 值
  682. redis.Set(key, "", time.Second)
  683. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  684. redis.Set(keyOne, "", time.Second)
  685. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  686. redis.Set(keyThree, "", time.Second)
  687. if updateErr == nil {
  688. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  689. if updateErr != nil {
  690. utils.ErrorLog("%v", updateErr)
  691. }
  692. c.ServeSuccessJSON(map[string]interface{}{
  693. "prescription": &prescription,
  694. })
  695. } else {
  696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  697. }
  698. }
  699. }
  700. func (c *DialysisApiController) PostSoulution() {
  701. patient, _ := c.GetInt64("patient", 0)
  702. recordDateStr := c.GetString("record_date")
  703. if patient <= 0 {
  704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  705. return
  706. }
  707. adminUserInfo := c.GetAdminUserInfo()
  708. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  709. if patientInfo.ID == 0 {
  710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  711. return
  712. }
  713. if len(recordDateStr) == 0 {
  714. recordDateStr = time.Now().Format("2006-01-02")
  715. }
  716. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  717. if parseDateErr != nil {
  718. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  720. return
  721. }
  722. mode_id, _ := c.GetInt64("mode_id", 0)
  723. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  724. dialyzer, _ := c.GetInt64("dialyzer", 0)
  725. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  726. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  727. replacement_total, _ := c.GetFloat("replacement_total", 0)
  728. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  729. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  730. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  731. replacement_way, _ := c.GetInt64("replacement_way", 0)
  732. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  733. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  734. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  735. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  736. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  737. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  738. kalium, _ := c.GetFloat("kalium", 0)
  739. sodium, _ := c.GetFloat("sodium", 0)
  740. calcium, _ := c.GetFloat("calcium", 0)
  741. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  742. glucose, _ := c.GetFloat("glucose", 0)
  743. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  744. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  745. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  746. conductivity, _ := c.GetFloat("conductivity", 0)
  747. remark := c.GetString("remark")
  748. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  749. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  750. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  751. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  752. body_fluid, _ := c.GetInt64("body_fluid", 0)
  753. special_medicine, _ := c.GetInt64("special_medicine", 0)
  754. special_medicine_other := c.GetString("special_medicine_other")
  755. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  756. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  757. blood_access, _ := c.GetInt64("blood_access", 0)
  758. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  759. body_fluid_other := c.GetString("body_fluid_other")
  760. target_ktv, _ := c.GetFloat("target_ktv", 0)
  761. niprocart, _ := c.GetInt64("niprocart", 0)
  762. jms, _ := c.GetInt64("jms", 0)
  763. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  764. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  765. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  766. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  767. filtryzer, _ := c.GetInt64("filtryzer", 0)
  768. dialyzers, _ := c.GetInt64("dialyzers", 0)
  769. injector, _ := c.GetInt64("injector", 0)
  770. bloodlines, _ := c.GetInt64("bloodlines", 0)
  771. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  772. safe_package, _ := c.GetInt64("package", 0)
  773. a_liquid, _ := c.GetInt64("a_liquid", 0)
  774. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  775. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  776. blood := c.GetString("blood")
  777. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  778. dialysis_irrigation := c.GetString("dialysis_irrigation")
  779. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  780. displace_speed := c.GetString("displace_speed")
  781. illness, _ := c.GetInt64("illness")
  782. amylaceum := c.GetString("amylaceum")
  783. single_time := c.GetString("single_time")
  784. single_water := c.GetString("single_water")
  785. replacement_flow := c.GetString("replacement_flow")
  786. plasma_separator := c.GetString("plasma_separator")
  787. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  788. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  789. oxygen_flow := c.GetString("oxygen_flow")
  790. oxygen_time := c.GetString("oxygen_time")
  791. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  792. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  793. puncture_needle := c.GetString("puncture_needle")
  794. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  795. epo := c.GetString("epo")
  796. epo_count, _ := c.GetFloat("epo_count", 0)
  797. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  798. impulse := c.GetString("impulse")
  799. preImpules, parseDateErr := strconv.ParseFloat(impulse, 64)
  800. admin_user_id, _ := c.GetInt64("admin_user_id")
  801. fmt.Println("", preImpules)
  802. is_water, _ := c.GetInt64("is_water")
  803. dry_water_hour := c.GetString("dry_water_hour")
  804. drhy_water := c.GetString("drhy_water")
  805. water_machine := c.GetString("water_machine")
  806. add_amount, _ := c.GetFloat("add_amount")
  807. reduce_amount, _ := c.GetFloat("reduce_amount")
  808. dialysis_remark := c.GetString("dialysis_remark")
  809. prescribing_number, _ := c.GetFloat("prescribing_number")
  810. treatment_remark := c.GetString("treatment_remark")
  811. prescription_sodium := c.GetString("prescription_sodium")
  812. start_sodium := c.GetString("start_sodium")
  813. sodium_curve := c.GetString("sodium_curve")
  814. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  815. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  816. prescription_water, _ := c.GetFloat("prescription_water")
  817. dialysis_strainer := c.GetString("dialysis_strainer")
  818. chaptalization := c.GetString("chaptalization")
  819. var prescription_doctor int64
  820. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  821. if appRole.UserType == 2 || appRole.UserType == 1 {
  822. prescription_doctor = appRole.AdminUserId
  823. }
  824. if mode_id > 0 {
  825. var str string
  826. //查找该机构用的是什么透析器
  827. filedConfig, _ := service.GetFiledConfig(adminUserInfo.CurrentOrgId)
  828. if filedConfig.ID > 0 {
  829. str = dialyzerPerfusionApparatus
  830. } else {
  831. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  832. }
  833. if adminUserInfo.CurrentOrgId == 10346 {
  834. service.ModifyScheduleModeOne(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  835. } else {
  836. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  837. }
  838. }
  839. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  840. //
  841. //if template.TemplateId == 2 || template.TemplateId == 6 {
  842. // if appRole.UserType == 3 {
  843. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  844. // if getPermissionErr != nil {
  845. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  846. // return
  847. // } else if headNursePermission == nil {
  848. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  849. // return
  850. // }
  851. // }
  852. //}
  853. // 查询信息规挡的设置天数
  854. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  855. if infor.ID > 0 && infor.WeekDay > 0 {
  856. var cha_time int64
  857. timeNowStr := time.Now().Format("2006-01-02")
  858. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  859. //今日的日期减去设置的日期
  860. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  861. if cha_time >= recordDate.Unix() {
  862. //查询审核是否允许
  863. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  864. //申请状态不允许的情况 拒绝修改
  865. if infor.ApplicationStatus != 1 {
  866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  867. return
  868. }
  869. }
  870. }
  871. prescription := models.DialysisPrescription{
  872. UserOrgId: adminUserInfo.CurrentOrgId,
  873. PatientId: patient,
  874. RecordDate: recordDate.Unix(),
  875. ModeId: mode_id,
  876. DialysisDuration: dialysis_duration,
  877. Dialyzer: dialyzer,
  878. PerfusionApparatus: perfusion_apparatus,
  879. BloodFlowVolume: blood_flow_volume,
  880. DewaterAmount: dewater_amount,
  881. DisplaceLiqui: displace_liqui,
  882. ReplacementWay: replacement_way,
  883. Anticoagulant: anticoagulant,
  884. AnticoagulantShouji: anticoagulant_shouji,
  885. AnticoagulantWeichi: anticoagulant_weichi,
  886. AnticoagulantZongliang: anticoagulant_zongliang,
  887. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  888. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  889. Kalium: kalium,
  890. Sodium: sodium,
  891. Calcium: calcium,
  892. Bicarbonate: bicarbonate,
  893. Glucose: glucose,
  894. // DryWeight: dry_weight,
  895. DialysateFlow: dialysate_flow,
  896. DialysateTemperature: dialysate_temperature,
  897. Conductivity: conductivity,
  898. Remark: remark,
  899. PrescriptionDoctor: prescription_doctor,
  900. Status: 1,
  901. CreatedTime: time.Now().Unix(),
  902. UpdatedTime: time.Now().Unix(),
  903. DialysisDurationMinute: dialysisDurationMinute,
  904. DialysisDurationHour: dialysisDurationHour,
  905. TargetUltrafiltration: targetUltrafiltration,
  906. DialysateFormulation: dialysateFormulation,
  907. ReplacementTotal: replacement_total,
  908. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  909. BodyFluid: body_fluid,
  910. SpecialMedicine: special_medicine,
  911. SpecialMedicineOther: special_medicine_other,
  912. DisplaceLiquiPart: displace_liqui_part,
  913. DisplaceLiquiValue: displace_liqui_value,
  914. BloodAccess: blood_access,
  915. Ultrafiltration: ultrafiltration,
  916. BodyFluidOther: body_fluid_other,
  917. TargetKtv: target_ktv,
  918. Niprocart: niprocart,
  919. Jms: jms,
  920. FistulaNeedleSet: fistula_needle_set,
  921. FistulaNeedleSet16: fistula_needle_set_16,
  922. Hemoperfusion: hemoperfusion,
  923. DialyserSterilised: dialyser_sterilised,
  924. Filtryzer: filtryzer,
  925. Dialyzers: dialyzers,
  926. Injector: injector,
  927. Bloodlines: bloodlines,
  928. TubingHemodialysis: tubing_hemodialysis,
  929. Package: safe_package,
  930. ALiquid: a_liquid,
  931. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  932. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  933. Blood: blood,
  934. DialysisIrrigation: dialysis_irrigation,
  935. DialysisDialyszers: dialysis_dialyszers,
  936. AntioxidantCommodityName: antioxidant_commodity_name,
  937. DisplaceSpeed: displace_speed,
  938. Illness: illness,
  939. Amylaceum: amylaceum,
  940. SingleTime: single_time,
  941. SingleWater: single_water,
  942. ReplacementFlow: replacement_flow,
  943. PlasmaSeparator: plasma_separator,
  944. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  945. OxygenTime: oxygen_time,
  946. OxygenUptake: oxygen_uptake,
  947. OxygenFlow: oxygen_flow,
  948. HemodialysisPipelines: hemodialysis_pipelines,
  949. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  950. PunctureNeedle: puncture_needle,
  951. PunctureNeedleCount: puncture_needle_count,
  952. Epo: epo,
  953. EpoCount: epo_count,
  954. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  955. PreImpulse: preImpules,
  956. AdminUserId: admin_user_id,
  957. IsWater: is_water,
  958. DryWaterHour: dry_water_hour,
  959. DrhyWater: drhy_water,
  960. WaterMachine: water_machine,
  961. AddAmount: add_amount,
  962. ReduceAmount: reduce_amount,
  963. DialysisRemark: dialysis_remark,
  964. PrescribingNumber: prescribing_number,
  965. StartSodium: start_sodium,
  966. PrescriptionSodium: prescription_sodium,
  967. SodiumCurve: sodium_curve,
  968. TreatmentRemark: treatment_remark,
  969. DialysisFluidFlow: dialysis_fluid_flow,
  970. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  971. PrescriptionWater: prescription_water,
  972. DialysisStrainer: dialysis_strainer,
  973. Chaptalization: chaptalization,
  974. }
  975. //查询最近透析准备表里是否存在 透析器 灌流器
  976. //splitStr := strings.Split(dialysis_dialyszers, ",")
  977. //
  978. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  979. //
  980. //mation, _ := service.GetGoodInfoMation(adminUserInfo.CurrentOrgId)
  981. //if len(mation)>0{
  982. // for _, item := range splitStr {
  983. // for _,it := range mation{
  984. // if(item == it.SpecificationName){
  985. //
  986. // //查询最近一次的透析器
  987. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.CurrentOrgId,patient)
  988. //
  989. // if errcode == gorm.ErrRecordNotFound{
  990. // //插入数据
  991. // prepare := models.DialysisBeforePrepare{
  992. // UserOrgId: adminUserInfo.CurrentOrgId,
  993. // PatientId: patient,
  994. // RecordDate: recordDate.Unix(),
  995. // GoodTypeId: it.GoodTypeId,
  996. // GoodId: it.ID,
  997. // Count: 1,
  998. // Ctime: time.Now().Unix(),
  999. // Creater: adminUserInfo.AdminUser.Id,
  1000. // Status:1,
  1001. //
  1002. // }
  1003. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1004. // fmt.Println("",errcode)
  1005. // }
  1006. // }
  1007. // }
  1008. //
  1009. // }
  1010. //
  1011. // for _, item := range splitIrrigation {
  1012. // for _,it := range mation{
  1013. // if(item == it.SpecificationName){
  1014. // //查询最近一次的透析器
  1015. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.CurrentOrgId,patient)
  1016. // if errcode == gorm.ErrRecordNotFound{
  1017. // //插入数据
  1018. // prepare := models.DialysisBeforePrepare{
  1019. // UserOrgId: adminUserInfo.CurrentOrgId,
  1020. // PatientId: patient,
  1021. // RecordDate: recordDate.Unix(),
  1022. // GoodTypeId: it.GoodTypeId,
  1023. // GoodId: it.ID,
  1024. // Count: 1,
  1025. // Ctime: time.Now().Unix(),
  1026. // Creater: adminUserInfo.AdminUser.Id,
  1027. // Status:1,
  1028. //
  1029. // }
  1030. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1031. // fmt.Println(errcode)
  1032. // }
  1033. // }
  1034. // }
  1035. // }
  1036. //}
  1037. //创建步骤表
  1038. finish := models.XtDialysisFinish{
  1039. IsFinish: 1,
  1040. UserOrgId: adminUserInfo.CurrentOrgId,
  1041. Status: 1,
  1042. Ctime: time.Now().Unix(),
  1043. Mtime: 0,
  1044. Module: 1,
  1045. RecordDate: recordDate.Unix(),
  1046. Sourse: 1,
  1047. PatientId: patient,
  1048. }
  1049. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 1, patient)
  1050. if dialysisFinish.ID == 0 {
  1051. service.CreateDialysisFinish(finish)
  1052. }
  1053. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1054. if dialysisPrescription.ID == 0 { //新增
  1055. if appRole.UserType == 2 || appRole.UserType == 1 {
  1056. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1057. }
  1058. prescription.Creater = adminUserInfo.AdminUser.Id
  1059. } else { //修改
  1060. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  1061. //if template.TemplateId == 1 {
  1062. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1063. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1064. // if getPermissionErr != nil {
  1065. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1066. // return
  1067. // } else if headNursePermission == nil {
  1068. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1069. // return
  1070. // }
  1071. // }
  1072. //}
  1073. if appRole.UserType == 2 || appRole.UserType == 1 {
  1074. prescription_doctor := adminUserInfo.AdminUser.Id
  1075. prescription.PrescriptionDoctor = prescription_doctor
  1076. } else {
  1077. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  1078. }
  1079. if dialysisPrescription.Creater == 0 {
  1080. prescription.Creater = adminUserInfo.AdminUser.Id
  1081. } else {
  1082. prescription.Creater = dialysisPrescription.Creater
  1083. }
  1084. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1085. prescription.UpdatedTime = time.Now().Unix()
  1086. prescription.Modifier = adminUserInfo.AdminUser.Id
  1087. prescription.ID = dialysisPrescription.ID
  1088. }
  1089. solution := models.DialysisSolution{
  1090. RegistrarsId: adminUserInfo.AdminUser.Id,
  1091. UserOrgId: adminUserInfo.CurrentOrgId,
  1092. Doctor: prescription_doctor,
  1093. PatientId: patient,
  1094. ModeId: mode_id,
  1095. DialysisDuration: dialysis_duration,
  1096. PerfusionApparatus: perfusion_apparatus,
  1097. BloodFlowVolume: blood_flow_volume,
  1098. Dewater: dewater_amount,
  1099. DisplaceLiqui: displace_liqui,
  1100. ReplacementWay: replacement_way,
  1101. Anticoagulant: anticoagulant,
  1102. AnticoagulantShouji: anticoagulant_shouji,
  1103. AnticoagulantWeichi: anticoagulant_weichi,
  1104. AnticoagulantZongliang: anticoagulant_zongliang,
  1105. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1106. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1107. Kalium: kalium,
  1108. Sodium: sodium,
  1109. Calcium: calcium,
  1110. Bicarbonate: bicarbonate,
  1111. Glucose: glucose,
  1112. // DryWeight: dry_weight,
  1113. DialysateFlow: dialysate_flow,
  1114. DialysateTemperature: dialysate_temperature,
  1115. Conductivity: conductivity,
  1116. Remark: remark,
  1117. Status: 1,
  1118. CreatedTime: time.Now().Unix(),
  1119. UpdatedTime: time.Now().Unix(),
  1120. DialysisDurationMinute: dialysisDurationMinute,
  1121. DialysisDurationHour: dialysisDurationHour,
  1122. TargetUltrafiltration: targetUltrafiltration,
  1123. DialysateFormulation: dialysateFormulation,
  1124. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1125. BodyFluid: body_fluid,
  1126. SpecialMedicine: special_medicine,
  1127. SpecialMedicineOther: special_medicine_other,
  1128. DisplaceLiquiPart: displace_liqui_part,
  1129. DisplaceLiquiValue: displace_liqui_value,
  1130. BloodAccess: blood_access,
  1131. Ultrafiltration: ultrafiltration,
  1132. BodyFluidOther: body_fluid_other,
  1133. ReplacementTotal: replacement_total,
  1134. TargetKtv: target_ktv,
  1135. DialysisIrrigation: dialysis_irrigation,
  1136. DialysisDialyszers: dialysis_dialyszers,
  1137. HemodialysisPipelines: hemodialysis_pipelines,
  1138. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1139. PunctureNeedle: puncture_needle,
  1140. PunctureNeedleCount: puncture_needle_count,
  1141. Epo: epo,
  1142. EpoCount: epo_count,
  1143. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1144. OxygenUptake: oxygen_uptake,
  1145. OxygenFlow: oxygen_flow,
  1146. OxygenTime: oxygen_time,
  1147. PreImpulse: preImpules,
  1148. SolutionStatus: 1,
  1149. DialysisRemark: dialysis_remark,
  1150. PrescribingNumber: prescribing_number,
  1151. StartSodium: start_sodium,
  1152. PrescriptionSodium: prescription_sodium,
  1153. SodiumCurve: sodium_curve,
  1154. TreatmentRemark: treatment_remark,
  1155. DialysisFluidFlow: dialysis_fluid_flow,
  1156. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1157. PrescriptionWater: prescribing_number,
  1158. DialysisStrainer: dialysis_strainer,
  1159. Chaptalization: chaptalization,
  1160. }
  1161. //针对河间咸得
  1162. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 {
  1163. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1164. prescription.DisplaceLiquiPart = 0
  1165. prescription.DisplaceLiquiValue = 0
  1166. }
  1167. }
  1168. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 {
  1169. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  1170. solution.DisplaceLiquiPart = 0
  1171. solution.DisplaceLiquiValue = 0
  1172. }
  1173. }
  1174. if adminUserInfo.CurrentOrgId == 10340 && prescription.AdminUserId == 0 {
  1175. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1176. }
  1177. err := service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  1178. //创建步骤表
  1179. finishOne := models.XtDialysisFinish{
  1180. IsFinish: 1,
  1181. UserOrgId: adminUserInfo.CurrentOrgId,
  1182. Status: 1,
  1183. Ctime: time.Now().Unix(),
  1184. Mtime: 0,
  1185. Module: 1,
  1186. RecordDate: recordDate.Unix(),
  1187. Sourse: 1,
  1188. PatientId: patient,
  1189. }
  1190. dialysisFinishOne, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 1, patient)
  1191. if dialysisFinishOne.ID == 0 {
  1192. service.CreateDialysisFinish(finishOne)
  1193. }
  1194. //获取最新1条
  1195. dialysisSolution, _ := service.GetLastPatientDialysisSolution(patient, adminUserInfo.CurrentOrgId)
  1196. //更新状态
  1197. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  1198. //长沙南雅医院,自动生成抗凝剂的临时处方
  1199. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10340 {
  1200. if prescribing_number == 0 {
  1201. prescribing_number = 1
  1202. }
  1203. advice := models.DoctorAdvice{
  1204. UserOrgId: adminUserInfo.CurrentOrgId,
  1205. PatientId: patient,
  1206. GroupNo: 0,
  1207. AdviceType: 2,
  1208. RecordDate: recordDate.Unix(),
  1209. AdviceDate: recordDate.Unix(),
  1210. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1211. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1212. AdviceDesc: "",
  1213. ReminderDate: 0,
  1214. SingleDose: anticoagulant_zongliang,
  1215. SingleDoseUnit: "iu",
  1216. DrugSpec: 0,
  1217. DrugSpecUnit: "",
  1218. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1219. PrescribingNumberUnit: "支",
  1220. DeliveryWay: "静脉注射",
  1221. ExecutionFrequency: "上机前",
  1222. AdviceDoctor: 0,
  1223. Status: 1,
  1224. CreatedTime: time.Now().Unix(),
  1225. UpdatedTime: time.Now().Unix(),
  1226. IsPrescription: 1,
  1227. ExecutionState: 2,
  1228. StopState: 2,
  1229. IsSettle: 2,
  1230. }
  1231. // 查询排班信息
  1232. schedulePatient, _ := service.GetScheduleByPatient(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1233. if schedulePatient.ID > 0 {
  1234. if schedulePatient.ScheduleType == 1 {
  1235. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1236. }
  1237. if schedulePatient.ScheduleType == 2 {
  1238. advice.StartTime = recordDate.Unix() + 11*60*60
  1239. }
  1240. }
  1241. // 抗凝剂名称
  1242. switch anticoagulant {
  1243. case 1:
  1244. advice.AdviceName = "无肝素"
  1245. break
  1246. case 2:
  1247. advice.AdviceName = "普通肝素"
  1248. break
  1249. case 3:
  1250. advice.AdviceName = "低分子肝素"
  1251. break
  1252. case 4:
  1253. advice.AdviceName = "阿加曲班"
  1254. break
  1255. case 5:
  1256. advice.AdviceName = "枸橼酸钠"
  1257. break
  1258. case 6:
  1259. advice.AdviceName = "低分子肝素钙"
  1260. break
  1261. case 7:
  1262. advice.AdviceName = "低分子肝素钠"
  1263. break
  1264. case 8:
  1265. advice.AdviceName = "依诺肝素"
  1266. break
  1267. case 9:
  1268. advice.AdviceName = "达肝素"
  1269. break
  1270. case 10:
  1271. advice.AdviceName = "体外抗凝"
  1272. break
  1273. case 11:
  1274. advice.AdviceName = "那曲肝素"
  1275. break
  1276. case 12:
  1277. advice.AdviceName = "无抗凝剂"
  1278. break
  1279. }
  1280. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  1281. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 {
  1282. advice.AdviceDoctor = appRole.AdminUserId
  1283. }
  1284. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  1285. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1286. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  1287. advice.AdviceName = "低分子肝素钠注射液"
  1288. // 修改患者临时医嘱里的抗凝剂医嘱
  1289. advice.ID = advicePrescription.ID
  1290. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  1291. } else {
  1292. // 新增患者临时医嘱里的抗凝剂医嘱
  1293. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  1294. advice.AdviceName = "低分子肝素钠注射液"
  1295. service.CreateDoctorAdvice(&advice)
  1296. }
  1297. }
  1298. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  1299. redis := service.RedisClient()
  1300. //清空key 值
  1301. redis.Set(key, "", time.Second)
  1302. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  1303. redis.Set(keyOne, "", time.Second)
  1304. }
  1305. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1306. redis := service.RedisClient()
  1307. //清空key 值
  1308. redis.Set(key, "", time.Second)
  1309. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1310. //清空key 值
  1311. redis.Set(keyOne, "", time.Second)
  1312. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1313. redis.Set(keyTwo, "", time.Second)
  1314. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1315. redis.Set(keyThree, "", time.Second)
  1316. defer redis.Close()
  1317. if err == nil {
  1318. c.ServeSuccessJSON(map[string]interface{}{
  1319. "solution": &solution,
  1320. "prescription": &prescription,
  1321. })
  1322. } else {
  1323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1324. }
  1325. }
  1326. func (c *DialysisApiController) PostDouleCheck() {
  1327. id, _ := c.GetInt64("patient", 0)
  1328. recordDateStr := c.GetString("record_date")
  1329. checkTimeStr := c.GetString("check_time")
  1330. firstCheckTimeStr := c.GetString("first_check_time")
  1331. creater, _ := c.GetInt64("creater", 0)
  1332. modifier, _ := c.GetInt64("modifier", 0)
  1333. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  1334. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  1335. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  1336. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  1337. dialysis_item_desc := c.GetString("dialysis_item_desc")
  1338. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  1339. vascular_access_desc := c.GetString("vascular_access_desc")
  1340. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  1341. collator, _ := c.GetInt64("collator", 0)
  1342. employee_number := c.GetString("employee_number")
  1343. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  1344. needle_batch_number := c.GetString("needle_batch_number")
  1345. if id <= 0 {
  1346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1347. return
  1348. }
  1349. adminUserInfo := c.GetAdminUserInfo()
  1350. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  1351. if patient.ID == 0 {
  1352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1353. return
  1354. }
  1355. if len(recordDateStr) == 0 {
  1356. recordDateStr = time.Now().Format("2006-01-02")
  1357. }
  1358. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1359. if parseDateErr != nil {
  1360. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1362. return
  1363. }
  1364. var checkDate int64
  1365. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  1366. list, _ := service.GetRoleList(adminUserInfo.CurrentOrgId, modifier)
  1367. if employee_number != list.JobNumber {
  1368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorEmployeeNumber)
  1369. return
  1370. }
  1371. }
  1372. if len(checkTimeStr) == 0 {
  1373. //checkTimeStr = time.Now().Format("2006-01-02 15:04")
  1374. checkDate = 0
  1375. } else {
  1376. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", checkTimeStr)
  1377. checkDate = checkDateUnix.Unix()
  1378. }
  1379. var firstCheckTimeDate int64
  1380. if len(firstCheckTimeStr) == 0 {
  1381. //firstCheckTimeStr = time.Now().Format("2006-01-02 15:04")
  1382. firstCheckTimeDate = 0
  1383. } else {
  1384. firstCheckTimeDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", firstCheckTimeStr)
  1385. firstCheckTimeDate = firstCheckTimeDateUnix.Unix()
  1386. }
  1387. doubleCheck := models.DoubleCheck{
  1388. UserOrgId: adminUserInfo.CurrentOrgId,
  1389. PatientId: id,
  1390. DialysisItemCheck: dialysis_item_check,
  1391. DialysisParameterCheck: dialysis_parameter_check,
  1392. VascularAccessVerification: vascular_access_verification,
  1393. PipelineConnectionCheck: pipeline_connection_check,
  1394. DialysisItemDesc: dialysis_item_desc,
  1395. DialysisParameterDesc: dialysis_parameter_desc,
  1396. VascularAccessDesc: vascular_access_desc,
  1397. PipelineConnectionDesc: pipeline_connection_desc,
  1398. Collator: collator,
  1399. Status: 1,
  1400. CreatedTime: time.Now().Unix(),
  1401. UpdatedTime: time.Now().Unix(),
  1402. CheckDate: recordDate.Unix(),
  1403. EmployeeNumber: employee_number,
  1404. DialyzerBatchNumber: dialyzer_batch_number,
  1405. NeedleBatchNumber: needle_batch_number,
  1406. }
  1407. // 查询信息规挡的设置天数
  1408. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1409. if infor.ID > 0 && infor.WeekDay > 0 {
  1410. var cha_time int64
  1411. timeNowStr := time.Now().Format("2006-01-02")
  1412. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1413. //今日的日期减去设置的日期
  1414. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1415. if cha_time >= recordDate.Unix() {
  1416. //查询审核是否允许
  1417. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1418. //申请状态不允许的情况 拒绝修改
  1419. if infor.ApplicationStatus != 1 {
  1420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1421. return
  1422. }
  1423. }
  1424. }
  1425. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1426. if check.ID == 0 { //新增
  1427. doubleCheck.FirstCheckTime = firstCheckTimeDate
  1428. doubleCheck.CheckTime = checkDate
  1429. doubleCheck.Creater = creater
  1430. doubleCheck.Modifier = modifier
  1431. err := service.AddSigleDoubleCheck(&doubleCheck)
  1432. //创建步骤表
  1433. finish := models.XtDialysisFinish{
  1434. IsFinish: 1,
  1435. UserOrgId: adminUserInfo.CurrentOrgId,
  1436. Status: 1,
  1437. Ctime: time.Now().Unix(),
  1438. Mtime: 0,
  1439. Module: 5,
  1440. RecordDate: recordDate.Unix(),
  1441. Sourse: 1,
  1442. PatientId: id,
  1443. }
  1444. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 5, id)
  1445. if dialysisFinish.ID == 0 {
  1446. service.CreateDialysisFinish(finish)
  1447. }
  1448. // 查询信息规挡的设置天数
  1449. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1450. if infor.ID > 0 {
  1451. var cha_time int64
  1452. timeNowStr := time.Now().Format("2006-01-02")
  1453. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1454. //今日的日期减去设置的日期
  1455. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1456. if cha_time >= recordDate.Unix() {
  1457. //查询审核是否允许
  1458. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1459. //申请状态不允许的情况 拒绝修改
  1460. if infor.ApplicationStatus != 1 {
  1461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1462. return
  1463. }
  1464. }
  1465. }
  1466. redis := service.RedisClient()
  1467. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1468. //清空key 值
  1469. redis.Set(key, "", time.Second)
  1470. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1471. redis.Set(keyTwo, "", time.Second)
  1472. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":prescriptions_list_all"
  1473. redis.Set(keyThree, "", time.Second)
  1474. defer redis.Close()
  1475. if err == nil {
  1476. c.ServeSuccessJSON(map[string]interface{}{
  1477. "doubleCheck": doubleCheck,
  1478. })
  1479. } else {
  1480. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1481. }
  1482. } else { //修改
  1483. doubleCheck.FirstCheckTime = firstCheckTimeDate
  1484. doubleCheck.CheckTime = checkDate
  1485. doubleCheck.Creater = creater
  1486. doubleCheck.Modifier = modifier
  1487. doubleCheck.CreatedTime = check.CreatedTime
  1488. doubleCheck.UpdatedTime = time.Now().Unix()
  1489. doubleCheck.ID = check.ID
  1490. redis := service.RedisClient()
  1491. err := service.UpdateDoubleCheck(&doubleCheck)
  1492. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1493. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1494. redis.Set(keyTwo, "", time.Second)
  1495. //清空key 值
  1496. redis.Set(key, "", time.Second)
  1497. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":prescriptions_list_all"
  1498. redis.Set(keyThree, "", time.Second)
  1499. defer redis.Close()
  1500. if err == nil {
  1501. c.ServeSuccessJSON(map[string]interface{}{
  1502. "doubleCheck": doubleCheck,
  1503. })
  1504. } else {
  1505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1506. }
  1507. }
  1508. }
  1509. func (c *DialysisApiController) PostReceiveTreatmentAsses() {
  1510. id, _ := c.GetInt64("patient", 0)
  1511. recordDateStr := c.GetString("record_date")
  1512. way, _ := c.GetInt64("way", 0)
  1513. consciousness, _ := c.GetInt64("consciousness", 0)
  1514. appetite, _ := c.GetInt64("appetite", 0)
  1515. condition, _ := c.GetInt64("condition", 0)
  1516. posture, _ := c.GetInt64("posture")
  1517. score := c.GetString("score")
  1518. sick_condition, _ := c.GetInt64("sick_condition", 0)
  1519. danger_level, _ := c.GetInt64("danger_level", 0)
  1520. intake, _ := c.GetInt64("intake", 0)
  1521. nutrition, _ := c.GetInt64("nutrition", 0)
  1522. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  1523. psychological_assessment_other := c.GetString("psychological_assessment_other")
  1524. sick_condition_other := c.GetString("sick_condition_other")
  1525. //precaution, _ := c.GetInt64("precaution", 0)
  1526. precaution := c.GetString("precaution")
  1527. precaution_other := c.GetString("precaution_other")
  1528. psychological_other := c.GetString("psychological_other")
  1529. admission_number := c.GetString("admission_number")
  1530. tumble, _ := c.GetInt64("tumble")
  1531. his_department := c.GetString("his_department")
  1532. his_bed := c.GetString("his_bed")
  1533. diacrisis := c.GetString("diacrisis")
  1534. if id <= 0 {
  1535. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1536. return
  1537. }
  1538. adminUserInfo := c.GetAdminUserInfo()
  1539. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  1540. if patient.ID == 0 {
  1541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1542. return
  1543. }
  1544. if len(recordDateStr) == 0 {
  1545. recordDateStr = time.Now().Format("2006-01-02")
  1546. }
  1547. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1548. if parseDateErr != nil {
  1549. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1550. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1551. return
  1552. }
  1553. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1554. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1555. UserOrgId: adminUserInfo.CurrentOrgId,
  1556. PatientId: id,
  1557. RecordDate: recordDate.Unix(),
  1558. Way: way,
  1559. Consciousness: consciousness,
  1560. Appetite: appetite,
  1561. Condition: condition,
  1562. SickCondition: sick_condition,
  1563. DangerLevel: danger_level,
  1564. Intake: intake,
  1565. Nutrition: nutrition,
  1566. PsychologicalAssessment: psychological_assessment,
  1567. PsychologicalAssessmentOther: psychological_assessment_other,
  1568. SickConditionOther: sick_condition_other,
  1569. Posture: posture,
  1570. CreatedTime: time.Now().Unix(),
  1571. UpdateTime: time.Now().Unix(),
  1572. Status: 1,
  1573. Score: score,
  1574. Precaution: precaution,
  1575. PrecautionOther: precaution_other,
  1576. PsychologicalOther: psychological_other,
  1577. AdmissionNumber: admission_number,
  1578. Tumble: tumble,
  1579. HisDepartment: his_department,
  1580. HisBed: his_bed,
  1581. Diacrisis: diacrisis,
  1582. }
  1583. // 查询信息规挡的设置天数
  1584. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1585. if infor.ID > 0 && infor.WeekDay > 0 {
  1586. var cha_time int64
  1587. timeNowStr := time.Now().Format("2006-01-02")
  1588. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1589. //今日的日期减去设置的日期
  1590. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1591. if cha_time >= recordDate.Unix() {
  1592. //查询审核是否允许
  1593. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1594. //申请状态不允许的情况 拒绝修改
  1595. if infor.ApplicationStatus != 1 {
  1596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1597. return
  1598. }
  1599. }
  1600. }
  1601. if receiveTreatment.ID == 0 { //新增
  1602. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1603. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1604. //创建步骤表
  1605. finish := models.XtDialysisFinish{
  1606. IsFinish: 1,
  1607. UserOrgId: adminUserInfo.CurrentOrgId,
  1608. Status: 1,
  1609. Ctime: time.Now().Unix(),
  1610. Mtime: 0,
  1611. Module: 2,
  1612. RecordDate: recordDate.Unix(),
  1613. Sourse: 1,
  1614. PatientId: id,
  1615. }
  1616. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 2, id)
  1617. if dialysisFinish.ID == 0 {
  1618. service.CreateDialysisFinish(finish)
  1619. }
  1620. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1621. redis := service.RedisClient()
  1622. //清空key 值
  1623. redis.Set(key, "", time.Second)
  1624. defer redis.Close()
  1625. if err == nil {
  1626. c.ServeSuccessJSON(map[string]interface{}{
  1627. "receiveTreatmentAsses": receiveTreatmentAsses,
  1628. })
  1629. } else {
  1630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1631. }
  1632. } else { //修改
  1633. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1634. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1635. // if getPermissionErr != nil {
  1636. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1637. // return
  1638. // } else if headNursePermission == nil {
  1639. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1640. // return
  1641. // }
  1642. //}
  1643. // 查询信息规挡的设置天数
  1644. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1645. if infor.ID > 0 && infor.WeekDay > 0 {
  1646. var cha_time int64
  1647. timeNowStr := time.Now().Format("2006-01-02")
  1648. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1649. //今日的日期减去设置的日期
  1650. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1651. if cha_time >= recordDate.Unix() {
  1652. //查询审核是否允许
  1653. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1654. //申请状态不允许的情况 拒绝修改
  1655. if infor.ApplicationStatus != 1 {
  1656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1657. return
  1658. }
  1659. }
  1660. }
  1661. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1662. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1663. receiveTreatmentAsses.UpdateTime = time.Now().Unix()
  1664. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1665. receiveTreatmentAsses.ID = receiveTreatment.ID
  1666. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1667. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1668. redis := service.RedisClient()
  1669. defer redis.Close()
  1670. redis.Set(keyOne, "", time.Second*60*60*18)
  1671. if err == nil {
  1672. c.ServeSuccessJSON(map[string]interface{}{
  1673. "receiveTreatmentAsses": receiveTreatmentAsses,
  1674. })
  1675. } else {
  1676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1677. }
  1678. }
  1679. }
  1680. func (c *DialysisApiController) PostAssessmentAfterDislysis() {
  1681. patient, _ := c.GetInt64("patient", 0)
  1682. recordDateStr := c.GetString("record_date")
  1683. fmt.Println(recordDateStr)
  1684. if patient <= 0 {
  1685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1686. return
  1687. }
  1688. adminUserInfo := c.GetAdminUserInfo()
  1689. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1690. if patientInfo.ID == 0 {
  1691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1692. return
  1693. }
  1694. if len(recordDateStr) == 0 {
  1695. recordDateStr = time.Now().Format("2006-01-02")
  1696. }
  1697. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1698. if parseDateErr != nil {
  1699. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1701. return
  1702. }
  1703. // data := make(map[string]interface{}, 0)
  1704. var data models.AssessmentAfterDislysis
  1705. var err error
  1706. err = json.Unmarshal(c.Ctx.Input.RequestBody, &data)
  1707. fmt.Println(err)
  1708. if err != nil {
  1709. c.ErrorLog("数据解析错误:%v", err)
  1710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1711. return
  1712. }
  1713. assessment, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1714. assessment.DialysisOrderId = data.DialysisOrderId
  1715. assessment.Evaluator = adminUserInfo.AdminUser.Id
  1716. assessment.Status = 1
  1717. assessment.WeightAfter = data.WeightAfter
  1718. assessment.WeightLoss = data.WeightLoss
  1719. assessment.Temperature = data.Temperature
  1720. assessment.SystolicBloodPressure = data.SystolicBloodPressure
  1721. assessment.DiastolicBloodPressure = data.DiastolicBloodPressure
  1722. assessment.PulseFrequency = data.PulseFrequency
  1723. assessment.ActualUltrafiltration = data.ActualUltrafiltration
  1724. assessment.ActualDisplacement = data.ActualDisplacement
  1725. assessment.ActualTreatmentHour = data.ActualTreatmentHour
  1726. assessment.ActualTreatmentMinute = data.ActualTreatmentMinute
  1727. assessment.Cruor = data.Cruor
  1728. assessment.SymptomAfterDialysis = data.SymptomAfterDialysis
  1729. assessment.DialysisIntakes = data.DialysisIntakes
  1730. assessment.InternalFistula = data.InternalFistula
  1731. assessment.BloodAccessPartId = data.BloodAccessPartId
  1732. assessment.BloodAccessPartOperaId = data.BloodAccessPartOperaId
  1733. assessment.Catheter = data.Catheter
  1734. assessment.Complication = data.Complication
  1735. assessment.PuncturePointOozingBlood = data.PuncturePointOozingBlood
  1736. assessment.PuncturePointHaematoma = data.PuncturePointHaematoma
  1737. assessment.InternalFistulaTremorAc = data.InternalFistulaTremorAc
  1738. assessment.PatientGose = data.PatientGose
  1739. assessment.InpatientDepartment = data.InpatientDepartment
  1740. assessment.ObservationContent = data.ObservationContent
  1741. assessment.ObservationContentOther = data.ObservationContentOther
  1742. assessment.Remark = data.Remark
  1743. assessment.BreathingRate = data.BreathingRate
  1744. assessment.DialysisProcess = data.DialysisProcess
  1745. assessment.InAdvanceMinute = data.InAdvanceMinute
  1746. assessment.InAdvanceReasonOther = data.InAdvanceReasonOther
  1747. assessment.InAdvanceReason = data.InAdvanceReason
  1748. assessment.HemostasisOpera = data.HemostasisOpera
  1749. assessment.HemostasisMinute = data.HemostasisMinute
  1750. assessment.TremorNoise = data.TremorNoise
  1751. assessment.DisequilibriumSyndrome = data.DisequilibriumSyndrome
  1752. assessment.DisequilibriumSyndromeOption = data.DisequilibriumSyndromeOption
  1753. assessment.ArterialTube = data.ArterialTube
  1754. assessment.IntravenousTube = data.IntravenousTube
  1755. assessment.DialysisIntakesUnit = data.DialysisIntakesUnit
  1756. assessment.Dialyzer = data.Dialyzer
  1757. assessment.IsEat = data.IsEat
  1758. assessment.CvcA = data.CvcA
  1759. assessment.CvcV = data.CvcV
  1760. assessment.Channel = data.Channel
  1761. assessment.ReturnBlood = data.ReturnBlood
  1762. assessment.RehydrationVolume = data.RehydrationVolume
  1763. assessment.DialysisDuring = data.DialysisDuring
  1764. assessment.StrokeVolume = data.StrokeVolume
  1765. assessment.BloodFlow = data.BloodFlow
  1766. assessment.SealingFluidDispose = data.SealingFluidDispose
  1767. assessment.SealingFluidSpecial = data.SealingFluidSpecial
  1768. assessment.DosageOfAnticoagulants = data.DosageOfAnticoagulants
  1769. assessment.SupineSystolicBloodPressure = data.SupineSystolicBloodPressure
  1770. assessment.SettingPressure = data.SettingPressure
  1771. assessment.SupineDiastolicBloodPressure = data.SupineDiastolicBloodPressure
  1772. assessment.DiastolicPressure = data.DiastolicPressure
  1773. assessment.AdditionalWeight = data.AdditionalWeight
  1774. assessment.OtherComplication = data.OtherComplication
  1775. assessment.Ktv = data.Ktv
  1776. assessment.Urr = data.Urr
  1777. assessment.Hypertenison = data.Hypertenison
  1778. assessment.Hypopiesia = data.Hypopiesia
  1779. assessment.LeaveOfficeMethod = data.LeaveOfficeMethod
  1780. assessment.Lapse = data.Lapse
  1781. assessment.Consciousness = data.Consciousness
  1782. assessment.Fallrisk = data.Fallrisk
  1783. assessment.MachineRun = data.MachineRun
  1784. assessment.AfterUrea = data.AfterUrea
  1785. assessment.PipCoagulation = data.PipCoagulation
  1786. assessment.AccumulatedBloodVolume = data.AccumulatedBloodVolume
  1787. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1788. if assessment.ID > 0 {
  1789. if appRole.UserType == 2 || appRole.UserType == 1 {
  1790. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1791. assessment.AssessmentTime = time.Now().Unix()
  1792. } else {
  1793. if assessment.Creater == 0 {
  1794. assessment.Modifier = adminUserInfo.AdminUser.Id
  1795. assessment.Creater = adminUserInfo.AdminUser.Id
  1796. } else {
  1797. assessment.Modifier = adminUserInfo.AdminUser.Id
  1798. }
  1799. }
  1800. assessment.UpdatedTime = time.Now().Unix()
  1801. // 查询信息规挡的设置天数
  1802. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1803. if infor.ID > 0 {
  1804. var cha_time int64
  1805. timeNowStr := time.Now().Format("2006-01-02")
  1806. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1807. //今日的日期减去设置的日期
  1808. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1809. if cha_time >= recordDate.Unix() {
  1810. //查询审核是否允许
  1811. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1812. //申请状态不允许的情况 拒绝修改
  1813. if infor.ApplicationStatus != 1 {
  1814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1815. return
  1816. }
  1817. }
  1818. }
  1819. err = service.UpdateAssessmentAfterDislysisRecord(&assessment)
  1820. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1821. redis := service.RedisClient()
  1822. //清空key 值
  1823. redis.Set(key, "", time.Second)
  1824. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1825. redis.Set(keyThree, "", time.Second)
  1826. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1827. redis.Set(keyTwo, "", time.Second)
  1828. defer redis.Close()
  1829. } else {
  1830. if appRole.UserType == 2 || appRole.UserType == 1 {
  1831. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1832. assessment.AssessmentTime = time.Now().Unix()
  1833. } else {
  1834. assessment.Creater = adminUserInfo.AdminUser.Id
  1835. }
  1836. assessment.CreatedTime = time.Now().Unix()
  1837. assessment.UpdatedTime = time.Now().Unix()
  1838. assessment.UserOrgId = adminUserInfo.CurrentOrgId
  1839. assessment.PatientId = patient
  1840. assessment.AssessmentDate = recordDate.Unix()
  1841. err = service.AddSigleAssessmentAfterDislysisRecord(&assessment)
  1842. finish := models.XtDialysisFinish{
  1843. IsFinish: 1,
  1844. UserOrgId: adminUserInfo.CurrentOrgId,
  1845. Status: 1,
  1846. Ctime: time.Now().Unix(),
  1847. Mtime: 0,
  1848. Module: 9,
  1849. RecordDate: recordDate.Unix(),
  1850. Sourse: 1,
  1851. PatientId: patient,
  1852. }
  1853. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 9, patient)
  1854. if dialysisFinish.ID == 0 {
  1855. service.CreateDialysisFinish(finish)
  1856. }
  1857. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1858. redis := service.RedisClient()
  1859. //清空key 值
  1860. redis.Set(key, "", time.Second)
  1861. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1862. redis.Set(keyThree, "", time.Second)
  1863. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1864. redis.Set(keyTwo, "", time.Second)
  1865. defer redis.Close()
  1866. }
  1867. if err != nil {
  1868. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1869. return
  1870. }
  1871. c.ServeSuccessJSON(map[string]interface{}{
  1872. "AssessmentAfterDislysis": &assessment,
  1873. })
  1874. }
  1875. func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
  1876. patient, _ := c.GetInt64("patient", 0)
  1877. recordDateStr := c.GetString("record_date")
  1878. if patient <= 0 {
  1879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1880. return
  1881. }
  1882. adminUserInfo := c.GetAdminUserInfo()
  1883. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1884. if patientInfo.ID == 0 {
  1885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1886. return
  1887. }
  1888. if len(recordDateStr) == 0 {
  1889. recordDateStr = time.Now().Format("2006-01-02")
  1890. }
  1891. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1892. if parseDateErr != nil {
  1893. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1895. return
  1896. }
  1897. weight_before, _ := c.GetFloat("weight_before", 0)
  1898. dry_weight, _ := c.GetFloat("dry_weight", 0)
  1899. additional_weight, _ := c.GetFloat("additional_weight", 0)
  1900. temperature, _ := c.GetFloat("temperature", 0)
  1901. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1902. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1903. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1904. last_post_dialysis := c.GetString("last_post_dialysis")
  1905. dialysis_interphase := c.GetString("dialysis_interphase")
  1906. symptom_before_dialysis := c.GetString("symptom_before_dialysis")
  1907. bloodAccessPartOperaId, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1908. //bloodAccessPartId, _ := c.GetInt64("blood_access_part_id", 0)
  1909. bloodAccessPartId := c.GetString("blood_access_part_id")
  1910. internalFistula := c.GetString("internal_fistula")
  1911. internal_fistula_skin := c.GetString("internal_fistula_skin")
  1912. catheter := c.GetString("catheter")
  1913. catheter_bend, _ := c.GetInt("catheter_bend")
  1914. complication := c.GetString("complication")
  1915. is_hemorrhage, _ := c.GetInt64("is_hemorrhage", 0)
  1916. hemorrhage := c.GetString("hemorrhage")
  1917. hemorrhage_other := c.GetString("hemorrhage_other")
  1918. remark := c.GetString("remark")
  1919. puncture_method := c.GetString("puncture_method")
  1920. dialysis_count := c.GetString("dialysis_count")
  1921. emergency_treatment, _ := c.GetInt64("emergency_treatment", 0)
  1922. emergency_treatment_other := c.GetString("emergency_treatment_other")
  1923. ductus_arantii := c.GetString("ductus_arantii")
  1924. venous_catheterization_part_other := c.GetString("venous_catheterization_part_other")
  1925. venous_catheterization_part, _ := c.GetInt64("venous_catheterization_part", 0)
  1926. venous_catheterization, _ := c.GetInt64("venous_catheterization", 0)
  1927. //puncture_way, _ := c.GetInt64("puncture_way", 0)
  1928. puncture_way := c.GetString("puncture_way")
  1929. blood_access_noise, _ := c.GetInt64("blood_access_noise", 0)
  1930. internal_fistula_other := c.GetString("internal_fistula_other")
  1931. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  1932. breathing_rate := c.GetString("breathing_rate")
  1933. is_infect, _ := c.GetInt64("is_infect", 0)
  1934. exposed, _ := c.GetFloat("exposed", 0)
  1935. skin := c.GetString("skin")
  1936. skin_other := c.GetString("skin_other")
  1937. infect_other := c.GetString("infect_other")
  1938. ductus_arantii_other := c.GetString("ductus_arantii_other")
  1939. machine_type := c.GetString("machine_type")
  1940. puncture_needle := c.GetString("puncture_needle")
  1941. //humor_excessive_symptom, _ := c.GetInt64("humor_excessive_symptom", 0)
  1942. humor_excessive_symptom := c.GetString("humor_excessive_symptom")
  1943. phinholing := c.GetString("pinholing")
  1944. catheter_suture := c.GetString("catheter_suture")
  1945. catheter_suture_other := c.GetString("catheter_suture_other")
  1946. edema := c.GetString("edema")
  1947. urine_volume, _ := c.GetFloat("urine_volume", 0)
  1948. special_treatment := c.GetString("special_treatment")
  1949. catheter_maintenance := c.GetString("catheter_maintenance")
  1950. thrombusType := c.GetString("thromubus_type")
  1951. thrombusInt, _ := strconv.ParseInt(thrombusType, 10, 64)
  1952. thrombus_a := c.GetString("thromubus_a")
  1953. thrombus_av := c.GetString("thrombus_av")
  1954. thrombus_v := c.GetString("thromubus_v")
  1955. dehydration := c.GetString("dehydration")
  1956. pre_dialysis_drugs := c.GetString("pre_dialysis_drugs")
  1957. period, _ := c.GetInt64("period")
  1958. estimated_food_intake := c.GetString("estimated_food_intake")
  1959. blood_pressure_during_dialysis := c.GetString("blood_pressure_during_dialysis")
  1960. urea_befor := c.GetString("urea_befor")
  1961. suction := c.GetString("suction")
  1962. weight_befor_remake := c.GetString("weight_befor_remake")
  1963. height := c.GetString("height")
  1964. age := c.GetString("age")
  1965. his_department := c.GetString("his_department")
  1966. his_bed := c.GetString("his_bed")
  1967. point_puncture := c.GetString("point_puncture")
  1968. catheter_evaluation_program := c.GetString("catheter_evaluation_program")
  1969. skin_site_catheterization := c.GetString("skin_site_catheterization")
  1970. pathway_formation_time := c.GetString("pathway_formation_time")
  1971. timeLayout := "2006-01-02"
  1972. loc, _ := time.LoadLocation("Local")
  1973. var startTime int64
  1974. if len(pathway_formation_time) > 0 {
  1975. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", pathway_formation_time+" 00:00:00", loc)
  1976. startTime = theTime.Unix()
  1977. }
  1978. whether_unobstructed, _ := c.GetInt64("whether_unobstructed")
  1979. lien_necessary, _ := c.GetInt64("lien_necessary")
  1980. befor_symptoms := c.GetString("befor_symptoms")
  1981. assessmentBeforeDislysis := models.PredialysisEvaluation{
  1982. DialysisCount: dialysis_count,
  1983. EmergencyTreatment: emergency_treatment,
  1984. EmergencyTreatmentOther: emergency_treatment_other,
  1985. DuctusArantii: ductus_arantii,
  1986. VenousCatheterization: venous_catheterization,
  1987. VenousCatheterizationPart: venous_catheterization_part,
  1988. VenousCatheterizationPartOther: venous_catheterization_part_other,
  1989. PunctureWay: puncture_way,
  1990. BloodAccessInternalFistula: blood_access_internal_fistula,
  1991. BloodAccessNoise: blood_access_noise,
  1992. InternalFistulaOther: internal_fistula_other,
  1993. Evaluator: adminUserInfo.AdminUser.Id,
  1994. UserOrgId: adminUserInfo.CurrentOrgId,
  1995. PatientId: patient,
  1996. AssessmentDate: recordDate.Unix(),
  1997. Temperature: temperature,
  1998. PulseFrequency: pulse_frequency,
  1999. SystolicBloodPressure: systolic_blood_pressure,
  2000. DiastolicBloodPressure: diastolic_blood_pressure,
  2001. WeightBefore: weight_before,
  2002. DryWeight: dry_weight,
  2003. AdditionalWeight: additional_weight,
  2004. DialysisInterphase: dialysis_interphase,
  2005. LastPostDialysis: last_post_dialysis,
  2006. SymptomBeforeDialysis: symptom_before_dialysis,
  2007. InternalFistula: internalFistula,
  2008. InternalFistulaSkin: internal_fistula_skin,
  2009. Catheter: catheter,
  2010. CatheterBend: catheter_bend,
  2011. Complication: complication,
  2012. CreatedTime: time.Now().Unix(),
  2013. Status: 1,
  2014. Remark: remark,
  2015. IsHemorrhage: is_hemorrhage,
  2016. Hemorrhage: hemorrhage,
  2017. HemorrhageOther: hemorrhage_other,
  2018. BloodAccessPartId: bloodAccessPartId,
  2019. BloodAccessPartOperaId: bloodAccessPartOperaId,
  2020. PunctureMethod: puncture_method,
  2021. BreathingRate: breathing_rate,
  2022. IsInfect: is_infect,
  2023. Exposed: exposed,
  2024. Skin: skin,
  2025. SkinOther: skin_other,
  2026. InfectOther: infect_other,
  2027. DuctusArantiiOther: ductus_arantii_other,
  2028. MachineType: machine_type,
  2029. PunctureNeedle: puncture_needle,
  2030. HumorExcessiveSymptom: humor_excessive_symptom,
  2031. Phinholing: phinholing,
  2032. CatheterSuture: catheter_suture,
  2033. CatheterSutureOther: catheter_suture_other,
  2034. Edema: edema,
  2035. UrineVolume: urine_volume,
  2036. SpecialTreatment: special_treatment,
  2037. CatheterMaintenance: catheter_maintenance,
  2038. ThromubusType: thrombusInt,
  2039. ThrombusAv: thrombus_av,
  2040. ThromubusA: thrombus_a,
  2041. ThromubusV: thrombus_v,
  2042. Dehydration: dehydration,
  2043. PreDialysisDrugs: pre_dialysis_drugs,
  2044. Period: period,
  2045. EstimatedFoodIntake: estimated_food_intake,
  2046. BloodPressureDuringDialysis: blood_pressure_during_dialysis,
  2047. UreaBefor: urea_befor,
  2048. Suction: suction,
  2049. WeightBeforRemake: weight_befor_remake,
  2050. Height: height,
  2051. Age: age,
  2052. HisDepartment: his_department,
  2053. HisBed: his_bed,
  2054. PointPuncture: point_puncture,
  2055. CatheterEvaluationProgram: catheter_evaluation_program,
  2056. SkinSiteCatheterization: skin_site_catheterization,
  2057. PathwayFormationTime: startTime,
  2058. WhetherUnobstructed: whether_unobstructed,
  2059. LienNecessary: lien_necessary,
  2060. BeforSymptoms: befor_symptoms,
  2061. }
  2062. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2063. _, evaluation := service.FindPredialysisEvaluationByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2064. if evaluation.ID == 0 { //新增
  2065. if appRole.UserType == 2 || appRole.UserType == 1 {
  2066. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2067. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  2068. } else {
  2069. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  2070. }
  2071. // 查询信息规挡的设置天数
  2072. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2073. if infor.ID > 0 && infor.WeekDay > 0 {
  2074. var cha_time int64
  2075. timeNowStr := time.Now().Format("2006-01-02")
  2076. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2077. //今日的日期减去设置的日期
  2078. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2079. if cha_time >= recordDate.Unix() {
  2080. //查询审核是否允许
  2081. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2082. //申请状态不允许的情况 拒绝修改
  2083. if infor.ApplicationStatus != 1 {
  2084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2085. return
  2086. }
  2087. }
  2088. }
  2089. err := service.AddSigleAssessmentBeforeDislysisRecord(&assessmentBeforeDislysis)
  2090. //创建步骤表
  2091. finish := models.XtDialysisFinish{
  2092. IsFinish: 1,
  2093. UserOrgId: adminUserInfo.CurrentOrgId,
  2094. Status: 1,
  2095. Ctime: time.Now().Unix(),
  2096. Mtime: 0,
  2097. Module: 3,
  2098. RecordDate: recordDate.Unix(),
  2099. Sourse: 1,
  2100. PatientId: patient,
  2101. }
  2102. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 3, patient)
  2103. if dialysisFinish.ID == 0 {
  2104. service.CreateDialysisFinish(finish)
  2105. }
  2106. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10469 {
  2107. var dewater_amount float64
  2108. dewater_amount = 0
  2109. if dry_weight > 0 {
  2110. dewater_amount = weight_before - dry_weight - additional_weight
  2111. dewater_amount = dewater_amount * 1000
  2112. if dewater_amount <= 0 {
  2113. dewater_amount = 0
  2114. }
  2115. } else {
  2116. dewater_amount = 0
  2117. }
  2118. // 计算透析处方的相关超滤量
  2119. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2120. var lastDialysisPrescribe *models.DialysisPrescription
  2121. var dialysisSolution *models.DialysisSolution
  2122. var dialysisPrescribe *models.DialysisPrescription
  2123. var mode_id int64
  2124. if schedual != nil {
  2125. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  2126. if dialysisPrescribe == nil {
  2127. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2128. }
  2129. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2130. // 获取透析模版
  2131. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2132. mode_id = schedual.ModeId
  2133. } else {
  2134. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  2135. // 获取透析模版
  2136. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2137. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  2138. if dialysisPrescribe == nil && dialysisSolution != nil {
  2139. mode_id = dialysisSolution.ModeId
  2140. }
  2141. if dialysisPrescribe == nil && dialysisSolution == nil {
  2142. mode_id = 0
  2143. }
  2144. }
  2145. // 插入透析处方
  2146. if dialysisPrescribe == nil && dialysisSolution != nil {
  2147. var newprescribe models.DialysisPrescription
  2148. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  2149. newprescribe.PatientId = dialysisSolution.PatientId
  2150. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2151. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2152. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2153. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2154. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2155. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2156. newprescribe.ModeId = dialysisSolution.ModeId
  2157. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2158. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2159. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2160. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2161. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2162. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2163. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2164. newprescribe.Glucose = dialysisSolution.Glucose
  2165. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2166. newprescribe.Kalium = dialysisSolution.Kalium
  2167. newprescribe.Sodium = dialysisSolution.Sodium
  2168. newprescribe.Calcium = dialysisSolution.Calcium
  2169. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2170. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2171. newprescribe.Conductivity = dialysisSolution.Conductivity
  2172. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2173. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2174. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2175. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2176. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2177. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2178. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2179. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2180. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2181. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2182. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2183. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2184. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2185. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2186. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2187. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2188. newprescribe.CreatedTime = time.Now().Unix()
  2189. newprescribe.UpdatedTime = time.Now().Unix()
  2190. newprescribe.RecordDate = recordDate.Unix()
  2191. newprescribe.DewaterAmount = dewater_amount
  2192. newprescribe.TargetUltrafiltration = dewater_amount
  2193. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2194. newprescribe.Status = 1
  2195. err := service.AddSigleRecord(&newprescribe)
  2196. if err != nil {
  2197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2198. }
  2199. }
  2200. if dialysisPrescribe == nil && dialysisSolution == nil {
  2201. if lastDialysisPrescribe != nil {
  2202. var newprescribe models.DialysisPrescription
  2203. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  2204. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  2205. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2206. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2207. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2208. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2209. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2210. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2211. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2212. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2213. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2214. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2215. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2216. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2217. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2218. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2219. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2220. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2221. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2222. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2223. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2224. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2225. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2226. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2227. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2228. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2229. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2230. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2231. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2232. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2233. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2234. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2235. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2236. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2237. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2238. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2239. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2240. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2241. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2242. newprescribe.CreatedTime = time.Now().Unix()
  2243. newprescribe.UpdatedTime = time.Now().Unix()
  2244. newprescribe.RecordDate = recordDate.Unix()
  2245. newprescribe.DewaterAmount = dewater_amount
  2246. newprescribe.TargetUltrafiltration = dewater_amount
  2247. newprescribe.Status = 1
  2248. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2249. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2250. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2251. err := service.AddSigleRecord(&newprescribe)
  2252. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2253. redis := service.RedisClient()
  2254. defer redis.Close()
  2255. //清空key 值
  2256. redis.Set(key, "", time.Second)
  2257. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2258. redis.Set(keyOne, "", time.Second)
  2259. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2260. redis.Set(keyThree, "", time.Second)
  2261. if err != nil {
  2262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2263. }
  2264. } else {
  2265. var newprescribe models.DialysisPrescription
  2266. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2267. newprescribe.PatientId = patient
  2268. newprescribe.ModeId = mode_id
  2269. newprescribe.CreatedTime = time.Now().Unix()
  2270. newprescribe.UpdatedTime = time.Now().Unix()
  2271. newprescribe.RecordDate = recordDate.Unix()
  2272. newprescribe.DewaterAmount = dewater_amount
  2273. newprescribe.TargetUltrafiltration = dewater_amount
  2274. newprescribe.Status = 1
  2275. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2276. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2277. newprescribe.Modifier = adminUserInfo.AdminUser.Id
  2278. err := service.AddSigleRecord(&newprescribe)
  2279. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2280. redis := service.RedisClient()
  2281. defer redis.Close()
  2282. //清空key 值
  2283. redis.Set(key, "", time.Second)
  2284. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2285. redis.Set(keyOne, "", time.Second)
  2286. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2287. redis.Set(keyThree, "", time.Second)
  2288. if err != nil {
  2289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2290. }
  2291. }
  2292. }
  2293. }
  2294. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2295. redis := service.RedisClient()
  2296. //清空key 值
  2297. redis.Set(key, "", time.Second)
  2298. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2299. redis.Set(keyOne, "", time.Second)
  2300. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2301. redis.Set(keyTwo, "", time.Second)
  2302. defer redis.Close()
  2303. if err == nil {
  2304. c.ServeSuccessJSON(map[string]interface{}{
  2305. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  2306. })
  2307. } else {
  2308. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2310. }
  2311. } else { //修改
  2312. //if appRole.UserType == 3 {
  2313. // if evaluation.Creater != adminUserInfo.AdminUser.Id && evaluation.Creater != 0 {
  2314. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2315. // if getPermissionErr != nil {
  2316. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2317. // return
  2318. // } else if headNursePermission == nil {
  2319. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2320. // return
  2321. // }
  2322. // }
  2323. //}
  2324. if appRole.UserType == 2 || appRole.UserType == 1 {
  2325. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2326. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  2327. } else {
  2328. if evaluation.Creater == 0 {
  2329. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  2330. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  2331. } else {
  2332. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  2333. }
  2334. }
  2335. assessmentBeforeDislysis.UpdatedTime = time.Now().Unix()
  2336. assessmentBeforeDislysis.ID = evaluation.ID
  2337. assessmentBeforeDislysis.CreatedTime = evaluation.CreatedTime
  2338. //
  2339. //新增逻辑
  2340. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  2341. var dewater_amount float64
  2342. dewater_amount = 0
  2343. if evaluation.DryWeight > 0 {
  2344. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  2345. if templateInfo.TemplateId == 17 || templateInfo.TemplateId == 22 || templateInfo.TemplateId == 21 || templateInfo.TemplateId == 34 {
  2346. dewater_amount = dewater_amount * 1000
  2347. }
  2348. if dewater_amount <= 0 {
  2349. dewater_amount = 0
  2350. }
  2351. } else {
  2352. dewater_amount = 0
  2353. }
  2354. // 计算透析处方的相关超滤量
  2355. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2356. var lastDialysisPrescribe *models.DialysisPrescription
  2357. var dialysisSolution *models.DialysisSolution
  2358. var dialysisPrescribe *models.DialysisPrescription
  2359. var mode_id int64
  2360. if schedual != nil {
  2361. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  2362. if dialysisPrescribe == nil {
  2363. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2364. }
  2365. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2366. // 获取透析模版
  2367. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2368. mode_id = schedual.ModeId
  2369. } else {
  2370. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  2371. // 获取透析模版
  2372. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2373. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  2374. if dialysisPrescribe == nil && dialysisSolution != nil {
  2375. mode_id = dialysisSolution.ModeId
  2376. }
  2377. if dialysisPrescribe == nil && dialysisSolution == nil {
  2378. mode_id = 0
  2379. }
  2380. }
  2381. // 插入透析处方
  2382. if dialysisPrescribe == nil && dialysisSolution != nil {
  2383. var newprescribe models.DialysisPrescription
  2384. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  2385. newprescribe.PatientId = dialysisSolution.PatientId
  2386. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2387. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2388. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2389. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2390. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2391. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2392. newprescribe.ModeId = dialysisSolution.ModeId
  2393. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2394. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2395. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2396. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2397. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2398. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2399. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2400. newprescribe.Glucose = dialysisSolution.Glucose
  2401. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2402. newprescribe.Kalium = dialysisSolution.Kalium
  2403. newprescribe.Sodium = dialysisSolution.Sodium
  2404. newprescribe.Calcium = dialysisSolution.Calcium
  2405. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2406. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2407. newprescribe.Conductivity = dialysisSolution.Conductivity
  2408. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2409. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2410. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2411. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2412. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2413. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2414. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2415. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2416. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2417. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2418. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2419. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2420. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2421. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2422. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2423. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2424. newprescribe.CreatedTime = time.Now().Unix()
  2425. newprescribe.UpdatedTime = time.Now().Unix()
  2426. newprescribe.RecordDate = recordDate.Unix()
  2427. newprescribe.DewaterAmount = dewater_amount
  2428. newprescribe.TargetUltrafiltration = dewater_amount
  2429. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2430. newprescribe.Status = 1
  2431. err := service.AddSigleRecord(&newprescribe)
  2432. if err != nil {
  2433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2434. }
  2435. }
  2436. if dialysisPrescribe == nil && dialysisSolution == nil {
  2437. if lastDialysisPrescribe != nil {
  2438. var newprescribe models.DialysisPrescription
  2439. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  2440. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  2441. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2442. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2443. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2444. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2445. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2446. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2447. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2448. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2449. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2450. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2451. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2452. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2453. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2454. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2455. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2456. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2457. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2458. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2459. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2460. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2461. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2462. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2463. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2464. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2465. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2466. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2467. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2468. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2469. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2470. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2471. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2472. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2473. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2474. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2475. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2476. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2477. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2478. newprescribe.CreatedTime = time.Now().Unix()
  2479. newprescribe.UpdatedTime = time.Now().Unix()
  2480. newprescribe.RecordDate = recordDate.Unix()
  2481. newprescribe.DewaterAmount = dewater_amount
  2482. newprescribe.TargetUltrafiltration = dewater_amount
  2483. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2484. newprescribe.Status = 1
  2485. err := service.AddSigleRecord(&newprescribe)
  2486. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2487. redis := service.RedisClient()
  2488. defer redis.Close()
  2489. //清空key 值
  2490. redis.Set(key, "", time.Second)
  2491. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2492. redis.Set(keyOne, "", time.Second)
  2493. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2494. redis.Set(keyThree, "", time.Second)
  2495. if err != nil {
  2496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2497. }
  2498. } else {
  2499. var newprescribe models.DialysisPrescription
  2500. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2501. newprescribe.PatientId = patient
  2502. newprescribe.ModeId = mode_id
  2503. newprescribe.CreatedTime = time.Now().Unix()
  2504. newprescribe.UpdatedTime = time.Now().Unix()
  2505. newprescribe.RecordDate = recordDate.Unix()
  2506. newprescribe.DewaterAmount = dewater_amount
  2507. newprescribe.TargetUltrafiltration = dewater_amount
  2508. newprescribe.Status = 1
  2509. err := service.AddSigleRecord(&newprescribe)
  2510. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2511. redis := service.RedisClient()
  2512. defer redis.Close()
  2513. //清空key 值
  2514. redis.Set(key, "", time.Second)
  2515. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2516. redis.Set(keyOne, "", time.Second)
  2517. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2518. redis.Set(keyThree, "", time.Second)
  2519. if err != nil {
  2520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2521. }
  2522. }
  2523. }
  2524. // 查询信息规挡的设置天数
  2525. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2526. if infor.ID > 0 {
  2527. var cha_time int64
  2528. timeNowStr := time.Now().Format("2006-01-02")
  2529. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2530. //今日的日期减去设置的日期
  2531. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2532. if cha_time >= recordDate.Unix() {
  2533. //查询审核是否允许
  2534. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2535. //申请状态不允许的情况 拒绝修改
  2536. if infor.ApplicationStatus != 1 {
  2537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2538. return
  2539. }
  2540. }
  2541. }
  2542. err := service.UpadatePredialysisEvaluation(&assessmentBeforeDislysis)
  2543. //创建步骤表
  2544. finish := models.XtDialysisFinish{
  2545. IsFinish: 1,
  2546. UserOrgId: adminUserInfo.CurrentOrgId,
  2547. Status: 1,
  2548. Ctime: time.Now().Unix(),
  2549. Mtime: 0,
  2550. Module: 3,
  2551. RecordDate: recordDate.Unix(),
  2552. Sourse: 1,
  2553. PatientId: patient,
  2554. }
  2555. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 3, patient)
  2556. if dialysisFinish.ID == 0 {
  2557. service.CreateDialysisFinish(finish)
  2558. }
  2559. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2560. redis := service.RedisClient()
  2561. //清空key 值
  2562. redis.Set(key, "", time.Second)
  2563. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2564. redis.Set(keyOne, "", time.Second)
  2565. defer redis.Close()
  2566. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2567. redis.Set(keyTwo, "", time.Second)
  2568. if err == nil {
  2569. c.ServeSuccessJSON(map[string]interface{}{
  2570. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  2571. })
  2572. } else {
  2573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2574. }
  2575. }
  2576. }
  2577. func (c *DialysisApiController) PostTreatmentSummary() {
  2578. patient, _ := c.GetInt64("patient", 0)
  2579. recordDateStr := c.GetString("record_date")
  2580. if patient <= 0 {
  2581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2582. return
  2583. }
  2584. adminUserInfo := c.GetAdminUserInfo()
  2585. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2586. if patientInfo.ID == 0 {
  2587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2588. return
  2589. }
  2590. if len(recordDateStr) == 0 {
  2591. recordDateStr = time.Now().Format("2006-01-02")
  2592. }
  2593. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2594. if parseDateErr != nil {
  2595. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2597. return
  2598. }
  2599. mission := c.GetString("mission")
  2600. dialysis_summary := c.GetString("dialysis_summary")
  2601. nursingRecord := c.GetString("nursing_record")
  2602. specialRecord := c.GetString("special_record")
  2603. sj_nurse := adminUserInfo.AdminUser.Id
  2604. zl_nurse := adminUserInfo.AdminUser.Id
  2605. hd_nurse := adminUserInfo.AdminUser.Id
  2606. xj_nurse := adminUserInfo.AdminUser.Id
  2607. zl_doctor := adminUserInfo.AdminUser.Id
  2608. treatmentSummary := models.TreatmentSummary{
  2609. UserOrgId: adminUserInfo.CurrentOrgId,
  2610. PatientId: patient,
  2611. AssessmentDate: recordDate.Unix(),
  2612. Mission: mission,
  2613. DialysisSummary: dialysis_summary,
  2614. SjNurse: sj_nurse,
  2615. ZlNurse: zl_nurse,
  2616. HdNurse: hd_nurse,
  2617. XjNurse: xj_nurse,
  2618. ZlDoctor: zl_doctor,
  2619. Status: 1,
  2620. CreatedTime: time.Now().Unix(),
  2621. NursingRecord: nursingRecord,
  2622. SpecialRecord: specialRecord,
  2623. }
  2624. _, tempTreatmentSummary := service.FindTreatmentSummaryByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2625. if tempTreatmentSummary.ID == 0 { //新增
  2626. treatmentSummary.Creater = adminUserInfo.AdminUser.Id
  2627. // 查询信息规挡的设置天数
  2628. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2629. if infor.ID > 0 && infor.WeekDay > 0 {
  2630. var cha_time int64
  2631. timeNowStr := time.Now().Format("2006-01-02")
  2632. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2633. //今日的日期减去设置的日期
  2634. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2635. if cha_time >= recordDate.Unix() {
  2636. //查询审核是否允许
  2637. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2638. //申请状态不允许的情况 拒绝修改
  2639. if infor.ApplicationStatus != 1 {
  2640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2641. return
  2642. }
  2643. }
  2644. }
  2645. err := service.AddSigleSummaryRecord(&treatmentSummary)
  2646. finish := models.XtDialysisFinish{
  2647. IsFinish: 1,
  2648. UserOrgId: adminUserInfo.CurrentOrgId,
  2649. Status: 1,
  2650. Ctime: time.Now().Unix(),
  2651. Mtime: 0,
  2652. Module: 10,
  2653. RecordDate: recordDate.Unix(),
  2654. Sourse: 1,
  2655. PatientId: patient,
  2656. }
  2657. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 10, patient)
  2658. if dialysisFinish.ID == 0 {
  2659. service.CreateDialysisFinish(finish)
  2660. }
  2661. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  2662. redis := service.RedisClient()
  2663. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  2664. redis.Set(keyOne, "", time.Second)
  2665. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2666. redis.Set(keyThree, "", time.Second)
  2667. defer redis.Close()
  2668. //清空key 值
  2669. redis.Set(key, "", time.Second)
  2670. if err == nil {
  2671. c.ServeSuccessJSON(map[string]interface{}{
  2672. "summary": treatmentSummary,
  2673. })
  2674. } else {
  2675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2676. }
  2677. } else { //修改
  2678. //if tempTreatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  2679. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2680. // if getPermissionErr != nil {
  2681. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2682. // return
  2683. // } else if headNursePermission == nil {
  2684. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2685. // return
  2686. // }
  2687. //}
  2688. // 查询信息规挡的设置天数
  2689. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2690. if infor.ID > 0 && infor.WeekDay > 0 {
  2691. var cha_time int64
  2692. timeNowStr := time.Now().Format("2006-01-02")
  2693. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2694. //今日的日期减去设置的日期
  2695. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2696. if cha_time >= recordDate.Unix() {
  2697. //查询审核是否允许
  2698. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2699. //申请状态不允许的情况 拒绝修改
  2700. if infor.ApplicationStatus != 1 {
  2701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2702. return
  2703. }
  2704. }
  2705. }
  2706. treatmentSummary.Creater = tempTreatmentSummary.Creater
  2707. treatmentSummary.CreatedTime = tempTreatmentSummary.CreatedTime
  2708. treatmentSummary.UpdatedTime = time.Now().Unix()
  2709. treatmentSummary.Modifier = adminUserInfo.AdminUser.Id
  2710. treatmentSummary.ID = tempTreatmentSummary.ID
  2711. err := service.UpdateSummeRecord(&treatmentSummary)
  2712. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  2713. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  2714. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2715. //清空key 值
  2716. redis := service.RedisClient()
  2717. redis.Set(key, "", time.Second)
  2718. redis.Set(keyOne, "", time.Second)
  2719. redis.Set(keyThree, "", time.Second)
  2720. defer redis.Close()
  2721. if err == nil {
  2722. c.ServeSuccessJSON(map[string]interface{}{
  2723. "summary": treatmentSummary,
  2724. })
  2725. } else {
  2726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2727. }
  2728. }
  2729. }
  2730. func (c *DialysisApiController) GetDeviceList() {
  2731. adminUserInfo := c.GetAdminUserInfo()
  2732. device, _ := service.FindAllDeviceInfo(adminUserInfo.CurrentOrgId)
  2733. c.ServeSuccessJSON(map[string]interface{}{
  2734. "device": device,
  2735. })
  2736. }
  2737. func (c *DialysisApiController) GetAllDeviceZone() {
  2738. adminUserInfo := c.GetAdminUserInfo()
  2739. err, zone := service.GetAllDeviceZone(adminUserInfo.CurrentOrgId)
  2740. dics, _, err := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  2741. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  2742. if err == nil {
  2743. c.ServeSuccessJSON(map[string]interface{}{
  2744. "zone": zone,
  2745. "dics": dics,
  2746. "efs": efs,
  2747. })
  2748. }
  2749. }
  2750. func (c *DialysisApiController) GetDialysisWatch() {
  2751. page, _ := c.GetInt64("page", 1)
  2752. limit, _ := c.GetInt64("limit", 10)
  2753. schedulType, _ := c.GetInt64("schedul_type", 0)
  2754. startTime, _ := c.GetInt64("schedul_time", 0)
  2755. partitionType, _ := c.GetInt64("partition_type", 0)
  2756. keywords := c.GetString("keywords")
  2757. start_time, _ := c.GetInt64("start_time")
  2758. end_time, _ := c.GetInt64("end_time")
  2759. adminUserInfo := c.GetAdminUserInfo()
  2760. if len(keywords) > 0 {
  2761. dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  2762. if err == nil {
  2763. c.ServeSuccessJSON(map[string]interface{}{
  2764. "schedule": dialysisSchedule,
  2765. "total": total,
  2766. })
  2767. } else {
  2768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2769. }
  2770. } else {
  2771. dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  2772. if err == nil {
  2773. c.ServeSuccessJSON(map[string]interface{}{
  2774. "schedule": dialysisSchedule,
  2775. "total": total,
  2776. })
  2777. } else {
  2778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2779. }
  2780. }
  2781. }
  2782. //func (c *DialysisApiController) GetDialysisWatch() {
  2783. // page, _ := c.GetInt64("page", 1)
  2784. // limit, _ := c.GetInt64("limit", 10)
  2785. // schedulType, _ := c.GetInt64("schedul_type", 0)
  2786. // startTime, _ := c.GetInt64("schedul_time", 0)
  2787. // partitionType, _ := c.GetInt64("partition_type", 0)
  2788. // keywords := c.GetString("keywords")
  2789. //
  2790. // adminUserInfo := c.GetAdminUserInfo()
  2791. // if len(keywords) > 0 {
  2792. // dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit)
  2793. //
  2794. // //获取所有床位号
  2795. // numberList, _ := service.GetAllDeviceNumberByListSix(adminUserInfo.CurrentOrgId)
  2796. //
  2797. // //获取透析处方
  2798. // prescriptions, _ := service.GetAllPrescriptionByListTwo(adminUserInfo.CurrentOrgId, startTime)
  2799. // //获取透前评估
  2800. // assessmentBefores, _ := service.GetAllAssessmentBeforesByListThree(adminUserInfo.CurrentOrgId, startTime)
  2801. // //获取上机
  2802. // dialysisOrders, _ := service.GetAllDialysisOrdersByListThree(adminUserInfo.CurrentOrgId, startTime)
  2803. // //获取透后
  2804. // AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListThree(adminUserInfo.CurrentOrgId, startTime)
  2805. //
  2806. // //获取透后监测
  2807. // monitorlist, _ := service.GetAllMonitorListThree(adminUserInfo.CurrentOrgId, startTime)
  2808. //
  2809. // //获取所有的患者
  2810. // patients, _ := service.GetAllPatientListByListSix(adminUserInfo.CurrentOrgId,keywords)
  2811. //
  2812. // //获取所有透析模式
  2813. // treatments, _ := service.GetAllTreatModeByList(adminUserInfo.CurrentOrgId)
  2814. //
  2815. // for key, scheduals := range dialysisSchedule {
  2816. // // 获取患者信息
  2817. // for _, patient := range patients {
  2818. // if scheduals.PatientId == patient.ID {
  2819. // dialysisSchedule[key].MonitorPatients = patient
  2820. // break
  2821. // }
  2822. // }
  2823. // // 床位信息
  2824. // for _, device := range numberList {
  2825. // if scheduals.BedId == device.ID {
  2826. // dialysisSchedule[key].DeviceNumber = device
  2827. // break
  2828. // }
  2829. // }
  2830. //
  2831. // // 医嘱信息
  2832. // for _, prescription := range prescriptions {
  2833. // if scheduals.PatientId == prescription.PatientId {
  2834. // dialysisSchedule[key].Prescription = prescription
  2835. // break
  2836. // }
  2837. // }
  2838. //
  2839. // // 透前评估
  2840. // for _, assessmentBefore := range assessmentBefores {
  2841. // if scheduals.PatientId == assessmentBefore.PatientId {
  2842. // dialysisSchedule[key].AssessmentBeforeDislysis = assessmentBefore
  2843. // break
  2844. // }
  2845. // }
  2846. //
  2847. // // 透析上下机
  2848. // for _, dialysisOrder := range dialysisOrders {
  2849. // if scheduals.PatientId == dialysisOrder.PatientId {
  2850. // dialysisSchedule[key].DialysisOrder = dialysisOrder
  2851. // break
  2852. // }
  2853. // }
  2854. //
  2855. // records := make([]*models.MonitoringRecord, 0)
  2856. // // 透析监测
  2857. // for _, it := range monitorlist {
  2858. // records := append(records, it)
  2859. // if scheduals.PatientId == it.PatientId {
  2860. // dialysisSchedule[key].MonitoringRecord = records
  2861. // }
  2862. // }
  2863. //
  2864. // // 透后评估
  2865. // for _, afterDislysis := range AssessmentAfterDislysis {
  2866. // if scheduals.PatientId == afterDislysis.PatientId {
  2867. // dialysisSchedule[key].AssessmentAfterDislysis = afterDislysis
  2868. // break
  2869. // }
  2870. // }
  2871. //
  2872. // //透析模式
  2873. // for _, treatment := range treatments {
  2874. // if scheduals.ModeId == treatment.ID {
  2875. // dialysisSchedule[key].TreatmentMode = treatment
  2876. // break
  2877. // }
  2878. // }
  2879. // }
  2880. // //获取所有床位号
  2881. // if err == nil {
  2882. // c.ServeSuccessJSON(map[string]interface{}{
  2883. // "schedule": dialysisSchedule,
  2884. // "total": total,
  2885. // })
  2886. // } else {
  2887. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2888. // }
  2889. //
  2890. // } else {
  2891. // dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit)
  2892. // if err == nil {
  2893. // c.ServeSuccessJSON(map[string]interface{}{
  2894. // "schedule": dialysisSchedule,
  2895. // "total": total,
  2896. // })
  2897. // } else {
  2898. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2899. // }
  2900. // }
  2901. //}
  2902. func (c *DialysisApiController) GetSchedualPatientsInfo() {
  2903. patientId, _ := c.GetInt64("id", 0)
  2904. record_date, _ := c.GetInt64("record_date", 0)
  2905. adminUserInfo := c.GetAdminUserInfo()
  2906. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2907. var dialysisStatus int64
  2908. if dialysisOrder == nil { //没有透析记录
  2909. dialysisStatus = 0 //未透析
  2910. } else {
  2911. dialysisStatus = dialysisOrder.Stage
  2912. }
  2913. //用户基本信息
  2914. schedualPatientInfo, _ := service.FindPatientInfoById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2915. //接诊评估
  2916. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2917. //透前评估
  2918. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2919. //临时医嘱
  2920. DoctorAdvice, _ := service.FindDoctorAdviceById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2921. //双人核对
  2922. DoubleCheck, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2923. //透析监测
  2924. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientId, record_date)
  2925. //透后评估
  2926. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2927. //透析小结
  2928. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2929. //透析处方
  2930. dialysisPrescription, _ := service.FindPatientPrescribeById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2931. if dialysisPrescription.ID == 0 {
  2932. solution, _ := service.FindDialysisSolution(adminUserInfo.CurrentOrgId, patientId)
  2933. c.ServeSuccessJSON(map[string]interface{}{
  2934. "patientInfo": schedualPatientInfo,
  2935. "dialysisPrescription": solution,
  2936. "receiverTreatmentAccess": receiverTreatmentAccess,
  2937. "predialysisEvaluation": PredialysisEvaluation,
  2938. "doctorAdvice": DoctorAdvice,
  2939. "doubleCheck": DoubleCheck,
  2940. "assessmentAfterDislysis": AssessmentAfterDislysis,
  2941. "treatmentSummary": TreatmentSummary,
  2942. "monitorRecord": Record,
  2943. "dialysisStatus": dialysisStatus,
  2944. "dialysisOrder": dialysisOrder,
  2945. "isSolution": 1,
  2946. })
  2947. } else {
  2948. c.ServeSuccessJSON(map[string]interface{}{
  2949. "patientInfo": schedualPatientInfo,
  2950. "dialysisPrescription": dialysisPrescription,
  2951. "receiverTreatmentAccess": receiverTreatmentAccess,
  2952. "predialysisEvaluation": PredialysisEvaluation,
  2953. "doctorAdvice": DoctorAdvice,
  2954. "doubleCheck": DoubleCheck,
  2955. "assessmentAfterDislysis": AssessmentAfterDislysis,
  2956. "treatmentSummary": TreatmentSummary,
  2957. "monitorRecord": Record,
  2958. "dialysisStatus": dialysisStatus,
  2959. "dialysisOrder": dialysisOrder,
  2960. "isSolution": 2,
  2961. })
  2962. }
  2963. }
  2964. func (c *DialysisApiController) CreateDoctorAdvice() {
  2965. patient, _ := c.GetInt64("id", 0)
  2966. dialysis_id, _ := c.GetInt64("dialysis_id", 0)
  2967. record_date, _ := c.GetInt64("record_date", 0)
  2968. if patient <= 0 {
  2969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2970. return
  2971. }
  2972. adminUserInfo := c.GetAdminUserInfo()
  2973. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2974. if patientInfo.ID == 0 {
  2975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2976. return
  2977. }
  2978. var advice models.DoctorAdvice
  2979. code, subAdivice := adviceFormDatas(&advice, c.Ctx.Input.RequestBody, "create")
  2980. if code > 0 {
  2981. c.ServeFailJSONWithSGJErrorCode(code)
  2982. return
  2983. }
  2984. if advice.ParentId > 0 {
  2985. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  2986. if old.ID == 0 || old.PatientId != patient {
  2987. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2988. return
  2989. }
  2990. if old.StopState == 1 || old.ExecutionState == 1 {
  2991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2992. return
  2993. }
  2994. if old.ParentId > 0 {
  2995. advice.ParentId = old.ParentId
  2996. }
  2997. advice.StartTime = old.StartTime
  2998. advice.AdviceDoctor = old.AdviceDoctor
  2999. advice.DeliveryWay = old.DeliveryWay
  3000. advice.ExecutionFrequency = old.ExecutionFrequency
  3001. }
  3002. advice.RecordDate = record_date
  3003. advice.DialysisOrderId = dialysis_id
  3004. advice.Status = 1
  3005. advice.CreatedTime = time.Now().Unix()
  3006. advice.UpdatedTime = time.Now().Unix()
  3007. advice.StopState = 2
  3008. advice.ExecutionState = 2
  3009. advice.AdviceType = 2
  3010. advice.UserOrgId = adminUserInfo.CurrentOrgId
  3011. advice.PatientId = patient
  3012. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3013. err := service.CreateDoctorAdvice(&advice)
  3014. if err != nil {
  3015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3016. return
  3017. }
  3018. for _, subAdvice := range subAdivice {
  3019. subAdvice.ParentId = advice.ID
  3020. subAdvice.PatientId = patient
  3021. subAdvice.RecordDate = record_date
  3022. subAdvice.CreatedTime = time.Now().Unix()
  3023. subAdvice.UpdatedTime = time.Now().Unix()
  3024. subAdvice.UserOrgId = adminUserInfo.CurrentOrgId
  3025. }
  3026. service.CreateSubDoctorAdvice(subAdivice)
  3027. _, subAdivices := service.FindAllSubDoctorAdvice(patient, advice.ID)
  3028. c.ServeSuccessJSON(map[string]interface{}{
  3029. "msg": "ok",
  3030. "advice": advice,
  3031. "subAdvice": subAdivices,
  3032. })
  3033. return
  3034. }
  3035. func (c *DialysisApiController) EditDoctorAdvice() {
  3036. patient, _ := c.GetInt64("patient", 0)
  3037. id, _ := c.GetInt64("id", 0)
  3038. parent_id, _ := c.GetInt64("parent_id", 0)
  3039. execution_time := c.GetString("execution_time")
  3040. // execution_staff, _ := c.GetInt64("execution_staff", 0)
  3041. // checker, _ := c.GetInt64("checker", 0)
  3042. if id <= 0 || patient <= 0 {
  3043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3044. return
  3045. }
  3046. adminUserInfo := c.GetAdminUserInfo()
  3047. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3048. if advice.ID == 0 || advice.PatientId != patient {
  3049. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3050. return
  3051. }
  3052. if len(execution_time) <= 0 {
  3053. utils.ErrorLog("execution_time")
  3054. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3055. return
  3056. }
  3057. execution_staff := adminUserInfo.AdminUser.Id
  3058. checker := adminUserInfo.AdminUser.Id
  3059. timeLayout2 := "2006-01-02 15:04"
  3060. loc, _ := time.LoadLocation("Local")
  3061. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  3062. if errs != nil {
  3063. utils.ErrorLog(errs.Error())
  3064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3065. return
  3066. }
  3067. advices := models.DoctorAdvice{
  3068. ExecutionStaff: execution_staff,
  3069. ExecutionTime: theTime.Unix(),
  3070. Checker: checker,
  3071. UpdatedTime: time.Now().Unix(),
  3072. }
  3073. var err error
  3074. if parent_id > 0 {
  3075. err = service.ExceDoctorAdviceById(&advices, parent_id, patient)
  3076. } else {
  3077. err = service.ExceDoctorAdviceById(&advices, id, patient)
  3078. }
  3079. if err != nil {
  3080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  3081. return
  3082. }
  3083. c.ServeSuccessJSON(map[string]interface{}{
  3084. "msg": "ok",
  3085. "advice": advice,
  3086. })
  3087. return
  3088. }
  3089. func (c *DialysisApiController) GetDoctorAdvice() {
  3090. patient, _ := c.GetInt64("patient_id", 0)
  3091. parent_id, _ := c.GetInt64("parent_id", 0)
  3092. adviceId, _ := c.GetInt64("id", 0)
  3093. if patient <= 0 {
  3094. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3095. return
  3096. }
  3097. dminUserInfo := c.GetAdminUserInfo()
  3098. patientInfo, _ := service.FindPatientById(dminUserInfo.CurrentOrgId, patient)
  3099. if patientInfo.ID == 0 {
  3100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3101. return
  3102. }
  3103. var subAdvice []*models.DoctorAdvice
  3104. var advice models.DoctorAdvice
  3105. if parent_id > 0 {
  3106. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, parent_id)
  3107. if advice.ID == 0 || advice.PatientId != patient {
  3108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3109. return
  3110. }
  3111. subAdvice = service.FindSubAdivceById(patient, parent_id)
  3112. } else {
  3113. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, adviceId)
  3114. if advice.ID == 0 || advice.PatientId != patient {
  3115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3116. return
  3117. }
  3118. subAdvice = service.FindSubAdivceById(patient, adviceId)
  3119. }
  3120. c.ServeSuccessJSON(map[string]interface{}{
  3121. "msg": "ok",
  3122. "advice": advice,
  3123. "subAdvice": subAdvice,
  3124. })
  3125. }
  3126. func (this *DialysisApiController) DelMonitor() {
  3127. recordID, _ := this.GetInt64("record_id")
  3128. patientID, _ := this.GetInt64("patient_id")
  3129. if recordID <= 0 || patientID <= 0 {
  3130. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3131. return
  3132. }
  3133. adminInfo := this.GetAdminUserInfo()
  3134. patient, getPatientErr := service.MobileGetPatientById(adminInfo.CurrentOrgId, patientID)
  3135. if getPatientErr != nil {
  3136. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3137. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3138. return
  3139. } else if patient == nil {
  3140. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3141. return
  3142. }
  3143. monitor, getMonitorErr := service.GetMonitor(adminInfo.CurrentOrgId, patientID, recordID)
  3144. if getMonitorErr != nil {
  3145. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3146. return
  3147. }
  3148. //if monitor != nil {
  3149. // if monitor.MonitoringNurse != adminInfo.AdminUser.Id {
  3150. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, adminInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3151. // if getPermissionErr != nil {
  3152. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3153. // return
  3154. // } else if headNursePermission == nil {
  3155. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3156. // return
  3157. // }
  3158. // }
  3159. //}
  3160. // 查询信息规挡的设置天数
  3161. infor, _ := service.GetDialysisInformationSetting(adminInfo.CurrentOrgId)
  3162. if infor.ID > 0 && infor.WeekDay > 0 {
  3163. var cha_time int64
  3164. timeNowStr := time.Now().Format("2006-01-02")
  3165. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3166. //今日的日期减去设置的日期
  3167. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3168. if cha_time >= monitor.MonitoringDate {
  3169. //查询审核是否允许
  3170. infor, _ := service.GetDialysisInformationByRecordDate(patientID, monitor.MonitoringDate, adminInfo.CurrentOrgId)
  3171. //申请状态不允许的情况 拒绝修改
  3172. if infor.ApplicationStatus != 1 {
  3173. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3174. return
  3175. }
  3176. }
  3177. }
  3178. err := service.DisableMonitor(adminInfo.CurrentOrgId, patientID, recordID, adminInfo.AdminUser.Id)
  3179. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_records"
  3180. redis := service.RedisClient()
  3181. //清空key 值
  3182. redis.Set(key, "", time.Second)
  3183. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_record_list_all"
  3184. redis.Set(keyOne, "", time.Second)
  3185. defer redis.Close()
  3186. if err != nil {
  3187. this.ErrorLog("删除透析监测记录失败:%v", err)
  3188. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  3189. return
  3190. }
  3191. this.ServeSuccessJSON(map[string]interface{}{
  3192. "record_id": monitor.ID,
  3193. })
  3194. }
  3195. func (c *DialysisApiController) CreateMonitor() {
  3196. patient, _ := c.GetInt64("id", 0)
  3197. dialysis_order_id, _ := c.GetInt64("dialysis_order_id", 0)
  3198. monitoring_date, _ := c.GetInt64("monitoring_date", 0)
  3199. operate_time, _ := c.GetInt64("operate_time", 0)
  3200. // monitoring_time := c.GetString("monitoring_time")
  3201. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  3202. breathing_rated := c.GetString("breathing_rated")
  3203. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  3204. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  3205. blood_pressure_type, _ := c.GetInt64("blood_pressure_type", 0)
  3206. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3207. venous_pressure, _ := c.GetFloat("venous_pressure", 0)
  3208. venous_pressure_type, _ := c.GetInt64("venous_pressure_type", 1)
  3209. transmembrane_pressure, _ := c.GetFloat("transmembrane_pressure", 0)
  3210. transmembrane_pressure_type, _ := c.GetInt64("transmembrane_pressure_type", 1)
  3211. ultrafiltration_rate, _ := c.GetFloat("ultrafiltration_rate", 0)
  3212. ultrafiltration_volume, _ := c.GetFloat("ultrafiltration_volume", 0)
  3213. sodium_concentration, _ := c.GetFloat("sodium_concentration", 0)
  3214. arterial_pressure, _ := c.GetFloat("arterial_pressure", 0)
  3215. arterial_pressure_type, _ := c.GetInt64("arterial_pressure_type", 1)
  3216. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3217. temperature, _ := c.GetFloat("temperature", 0)
  3218. replacement_rate, _ := c.GetFloat("replacement_rate", 0)
  3219. displacement_quantity, _ := c.GetFloat("displacement_quantity", 0)
  3220. conductivity, _ := c.GetFloat("conductivity", 0)
  3221. displacement_flow_quantity, _ := c.GetFloat("displacement_flow_quantity", 0)
  3222. heparin, _ := c.GetFloat("heparin", 0)
  3223. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3224. ktv, _ := c.GetFloat("ktv", 0)
  3225. symptom := c.GetString("symptom")
  3226. dispose := c.GetString("dispose")
  3227. result := c.GetString("results")
  3228. monitoring_nurse, _ := c.GetInt64("monitoring_nurse", 0)
  3229. monitor_anticoagulant, _ := c.GetInt64("monitor_anticoagulant")
  3230. monitor_anticoagulant_value := c.GetString("monitor_anticoagulant_value")
  3231. replacement_speed, _ := c.GetFloat("replacement_speed")
  3232. dicarbonate, _ := c.GetFloat("dicarbonate")
  3233. monitoring_date = monitoring_date / 1000
  3234. // operate_time = operate_time / 1000
  3235. if patient <= 0 {
  3236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3237. return
  3238. }
  3239. adminUserInfo := c.GetAdminUserInfo()
  3240. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3241. if patientInfo.ID == 0 {
  3242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3243. return
  3244. }
  3245. monitorRecord := models.MonitoringRecord{
  3246. PatientId: patient,
  3247. MonitoringDate: monitoring_date,
  3248. DialysisOrderId: dialysis_order_id,
  3249. OperateTime: operate_time,
  3250. // MonitoringTime: monitoring_time,
  3251. PulseFrequency: pulse_frequency,
  3252. BreathingRate: breathing_rated,
  3253. SystolicBloodPressure: systolic_blood_pressure,
  3254. DiastolicBloodPressure: diastolic_blood_pressure,
  3255. BloodPressureType: blood_pressure_type,
  3256. BloodFlowVolume: blood_flow_volume,
  3257. VenousPressure: venous_pressure,
  3258. VenousPressureType: venous_pressure_type,
  3259. TransmembranePressure: transmembrane_pressure,
  3260. TransmembranePressureType: transmembrane_pressure_type,
  3261. UltrafiltrationRate: ultrafiltration_rate,
  3262. UltrafiltrationVolume: ultrafiltration_volume,
  3263. SodiumConcentration: sodium_concentration,
  3264. ArterialPressure: arterial_pressure,
  3265. ArterialPressureType: arterial_pressure_type,
  3266. DialysateTemperature: dialysate_temperature,
  3267. Temperature: temperature,
  3268. ReplacementRate: replacement_rate,
  3269. DisplacementQuantity: displacement_quantity,
  3270. Ktv: ktv,
  3271. Symptom: symptom,
  3272. Dispose: dispose,
  3273. Result: result,
  3274. MonitoringNurse: monitoring_nurse,
  3275. Status: 1,
  3276. CreatedTime: time.Now().Unix(),
  3277. UpdatedTime: time.Now().Unix(),
  3278. UserOrgId: adminUserInfo.CurrentOrgId,
  3279. Conductivity: conductivity,
  3280. DisplacementFlowQuantity: displacement_flow_quantity,
  3281. Heparin: heparin,
  3282. DialysateFlow: dialysate_flow,
  3283. MonitorAnticoagulant: monitor_anticoagulant,
  3284. MonitorAnticoagulantValue: monitor_anticoagulant_value,
  3285. ReplacementSpeed: replacement_speed,
  3286. Dicarbonate: dicarbonate,
  3287. }
  3288. // 查询信息规挡的设置天数
  3289. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3290. if infor.ID > 0 && infor.WeekDay > 0 {
  3291. var cha_time int64
  3292. timeNowStr := time.Now().Format("2006-01-02")
  3293. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3294. //今日的日期减去设置的日期
  3295. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3296. if cha_time >= monitoring_date {
  3297. //查询审核是否允许
  3298. infor, _ := service.GetDialysisInformationByRecordDate(patient, monitoring_date, adminUserInfo.CurrentOrgId)
  3299. //申请状态不允许的情况 拒绝修改
  3300. if infor.ApplicationStatus != 1 {
  3301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3302. return
  3303. }
  3304. }
  3305. }
  3306. err := service.CreateMonitor(&monitorRecord)
  3307. finish := models.XtDialysisFinish{
  3308. IsFinish: 1,
  3309. UserOrgId: adminUserInfo.CurrentOrgId,
  3310. Status: 1,
  3311. Ctime: time.Now().Unix(),
  3312. Mtime: 0,
  3313. Module: 7,
  3314. RecordDate: monitoring_date,
  3315. Sourse: 1,
  3316. PatientId: patient,
  3317. }
  3318. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, monitoring_date, 7, patient)
  3319. if dialysisFinish.ID == 0 {
  3320. service.CreateDialysisFinish(finish)
  3321. }
  3322. redis := service.RedisClient()
  3323. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_record_list_all"
  3324. redis.Set(key, "", time.Second)
  3325. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  3326. redis.Set(keyOne, "", time.Second)
  3327. redis.Close()
  3328. if err != nil {
  3329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3330. return
  3331. }
  3332. c.ServeSuccessJSON(map[string]interface{}{
  3333. "msg": "ok",
  3334. "monitor": monitorRecord,
  3335. })
  3336. return
  3337. }
  3338. // 已弃用
  3339. // func (c *DialysisApiController) CreateRecordData() {
  3340. // patient, _ := c.GetInt64("id", 0)
  3341. // status, _ := c.GetInt64("status", 0)
  3342. // now := time.Now()
  3343. // year, month, day := now.Date()
  3344. // today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  3345. // todayTimeStamp := today_time.Unix()
  3346. // if patient <= 0 {
  3347. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3348. // return
  3349. // }
  3350. // adminUserInfo := c.GetAdminUserInfo()
  3351. // patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3352. // if patientInfo.ID == 0 {
  3353. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3354. // return
  3355. // }
  3356. // record := &models.DialysisOrder{
  3357. // DialysisDate: todayTimeStamp,
  3358. // UserOrgId: adminUserInfo.CurrentOrgId,
  3359. // PatientId: patient,
  3360. // Stage: status,
  3361. // Status: 1,
  3362. // CreatedTime: time.Now().Unix(),
  3363. // UpdatedTime: time.Now().Unix(),
  3364. // }
  3365. // if status == 1 {
  3366. // //创建透析记录
  3367. // err := service.CreateDialysisRecord(patient, adminUserInfo.CurrentOrgId, record)
  3368. // if err == nil {
  3369. // c.ServeSuccessJSON(map[string]interface{}{
  3370. // "dialysisOrder": record,
  3371. // })
  3372. // } else {
  3373. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3374. // }
  3375. // } else {
  3376. // record_id, _ := c.GetInt64("record_id", 0)
  3377. // //修改透析记录状态
  3378. // errs := service.ModifyDialysisRecord(record_id)
  3379. // //结束时候透析次数加1
  3380. // service.UpdateSolutionByPatientId(patient)
  3381. // if errs == nil {
  3382. // c.ServeSuccessJSON(map[string]interface{}{
  3383. // "dialysisOrder": record,
  3384. // })
  3385. // } else {
  3386. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3387. // }
  3388. // }
  3389. // }
  3390. func adviceFormDatas(advice *models.DoctorAdvice, data []byte, action string) (code int, subAdvice []*models.DoctorAdvice) {
  3391. dataBody := make(map[string]interface{}, 0)
  3392. err := json.Unmarshal(data, &dataBody)
  3393. if err != nil {
  3394. utils.ErrorLog(err.Error())
  3395. code = enums.ErrorCodeParamWrong
  3396. return
  3397. }
  3398. timeLayout := "2006-01-02 "
  3399. timeLayout2 := "2006-01-02 15:04"
  3400. loc, _ := time.LoadLocation("Local")
  3401. if action == "create" {
  3402. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3403. utils.ErrorLog("advice_type")
  3404. code = enums.ErrorCodeParamWrong
  3405. return
  3406. }
  3407. adviceType := int64(dataBody["advice_type"].(float64))
  3408. if adviceType != 1 && adviceType != 2 {
  3409. utils.ErrorLog("advice_type != 1&&2")
  3410. code = enums.ErrorCodeParamWrong
  3411. return
  3412. }
  3413. advice.AdviceType = adviceType
  3414. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3415. utils.ErrorLog("advice_date")
  3416. code = enums.ErrorCodeParamWrong
  3417. return
  3418. }
  3419. adviceDate, _ := dataBody["advice_date"].(string)
  3420. if len(adviceDate) == 0 {
  3421. utils.ErrorLog("len(adviceDate) == 0")
  3422. code = enums.ErrorCodeParamWrong
  3423. return
  3424. }
  3425. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  3426. if err != nil {
  3427. utils.ErrorLog(err.Error())
  3428. code = enums.ErrorCodeParamWrong
  3429. return
  3430. }
  3431. advice.AdviceDate = theTime.Unix()
  3432. }
  3433. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3434. utils.ErrorLog("start_time")
  3435. code = enums.ErrorCodeParamWrong
  3436. return
  3437. }
  3438. startDate, _ := dataBody["start_time"].(string)
  3439. if len(startDate) == 0 {
  3440. utils.ErrorLog("len(startDate) == 0")
  3441. code = enums.ErrorCodeParamWrong
  3442. return
  3443. }
  3444. theTime, err := time.ParseInLocation(timeLayout2, startDate, loc)
  3445. if err != nil {
  3446. utils.ErrorLog(err.Error())
  3447. code = enums.ErrorCodeParamWrong
  3448. return
  3449. }
  3450. advice.StartTime = theTime.Unix()
  3451. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  3452. utils.ErrorLog("advice_name")
  3453. code = enums.ErrorCodeParamWrong
  3454. return
  3455. }
  3456. adviceName, _ := dataBody["advice_name"].(string)
  3457. if len(adviceName) == 0 {
  3458. utils.ErrorLog("len(advice_name) == 0")
  3459. code = enums.ErrorCodeParamWrong
  3460. return
  3461. }
  3462. advice.AdviceName = adviceName
  3463. if dataBody["delivery_way"] == nil || reflect.TypeOf(dataBody["delivery_way"]).String() != "string" {
  3464. utils.ErrorLog("delivery_way")
  3465. code = enums.ErrorCodeParamWrong
  3466. return
  3467. }
  3468. deliveryWay, _ := dataBody["delivery_way"].(string)
  3469. if len(deliveryWay) == 0 {
  3470. utils.ErrorLog("len(deliveryWay) == 0")
  3471. code = enums.ErrorCodeParamWrong
  3472. return
  3473. }
  3474. advice.DeliveryWay = deliveryWay
  3475. if dataBody["execution_frequency"] == nil || reflect.TypeOf(dataBody["execution_frequency"]).String() != "string" {
  3476. utils.ErrorLog("execution_frequency")
  3477. code = enums.ErrorCodeParamWrong
  3478. return
  3479. }
  3480. execution_frequency, _ := dataBody["execution_frequency"].(string)
  3481. if len(execution_frequency) == 0 {
  3482. utils.ErrorLog("len(execution_frequency) == 0")
  3483. code = enums.ErrorCodeParamWrong
  3484. return
  3485. }
  3486. advice.ExecutionFrequency = execution_frequency
  3487. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3488. adviceDsc, _ := dataBody["advice_desc"].(string)
  3489. advice.AdviceDesc = adviceDsc
  3490. }
  3491. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3492. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3493. advice.DrugSpecUnit = drugSpecUnit
  3494. }
  3495. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3496. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3497. advice.SingleDose = singleDose
  3498. }
  3499. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3500. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3501. advice.SingleDoseUnit = singleDoseUnit
  3502. }
  3503. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3504. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3505. advice.PrescribingNumber = prescribingNumber
  3506. }
  3507. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3508. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3509. advice.PrescribingNumberUnit = prescribingNumberUnit
  3510. }
  3511. if dataBody["subAdviceForm"] != nil && reflect.TypeOf(dataBody["subAdviceForm"]).String() == "[]interface {}" {
  3512. thisContagions, _ := dataBody["subAdviceForm"].([]interface{})
  3513. if len(thisContagions) > 0 {
  3514. for _, item := range thisContagions {
  3515. items := item.(map[string]interface{})
  3516. advice_name, _ := items["advice_name"].(string)
  3517. advice_desc, _ := items["advice_desc"].(string)
  3518. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  3519. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  3520. single_dose_unit, _ := items["single_dose_unit"].(string)
  3521. prescribing_number, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
  3522. single_dose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
  3523. advice := &models.DoctorAdvice{
  3524. AdviceName: advice_name,
  3525. AdviceDesc: advice_desc,
  3526. SingleDose: single_dose,
  3527. SingleDoseUnit: single_dose_unit,
  3528. DrugSpecUnit: drug_spec_unit,
  3529. PrescribingNumber: prescribing_number,
  3530. PrescribingNumberUnit: prescribing_number_unit,
  3531. }
  3532. subAdvice = append(subAdvice, advice)
  3533. }
  3534. }
  3535. }
  3536. return
  3537. }
  3538. func (c *DialysisApiController) GetDialysisOrder() {
  3539. //xtno := c.GetString("xtno")
  3540. xtdate := c.GetString("xtdate")
  3541. patient_id, _ := c.GetInt64("patient_id")
  3542. timeLayout := "2006-01-02"
  3543. loc, _ := time.LoadLocation("Local")
  3544. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  3545. if err != nil {
  3546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3547. return
  3548. }
  3549. xttime := theTime.Unix()
  3550. operatorIDs := make([]int64, 0)
  3551. adminUserInfo := c.GetAdminUserInfo()
  3552. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  3553. patientInfo, _ := service.FindPatientWithDeviceByPatientId(adminUserInfo.CurrentOrgId, patient_id, xttime)
  3554. //透析单
  3555. dialysisOrder, _ := service.MobileGetSchedualDialysisRecordTen(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3556. if dialysisOrder != nil {
  3557. if dialysisOrder.FinishNurse > 0 {
  3558. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  3559. }
  3560. if dialysisOrder.StartNurse > 0 {
  3561. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  3562. }
  3563. }
  3564. //透前评估
  3565. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3566. predialysName, err := service.FindPredialysisName(PredialysisEvaluation.BloodAccessPartOperaId, adminUserInfo.CurrentOrgId)
  3567. //透后评估
  3568. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3569. if AssessmentAfterDislysis.Modifier > 0 {
  3570. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  3571. }
  3572. //上次透前评估
  3573. lastPredialysisEvaluation, _ := service.GetLastTimePredialysisEvaluation(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3574. lastOrder, _ := service.GetLastTimeOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3575. //透析处方
  3576. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3577. if dialysisPrescription.PrescriptionDoctor > 0 {
  3578. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  3579. }
  3580. //获取病人的透析模式
  3581. schedule, err := service.FindDialysisMode(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3582. order, err := service.FindDialysisMacher(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3583. nurse, err := service.FindPunctureNurse(order.PunctureNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3584. startNuse, err := service.FindeStartNuse(order.StartNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3585. FinishNuse, err := service.FindeStartNuse(order.FinishNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3586. //获取透析处方
  3587. dialysisway, err := service.FindDialysisWay(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3588. //获取临时医嘱
  3589. doctorAdvice, _ := service.FindDoctorOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3590. //config, err := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3591. //获取医嘱内容
  3592. doctor, err := service.FindDoctor(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3593. DoctorName, err := service.FindDoctorName(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3594. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3595. doctorAdevieInfo, err := service.FindDoctorAdviceByInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3596. //获取上次的透后体重
  3597. // assessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3598. assessmentAfterDislysis, _ := service.MobileGetLast(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3599. //获取透析次数
  3600. _, total, err := service.GetTotalDialysisCout(adminUserInfo.CurrentOrgId, patientInfo.ID)
  3601. if len(DoctorAdvice) > 0 {
  3602. for _, item := range DoctorAdvice {
  3603. if item.AdviceDoctor > 0 {
  3604. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3605. }
  3606. if item.ExecutionStaff > 0 {
  3607. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3608. }
  3609. if item.Checker > 0 {
  3610. operatorIDs = append(operatorIDs, item.Checker)
  3611. }
  3612. }
  3613. }
  3614. //透析监测
  3615. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3616. //透析检测
  3617. //monitor, err := service.FindAllMonitor(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3618. //透析小结
  3619. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3620. //接诊评估
  3621. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3622. check, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3623. if adminUserInfo.CurrentOrgId != 10101 && adminUserInfo.CurrentOrgId != 10445 && adminUserInfo.CurrentOrgId != 10345 {
  3624. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3625. patientInfo.TotalDialysis = dialysis_count
  3626. }
  3627. if adminUserInfo.CurrentOrgId == 10101 || adminUserInfo.CurrentOrgId == 10445 || adminUserInfo.CurrentOrgId == 10345 {
  3628. if xttime <= 1672416000 {
  3629. dialysis_count, _ := service.GetDialysisOrderCountOne(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3630. patientInfo.TotalDialysis = dialysis_count
  3631. }
  3632. if xttime >= 1672502400 {
  3633. dialysis_count, _ := service.GetDialysisOrderCountTwo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3634. patientInfo.TotalDialysis = dialysis_count
  3635. }
  3636. }
  3637. //相关操作对应的操作人
  3638. //operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3639. operators, err := service.GetAdminUserEsOne(adminUserInfo.CurrentOrgId)
  3640. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  3641. //获取当前日期月份的第一天
  3642. firstmonth := service.GetFirstDateOfMonth(theTime)
  3643. firstMonthDate := firstmonth.Unix()
  3644. //获取当前月份的病人透析次数
  3645. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.CurrentOrgId)
  3646. //获取his数据
  3647. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3648. //hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3649. config, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3650. project_config, _ := service.GetHisProjectConfig(adminUserInfo.CurrentOrgId)
  3651. projects, _ := service.FindAllHisProjectById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3652. //获取诊断
  3653. prescriptionInfo, _ := service.GetPrescriptionInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3654. patientDiagnose, _ := service.FindPatientDianose(adminUserInfo.CurrentOrgId)
  3655. //if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  3656. // for _, item := range projects {
  3657. // var advice *models.HisDoctorAdviceInfo
  3658. // advice.ID = item.ID
  3659. // advice.Checker = item.Checker
  3660. // advice.CheckTime = item.CheckTime
  3661. // advice.CheckState = item.CheckState
  3662. // advice.ExecutionState = item.ExecutionState
  3663. // advice.ExecutionStaff = item.ExecutionStaff
  3664. // advice.PrescribingNumber = float64(item.Count)
  3665. // advice.PrescribingNumberUnit = item.Unit
  3666. // advice.AdviceDoctor = item.Doctor
  3667. // if item.Type == 3 {
  3668. // advice.AdviceName = item.GoodInfo.GoodName
  3669. // } else if item.Type == 2 {
  3670. // advice.AdviceName = item.HisProject.ProjectName
  3671. // }
  3672. // advice.StartTime = item.StartTime
  3673. // hisAdvice = append(hisAdvice, advice)
  3674. // }
  3675. //}
  3676. if config.IsOpen == 1 {
  3677. c.ServeSuccessJSON(map[string]interface{}{
  3678. "xtdate": xtdate,
  3679. "users": adminUser,
  3680. "patientInfo": patientInfo,
  3681. "PredialysisEvaluation": PredialysisEvaluation,
  3682. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3683. "dialysisPrescription": dialysisPrescription,
  3684. "advices": hisAdvice,
  3685. "monitors": Record,
  3686. "summary": TreatmentSummary,
  3687. "receiverTreatmentAccess": receiverTreatmentAccess,
  3688. "dialysisOrder": dialysisOrder,
  3689. "operators": operators,
  3690. "org_template_info": templateInfo,
  3691. "check": check,
  3692. "schedule": schedule,
  3693. "dialysisway": dialysisway,
  3694. "order": order,
  3695. "doctorAdvice": doctorAdvice,
  3696. "doctor": doctor,
  3697. "nurse": nurse,
  3698. "doctorAdevieInfo": doctorAdevieInfo,
  3699. "total": total,
  3700. "startNuse": startNuse,
  3701. "DoctorName": DoctorName,
  3702. "assessmentAfterDislysis": assessmentAfterDislysis,
  3703. "predialysName": predialysName,
  3704. "FinishNuse": FinishNuse,
  3705. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  3706. "dialysiscount": dialysiscount,
  3707. "last_order": lastOrder,
  3708. "project_config": project_config,
  3709. "projects": projects,
  3710. "prescriptionInfo": prescriptionInfo,
  3711. "patientDiagnose": patientDiagnose,
  3712. })
  3713. }
  3714. if config.IsOpen == 0 || config.IsOpen == 2 {
  3715. c.ServeSuccessJSON(map[string]interface{}{
  3716. "xtdate": xtdate,
  3717. "users": adminUser,
  3718. "patientInfo": patientInfo,
  3719. "PredialysisEvaluation": PredialysisEvaluation,
  3720. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3721. "dialysisPrescription": dialysisPrescription,
  3722. "advices": DoctorAdvice,
  3723. "monitors": Record,
  3724. "summary": TreatmentSummary,
  3725. "receiverTreatmentAccess": receiverTreatmentAccess,
  3726. "dialysisOrder": dialysisOrder,
  3727. "operators": operators,
  3728. "org_template_info": templateInfo,
  3729. "check": check,
  3730. "schedule": schedule,
  3731. "dialysisway": dialysisway,
  3732. "order": order,
  3733. "doctorAdvice": doctorAdvice,
  3734. "doctor": doctor,
  3735. "nurse": nurse,
  3736. "doctorAdevieInfo": doctorAdevieInfo,
  3737. "total": total,
  3738. "startNuse": startNuse,
  3739. "DoctorName": DoctorName,
  3740. "assessmentAfterDislysis": assessmentAfterDislysis,
  3741. "predialysName": predialysName,
  3742. "FinishNuse": FinishNuse,
  3743. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  3744. "dialysiscount": dialysiscount,
  3745. "last_order": lastOrder,
  3746. "project_config": project_config,
  3747. "projects": projects,
  3748. "prescriptionInfo": prescriptionInfo,
  3749. "patientDiagnose": patientDiagnose,
  3750. })
  3751. }
  3752. }
  3753. func (c *DialysisApiController) GetLongAdvice() {
  3754. patient_id, _ := c.GetInt64("patient_id")
  3755. adminUserInfo := c.GetAdminUserInfo()
  3756. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  3757. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3758. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3759. c.ServeSuccessJSON(map[string]interface{}{
  3760. "status": "1",
  3761. })
  3762. return
  3763. } else { //开启推送提醒
  3764. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3765. var advice_three []*models.DoctorAdvice
  3766. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  3767. recordDateStr := time.Now().Format("2006-01-02")
  3768. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3769. nowtime := recordDate.Unix()
  3770. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  3771. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  3772. for _, advice := range advices {
  3773. if advice.FrequencyType == 3 {
  3774. t := time.Now()
  3775. week := int(t.Weekday())
  3776. switch week {
  3777. case 1:
  3778. if strings.Index(advice.WeekDay, "周一") == -1 {
  3779. advice_three = append(advice_three, advice)
  3780. }
  3781. break
  3782. case 2:
  3783. if strings.Index(advice.WeekDay, "周二") == -1 {
  3784. advice_three = append(advice_three, advice)
  3785. }
  3786. break
  3787. case 3:
  3788. if strings.Index(advice.WeekDay, "周三") == -1 {
  3789. advice_three = append(advice_three, advice)
  3790. }
  3791. break
  3792. case 4:
  3793. if strings.Index(advice.WeekDay, "周四") == -1 {
  3794. advice_three = append(advice_three, advice)
  3795. }
  3796. break
  3797. case 5:
  3798. if strings.Index(advice.WeekDay, "周五") == -1 {
  3799. advice_three = append(advice_three, advice)
  3800. }
  3801. break
  3802. case 6:
  3803. if strings.Index(advice.WeekDay, "周六") == -1 {
  3804. advice_three = append(advice_three, advice)
  3805. }
  3806. break
  3807. case 0:
  3808. if strings.Index(advice.WeekDay, "周日") == -1 {
  3809. advice_three = append(advice_three, advice)
  3810. }
  3811. break
  3812. }
  3813. }
  3814. }
  3815. for _, advice := range advices_two {
  3816. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3817. now := p.Unix()
  3818. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3819. dayStr2 := "-" + dayStr
  3820. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3821. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3822. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  3823. for _, ad := range advices {
  3824. advice_three = append(advice_three, ad)
  3825. }
  3826. }
  3827. if err == nil {
  3828. c.ServeSuccessJSON(map[string]interface{}{
  3829. "status": "2",
  3830. "advices": advices,
  3831. "advices_two": RemoveRepeatedElement(advice_three),
  3832. "is_open_remind": config.IsOpenRemind,
  3833. })
  3834. }
  3835. }
  3836. }
  3837. func (c *DialysisApiController) GetLongAdviceOne() {
  3838. patient_id, _ := c.GetInt64("patient_id")
  3839. schedule_date := c.GetString("schedule_date")
  3840. adminUserInfo := c.GetAdminUserInfo()
  3841. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  3842. timeLayout := "2006-01-02"
  3843. loc, _ := time.LoadLocation("Local")
  3844. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  3845. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3846. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3847. c.ServeSuccessJSON(map[string]interface{}{
  3848. "status": "1",
  3849. })
  3850. return
  3851. } else { //开启推送提醒
  3852. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3853. var advice_three []*models.DoctorAdvice
  3854. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  3855. //recordDateStr := time.Now().Format("2006-01-02")
  3856. //recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3857. //
  3858. //nowtime := recordDate.Unix()
  3859. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  3860. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  3861. for _, advice := range advices {
  3862. if advice.FrequencyType == 3 {
  3863. t := time.Now()
  3864. week := int(t.Weekday())
  3865. switch week {
  3866. case 1:
  3867. if strings.Index(advice.WeekDay, "周一") == -1 {
  3868. advice_three = append(advice_three, advice)
  3869. }
  3870. break
  3871. case 2:
  3872. if strings.Index(advice.WeekDay, "周二") == -1 {
  3873. advice_three = append(advice_three, advice)
  3874. }
  3875. break
  3876. case 3:
  3877. if strings.Index(advice.WeekDay, "周三") == -1 {
  3878. advice_three = append(advice_three, advice)
  3879. }
  3880. break
  3881. case 4:
  3882. if strings.Index(advice.WeekDay, "周四") == -1 {
  3883. advice_three = append(advice_three, advice)
  3884. }
  3885. break
  3886. case 5:
  3887. if strings.Index(advice.WeekDay, "周五") == -1 {
  3888. advice_three = append(advice_three, advice)
  3889. }
  3890. break
  3891. case 6:
  3892. if strings.Index(advice.WeekDay, "周六") == -1 {
  3893. advice_three = append(advice_three, advice)
  3894. }
  3895. break
  3896. case 0:
  3897. if strings.Index(advice.WeekDay, "周日") == -1 {
  3898. advice_three = append(advice_three, advice)
  3899. }
  3900. break
  3901. }
  3902. }
  3903. }
  3904. for _, advice := range advices_two {
  3905. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3906. now := p.Unix()
  3907. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3908. dayStr2 := "-" + dayStr
  3909. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3910. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3911. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  3912. for _, ad := range advices {
  3913. advice_three = append(advice_three, ad)
  3914. }
  3915. }
  3916. if err == nil {
  3917. c.ServeSuccessJSON(map[string]interface{}{
  3918. "status": "2",
  3919. "advices": advices,
  3920. "advices_two": RemoveRepeatedElement(advice_three),
  3921. "is_open_remind": config.IsOpenRemind,
  3922. })
  3923. }
  3924. }
  3925. }
  3926. func (c *DialysisApiController) GetLongAdviceTwo() {
  3927. patient_id, _ := c.GetInt64("patient_id")
  3928. schedule_date, _ := c.GetInt64("schedule_date")
  3929. adminUserInfo := c.GetAdminUserInfo()
  3930. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  3931. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3932. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3933. c.ServeSuccessJSON(map[string]interface{}{
  3934. "status": "1",
  3935. })
  3936. return
  3937. } else { //开启推送提醒
  3938. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3939. var advice_three []*models.DoctorAdvice
  3940. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  3941. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  3942. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  3943. for _, advice := range advices {
  3944. if advice.FrequencyType == 3 {
  3945. t := time.Now()
  3946. week := int(t.Weekday())
  3947. switch week {
  3948. case 1:
  3949. if strings.Index(advice.WeekDay, "周一") == -1 {
  3950. advice_three = append(advice_three, advice)
  3951. }
  3952. break
  3953. case 2:
  3954. if strings.Index(advice.WeekDay, "周二") == -1 {
  3955. advice_three = append(advice_three, advice)
  3956. }
  3957. break
  3958. case 3:
  3959. if strings.Index(advice.WeekDay, "周三") == -1 {
  3960. advice_three = append(advice_three, advice)
  3961. }
  3962. break
  3963. case 4:
  3964. if strings.Index(advice.WeekDay, "周四") == -1 {
  3965. advice_three = append(advice_three, advice)
  3966. }
  3967. break
  3968. case 5:
  3969. if strings.Index(advice.WeekDay, "周五") == -1 {
  3970. advice_three = append(advice_three, advice)
  3971. }
  3972. break
  3973. case 6:
  3974. if strings.Index(advice.WeekDay, "周六") == -1 {
  3975. advice_three = append(advice_three, advice)
  3976. }
  3977. break
  3978. case 0:
  3979. if strings.Index(advice.WeekDay, "周日") == -1 {
  3980. advice_three = append(advice_three, advice)
  3981. }
  3982. break
  3983. }
  3984. }
  3985. }
  3986. for _, advice := range advices_two {
  3987. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3988. now := p.Unix()
  3989. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3990. dayStr2 := "-" + dayStr
  3991. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3992. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3993. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  3994. for _, ad := range advices {
  3995. advice_three = append(advice_three, ad)
  3996. }
  3997. }
  3998. if err == nil {
  3999. c.ServeSuccessJSON(map[string]interface{}{
  4000. "status": "2",
  4001. "advices": advices,
  4002. "advices_two": RemoveRepeatedElement(advice_three),
  4003. "is_open_remind": config.IsOpenRemind,
  4004. })
  4005. }
  4006. }
  4007. }
  4008. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4009. newArr = make([]*models.DoctorAdvice, 0)
  4010. for i := 0; i < len(arr); i++ {
  4011. repeat := false
  4012. for j := i + 1; j < len(arr); j++ {
  4013. if arr[i].ID == arr[j].ID {
  4014. repeat = true
  4015. break
  4016. }
  4017. }
  4018. if !repeat {
  4019. newArr = append(newArr, arr[i])
  4020. }
  4021. }
  4022. return
  4023. }
  4024. func (c *DialysisApiController) CreateRemindDoctorAdvice() {
  4025. patient, _ := c.GetInt64("id", 0)
  4026. groupNo, _ := c.GetInt64("groupno", 0)
  4027. if patient <= 0 {
  4028. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4029. return
  4030. }
  4031. adminUserInfo := c.GetAdminUserInfo()
  4032. dataBody := make(map[string]interface{}, 0)
  4033. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4034. if err != nil {
  4035. utils.ErrorLog(err.Error())
  4036. return
  4037. }
  4038. utils.ErrorLog("%v", dataBody)
  4039. timeLayout := "2006-01-02 15:04"
  4040. loc, _ := time.LoadLocation("Local")
  4041. timeLayout2 := "2006-01-02"
  4042. loc2, _ := time.LoadLocation("Local")
  4043. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4044. utils.ErrorLog("advice_type")
  4045. return
  4046. }
  4047. adviceType := int64(2)
  4048. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4049. utils.ErrorLog("advice_date")
  4050. return
  4051. }
  4052. adviceDate, _ := dataBody["advice_date"].(string)
  4053. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4054. AdviceDate := theTime.Unix()
  4055. RecordDate := theTime.Unix()
  4056. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4057. utils.ErrorLog("start_time")
  4058. return
  4059. }
  4060. startTime, _ := dataBody["start_time"].(string)
  4061. if len(startTime) == 0 {
  4062. utils.ErrorLog("len(start_time) == 0")
  4063. return
  4064. }
  4065. theTimeUnix, err := time.ParseInLocation(timeLayout, startTime, loc)
  4066. fmt.Println("theTimeUnix", theTimeUnix.Unix())
  4067. //if err != nil {
  4068. // utils.ErrorLog(err.Error())
  4069. // return
  4070. //}
  4071. StartTime := theTimeUnix.Unix()
  4072. fmt.Println("startTIME", StartTime)
  4073. Remark := ""
  4074. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4075. remark, _ := dataBody["remark"].(string)
  4076. Remark = remark
  4077. }
  4078. var advices []*models.GroupAdvice
  4079. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4080. utils.ErrorLog("advices")
  4081. return
  4082. }
  4083. adviceNames := dataBody["advices"].([]interface{})
  4084. for _, adviceNameMap := range adviceNames {
  4085. adviceNameM := adviceNameMap.(map[string]interface{})
  4086. var advice models.GroupAdvice
  4087. advice.Remark = Remark
  4088. advice.AdviceType = adviceType
  4089. advice.StartTime = StartTime
  4090. if StartTime < 0 {
  4091. advice.StartTime = time.Now().Unix()
  4092. }
  4093. advice.AdviceDate = AdviceDate
  4094. advice.RecordDate = RecordDate
  4095. advice.Status = 1
  4096. advice.CreatedTime = time.Now().Unix()
  4097. advice.UpdatedTime = time.Now().Unix()
  4098. advice.StopState = 2
  4099. advice.ExecutionState = 2
  4100. advice.UserOrgId = adminUserInfo.CurrentOrgId
  4101. advice.PatientId = patient
  4102. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4103. advice.IsSettle = 2
  4104. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4105. utils.ErrorLog("advice_name")
  4106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4107. return
  4108. }
  4109. adviceName, _ := adviceNameM["advice_name"].(string)
  4110. if len(adviceName) == 0 {
  4111. utils.ErrorLog("len(advice_name) == 0")
  4112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4113. return
  4114. }
  4115. advice.AdviceName = adviceName
  4116. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4117. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4118. advice.DrugSpec = drugSpec
  4119. }
  4120. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4121. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4122. advice.AdviceDesc = adviceDesc
  4123. }
  4124. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4125. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4126. advice.DrugSpecUnit = drugSpecUnit
  4127. }
  4128. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4129. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4130. // advice.SingleDose = singleDose
  4131. //}
  4132. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4133. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4134. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4135. }
  4136. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4137. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4138. advice.SingleDoseUnit = singleDoseUnit
  4139. }
  4140. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4141. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4142. // advice.PrescribingNumber = prescribingNumber
  4143. //}
  4144. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4145. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4146. }
  4147. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4148. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4149. advice.PrescribingNumberUnit = prescribingNumberUnit
  4150. }
  4151. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4152. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4153. advice.DeliveryWay = deliveryWay
  4154. }
  4155. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4156. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4157. advice.ExecutionFrequency = executionFrequency
  4158. }
  4159. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  4160. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  4161. advice.FrequencyType = frequency_type
  4162. }
  4163. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  4164. day_count := int64(adviceNameM["day_count"].(float64))
  4165. advice.DayCount = day_count
  4166. }
  4167. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  4168. way := int64(adviceNameM["way"].(float64))
  4169. advice.Way = way
  4170. }
  4171. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  4172. drug_id := int64(adviceNameM["drug_id"].(float64))
  4173. advice.DrugId = drug_id
  4174. }
  4175. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  4176. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  4177. advice.DrugNameId = drug_name_id
  4178. }
  4179. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  4180. week_day, _ := adviceNameM["week_day"].(string)
  4181. advice.WeekDay = week_day
  4182. }
  4183. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  4184. template_id, _ := adviceNameM["template_id"].(string)
  4185. advice.TemplateId = template_id
  4186. }
  4187. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4188. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4189. advice.ExecutionFrequency = executionFrequency
  4190. }
  4191. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  4192. children := adviceNameM["child"].([]interface{})
  4193. if len(children) > 0 {
  4194. for _, childrenMap := range children {
  4195. childMap := childrenMap.(map[string]interface{})
  4196. var child models.GroupAdvice
  4197. child.Remark = Remark
  4198. child.AdviceType = adviceType
  4199. child.StartTime = StartTime
  4200. child.AdviceDate = AdviceDate
  4201. child.RecordDate = RecordDate
  4202. child.Status = 1
  4203. child.CreatedTime = time.Now().Unix()
  4204. child.UpdatedTime = time.Now().Unix()
  4205. child.StopState = 2
  4206. child.ExecutionState = 2
  4207. child.UserOrgId = adminUserInfo.CurrentOrgId
  4208. child.PatientId = patient
  4209. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  4210. child.IsSettle = 2
  4211. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  4212. utils.ErrorLog("child advice_name")
  4213. return
  4214. }
  4215. childAdviceName, _ := childMap["advice_name"].(string)
  4216. if len(childAdviceName) == 0 {
  4217. utils.ErrorLog("len(child advice_name) == 0")
  4218. return
  4219. }
  4220. child.AdviceName = childAdviceName
  4221. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  4222. childAdviceDesc, _ := childMap["advice_desc"].(string)
  4223. child.AdviceDesc = childAdviceDesc
  4224. }
  4225. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  4226. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  4227. child.DrugSpec = childDrugSpec
  4228. }
  4229. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  4230. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  4231. child.DrugSpecUnit = childDrugSpecUnit
  4232. }
  4233. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  4234. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4235. child.SingleDose = childSingleDose
  4236. }
  4237. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  4238. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4239. child.SingleDose = childMap["single_dose"].(float64)
  4240. }
  4241. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  4242. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4243. child.Remark = childMap["remark"].(string)
  4244. }
  4245. if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
  4246. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4247. child.DrugId = int64(childMap["drug_id"].(float64))
  4248. }
  4249. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  4250. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  4251. child.SingleDoseUnit = childSingleDoseUnit
  4252. }
  4253. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  4254. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  4255. child.PrescribingNumber = childPrescribingNumber
  4256. }
  4257. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  4258. //childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  4259. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  4260. }
  4261. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  4262. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  4263. child.PrescribingNumberUnit = childPrescribingNumberUnit
  4264. }
  4265. child.DeliveryWay = advice.DeliveryWay
  4266. child.ExecutionFrequency = advice.ExecutionFrequency
  4267. advice.Children = append(advice.Children, &child)
  4268. }
  4269. }
  4270. }
  4271. advices = append(advices, &advice)
  4272. }
  4273. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  4274. //创建步骤表
  4275. finish := models.XtDialysisFinish{
  4276. IsFinish: 1,
  4277. UserOrgId: adminUserInfo.CurrentOrgId,
  4278. Status: 1,
  4279. Ctime: time.Now().Unix(),
  4280. Mtime: 0,
  4281. Module: 4,
  4282. RecordDate: AdviceDate,
  4283. Sourse: 1,
  4284. PatientId: patient,
  4285. }
  4286. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, AdviceDate, 4, patient)
  4287. if dialysisFinish.ID == 0 {
  4288. service.CreateDialysisFinish(finish)
  4289. }
  4290. redis := service.RedisClient()
  4291. formatAdviceDate := theTime.Format("2006-01-02")
  4292. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4293. redis.Set(key, "", time.Second)
  4294. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  4295. redis.Set(keyOne, "", time.Second)
  4296. keyFour := "scheduals_" + formatAdviceDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  4297. redis.Set(keyFour, "", time.Second)
  4298. defer redis.Close()
  4299. if err != nil {
  4300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4301. return
  4302. }
  4303. c.ServeSuccessJSON(map[string]interface{}{
  4304. "msg": "ok",
  4305. "advices": list,
  4306. })
  4307. return
  4308. }
  4309. func (c *DialysisApiController) GetSolution() {
  4310. patient_id, _ := c.GetInt64("patient_id")
  4311. mode_id, _ := c.GetInt64("mode_id")
  4312. adminUserInfo := c.GetAdminUserInfo()
  4313. solution, err := service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  4314. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  4315. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, mode_id)
  4316. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.CurrentOrgId)
  4317. if err != nil {
  4318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4319. return
  4320. }
  4321. c.ServeSuccessJSON(map[string]interface{}{
  4322. "solution": solution,
  4323. "prescription": prescription,
  4324. "system_prescription": system_prescription,
  4325. "dialysisPrescription": dialysisPrescription,
  4326. })
  4327. }
  4328. func (c *DialysisApiController) GetSchedule() {
  4329. schedual_type, _ := c.GetInt64("schedual_type")
  4330. adminUserInfo := c.GetAdminUserInfo()
  4331. //timeLayout := "2006-01-02 15:04:05"
  4332. //
  4333. //date := time.Now().Format("2006-01-02") + " 00:00:00"
  4334. //loc, _ := time.LoadLocation("Local")
  4335. //theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  4336. //scheduleTime := theStartTime.Unix()
  4337. scheduleTime, _ := c.GetInt64("record_date")
  4338. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.CurrentOrgId, scheduleTime, schedual_type)
  4339. c.ServeSuccessJSON(map[string]interface{}{
  4340. "number": deviceNumber,
  4341. })
  4342. }
  4343. func (this *DialysisApiController) GetTodayMonitor() {
  4344. thisTime := time.Now()
  4345. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4346. timeLayout := "2006-01-02 15:04:05"
  4347. loc, _ := time.LoadLocation("Local")
  4348. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4349. theAssessmentDateTime := theStartTime.Unix()
  4350. patientID, _ := this.GetInt64("patient_id")
  4351. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4352. adminInfo := this.GetAdminUserInfo()
  4353. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  4354. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  4355. template, _ := service.GetOrgInfoTemplate(adminInfo.CurrentOrgId)
  4356. var ultrafiltration_rate float64
  4357. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  4358. //针对福建医师汇 获取透前评估预增脱水量
  4359. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  4360. fmt.Println("透前评估数据", evaluation)
  4361. if prescription.ID > 0 {
  4362. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4363. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4364. if template.TemplateId == 6 { //adminInfo.CurrentOrgId == 9538
  4365. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4366. record.UltrafiltrationRate = ultrafiltration_rate
  4367. }
  4368. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10121 {
  4369. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  4370. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  4371. record.UltrafiltrationRate = ultrafiltration_rate
  4372. }
  4373. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10234 {
  4374. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  4375. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  4376. record.UltrafiltrationRate = ultrafiltration_rate
  4377. }
  4378. if template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 { //adminInfo.CurrentOrgId == 9538
  4379. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4380. record.UltrafiltrationRate = ultrafiltration_rate
  4381. }
  4382. if template.TemplateId == 41 { //adminInfo.CurrentOrgId == 9538
  4383. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4384. record.UltrafiltrationRate = ultrafiltration_rate
  4385. }
  4386. if template.TemplateId == 43 { //adminInfo.CurrentOrgId == 9538
  4387. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4388. record.UltrafiltrationRate = ultrafiltration_rate
  4389. }
  4390. if template.TemplateId == 46 || template.TemplateId == 54 { //adminInfo.CurrentOrgId == 9538
  4391. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4392. record.UltrafiltrationRate = ultrafiltration_rate
  4393. }
  4394. if template.TemplateId == 47 { //adminInfo.CurrentOrgId == 9538
  4395. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4396. record.UltrafiltrationRate = ultrafiltration_rate
  4397. }
  4398. // 只针对方济医院
  4399. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  4400. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4401. ultrafiltration_rate = value
  4402. record.UltrafiltrationRate = ultrafiltration_rate
  4403. }
  4404. //长沙南雅
  4405. if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10340 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 9829 || adminInfo.CurrentOrgId == 10440 || adminInfo.CurrentOrgId == 10469 || adminInfo.CurrentOrgId == 10471 {
  4406. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4407. record.UltrafiltrationRate = ultrafiltration_rate
  4408. }
  4409. }
  4410. }
  4411. // record.UltrafiltrationRate = ultrafiltration_rate
  4412. record.UltrafiltrationVolume = 0
  4413. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  4414. if ultrafiltration_rate > 0 {
  4415. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4416. record.UltrafiltrationVolume = value
  4417. }
  4418. }
  4419. if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 41 || template.TemplateId == 43 || template.TemplateId == 47 || template.TemplateId == 54 {
  4420. if ultrafiltration_rate > 0 && adminInfo.CurrentOrgId != 9538 {
  4421. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4422. record.UltrafiltrationVolume = ultrafiltration_volume
  4423. }
  4424. }
  4425. //长沙南雅
  4426. if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 10469 || adminInfo.CurrentOrgId == 10471 {
  4427. if ultrafiltration_rate > 0 {
  4428. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4429. record.UltrafiltrationVolume = ultrafiltration_volume
  4430. }
  4431. }
  4432. if template.TemplateId == 47 || template.TemplateId == 54 {
  4433. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4434. }
  4435. this.ServeSuccessJSON(map[string]interface{}{
  4436. "monitor": record,
  4437. })
  4438. }
  4439. func (c *DialysisApiController) UploadDryWeight() {
  4440. patient_id, _ := c.GetInt64("id")
  4441. dry_weight, _ := c.GetFloat("dry_weight")
  4442. doctor_id, _ := c.GetInt64("doctor_id")
  4443. remark := c.GetString("remark")
  4444. adminUserInfo := c.GetAdminUserInfo()
  4445. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient_id)
  4446. fmt.Println(err)
  4447. if err == gorm.ErrRecordNotFound {
  4448. dryWeight := &models.SgjPatientDryweight{
  4449. PatientId: patient_id,
  4450. DryWeight: dry_weight,
  4451. Remakes: remark,
  4452. Ctime: time.Now().Unix(),
  4453. Mtime: time.Now().Unix(),
  4454. Creator: doctor_id,
  4455. Status: 1,
  4456. UserOrgId: adminUserInfo.CurrentOrgId,
  4457. AdjustedValue: "/",
  4458. UserId: adminUserInfo.AdminUser.Id,
  4459. }
  4460. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4461. loc, _ := time.LoadLocation("Local")
  4462. nowTime := time.Now()
  4463. nowDay := nowTime.Format("2006-01-02")
  4464. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4465. redis := service.RedisClient()
  4466. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4467. redis.Set(keyOne, "", time.Second)
  4468. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4469. redis.Set(key, "", time.Second)
  4470. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4471. redis.Set(keyTwo, "", time.Second)
  4472. redis.Close()
  4473. if createErr == nil {
  4474. c.ServeSuccessJSON(map[string]interface{}{
  4475. "msg": "提交成功",
  4476. "weight": dryWeight,
  4477. })
  4478. }
  4479. } else {
  4480. dryWeight := &models.SgjPatientDryweight{
  4481. PatientId: patient_id,
  4482. DryWeight: dry_weight,
  4483. Remakes: remark,
  4484. Ctime: time.Now().Unix(),
  4485. Mtime: time.Now().Unix(),
  4486. Creator: doctor_id,
  4487. Status: 1,
  4488. UserOrgId: adminUserInfo.CurrentOrgId,
  4489. AdjustedValue: "/",
  4490. UserId: adminUserInfo.AdminUser.Id,
  4491. }
  4492. var value float64
  4493. value = dry_weight - weightAdjust.DryWeight
  4494. fmt.Println(value)
  4495. if value < 0 {
  4496. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  4497. } else if value == 0 {
  4498. dryWeight.AdjustedValue = "/"
  4499. } else if value > 0 {
  4500. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  4501. }
  4502. fmt.Println(value)
  4503. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4504. loc, _ := time.LoadLocation("Local")
  4505. nowTime := time.Now()
  4506. nowDay := nowTime.Format("2006-01-02")
  4507. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4508. redis := service.RedisClient()
  4509. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4510. redis.Set(keyOne, "", time.Second)
  4511. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4512. redis.Set(key, "", time.Second)
  4513. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4514. redis.Set(keyTwo, "", time.Second)
  4515. redis.Close()
  4516. if createErr == nil {
  4517. c.ServeSuccessJSON(map[string]interface{}{
  4518. "msg": "提交成功",
  4519. "weight": dryWeight,
  4520. })
  4521. }
  4522. }
  4523. }
  4524. func (this *DialysisApiController) GetFuncPurview() {
  4525. adminUserInfo := this.GetAdminUserInfo()
  4526. user_id := adminUserInfo.AdminUser.Id
  4527. app_id := adminUserInfo.CurrentAppId
  4528. org_id := adminUserInfo.CurrentOrgId
  4529. create_url := this.GetString("create_url")
  4530. modify_url := this.GetString("modify_url")
  4531. modify_other_url := this.GetString("modify_other_url")
  4532. del_url := this.GetString("del_url")
  4533. del_other_url := this.GetString("del_other_url")
  4534. exce_url := this.GetString("exce_url")
  4535. check_url := this.GetString("check_url")
  4536. modify_exce_url := this.GetString("modify_exce_url")
  4537. module, _ := this.GetInt64("module", 0)
  4538. app_role, _ := service.GetAppRole(org_id, app_id, user_id)
  4539. var is_has_create bool
  4540. var is_has_modify bool
  4541. var is_has_modify_other bool
  4542. var is_has_del bool
  4543. var is_has_del_other bool
  4544. var is_has_exce bool
  4545. var is_has_check bool
  4546. var is_has_modify_exce bool
  4547. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  4548. if adminUserInfo.AdminUser.Id != org.Creator {
  4549. if app_role != nil {
  4550. if len(app_role.RoleIds) > 0 {
  4551. roles := strings.Split(app_role.RoleIds, ",")
  4552. var userRolePurviews string
  4553. for _, item := range roles {
  4554. role_id, _ := strconv.ParseInt(item, 10, 64)
  4555. purviews, _ := service.GetRoleFuncPurviewIds(role_id)
  4556. if len(userRolePurviews) == 0 {
  4557. userRolePurviews = purviews
  4558. } else {
  4559. userRolePurviews = userRolePurviews + "," + purviews
  4560. }
  4561. }
  4562. userRolePurviewsArr := RemoveRepeatedPurviewElement2(strings.Split(userRolePurviews, ","))
  4563. funcPurviews, _ := service.FindAllFuncPurview(userRolePurviewsArr)
  4564. for _, item := range funcPurviews {
  4565. //for _, url := range strings.Split(item.Urlfor,","){
  4566. if strings.Split(item.Urlfor, ",")[1] == create_url {
  4567. is_has_create = true
  4568. }
  4569. if strings.Split(item.Urlfor, ",")[1] == modify_url {
  4570. is_has_modify = true
  4571. }
  4572. if strings.Split(item.Urlfor, ",")[1] == modify_other_url {
  4573. is_has_modify_other = true
  4574. }
  4575. if strings.Split(item.Urlfor, ",")[1] == del_url {
  4576. is_has_del = true
  4577. }
  4578. if strings.Split(item.Urlfor, ",")[1] == del_other_url {
  4579. is_has_del_other = true
  4580. }
  4581. if strings.Split(item.Urlfor, ",")[1] == exce_url {
  4582. is_has_exce = true
  4583. }
  4584. if strings.Split(item.Urlfor, ",")[1] == check_url {
  4585. is_has_check = true
  4586. }
  4587. if strings.Split(item.Urlfor, ",")[1] == modify_exce_url {
  4588. is_has_modify_exce = true
  4589. }
  4590. }
  4591. } else {
  4592. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRole)
  4593. return
  4594. }
  4595. this.ServeSuccessJSON(map[string]interface{}{
  4596. "is_has_create": is_has_create,
  4597. "is_has_modify": is_has_modify,
  4598. "is_has_modify_other": is_has_modify_other,
  4599. "is_has_del": is_has_del,
  4600. "is_has_del_other": is_has_del_other,
  4601. "is_has_exce": is_has_exce,
  4602. "is_has_check": is_has_check,
  4603. "is_has_modify_exce": is_has_modify_exce,
  4604. "module": module,
  4605. })
  4606. } else {
  4607. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserIsExit)
  4608. return
  4609. }
  4610. } else {
  4611. this.ServeSuccessJSON(map[string]interface{}{
  4612. "is_has_create": true,
  4613. "is_has_modify": true,
  4614. "is_has_modify_other": true,
  4615. "is_has_del": true,
  4616. "is_has_del_other": true,
  4617. "is_has_exce": true,
  4618. "is_has_check": true,
  4619. "is_has_modify_exce": true,
  4620. "module": true,
  4621. })
  4622. }
  4623. }
  4624. func (this *DialysisApiController) GetOrderDoctorAdvice() {
  4625. patient_id, _ := this.GetInt64("patient_id", 0)
  4626. advice_date, _ := this.GetInt64("advice_date")
  4627. adminUserInfo := this.GetAdminUserInfo()
  4628. doctorAdvice, _ := service.GetBloodDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  4629. hisDoctorAdvice, _ := service.GetHisDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  4630. this.ServeSuccessJSON(map[string]interface{}{
  4631. "doctorAdvice": doctorAdvice,
  4632. "hisDoctorAdvice": hisDoctorAdvice,
  4633. })
  4634. }
  4635. func (this *DialysisApiController) GetLastOrNextDoctorAdvice() {
  4636. change_type, _ := this.GetInt64("type", 0)
  4637. record_date := this.GetString("record_time")
  4638. patient_id, _ := this.GetInt64("patient_id", 0)
  4639. timeLayout := "2006-01-02"
  4640. loc, _ := time.LoadLocation("Local")
  4641. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4642. record_time := theAdviceRecordTime.Unix()
  4643. adminUserInfo := this.GetAdminUserInfo()
  4644. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id)
  4645. if err == nil {
  4646. if len(advices) == 0 {
  4647. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4648. return
  4649. } else {
  4650. this.ServeSuccessJSON(map[string]interface{}{
  4651. "advices": advices,
  4652. "schedule": sch,
  4653. })
  4654. return
  4655. }
  4656. } else {
  4657. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4658. return
  4659. }
  4660. }
  4661. func (c *DialysisApiController) GetDialysisGoods() {
  4662. schedualDate := c.GetString("schedule_date")
  4663. schedule_type, _ := c.GetInt64("schedule_type")
  4664. partition_id, _ := c.GetInt64("partition_id")
  4665. page, _ := c.GetInt("page")
  4666. limit, _ := c.GetInt("limit")
  4667. keywords := c.GetString("keywords")
  4668. patient_id, _ := c.GetInt64("patient_id")
  4669. good_type, _ := c.GetInt64("good_type")
  4670. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  4671. if parseDateErr != nil && len(schedualDate) != 0 {
  4672. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4673. return
  4674. }
  4675. schedualEndDate := int64(0)
  4676. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  4677. if parseDateErr != nil && len(schedualDate) != 0 {
  4678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4679. return
  4680. }
  4681. schedualEndDate = endDate.Unix()
  4682. adminUser := c.GetAdminUserInfo()
  4683. _, err := service.FindStockOutByIsSys(adminUser.CurrentOrgId, 1, date.Unix())
  4684. goodTypes, _ := service.FindAllGoodType(adminUser.CurrentOrgId)
  4685. if err == gorm.ErrRecordNotFound {
  4686. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  4687. var ids []int64
  4688. for _, item := range list {
  4689. ids = append(ids, item.PatientId)
  4690. }
  4691. dialysisGoods, _, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  4692. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  4693. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4694. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4695. item.LastAutomaticReduceDetail = goodUser
  4696. item.LastDialysisBeforePrepare = lastGoodUserDetial
  4697. }
  4698. c.ServeSuccessJSON(map[string]interface{}{
  4699. "dialysis_goods": dialysisGoods,
  4700. "good_type": goodTypes,
  4701. "total": total,
  4702. })
  4703. return
  4704. } else if err == nil {
  4705. //获取当天排班的每个患者的库存使用情况
  4706. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  4707. var ids []int64
  4708. for _, item := range list {
  4709. ids = append(ids, item.PatientId)
  4710. }
  4711. dialysisGoods, err, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  4712. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  4713. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4714. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4715. fmt.Println(goodUser)
  4716. fmt.Println(lastGoodUserDetial)
  4717. item.LastAutomaticReduceDetail = goodUser
  4718. item.LastDialysisBeforePrepare = lastGoodUserDetial
  4719. }
  4720. if err == nil {
  4721. c.ServeSuccessJSON(map[string]interface{}{
  4722. "dialysis_goods": dialysisGoods,
  4723. "good_type": goodTypes,
  4724. "total": total,
  4725. })
  4726. return
  4727. } else {
  4728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4729. return
  4730. }
  4731. } else if err != nil {
  4732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4733. return
  4734. }
  4735. }
  4736. func (c *DialysisApiController) GetDialysisGoodsStatistics() {
  4737. start_time := c.GetString("start_time")
  4738. end_time := c.GetString("end_time")
  4739. timeLayout := "2006-01-02"
  4740. loc, _ := time.LoadLocation("Local")
  4741. var theStartTime int64
  4742. if len(start_time) > 0 {
  4743. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4744. if err != nil {
  4745. utils.ErrorLog(err.Error())
  4746. }
  4747. theStartTime = theTime.Unix()
  4748. }
  4749. var theEndtTime int64
  4750. if len(end_time) > 0 {
  4751. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4752. if err != nil {
  4753. utils.ErrorLog(err.Error())
  4754. }
  4755. theEndtTime = theTime.Unix()
  4756. }
  4757. adminUser := c.GetAdminUserInfo()
  4758. outInfo, err := service.MobileGetGoodsStatistics(adminUser.CurrentOrgId, theStartTime, theEndtTime)
  4759. if err == nil {
  4760. c.ServeSuccessJSON(map[string]interface{}{
  4761. "stock_out": outInfo,
  4762. })
  4763. return
  4764. } else {
  4765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4766. return
  4767. }
  4768. }
  4769. func (c *DialysisApiController) GetRoleList() {
  4770. orgId := c.GetAdminUserInfo().CurrentOrgId
  4771. admin_user_id, _ := c.GetInt64("admin_user_id")
  4772. list, err := service.GetRoleList(orgId, admin_user_id)
  4773. if err == nil {
  4774. c.ServeSuccessJSON(map[string]interface{}{
  4775. "adminRole": list,
  4776. })
  4777. return
  4778. } else {
  4779. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4780. return
  4781. }
  4782. }
  4783. func (c *DialysisApiController) GetInitPrintData() {
  4784. patient_id, _ := c.GetInt64("patient_id")
  4785. record_date, _ := c.GetInt64("record_date")
  4786. orgId := c.GetAdminUserInfo().CurrentOrgId
  4787. list, err := service.GetInitPrintData(patient_id, record_date, orgId)
  4788. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, record_date, orgId)
  4789. if err == nil {
  4790. c.ServeSuccessJSON(map[string]interface{}{
  4791. "list": list,
  4792. "assessmentAfterDislysis": assessmentAfterDislysis,
  4793. })
  4794. return
  4795. } else {
  4796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4797. return
  4798. }
  4799. }
  4800. func (c *DialysisApiController) GetInitPrintDataOne() {
  4801. patient_id, _ := c.GetInt64("patient_id")
  4802. start_time := c.GetString("record_date")
  4803. timeLayout := "2006-01-02"
  4804. loc, _ := time.LoadLocation("Local")
  4805. var theStartTime int64
  4806. if len(start_time) > 0 {
  4807. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4808. if err != nil {
  4809. utils.ErrorLog(err.Error())
  4810. }
  4811. theStartTime = theTime.Unix()
  4812. }
  4813. orgId := c.GetAdminUserInfo().CurrentOrgId
  4814. list, err := service.GetInitPrintData(patient_id, theStartTime, orgId)
  4815. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, theStartTime, orgId)
  4816. if err == nil {
  4817. c.ServeSuccessJSON(map[string]interface{}{
  4818. "list": list,
  4819. "assessmentAfterDislysis": assessmentAfterDislysis,
  4820. })
  4821. return
  4822. } else {
  4823. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4824. return
  4825. }
  4826. }
  4827. // 新接口
  4828. func (this *DialysisApiController) GetPatientDialysisSolutionGroupList() {
  4829. keyword := this.GetString("keywords")
  4830. limit, _ := this.GetInt64("limit")
  4831. page, _ := this.GetInt64("page")
  4832. partition_id, _ := this.GetInt64("partition_id")
  4833. schedule_type, _ := this.GetInt64("schedule_type")
  4834. start_time := this.GetString("schedule_date")
  4835. advice_ids := this.GetString("ids")
  4836. var ids []string
  4837. if advice_ids != "" {
  4838. ids = strings.Split(advice_ids, ",")
  4839. }
  4840. timeLayout := "2006-01-02"
  4841. loc, _ := time.LoadLocation("Local")
  4842. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4843. orgId := this.GetAdminUserInfo().CurrentOrgId
  4844. _, config := service.FindXTHisRecordByOrgId(orgId)
  4845. goodType, _ := service.GetAllGoodType(orgId)
  4846. if config.IsOpen != 1 {
  4847. list, total, err := service.GetPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  4848. if err == nil {
  4849. this.ServeSuccessJSON(map[string]interface{}{
  4850. "list": list,
  4851. "total": total,
  4852. "config": config,
  4853. "goodType": goodType,
  4854. })
  4855. return
  4856. } else {
  4857. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4858. return
  4859. }
  4860. }
  4861. if config.IsOpen == 1 {
  4862. list, total, err := service.GetHisPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  4863. if err == nil {
  4864. this.ServeSuccessJSON(map[string]interface{}{
  4865. "list": list,
  4866. "total": total,
  4867. "config": config,
  4868. "goodType": goodType,
  4869. })
  4870. return
  4871. }
  4872. }
  4873. }
  4874. func (this *DialysisApiController) GetDialysisAdviceTemplateList() {
  4875. keyword := this.GetString("keywords")
  4876. limit, _ := this.GetInt64("limit")
  4877. page, _ := this.GetInt64("page")
  4878. partition_id, _ := this.GetInt64("partition_id")
  4879. schedule_type, _ := this.GetInt64("schedule_type")
  4880. start_time := this.GetString("schedule_date")
  4881. ids := this.GetString("ids")
  4882. var idArray []string
  4883. if ids != "" {
  4884. idArray = strings.Split(ids, ",")
  4885. }
  4886. timeLayout := "2006-01-02"
  4887. loc, _ := time.LoadLocation("Local")
  4888. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4889. orgId := this.GetAdminUserInfo().CurrentOrgId
  4890. list, total, err := service.GetDialysisAdviceTemplateList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  4891. tablelist, _, err := service.GetDialysisAdviceSchedulistSix(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  4892. //获取长期医嘱
  4893. adviceList, _ := service.GetAllLongAdviceList(orgId)
  4894. _, config := service.FindXTHisRecordByOrgId(orgId)
  4895. drugList, _ := service.GetAllBaseDrugListTwenty(orgId)
  4896. if err == nil {
  4897. this.ServeSuccessJSON(map[string]interface{}{
  4898. "list": list,
  4899. "total": total,
  4900. "adviceList": adviceList,
  4901. "config": config,
  4902. "drugList": drugList,
  4903. "tablelist": tablelist,
  4904. })
  4905. return
  4906. } else {
  4907. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4908. return
  4909. }
  4910. }
  4911. func (this *DialysisApiController) SaveDialysisSetting() {
  4912. orgId := this.GetAdminUserInfo().CurrentOrgId
  4913. device_number_set, _ := this.GetInt64("device_number_set")
  4914. device_type_set, _ := this.GetInt64("device_type_set")
  4915. name_set, _ := this.GetInt64("name_set")
  4916. admission_number_set, _ := this.GetInt64("admission_number_set")
  4917. dialysis_no_set, _ := this.GetInt64("dialysis_no_set")
  4918. weight_befor_set, _ := this.GetInt64("weight_befor_set")
  4919. dry_weight_set, _ := this.GetInt64("dry_weight_set")
  4920. blood_pressure_set, _ := this.GetInt64("blood_pressure_set")
  4921. ultrafiltration_volume_set, _ := this.GetInt64("ultrafiltration_volume_set")
  4922. internal_fistula_set, _ := this.GetInt64("internal_fistula_set")
  4923. blood_flow_volume_set, _ := this.GetInt64("blood_flow_volume_set")
  4924. anticoagulant_set, _ := this.GetInt64("anticoagulant_set")
  4925. sealing_fluid_dispose_set, _ := this.GetInt64("sealing_fluid_dispose_set")
  4926. mode_id_set, _ := this.GetInt64("mode_id_set")
  4927. dialysis_time_set, _ := this.GetInt64("dialysis_time_set")
  4928. dialysis_dialyszers_set, _ := this.GetInt64("dialysis_dialyszers_set")
  4929. dialysis_irrigation_set, _ := this.GetInt64("dialysis_irrigation_set")
  4930. gaijiliang_set, _ := this.GetInt64("gaijiliang_set")
  4931. kalium_set, _ := this.GetInt64("kalium_set")
  4932. displace_liqui_value_set, _ := this.GetInt64("displace_liqui_value_set")
  4933. bicarbonate_set, _ := this.GetInt64("bicarbonate_set")
  4934. glucose_set, _ := this.GetInt64("glucose_set")
  4935. sodium_set, _ := this.GetInt64("sodium_set")
  4936. calcium_set, _ := this.GetInt64("calcium_set")
  4937. blood_access_set, _ := this.GetInt64("blood_access_set")
  4938. dialyzer_perfusion_apparatus_set, _ := this.GetInt64("dialyzer_perfusion_apparatus_set")
  4939. displace_liqui_part_set, _ := this.GetInt64("displace_liqui_part_set")
  4940. dialysisSetting := models.XtDialysisSetting{
  4941. Sodium: sodium_set,
  4942. Calcium: calcium_set,
  4943. BloodAccess: blood_access_set,
  4944. DialyzerPerfusionApparatus: dialyzer_perfusion_apparatus_set,
  4945. DisplaceLiquiPart: displace_liqui_part_set,
  4946. UserOrgId: orgId,
  4947. Status: 1,
  4948. DeviceNumber: device_number_set,
  4949. DeviceType: device_type_set,
  4950. Name: name_set,
  4951. AdmissionNumber: admission_number_set,
  4952. DialysisNo: dialysis_no_set,
  4953. WeightBefor: weight_befor_set,
  4954. DryWeight: dry_weight_set,
  4955. BloodPressure: blood_pressure_set,
  4956. UltrafiltrationVolume: ultrafiltration_volume_set,
  4957. InternalFistula: internal_fistula_set,
  4958. BloodFlowVolume: blood_flow_volume_set,
  4959. Anticoagulant: anticoagulant_set,
  4960. SealingFluidDispose: sealing_fluid_dispose_set,
  4961. ModeId: mode_id_set,
  4962. DialysisTime: dialysis_time_set,
  4963. DialysisDialyszers: dialysis_dialyszers_set,
  4964. DialysisIrrigation: dialysis_irrigation_set,
  4965. Gaijiliang: gaijiliang_set,
  4966. Kalium: kalium_set,
  4967. DisplaceLiquiValue: displace_liqui_value_set,
  4968. Bicarbonate: bicarbonate_set,
  4969. Glucose: glucose_set,
  4970. Ctime: time.Now().Unix(),
  4971. Mtime: time.Now().Unix(),
  4972. }
  4973. err := service.SaveDialysisSetting(dialysisSetting)
  4974. if err == nil {
  4975. this.ServeSuccessJSON(map[string]interface{}{
  4976. "dialysisSetting": dialysisSetting,
  4977. })
  4978. return
  4979. } else {
  4980. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4981. return
  4982. }
  4983. }
  4984. func (this *DialysisApiController) GetDialysisSetting() {
  4985. orgId := this.GetAdminUserInfo().CurrentOrgId
  4986. dialysisSett, _ := service.GetDialysisSetting(orgId)
  4987. this.ServeSuccessJSON(map[string]interface{}{
  4988. "dialysisSett": dialysisSett,
  4989. })
  4990. return
  4991. }
  4992. func (this *DialysisApiController) GetDialysisParameterList() {
  4993. keyword := this.GetString("keywords")
  4994. limit, _ := this.GetInt64("limit")
  4995. page, _ := this.GetInt64("page")
  4996. //partition_id, _ := this.GetInt64("partition_id")
  4997. partion_type := this.GetString("partition_id")
  4998. idSplit := strings.Split(partion_type, ",")
  4999. schedule_type, _ := this.GetInt64("schedule_type")
  5000. start_time := this.GetString("schedule_date")
  5001. timeLayout := "2006-01-02"
  5002. loc, _ := time.LoadLocation("Local")
  5003. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5004. orgId := this.GetAdminUserInfo().CurrentOrgId
  5005. scheduids := this.GetString("ids")
  5006. var ids []string
  5007. if scheduids != "" {
  5008. ids = strings.Split(scheduids, ",")
  5009. }
  5010. list, total, err := service.GetDialysisParameterList(keyword, limit, page, idSplit, schedule_type, startTime.Unix(), orgId, ids)
  5011. dialysisSett, _ := service.GetDialysisSetting(orgId)
  5012. if err == nil {
  5013. this.ServeSuccessJSON(map[string]interface{}{
  5014. "list": list,
  5015. "total": total,
  5016. "dialysisSett": dialysisSett,
  5017. })
  5018. return
  5019. } else {
  5020. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5021. return
  5022. }
  5023. }
  5024. func (this *DialysisApiController) GetDialysisGoodTotalCount() {
  5025. orgId := this.GetAdminUserInfo().CurrentOrgId
  5026. schedule_type, _ := this.GetInt64("schedule_type")
  5027. //partion_type, _ := this.GetInt64("partion_type")
  5028. start_time := this.GetString("selected_date")
  5029. partion_type := this.GetString("partion_type")
  5030. var ids []string
  5031. ids = strings.Split(partion_type, ",")
  5032. timeLayout := "2006-01-02"
  5033. loc, _ := time.LoadLocation("Local")
  5034. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5035. list, err := service.GetDialysisGoodTotalCount(orgId, schedule_type, ids, startTime.Unix())
  5036. if err == nil {
  5037. this.ServeSuccessJSON(map[string]interface{}{
  5038. "list": list,
  5039. })
  5040. return
  5041. } else {
  5042. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5043. return
  5044. }
  5045. }
  5046. func (this *DialysisApiController) GetDialysisAdviceSchedulist() {
  5047. orgId := this.GetAdminUserInfo().CurrentOrgId
  5048. schedule_type, _ := this.GetInt64("schedule_type")
  5049. //partion_type, _ := this.GetInt64("partion_type")
  5050. partion_type := this.GetString("partion_type")
  5051. var ids []string
  5052. ids = strings.Split(partion_type, ",")
  5053. start_time := this.GetString("selected_date")
  5054. timeLayout := "2006-01-02"
  5055. loc, _ := time.LoadLocation("Local")
  5056. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5057. list, err := service.GetDialysisAdviceSchedulist(orgId, schedule_type, ids, startTime.Unix())
  5058. tablelist, _ := service.GetDialysisAdviceSchedulistTwo(orgId, schedule_type, ids, startTime.Unix())
  5059. //获取长期医嘱
  5060. adviceList, _ := service.GetAllLongAdviceList(orgId)
  5061. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  5062. _, config := service.FindXTHisRecordByOrgId(orgId)
  5063. if err == nil {
  5064. this.ServeSuccessJSON(map[string]interface{}{
  5065. "list": list,
  5066. "drug": drug,
  5067. "adviceList": adviceList,
  5068. "config": config,
  5069. "tablelist": tablelist,
  5070. })
  5071. return
  5072. } else {
  5073. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5074. return
  5075. }
  5076. }
  5077. func (this *DialysisApiController) GetDialysisParameterGoodList() {
  5078. orgId := this.GetAdminUserInfo().CurrentOrgId
  5079. schedule_type, _ := this.GetInt64("schedule_type")
  5080. partion_type, _ := this.GetInt64("partion_type")
  5081. start_time := this.GetString("selected_date")
  5082. timeLayout := "2006-01-02"
  5083. loc, _ := time.LoadLocation("Local")
  5084. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5085. list, err := service.GetDialysisParameterGoodList(orgId, schedule_type, partion_type, startTime.Unix())
  5086. if err == nil {
  5087. this.ServeSuccessJSON(map[string]interface{}{
  5088. "list": list,
  5089. })
  5090. return
  5091. } else {
  5092. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5093. return
  5094. }
  5095. }
  5096. func (this *DialysisApiController) SaveHisDialysis() {
  5097. var ids []string
  5098. advice_ids := this.GetString("ids")
  5099. ids = strings.Split(advice_ids, ",")
  5100. orgId := this.GetAdminUserInfo().CurrentOrgId
  5101. service.SaveHisDialysis(orgId, ids)
  5102. returnData := make(map[string]interface{}, 0)
  5103. returnData["msg"] = "ok"
  5104. this.ServeSuccessJSON(returnData)
  5105. return
  5106. }
  5107. func (this *DialysisApiController) GetHisDialysisGoodCount() {
  5108. orgId := this.GetAdminUserInfo().CurrentOrgId
  5109. schedule_type, _ := this.GetInt64("schedule_type")
  5110. //partion_type, _ := this.GetInt64("partion_type")
  5111. partion_type := this.GetString("partion_type")
  5112. var ids []string
  5113. ids = strings.Split(partion_type, ",")
  5114. start_time := this.GetString("selected_date")
  5115. timeLayout := "2006-01-02"
  5116. loc, _ := time.LoadLocation("Local")
  5117. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5118. list, _ := service.GetHisDialysisGoodCountTwo(orgId, schedule_type, ids, startTime.Unix())
  5119. this.ServeSuccessJSON(map[string]interface{}{
  5120. "list": list,
  5121. })
  5122. return
  5123. }
  5124. func (this *DialysisApiController) GetPatientSchedule() {
  5125. orgId := this.GetAdminUserInfo().CurrentOrgId
  5126. patient_id, _ := this.GetInt64("patient_id")
  5127. schedule_date, _ := this.GetInt64("schedule_date")
  5128. schedulePatient, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgId)
  5129. this.ServeSuccessJSON(map[string]interface{}{
  5130. "schedulePatient": schedulePatient,
  5131. })
  5132. }
  5133. func (c *DialysisApiController) GetSchedulePrintList() {
  5134. page, _ := c.GetInt64("page", 1)
  5135. limit, _ := c.GetInt64("limit", 10)
  5136. schedulType, _ := c.GetInt64("schedule_type", 0)
  5137. partitionType, _ := c.GetInt64("partition_type", 0)
  5138. keywords := c.GetString("keywords")
  5139. schedule_date := c.GetString("schedule_date")
  5140. timeLayout := "2006-01-02"
  5141. loc, _ := time.LoadLocation("Local")
  5142. var theStartTime int64
  5143. if len(schedule_date) > 0 {
  5144. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  5145. if err != nil {
  5146. utils.ErrorLog(err.Error())
  5147. }
  5148. theStartTime = theTime.Unix()
  5149. }
  5150. adminUserInfo := c.GetAdminUserInfo()
  5151. list, total, _ := service.GetSchedulePrintList(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  5152. for _, item := range list {
  5153. order, _ := service.GetLastOrder(item.UserOrgId, item.PatientId, item.ScheduleDate)
  5154. item.DialysisOrderTwenty = order
  5155. }
  5156. listOne, _ := service.GetSchedulePrintListOne(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  5157. numberList, _ := service.GetAllBedNumberSix(adminUserInfo.CurrentOrgId)
  5158. c.ServeSuccessJSON(map[string]interface{}{
  5159. "list": list,
  5160. "total": total,
  5161. "numberList": numberList,
  5162. "listOne": listOne,
  5163. })
  5164. }
  5165. func (this *DialysisApiController) GetSolutionListByOrgId() {
  5166. orgId := this.GetAdminUserInfo().CurrentOrgId
  5167. list, _ := service.GetSolutionListByOrgId(orgId)
  5168. for _, item := range list {
  5169. //获取该模式最新的1条数据
  5170. solution, _ := service.GetNewPatientSolutionByModeId(item.PatientId, item.ModeId, orgId)
  5171. //更新状态值
  5172. service.UpdateDialysisSolutionStatus(solution.ID, item.ModeId, orgId, item.PatientId)
  5173. }
  5174. this.ServeSuccessJSON(map[string]interface{}{
  5175. "list": list,
  5176. })
  5177. }
  5178. func (this *DialysisApiController) ExcutionDoctorAdvice() {
  5179. orgId := this.GetAdminUserInfo().CurrentOrgId
  5180. is_open, _ := this.GetInt64("is_open")
  5181. idsStr := this.GetString("str")
  5182. recordIDStrs := strings.Split(idsStr, ",")
  5183. start_time := this.GetString("advice_date")
  5184. exec_time, _ := this.GetInt64("exec_time")
  5185. timeLayout := "2006-01-02"
  5186. loc, _ := time.LoadLocation("Local")
  5187. var startTime int64
  5188. if len(start_time) > 0 {
  5189. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5190. if err != nil {
  5191. //fmt.Println(err)
  5192. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5193. return
  5194. }
  5195. startTime = theTime.Unix()
  5196. }
  5197. config, _ := service.GetDrugOpenConfigOne(orgId)
  5198. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  5199. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5200. //his医嘱
  5201. if is_open == 1 {
  5202. groupList, _ := service.GetHisExcutionDoctorAdviceListGroupList(recordIDStrs, startTime, orgId)
  5203. //查找未执行医嘱
  5204. list, _ := service.GetHisExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  5205. for _, item := range list {
  5206. if item.Checker == this.GetAdminUserInfo().AdminUser.Id {
  5207. this.ServeSuccessJSON(map[string]interface{}{
  5208. "msg": "3",
  5209. })
  5210. return
  5211. }
  5212. }
  5213. for _, item := range groupList {
  5214. for _, it := range list {
  5215. if item.DrugId == it.DrugId {
  5216. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  5217. }
  5218. }
  5219. }
  5220. for _, item := range groupList {
  5221. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5222. var sum_out_count int64
  5223. for _, it := range item.ChildDoctorAdvice {
  5224. var prescribing_number int64
  5225. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  5226. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5227. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5228. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5229. }
  5230. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5231. prescribing_number = parseIntPrescribingNumber
  5232. }
  5233. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5234. prescribing_number = parseIntPrescribingNumber
  5235. }
  5236. sum_out_count += prescribing_number
  5237. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5238. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5239. //库存不足
  5240. if sum_out_count > drugStockOut.FlushCount {
  5241. this.ServeSuccessJSON(map[string]interface{}{
  5242. "msg": "2",
  5243. "drug": medical,
  5244. })
  5245. return
  5246. }
  5247. }
  5248. }
  5249. creater := this.GetAdminUserInfo().AdminUser.Id
  5250. //执行出库逻辑
  5251. for _, item := range list {
  5252. hisadvice := &models.HisDoctorAdviceInfo{
  5253. ID: item.ID,
  5254. UserOrgId: item.UserOrgId,
  5255. PatientId: item.PatientId,
  5256. AdviceType: item.AdviceType,
  5257. AdviceDate: item.AdviceDate,
  5258. StartTime: item.StartTime,
  5259. AdviceName: item.AdviceName,
  5260. AdviceDesc: item.AdviceDesc,
  5261. ReminderDate: item.ReminderDate,
  5262. SingleDose: item.SingleDose,
  5263. SingleDoseUnit: item.SingleDoseUnit,
  5264. DrugSpec: item.DrugSpec,
  5265. DrugSpecUnit: item.DrugSpecUnit,
  5266. PrescribingNumber: item.PrescribingNumber,
  5267. PrescribingNumberUnit: item.PrescribingNumberUnit,
  5268. DeliveryWay: item.DeliveryWay,
  5269. ExecutionFrequency: item.ExecutionFrequency,
  5270. AdviceDoctor: item.AdviceDoctor,
  5271. Status: 1,
  5272. CreatedTime: item.CreatedTime,
  5273. UpdatedTime: item.UpdatedTime,
  5274. AdviceAffirm: item.AdviceAffirm,
  5275. Remark: item.Remark,
  5276. StopTime: item.StopTime,
  5277. StopReason: item.StopReason,
  5278. StopDoctor: item.StopDoctor,
  5279. StopState: item.StopState,
  5280. ParentId: item.ParentId,
  5281. ExecutionTime: item.ExecutionTime,
  5282. ExecutionStaff: creater,
  5283. ExecutionState: item.ExecutionState,
  5284. Checker: item.Checker,
  5285. RecordDate: item.RecordDate,
  5286. DialysisOrderId: item.DialysisOrderId,
  5287. CheckTime: item.CheckTime,
  5288. CheckState: item.CheckState,
  5289. RemindType: item.RemindType,
  5290. FrequencyType: item.FrequencyType,
  5291. DayCount: item.DayCount,
  5292. WeekDay: item.WeekDay,
  5293. TemplateId: item.TemplateId,
  5294. Modifier: item.Modifier,
  5295. Way: item.Way,
  5296. DrugId: item.DrugId,
  5297. ExecutionFrequencyId: item.ExecutionFrequencyId,
  5298. }
  5299. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5300. if medical.IsUse == 2 {
  5301. if config.IsOpen != 1 {
  5302. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5303. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  5304. }
  5305. //不通过药房发药
  5306. if pharmacyConfig.IsOpen != 1 {
  5307. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  5308. }
  5309. //查询默认仓库
  5310. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5311. //查询默认仓库剩余多少库存
  5312. var sum_count int64
  5313. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5314. for _, its := range stockInfo {
  5315. if its.MaxUnit == medical.MaxUnit {
  5316. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5317. }
  5318. sum_count += its.StockMaxNumber + its.StockMinNumber
  5319. }
  5320. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5321. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5322. }
  5323. }
  5324. info := models.HisDoctorAdviceInfo{
  5325. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5326. ExecutionTime: exec_time,
  5327. ExecutionState: 1,
  5328. UpdatedTime: time.Now().Unix(),
  5329. }
  5330. //执行医嘱
  5331. service.UpdateHisDoctorAdviceExecution(info, item.ID)
  5332. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  5333. redis := service.RedisClient()
  5334. //清空key 值
  5335. redis.Set(key, "", time.Second)
  5336. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  5337. redis.Set(keyTwo, "", time.Second)
  5338. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5339. redis.Set(keyThree, "", time.Second)
  5340. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5341. theTime := toTime.Format("2006-01-02")
  5342. fmt.Println("theTIME", theTime)
  5343. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  5344. redis.Set(keyFour, "", time.Second)
  5345. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5346. redis.Set(keyFive, "", time.Second)
  5347. }
  5348. } else {
  5349. groupList, _ := service.GetExcutionDoctorAdviceGroupList(recordIDStrs, startTime, orgId)
  5350. //查找未执行医嘱
  5351. list, _ := service.GetExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  5352. for _, item := range groupList {
  5353. for _, it := range list {
  5354. if item.DrugId == it.DrugId {
  5355. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  5356. }
  5357. }
  5358. }
  5359. for _, item := range groupList {
  5360. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5361. var sum_out_count int64
  5362. for _, it := range item.ChildDoctorAdvice {
  5363. var prescribing_number int64
  5364. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  5365. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5366. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5367. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5368. }
  5369. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5370. prescribing_number = parseIntPrescribingNumber
  5371. }
  5372. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5373. prescribing_number = parseIntPrescribingNumber
  5374. }
  5375. sum_out_count += prescribing_number
  5376. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5377. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5378. //库存不足
  5379. if sum_out_count > drugStockOut.FlushCount {
  5380. this.ServeSuccessJSON(map[string]interface{}{
  5381. "msg": "2",
  5382. "drug": medical,
  5383. })
  5384. return
  5385. }
  5386. }
  5387. }
  5388. for _, item := range list {
  5389. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5390. dadvice := &models.DoctorAdvice{
  5391. ID: item.ID,
  5392. UserOrgId: item.UserOrgId,
  5393. PatientId: item.PatientId,
  5394. AdviceType: item.AdviceType,
  5395. AdviceDate: item.AdviceDate,
  5396. StartTime: item.StartTime,
  5397. AdviceName: item.AdviceName,
  5398. AdviceDesc: item.AdviceDesc,
  5399. ReminderDate: item.ReminderDate,
  5400. SingleDose: item.SingleDose,
  5401. SingleDoseUnit: item.SingleDoseUnit,
  5402. DrugSpec: item.DrugSpec,
  5403. DrugSpecUnit: item.DrugSpecUnit,
  5404. PrescribingNumber: item.PrescribingNumber,
  5405. PrescribingNumberUnit: item.PrescribingNumberUnit,
  5406. DeliveryWay: item.DeliveryWay,
  5407. ExecutionFrequency: item.ExecutionFrequency,
  5408. AdviceDoctor: item.AdviceDoctor,
  5409. Status: 1,
  5410. CreatedTime: item.CreatedTime,
  5411. UpdatedTime: item.UpdatedTime,
  5412. AdviceAffirm: item.AdviceAffirm,
  5413. Remark: item.Remark,
  5414. StopTime: item.StopTime,
  5415. StopReason: item.StopReason,
  5416. StopDoctor: item.StopDoctor,
  5417. StopState: item.StopState,
  5418. ParentId: item.ParentId,
  5419. ExecutionTime: item.ExecutionTime,
  5420. ExecutionStaff: item.ExecutionStaff,
  5421. ExecutionState: item.ExecutionState,
  5422. Checker: item.Checker,
  5423. RecordDate: item.ReminderDate,
  5424. DialysisOrderId: item.DialysisOrderId,
  5425. CheckTime: item.CheckTime,
  5426. CheckState: item.CheckState,
  5427. RemindType: item.RemindType,
  5428. FrequencyType: item.FrequencyType,
  5429. DayCount: item.DayCount,
  5430. WeekDay: item.WeekDay,
  5431. TemplateId: item.TemplateId,
  5432. Modifier: item.Modifier,
  5433. Way: item.Way,
  5434. DrugId: item.DrugId,
  5435. }
  5436. if medical.IsUse == 2 {
  5437. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5438. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  5439. }
  5440. if pharmacyConfig.IsOpen != 1 {
  5441. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  5442. }
  5443. //更新字典里面的库存
  5444. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5445. var sum_count int64
  5446. for _, its := range stockInfo {
  5447. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5448. if its.MaxUnit == baseDrug.MaxUnit {
  5449. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5450. }
  5451. sum_count += its.StockMaxNumber + its.StockMinNumber
  5452. }
  5453. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5454. //剩余库存
  5455. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5456. }
  5457. info := models.DoctorAdvice{
  5458. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5459. ExecutionTime: exec_time,
  5460. ExecutionState: 1,
  5461. UpdatedTime: time.Now().Unix(),
  5462. }
  5463. //执行医嘱
  5464. service.UpdateDoctorAdviceExecution(info, item.ID)
  5465. }
  5466. }
  5467. this.ServeSuccessJSON(map[string]interface{}{
  5468. "msg": "1",
  5469. })
  5470. return
  5471. }
  5472. func (this *DialysisApiController) CheckNewDoctorAdvice() {
  5473. orgId := this.GetAdminUserInfo().CurrentOrgId
  5474. idsStr := this.GetString("str")
  5475. recordIDStrs := strings.Split(idsStr, ",")
  5476. start_time := this.GetString("advice_date")
  5477. timeLayout := "2006-01-02"
  5478. loc, _ := time.LoadLocation("Local")
  5479. var startTime int64
  5480. if len(start_time) > 0 {
  5481. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5482. if err != nil {
  5483. //fmt.Println(err)
  5484. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5485. return
  5486. }
  5487. startTime = theTime.Unix()
  5488. }
  5489. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  5490. if config.IsOpen == 1 {
  5491. creater := this.GetAdminUserInfo().AdminUser.Id
  5492. //查询未核对的医嘱
  5493. advicelist, _ := service.GetHisCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  5494. for _, item := range advicelist {
  5495. if item.ExecutionStaff == creater {
  5496. this.ServeSuccessJSON(map[string]interface{}{
  5497. "msg": "2",
  5498. "advice": item,
  5499. })
  5500. return
  5501. }
  5502. service.CheckHisDoctorAdvice(item.ID, creater)
  5503. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  5504. redis := service.RedisClient()
  5505. //清空key 值
  5506. redis.Set(key, "", time.Second)
  5507. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  5508. redis.Set(keyTwo, "", time.Second)
  5509. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5510. redis.Set(keyThree, "", time.Second)
  5511. theTime := time.Now()
  5512. recordDate := theTime.Format("2006-01-02")
  5513. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  5514. redis.Set(keyFour, "", time.Second)
  5515. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5516. redis.Set(keyFive, "", time.Second)
  5517. }
  5518. } else {
  5519. //查询未核对的医嘱
  5520. advicelist, _ := service.GetCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  5521. creater := this.GetAdminUserInfo().AdminUser.Id
  5522. for _, item := range advicelist {
  5523. if item.ExecutionStaff == creater {
  5524. this.ServeSuccessJSON(map[string]interface{}{
  5525. "msg": "2",
  5526. "advice": item,
  5527. })
  5528. return
  5529. }
  5530. service.CheckDoctorAdvice(item.ID, creater)
  5531. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  5532. redis := service.RedisClient()
  5533. //清空key 值
  5534. redis.Set(key, "", time.Second)
  5535. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  5536. redis.Set(keyTwo, "", time.Second)
  5537. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5538. redis.Set(keyThree, "", time.Second)
  5539. theTime := time.Now()
  5540. recordDate := theTime.Format("2006-01-02")
  5541. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  5542. redis.Set(keyFour, "", time.Second)
  5543. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5544. redis.Set(keyFive, "", time.Second)
  5545. }
  5546. }
  5547. this.ServeSuccessJSON(map[string]interface{}{
  5548. "msg": "1",
  5549. })
  5550. return
  5551. }
  5552. func (this *DialysisApiController) SettleNewDoctorAdvice() {
  5553. orgId := this.GetAdminUserInfo().CurrentOrgId
  5554. is_open, _ := this.GetInt64("is_open")
  5555. idsStr := this.GetString("str")
  5556. recordIDStrs := strings.Split(idsStr, ",")
  5557. start_time := this.GetString("advice_date")
  5558. timeLayout := "2006-01-02"
  5559. loc, _ := time.LoadLocation("Local")
  5560. var startTime int64
  5561. if len(start_time) > 0 {
  5562. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5563. if err != nil {
  5564. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5565. return
  5566. }
  5567. startTime = theTime.Unix()
  5568. }
  5569. if is_open == 1 {
  5570. service.SettleHisNewDoctorAdvice(recordIDStrs, startTime, orgId)
  5571. } else {
  5572. service.SettleNewDoctorAdvice(recordIDStrs, startTime, orgId)
  5573. }
  5574. this.ServeSuccessJSON(map[string]interface{}{
  5575. "msg": "1",
  5576. })
  5577. return
  5578. }
  5579. func (this *DialysisApiController) ExcutionDoctorAdviceById() {
  5580. advice_id, _ := this.GetInt64("advice_id")
  5581. start_time := this.GetString("advice_date")
  5582. orgId := this.GetAdminUserInfo().CurrentOrgId
  5583. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  5584. exec_time, _ := this.GetInt64("exec_time")
  5585. //his医嘱
  5586. if config.IsOpen == 1 {
  5587. //查询医嘱
  5588. advice, _ := service.GetHisDocById(advice_id, orgId)
  5589. if advice.Checker == this.GetAdminUserInfo().AdminUser.Id {
  5590. this.ServeSuccessJSON(map[string]interface{}{
  5591. "msg": "3",
  5592. })
  5593. return
  5594. }
  5595. medical, _ := service.GetBaseDrugMedical(orgId)
  5596. var prescribing_number int64
  5597. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5598. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5599. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5600. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5601. }
  5602. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5603. prescribing_number = parseIntPrescribingNumber
  5604. }
  5605. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5606. prescribing_number = parseIntPrescribingNumber
  5607. }
  5608. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5609. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5610. //库存不足
  5611. if prescribing_number > drugStockOut.FlushCount {
  5612. this.ServeSuccessJSON(map[string]interface{}{
  5613. "msg": "2",
  5614. "drug": medical,
  5615. })
  5616. return
  5617. }
  5618. info := models.HisDoctorAdviceInfo{
  5619. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5620. ExecutionTime: exec_time,
  5621. ExecutionState: 1,
  5622. UpdatedTime: time.Now().Unix(),
  5623. }
  5624. //执行医嘱
  5625. service.UpdateHisDoctorAdviceExecution(info, advice.ID)
  5626. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  5627. redis := service.RedisClient()
  5628. //清空key 值
  5629. redis.Set(key, "", time.Second)
  5630. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  5631. redis.Set(keyTwo, "", time.Second)
  5632. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5633. redis.Set(keyThree, "", time.Second)
  5634. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5635. theTime := toTime.Format("2006-01-02")
  5636. fmt.Println("theTIME", theTime)
  5637. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  5638. redis.Set(keyFour, "", time.Second)
  5639. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5640. redis.Set(keyFive, "", time.Second)
  5641. //出库
  5642. if prescribing_number <= drugStockOut.FlushCount {
  5643. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  5644. //执行出库逻辑
  5645. hisadvice := &models.HisDoctorAdviceInfo{
  5646. ID: advice.ID,
  5647. UserOrgId: advice.UserOrgId,
  5648. PatientId: advice.PatientId,
  5649. AdviceType: advice.AdviceType,
  5650. AdviceDate: advice.AdviceDate,
  5651. StartTime: advice.StartTime,
  5652. AdviceName: advice.AdviceName,
  5653. AdviceDesc: advice.AdviceDesc,
  5654. ReminderDate: advice.ReminderDate,
  5655. SingleDose: advice.SingleDose,
  5656. SingleDoseUnit: advice.SingleDoseUnit,
  5657. DrugSpec: advice.DrugSpec,
  5658. DrugSpecUnit: advice.DrugSpecUnit,
  5659. PrescribingNumber: advice.PrescribingNumber,
  5660. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  5661. DeliveryWay: advice.DeliveryWay,
  5662. ExecutionFrequency: advice.ExecutionFrequency,
  5663. AdviceDoctor: advice.AdviceDoctor,
  5664. Status: 1,
  5665. CreatedTime: advice.CreatedTime,
  5666. UpdatedTime: advice.UpdatedTime,
  5667. AdviceAffirm: advice.AdviceAffirm,
  5668. Remark: advice.Remark,
  5669. StopTime: advice.StopTime,
  5670. StopReason: advice.StopReason,
  5671. StopDoctor: advice.StopDoctor,
  5672. StopState: advice.StopState,
  5673. ParentId: advice.ParentId,
  5674. ExecutionTime: advice.ExecutionTime,
  5675. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5676. ExecutionState: advice.ExecutionState,
  5677. Checker: advice.Checker,
  5678. RecordDate: advice.RecordDate,
  5679. DialysisOrderId: advice.DialysisOrderId,
  5680. CheckTime: advice.CheckTime,
  5681. CheckState: advice.CheckState,
  5682. RemindType: advice.RemindType,
  5683. FrequencyType: advice.FrequencyType,
  5684. DayCount: advice.DayCount,
  5685. WeekDay: advice.WeekDay,
  5686. TemplateId: advice.TemplateId,
  5687. Modifier: advice.Modifier,
  5688. Way: advice.Way,
  5689. DrugId: advice.DrugId,
  5690. ExecutionFrequencyId: advice.ExecutionFrequencyId,
  5691. }
  5692. if medical.IsUse == 2 {
  5693. if config.IsOpen != 1 {
  5694. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5695. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  5696. }
  5697. //不通过药房发药
  5698. if pharmacyConfig.IsOpen != 1 {
  5699. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  5700. }
  5701. //查询默认仓库
  5702. storeHouseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  5703. //查询默认仓库剩余多少库存
  5704. var sum_count int64
  5705. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  5706. for _, its := range stockInfo {
  5707. if its.MaxUnit == medical.MaxUnit {
  5708. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5709. }
  5710. sum_count += its.StockMaxNumber + its.StockMinNumber
  5711. }
  5712. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  5713. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5714. }
  5715. }
  5716. }
  5717. this.ServeSuccessJSON(map[string]interface{}{
  5718. "msg": "1",
  5719. })
  5720. return
  5721. }
  5722. if config.IsOpen == 2 || config.IsOpen == 0 {
  5723. advice, _ := service.GetBloodDocById(advice_id, orgId)
  5724. medical, _ := service.GetBaseDrugMedical(orgId)
  5725. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  5726. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5727. var prescribing_number int64
  5728. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5729. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5730. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5731. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5732. }
  5733. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5734. prescribing_number = parseIntPrescribingNumber
  5735. }
  5736. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5737. prescribing_number = parseIntPrescribingNumber
  5738. }
  5739. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5740. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5741. //库存不足
  5742. if prescribing_number > drugStockOut.FlushCount {
  5743. this.ServeSuccessJSON(map[string]interface{}{
  5744. "msg": "2",
  5745. "drug": medical,
  5746. })
  5747. return
  5748. }
  5749. info := models.DoctorAdvice{
  5750. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5751. ExecutionTime: exec_time,
  5752. ExecutionState: 1,
  5753. UpdatedTime: time.Now().Unix(),
  5754. }
  5755. //执行医嘱
  5756. service.UpdateDoctorAdviceExecution(info, advice.ID)
  5757. dadvice := &models.DoctorAdvice{
  5758. ID: advice.ID,
  5759. UserOrgId: advice.UserOrgId,
  5760. PatientId: advice.PatientId,
  5761. AdviceType: advice.AdviceType,
  5762. AdviceDate: advice.AdviceDate,
  5763. StartTime: advice.StartTime,
  5764. AdviceName: advice.AdviceName,
  5765. AdviceDesc: advice.AdviceDesc,
  5766. ReminderDate: advice.ReminderDate,
  5767. SingleDose: advice.SingleDose,
  5768. SingleDoseUnit: advice.SingleDoseUnit,
  5769. DrugSpec: advice.DrugSpec,
  5770. DrugSpecUnit: advice.DrugSpecUnit,
  5771. PrescribingNumber: advice.PrescribingNumber,
  5772. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  5773. DeliveryWay: advice.DeliveryWay,
  5774. ExecutionFrequency: advice.ExecutionFrequency,
  5775. AdviceDoctor: advice.AdviceDoctor,
  5776. Status: 1,
  5777. CreatedTime: advice.CreatedTime,
  5778. UpdatedTime: advice.UpdatedTime,
  5779. AdviceAffirm: advice.AdviceAffirm,
  5780. Remark: advice.Remark,
  5781. StopTime: advice.StopTime,
  5782. StopReason: advice.StopReason,
  5783. StopDoctor: advice.StopDoctor,
  5784. StopState: advice.StopState,
  5785. ParentId: advice.ParentId,
  5786. ExecutionTime: advice.ExecutionTime,
  5787. ExecutionStaff: advice.ExecutionStaff,
  5788. ExecutionState: advice.ExecutionState,
  5789. Checker: advice.Checker,
  5790. RecordDate: advice.ReminderDate,
  5791. DialysisOrderId: advice.DialysisOrderId,
  5792. CheckTime: advice.CheckTime,
  5793. CheckState: advice.CheckState,
  5794. RemindType: advice.RemindType,
  5795. FrequencyType: advice.FrequencyType,
  5796. DayCount: advice.DayCount,
  5797. WeekDay: advice.WeekDay,
  5798. TemplateId: advice.TemplateId,
  5799. Modifier: advice.Modifier,
  5800. Way: advice.Way,
  5801. DrugId: advice.DrugId,
  5802. }
  5803. if medical.IsUse == 2 {
  5804. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5805. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  5806. }
  5807. if pharmacyConfig.IsOpen != 1 {
  5808. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  5809. }
  5810. //更新字典里面的库存
  5811. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  5812. var sum_count int64
  5813. for _, its := range stockInfo {
  5814. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5815. if its.MaxUnit == baseDrug.MaxUnit {
  5816. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5817. }
  5818. sum_count += its.StockMaxNumber + its.StockMinNumber
  5819. }
  5820. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  5821. //剩余库存
  5822. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5823. }
  5824. }
  5825. this.ServeSuccessJSON(map[string]interface{}{
  5826. "msg": "1",
  5827. })
  5828. return
  5829. }
  5830. func (this *DialysisApiController) GetDialysisAdviceToday() {
  5831. orgId := this.GetAdminUserInfo().CurrentOrgId
  5832. schedule_type, _ := this.GetInt64("schedule_type")
  5833. //partion_type, _ := this.GetInt64("partion_type")
  5834. partion_type := this.GetString("partion_type")
  5835. var ids []string
  5836. ids = strings.Split(partion_type, ",")
  5837. start_time := this.GetString("selected_date")
  5838. timeLayout := "2006-01-02"
  5839. loc, _ := time.LoadLocation("Local")
  5840. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5841. list, err := service.GetDialysisAdviceSchedulistTen(orgId, schedule_type, ids, startTime.Unix())
  5842. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  5843. _, config := service.FindXTHisRecordByOrgId(orgId)
  5844. appId := this.GetAdminUserInfo().CurrentAppId
  5845. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  5846. if err == nil {
  5847. this.ServeSuccessJSON(map[string]interface{}{
  5848. "list": list,
  5849. "drug": drug,
  5850. "config": config,
  5851. "doctorList": doctorList,
  5852. })
  5853. return
  5854. } else {
  5855. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5856. return
  5857. }
  5858. }
  5859. func (this *DialysisApiController) GetMobileScheduleList() {
  5860. orgId := this.GetAdminUserInfo().CurrentOrgId
  5861. schedule, _ := service.GetMobileScheduleList(orgId)
  5862. if len(schedule) > 0 {
  5863. for _, its := range schedule {
  5864. //prescription, _ := service.GetPrescriptionList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  5865. //its.DialysisPrescription = prescription
  5866. //monitor, _ := service.GetLastMonitorRecordList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  5867. //its.MonitoringRecord = monitor
  5868. //after, _ := service.GetLastAfter(its.PatientId, its.ScheduleDate, its.UserOrgId)
  5869. //its.XtAssessmentAfterDislysis = after
  5870. order, _ := service.GetLastOrder(its.UserOrgId, its.PatientId, its.ScheduleDate)
  5871. service.UpdateDoctorSix(order.StartTime, order.PatientId, order.DialysisDate, order.UserOrgId)
  5872. }
  5873. }
  5874. this.ServeSuccessJSON(map[string]interface{}{
  5875. "schedule": schedule,
  5876. })
  5877. return
  5878. }
  5879. func (this *DialysisApiController) SaveDialysisInformationSetting() {
  5880. week_day, _ := this.GetInt64("week_day")
  5881. orgId := this.GetAdminUserInfo().CurrentOrgId
  5882. informaitonSetting := models.XtDialysisInformaitonSetting{
  5883. WeekDay: week_day,
  5884. UserOrgId: orgId,
  5885. Status: 1,
  5886. Ctime: time.Now().Unix(),
  5887. Mtime: 0,
  5888. }
  5889. information, _ := service.GetInformationSettingByOrgId(orgId)
  5890. if information.ID == 0 {
  5891. service.CreateInformationSetting(informaitonSetting)
  5892. }
  5893. if information.ID > 0 {
  5894. service.UpdateInformationSettingById(orgId, week_day)
  5895. }
  5896. this.ServeSuccessJSON(map[string]interface{}{
  5897. "informaitonSetting": informaitonSetting,
  5898. })
  5899. return
  5900. }
  5901. func (this *DialysisApiController) GetDialysisInformationSetting() {
  5902. orgId := this.GetAdminUserInfo().CurrentOrgId
  5903. limit, _ := this.GetInt64("limit")
  5904. page, _ := this.GetInt64("page")
  5905. informationSetting, _ := service.GetDialysisInformationSettingList(orgId)
  5906. //未审核
  5907. infor, total, _ := service.GetDialysisInformationIsNoCheck(orgId, limit, page, 2)
  5908. //全部
  5909. inforList, totalOne, _ := service.GetDialysisInformationIsNoCheckOne(orgId, limit, page, 1)
  5910. patients, _ := service.GetAllpatientThirty(orgId)
  5911. appId := this.GetAdminUserInfo().CurrentAppId
  5912. role, _ := service.GetAllDoctorListSix(orgId, appId)
  5913. this.ServeSuccessJSON(map[string]interface{}{
  5914. "informaitonSetting": informationSetting,
  5915. "infor": infor,
  5916. "total": total,
  5917. "totalOne": totalOne,
  5918. "inforList": inforList,
  5919. "patients": patients,
  5920. "adminList": role,
  5921. })
  5922. return
  5923. }
  5924. func (this *DialysisApiController) CheckDialysisInformation() {
  5925. id, _ := this.GetInt64("id")
  5926. application_status, _ := this.GetInt64("application_status")
  5927. timeNow := time.Now().Unix()
  5928. checker := this.GetAdminUserInfo().AdminUser.Id
  5929. information, _ := service.CheckDialysisInformation(id, application_status, timeNow, checker)
  5930. this.ServeSuccessJSON(map[string]interface{}{
  5931. "information": information,
  5932. })
  5933. return
  5934. }
  5935. func (this *DialysisApiController) GetDialysisPatientsFlow() {
  5936. page, _ := this.GetInt64("page", 1)
  5937. limit, _ := this.GetInt64("limit", 10)
  5938. schedulType, _ := this.GetInt64("schedul_type", 0)
  5939. startTime, _ := this.GetInt64("schedul_time", 0)
  5940. partitionType, _ := this.GetInt64("partition_type", 0)
  5941. keywords := this.GetString("keywords")
  5942. start_time, _ := this.GetInt64("start_time")
  5943. end_time, _ := this.GetInt64("end_time")
  5944. adminUserInfo := this.GetAdminUserInfo()
  5945. if len(keywords) > 0 {
  5946. dialysisSchedule, err, total := service.GetDialysisWatchByKeywordFlow(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  5947. if err == nil {
  5948. this.ServeSuccessJSON(map[string]interface{}{
  5949. "schedule": dialysisSchedule,
  5950. "total": total,
  5951. })
  5952. } else {
  5953. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5954. }
  5955. } else {
  5956. dialysisSchedule, err, total := service.GetDialysisWatchFlow(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  5957. fmt.Println("dialysisSchedule-----------------------", dialysisSchedule)
  5958. if err == nil {
  5959. this.ServeSuccessJSON(map[string]interface{}{
  5960. "schedule": dialysisSchedule,
  5961. "total": total,
  5962. })
  5963. } else {
  5964. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5965. }
  5966. }
  5967. }
  5968. func (this *DialysisApiController) SaveInformation() {
  5969. patient_id, _ := this.GetInt64("patient_id")
  5970. record_date, _ := this.GetInt64("record_date")
  5971. startTime := this.GetString("selected_date")
  5972. timeLayout := "2006-01-02 15:04"
  5973. loc, _ := time.LoadLocation("Local")
  5974. if len(startTime) == 0 {
  5975. utils.ErrorLog("len(start_time) == 0")
  5976. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5977. return
  5978. }
  5979. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  5980. if err != nil {
  5981. utils.ErrorLog(err.Error())
  5982. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5983. return
  5984. }
  5985. StartTime := theTime.Unix()
  5986. fmt.Println("startime-------------", StartTime)
  5987. module, _ := this.GetInt64("module")
  5988. remark := this.GetString("remark")
  5989. orgId := this.GetAdminUserInfo().CurrentOrgId
  5990. creater := this.GetAdminUserInfo().AdminUser.Id
  5991. information := models.XtDialysisInformation{
  5992. Module: module,
  5993. PatientId: patient_id,
  5994. RecordDate: record_date,
  5995. ApplicationDate: StartTime,
  5996. Creater: creater,
  5997. ApplicationStatus: 2,
  5998. Checker: 0,
  5999. CheckTime: 0,
  6000. Remark: remark,
  6001. UserOrgId: orgId,
  6002. Ctime: time.Now().Unix(),
  6003. Status: 1,
  6004. Mtime: 0,
  6005. }
  6006. infor, _ := service.GetDialysisInoformationById(patient_id, record_date, orgId, module)
  6007. if infor.ID == 0 {
  6008. err := service.CreatedDialysisInformation(information)
  6009. if err == nil {
  6010. this.ServeSuccessJSON(map[string]interface{}{
  6011. "information": information,
  6012. })
  6013. return
  6014. }
  6015. }
  6016. if infor.ID > 0 {
  6017. err := service.UpdateDialysisInformationById(patient_id, record_date, orgId, module, StartTime, remark)
  6018. if err == nil {
  6019. this.ServeSuccessJSON(map[string]interface{}{
  6020. "information": information,
  6021. })
  6022. return
  6023. }
  6024. }
  6025. }
  6026. func (this *DialysisApiController) GetLongDialysisAdviceToday() {
  6027. orgId := this.GetAdminUserInfo().CurrentOrgId
  6028. schedule_type, _ := this.GetInt64("schedule_type")
  6029. partion_type := this.GetString("partion_type")
  6030. var ids []string
  6031. ids = strings.Split(partion_type, ",")
  6032. start_time := this.GetString("selected_date")
  6033. timeLayout := "2006-01-02"
  6034. loc, _ := time.LoadLocation("Local")
  6035. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6036. list, err := service.GetLongDialysisAdviceToday(orgId, schedule_type, ids, startTime.Unix())
  6037. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  6038. _, config := service.FindXTHisRecordByOrgId(orgId)
  6039. appId := this.GetAdminUserInfo().CurrentAppId
  6040. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  6041. if err == nil {
  6042. this.ServeSuccessJSON(map[string]interface{}{
  6043. "list": list,
  6044. "drug": drug,
  6045. "config": config,
  6046. "doctorList": doctorList,
  6047. })
  6048. return
  6049. } else {
  6050. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6051. return
  6052. }
  6053. }