dialysis_api_controller.go 274KB

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