dialysis_api_controller.go 273KB

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