dialysis_api_controller.go 311KB

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