dialysis_api_controller.go 247KB

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