dialysis_api_controller.go 258KB

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