dialysis_api_controller.go 274KB

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