dialysis_api_controller.go 247KB

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