dialysis_api_controller.go 446KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "math"
  7. "net/http"
  8. "net/url"
  9. "reflect"
  10. "strconv"
  11. "strings"
  12. "time"
  13. "XT_New/enums"
  14. "XT_New/models"
  15. "XT_New/service"
  16. "XT_New/utils"
  17. "github.com/astaxie/beego"
  18. "github.com/jinzhu/gorm"
  19. )
  20. // type DialysisTestAPIController struct {
  21. // MobileBaseAPIController
  22. // }
  23. // [get]/m/api/test
  24. // func (this *DialysisTestAPIController) Test() {
  25. // orgID := int64(3907)
  26. // now := time.Now()
  27. // nextWeek := now.AddDate(0, 0, 7)
  28. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  29. // nextTwoWeek := now.AddDate(0, 0, 14)
  30. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  31. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  32. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  33. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  34. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. // return
  36. // }
  37. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  38. // if exchangeErr != nil {
  39. // this.ErrorLog("%v", exchangeErr)
  40. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. // return
  42. // }
  43. // this.ServeSuccessJSON(map[string]interface{}{
  44. // // "now": now,
  45. // // "next_week": nextWeek,f
  46. // // "next_week_mon": nextWeekMon,
  47. // // "next_week_sun": nextWeekSun,
  48. // // "next_two_week_mon": nextTwoWeekMon,
  49. // // "next_two_week_sun": nextTwoWeekSun,
  50. // "next_week_schs": nextWeekSchs,
  51. // "next_two_week_schs": nextTwoWeekSchs,
  52. // })
  53. // }
  54. type DialysisAPIController struct {
  55. MobileBaseAPIAuthController
  56. }
  57. // /m/api/scheduals [get]
  58. // @param type:int
  59. // @param date:string
  60. func (this *DialysisAPIController) Scheduals() {
  61. schedualType, _ := this.GetInt64("type")
  62. schedualDate := this.GetString("date")
  63. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  64. schedualType = 0
  65. }
  66. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  67. if parseDateErr != nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. adminInfo := this.GetMobileAdminUserInfo()
  72. orgID := adminInfo.Org.Id
  73. redis := service.RedisClient()
  74. defer redis.Close()
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. redis.Set(key, "", time.Second)
  77. scheduals_json_str, _ := redis.Get(key).Result()
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. for _, item := range scheduals {
  82. order, _ := service.GetMonitDialysisOrder(item.UserOrgId, item.PatientId, date.Unix())
  83. item.DialysisLastOrder = order
  84. solution, _ := service.GetMonitDialysisSolution(item.UserOrgId, item.PatientId, item.ModeId)
  85. item.DialysisSolution = solution
  86. }
  87. if err != nil {
  88. this.ErrorLog("获取排班信息失败:%v", err)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. } else {
  91. if len(scheduals) > 0 {
  92. devices, _ := service.GetAllDevicetByListSix(orgID)
  93. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  94. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  95. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  96. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  97. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  98. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  99. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  100. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  101. inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
  102. //monitor, _ := service.GetMonitorByListSix(orgID, date.Unix())
  103. for key, item := range scheduals {
  104. for _, infor := range inforMation {
  105. if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
  106. scheduals[key].NewDeviceInformation = infor
  107. break
  108. }
  109. }
  110. // 获取患者信息
  111. for _, patient := range patients {
  112. if item.PatientId == patient.ID {
  113. scheduals[key].SchedualPatient = patient
  114. break
  115. }
  116. }
  117. // 床位信息
  118. for _, device := range devices {
  119. if item.BedId == device.ID {
  120. scheduals[key].DeviceNumber = device
  121. break
  122. }
  123. }
  124. // 医嘱信息
  125. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  126. for _, advice := range advices {
  127. if item.PatientId == advice.PatientId {
  128. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  129. }
  130. }
  131. // 医嘱信息
  132. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  133. for _, hisAdvice := range hisAdvices {
  134. if item.PatientId == hisAdvice.PatientId {
  135. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  136. }
  137. }
  138. // 医嘱信息
  139. for _, prescription := range prescriptions {
  140. if item.PatientId == prescription.PatientId {
  141. scheduals[key].Prescription = prescription
  142. break
  143. }
  144. }
  145. // 透前评估
  146. for _, assessmentBefore := range assessmentBefores {
  147. if item.PatientId == assessmentBefore.PatientId {
  148. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  149. break
  150. }
  151. }
  152. // 透析上下机
  153. for _, dialysisOrder := range dialysisOrders {
  154. if item.PatientId == dialysisOrder.PatientId {
  155. scheduals[key].DialysisOrder = dialysisOrder
  156. break
  157. }
  158. }
  159. // 治疗小节
  160. for _, afterDislysis := range AssessmentAfterDislysis {
  161. if item.PatientId == afterDislysis.PatientId {
  162. scheduals[key].AssessmentAfterDislysis = afterDislysis
  163. break
  164. }
  165. }
  166. // 透后评估
  167. for _, treatmentSummary := range treatmentSummarys {
  168. if item.PatientId == treatmentSummary.PatientId {
  169. scheduals[key].TreatmentSummary = treatmentSummary
  170. break
  171. }
  172. }
  173. for _, check := range dobulecheck {
  174. if item.PatientId == check.PatientId {
  175. scheduals[key].DoubleCheck = check
  176. break
  177. }
  178. }
  179. //// 监测
  180. //scheduals[key].VMMonitoringRecord = make([]models.VMMonitoringRecord, 0)
  181. //for _, moni := range monitor {
  182. // if item.PatientId == moni.PatientId {
  183. // scheduals[key].VMMonitoringRecord = append(scheduals[key].VMMonitoringRecord, moni)
  184. // }
  185. //}
  186. }
  187. //缓存数据
  188. scheduals_json, err := json.Marshal(&scheduals)
  189. if err == nil {
  190. redis.Set(key, scheduals_json, time.Second*60)
  191. }
  192. }
  193. //获取今日所有的处方开的耗材
  194. _, configs := service.FindXTHisProjectByOrgId(orgID)
  195. project := make([]*models.HisPrescriptionProjectTwo, 0)
  196. if configs.ID > 0 && configs.IsOpen == 1 {
  197. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  198. }
  199. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  200. this.ServeSuccessJSON(map[string]interface{}{
  201. "scheduals": scheduals,
  202. "project": project,
  203. })
  204. }
  205. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  206. var dat []map[string]interface{}
  207. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  208. } else {
  209. }
  210. //获取今日所有的处方开的耗材
  211. _, configs := service.FindXTHisProjectByOrgId(orgID)
  212. project := make([]*models.HisPrescriptionProjectTwo, 0)
  213. if configs.ID > 0 && configs.IsOpen == 1 {
  214. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  215. }
  216. this.ServeSuccessJSON(map[string]interface{}{
  217. "scheduals": dat,
  218. "redis": "true",
  219. "date": schedualDate,
  220. "project": project,
  221. })
  222. }
  223. }
  224. // /m/api/waiting_scheduals [get]
  225. // @param date:string
  226. func (this *DialysisAPIController) WaitingScheduals() {
  227. schedualDate := this.GetString("date")
  228. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  229. if parseDateErr != nil && len(schedualDate) != 0 {
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. return
  232. }
  233. adminInfo := this.GetMobileAdminUserInfo()
  234. orgID := adminInfo.Org.Id
  235. redis := service.RedisClient()
  236. defer redis.Close()
  237. // cur_date := time.Now().Format("2006-01-02")
  238. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  239. wait_scheduals, _ := redis.Get(key).Result()
  240. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  241. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  242. if err != nil {
  243. this.ErrorLog("获取排班信息失败:%v", err)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. } else {
  246. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  247. for _, s := range scheduals {
  248. returnScheduals = append(returnScheduals, s)
  249. }
  250. if len(returnScheduals) > 0 {
  251. //缓存数据
  252. wait_scheduals_json, err := json.Marshal(scheduals)
  253. if err == nil {
  254. redis.Set(key, wait_scheduals_json, time.Second*30)
  255. }
  256. }
  257. this.ServeSuccessJSON(map[string]interface{}{
  258. "scheduals": scheduals,
  259. })
  260. }
  261. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  262. var dat []map[string]interface{}
  263. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  264. } else {
  265. }
  266. this.ServeSuccessJSON(map[string]interface{}{
  267. "scheduals": dat,
  268. "redis": "true",
  269. "date": schedualDate,
  270. })
  271. }
  272. }
  273. //else{
  274. // fmt.Println("33333333")
  275. //
  276. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  277. // if err != nil {
  278. // this.ErrorLog("获取排班信息失败:%v", err)
  279. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  280. // } else {
  281. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  282. // for _, s := range scheduals {
  283. //
  284. // returnScheduals = append(returnScheduals, s)
  285. // }
  286. //
  287. // this.ServeSuccessJSON(map[string]interface{}{
  288. // "scheduals": returnScheduals,
  289. // })
  290. // }
  291. //
  292. // }
  293. //if err == nil{
  294. //
  295. //
  296. //
  297. //
  298. //
  299. //}else{
  300. //}
  301. // /m/api/dialysis/record [get]
  302. // @param patient_id:int
  303. // @param date:string (yyyy-MM-dd)
  304. func (this *DialysisAPIController) DialysisRecord() {
  305. patientID, _ := this.GetInt64("patient_id")
  306. recordDateStr := this.GetString("date")
  307. if patientID <= 0 {
  308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  309. return
  310. }
  311. if len(recordDateStr) == 0 {
  312. recordDateStr = time.Now().Format("2006-01-02")
  313. }
  314. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  315. if parseDateErr != nil {
  316. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  318. return
  319. }
  320. adminInfo := this.GetMobileAdminUserInfo()
  321. ch := make(chan struct{})
  322. count := 24 // count 表示活动的协程个数
  323. var patient models.Patients
  324. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  325. var predialysisEvaluation *models.PredialysisEvaluation
  326. var lastPredialysisEvaluation *models.PredialysisEvaluation
  327. var doctorAdvices []*models.DoctorAdvice
  328. var dialysisOrder *models.DialysisOrder
  329. var doubleCheck *models.DoubleCheck
  330. var monitorRecords []*models.MonitoringRecord
  331. var lastMonitorRecord *models.MonitoringRecord
  332. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  333. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  334. var treatmentSummary *models.TreatmentSummary
  335. var dialysisPrescribe *models.DialysisPrescription
  336. var dialysisSolution *models.DialysisSolution
  337. var lastDialysisPrescribe *models.DialysisPrescription
  338. var systemDialysisPrescribe *models.SystemPrescription
  339. var is_project_open_config models.XtHisProjectConfig
  340. var projects []*models.HisPrescriptionProject
  341. var projectsOne []*models.HisPrescriptionProject
  342. var stockType []*models.GoodsTypeOne
  343. var prepare []*models.XtDialysisBeforePrepare
  344. var lastAssessment models.XtPatientVascularAccess
  345. var lastDryWeightDislysis *models.SgjPatientDryweight
  346. var gobalConfig models.GobalConfig
  347. var operators []*models.SgjUserAdminRoles
  348. // 先走redis,没有走数据库
  349. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  350. go func() {
  351. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  352. ch <- struct{}{}
  353. }()
  354. go func() {
  355. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  356. ch <- struct{}{}
  357. }()
  358. go func() {
  359. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  360. ch <- struct{}{}
  361. }()
  362. go func() {
  363. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  364. ch <- struct{}{}
  365. }()
  366. go func() {
  367. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  368. ch <- struct{}{}
  369. }()
  370. go func() {
  371. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  372. ch <- struct{}{}
  373. }()
  374. go func() {
  375. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  376. ch <- struct{}{}
  377. }()
  378. go func() {
  379. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  380. ch <- struct{}{}
  381. }()
  382. go func() {
  383. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  384. ch <- struct{}{}
  385. }()
  386. go func() {
  387. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  388. ch <- struct{}{}
  389. }()
  390. go func() {
  391. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  392. ch <- struct{}{}
  393. }()
  394. go func() {
  395. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  396. ch <- struct{}{}
  397. }()
  398. go func() {
  399. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  400. ch <- struct{}{}
  401. }()
  402. go func() {
  403. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  404. ch <- struct{}{}
  405. }()
  406. go func() {
  407. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  408. ch <- struct{}{}
  409. }()
  410. go func() {
  411. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  412. ch <- struct{}{}
  413. }()
  414. go func() {
  415. // 先走redis,没有走数据库
  416. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  417. ch <- struct{}{}
  418. }()
  419. go func() {
  420. // 先走redis,没有走数据库
  421. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  422. ch <- struct{}{}
  423. }()
  424. go func() {
  425. // // 先走redis,没有走数据库
  426. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  427. ch <- struct{}{}
  428. }()
  429. go func() {
  430. // 先走redis,没有走数据库
  431. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  432. ch <- struct{}{}
  433. }()
  434. go func() {
  435. // //获取最后一次血管通路
  436. // 先走redis,没有走数据库
  437. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  438. ch <- struct{}{}
  439. }()
  440. go func() {
  441. // 先走redis,没有走数据库
  442. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  443. ch <- struct{}{}
  444. }()
  445. go func() {
  446. // 先走redis,没有走数据库
  447. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  448. ch <- struct{}{}
  449. }()
  450. go func() {
  451. // 先走redis,没有走数据库
  452. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  453. ch <- struct{}{}
  454. }()
  455. for range ch {
  456. // 每次从ch中接收数据,表明一个活动的协程结束
  457. count--
  458. // 当所有活动的协程都结束时,关闭管道
  459. if count == 0 {
  460. close(ch)
  461. }
  462. }
  463. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  464. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  465. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  466. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  467. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  468. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  469. var team_projects []*models.HisPrescriptionProject
  470. //var index int64 = 0
  471. for _, item := range temp_team_projects {
  472. //组套里面非检验项目的
  473. if item.HisProject.CostClassify != 3 {
  474. projects = append(projects, item)
  475. }
  476. //组套里面检验项目的
  477. if item.HisProject.CostClassify == 3 {
  478. team_projects = append(team_projects, item)
  479. }
  480. }
  481. //针对茂名舒和
  482. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  483. if len(projects) > 0 {
  484. for _, item := range projects {
  485. if item.Type == 2 {
  486. if item.HisProject.IsShow == 1 {
  487. projectsOne = append(projectsOne, item)
  488. }
  489. }
  490. if item.Type == 3 {
  491. if item.GoodInfo.IsShow == 1 {
  492. projectsOne = append(projectsOne, item)
  493. }
  494. }
  495. }
  496. }
  497. } else {
  498. for _, item := range projects {
  499. projectsOne = append(projectsOne, item)
  500. }
  501. }
  502. team_projects = RemoveRepeatedCheckRecod(team_projects)
  503. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  504. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  505. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  506. var his_advices []*models.HisDoctorAdviceInfo
  507. var his_advices_one []*models.HisDoctorAdviceInfo
  508. if is_open_config.IsOpen == 1 {
  509. // 先走redis,没有走数据库
  510. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  511. }
  512. //针对茂名舒和
  513. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  514. if len(his_advices) > 0 {
  515. for _, item := range his_advices {
  516. drug, _ := service.GetDrugIsShow(item.DrugId, adminInfo.Org.Id)
  517. if drug.IsShow == 1 {
  518. his_advices_one = append(his_advices_one, item)
  519. }
  520. }
  521. }
  522. } else {
  523. if len(his_advices) > 0 {
  524. for _, item := range his_advices {
  525. his_advices_one = append(his_advices_one, item)
  526. }
  527. }
  528. }
  529. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  530. if is_advice_open.IsAdviceOpen == 1 {
  531. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  532. }
  533. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  534. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  535. var remind_lists []models.XtCheckRemind
  536. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  537. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  538. }
  539. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  540. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  541. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  542. lastMonitor, _ := service.GetLastMonitor(patientID, date.Unix(), adminInfo.Org.Id)
  543. firstMonitor, _ := service.GetFirstMonitorOne(patientID, date.Unix(), adminInfo.Org.Id)
  544. returnData := map[string]interface{}{
  545. "patient": patient,
  546. "schedual": schedual,
  547. "prescription": dialysisPrescribe,
  548. "solution": dialysisSolution,
  549. "last_prescription": lastDialysisPrescribe,
  550. "receiver_treatment_access": receiverTreatmentAccess,
  551. "predialysis_evaluation": predialysisEvaluation,
  552. "doctor_advices": doctorAdvices,
  553. "double_check": doubleCheck,
  554. "assessment_after_dislysis": assessmentAfterDislysis,
  555. "treatment_summary": treatmentSummary,
  556. "monitor_records": monitorRecords,
  557. "dialysis_order": dialysisOrder,
  558. "operators": operators,
  559. "last_predialysis_evaluation": lastPredialysisEvaluation,
  560. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  561. "last_monitor_record": lastMonitorRecord,
  562. "config": gobalConfig,
  563. "dry_weight": lastDryWeightDislysis,
  564. "system_prescription": systemDialysisPrescribe,
  565. "his_advices": his_advices_one,
  566. "is_open_config": is_open_config,
  567. "stockType": stockType,
  568. "prepare": prepare,
  569. "lastAssessment": lastAssessment,
  570. "prescribeOne": prescribeOne,
  571. "is_project_open_config": is_project_open_config,
  572. "project": projectsOne,
  573. "team_projects": team_projects,
  574. "is_advice_open": is_advice_open,
  575. "prescription_open": prescriptionConfig.IsOpen,
  576. "lastOrder": lastOrder,
  577. "remind_lists": remind_lists,
  578. "lastDialysisPrescription": lastDialysisPrescription,
  579. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  580. "dryWeightList": dryWeightList,
  581. "firstMonitor": firstMonitor,
  582. "lastMonitor": lastMonitor,
  583. }
  584. this.ServeSuccessJSON(returnData)
  585. }
  586. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  587. adminInfo := c.GetMobileAdminUserInfo()
  588. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  589. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  590. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  591. returnData := map[string]interface{}{
  592. "admin_users": adminUsers,
  593. "devices": devices,
  594. "device_numbers": device_numbers,
  595. }
  596. c.ServeSuccessJSON(returnData)
  597. }
  598. func (c *DialysisAPIController) PostAtreatmentInfo() {
  599. id, _ := c.GetInt64("patient", 0)
  600. recordDateStr := c.GetString("record_date")
  601. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  602. summaryContent := c.GetString("summaryContent")
  603. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  604. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  605. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  606. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  607. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  608. nursingRecord := c.GetString("nursing_record")
  609. fmt.Println("护理记录", nursingRecord)
  610. specialRecord := c.GetString("special_record")
  611. fmt.Println("特殊记录", specialRecord)
  612. adminUserInfo := c.GetMobileAdminUserInfo()
  613. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  614. checkStaffId = adminUserInfo.AdminUser.Id
  615. deboardNurseId = adminUserInfo.AdminUser.Id
  616. treatDoctor = adminUserInfo.AdminUser.Id
  617. if id <= 0 {
  618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  619. return
  620. }
  621. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  622. if patient.ID == 0 {
  623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  624. return
  625. }
  626. if len(recordDateStr) == 0 {
  627. recordDateStr = time.Now().Format("2006-01-02")
  628. }
  629. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  630. if parseDateErr != nil {
  631. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  633. return
  634. }
  635. summary := models.TreatmentSummary{
  636. UserOrgId: adminUserInfo.Org.Id,
  637. PatientId: id,
  638. AssessmentDate: recordDate.Unix(),
  639. Mission: propagandaAndEducationContent,
  640. DialysisSummary: summaryContent,
  641. SjNurse: changeMedicalNurseId,
  642. ZlNurse: treatNurseId,
  643. HdNurse: checkStaffId,
  644. XjNurse: deboardNurseId,
  645. ZlDoctor: treatDoctor,
  646. CreatedTime: time.Now().Unix(),
  647. Status: 1,
  648. NursingRecord: nursingRecord,
  649. SpecialRecord: specialRecord,
  650. }
  651. // 查询信息规挡的设置天数
  652. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  653. if infor.ID > 0 && infor.WeekDay > 0 {
  654. var cha_time int64
  655. timeNowStr := time.Now().Format("2006-01-02")
  656. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  657. //今日的日期减去设置的日期
  658. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  659. if cha_time >= recordDate.Unix() {
  660. //查询审核是否允许
  661. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  662. //申请状态不允许的情况 拒绝修改
  663. if infor.ApplicationStatus != 1 {
  664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  665. return
  666. }
  667. }
  668. }
  669. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  670. if treatmentSummary.ID == 0 { //新增
  671. summary.Creater = adminUserInfo.AdminUser.Id
  672. service.AddSigleSummaryRecord(&summary)
  673. finish := models.XtDialysisFinish{
  674. IsFinish: 1,
  675. UserOrgId: adminUserInfo.Org.Id,
  676. Status: 1,
  677. Ctime: time.Now().Unix(),
  678. Mtime: 0,
  679. Module: 10,
  680. RecordDate: recordDate.Unix(),
  681. Sourse: 1,
  682. PatientId: id,
  683. }
  684. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  685. if dialysisFinish.ID == 0 {
  686. service.CreateDialysisFinish(finish)
  687. }
  688. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  689. redis := service.RedisClient()
  690. //清空key 值
  691. redis.Set(key, "", time.Second)
  692. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  693. redis.Set(keyOne, "", time.Second)
  694. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  695. redis.Set(keyThree, "", time.Second)
  696. defer redis.Close()
  697. c.ServeSuccessJSON(map[string]interface{}{
  698. "summary": summary,
  699. })
  700. } else { //修改
  701. summary.Creater = treatmentSummary.Creater
  702. summary.CreatedTime = treatmentSummary.CreatedTime
  703. summary.Modifier = adminUserInfo.AdminUser.Id
  704. summary.ID = treatmentSummary.ID
  705. service.UpdateSummeRecord(&summary)
  706. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  707. redis := service.RedisClient()
  708. //清空key 值
  709. redis.Set(key, "", time.Second)
  710. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  711. redis.Set(keyOne, "", time.Second)
  712. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  713. redis.Set(keyThree, "", time.Second)
  714. defer redis.Close()
  715. c.ServeSuccessJSON(map[string]interface{}{
  716. "summary": summary,
  717. })
  718. }
  719. }
  720. func (c *DialysisAPIController) PostDoubleCheck() {
  721. id, _ := c.GetInt64("patient", 0)
  722. recordDateStr := c.GetString("record_date")
  723. checkTimeStr := c.GetString("check_time")
  724. firstCheckTimeStr := c.GetString("first_check_time")
  725. creater, _ := c.GetInt64("creater", 0)
  726. modifier, _ := c.GetInt64("modifier", 0)
  727. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  728. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  729. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  730. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  731. dialysis_item_desc := c.GetString("dialysis_item_desc")
  732. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  733. vascular_access_desc := c.GetString("vascular_access_desc")
  734. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  735. collator, _ := c.GetInt64("collator", 0)
  736. employee_number := c.GetString("employee_number")
  737. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  738. needle_batch_number := c.GetString("needle_batch_number")
  739. if id <= 0 {
  740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  741. return
  742. }
  743. adminUserInfo := c.GetMobileAdminUserInfo()
  744. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  745. if patient.ID == 0 {
  746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  747. return
  748. }
  749. if len(recordDateStr) == 0 {
  750. recordDateStr = time.Now().Format("2006-01-02")
  751. }
  752. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  753. if parseDateErr != nil {
  754. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  756. return
  757. }
  758. var checkDate int64
  759. if len(checkTimeStr) == 0 {
  760. checkDate = 0
  761. } else {
  762. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  763. checkDate = checkDateUnix.Unix()
  764. }
  765. var firstCheckDate int64
  766. if len(firstCheckTimeStr) == 0 {
  767. firstCheckDate = 0
  768. } else {
  769. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  770. firstCheckDate = firstCheckDateUnix.Unix()
  771. }
  772. if adminUserInfo.Org.Id == 10644 {
  773. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  774. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  775. if check.ID == 0 {
  776. if employee_number != list.JobNumber {
  777. c.ServeSuccessJSON(map[string]interface{}{
  778. "doubleCheck": check,
  779. "msg": "2",
  780. })
  781. return
  782. }
  783. }
  784. if check.ID > 0 {
  785. if employee_number != list.JobNumber {
  786. c.ServeSuccessJSON(map[string]interface{}{
  787. "doubleCheck": check,
  788. "msg": "2",
  789. })
  790. return
  791. }
  792. }
  793. }
  794. doubleCheck := models.DoubleCheck{
  795. UserOrgId: adminUserInfo.Org.Id,
  796. PatientId: id,
  797. DialysisItemCheck: dialysis_item_check,
  798. DialysisParameterCheck: dialysis_parameter_check,
  799. VascularAccessVerification: vascular_access_verification,
  800. PipelineConnectionCheck: pipeline_connection_check,
  801. DialysisItemDesc: dialysis_item_desc,
  802. DialysisParameterDesc: dialysis_parameter_desc,
  803. VascularAccessDesc: vascular_access_desc,
  804. PipelineConnectionDesc: pipeline_connection_desc,
  805. Collator: collator,
  806. Status: 1,
  807. CreatedTime: time.Now().Unix(),
  808. CheckDate: recordDate.Unix(),
  809. UpdatedTime: time.Now().Unix(),
  810. EmployeeNumber: employee_number,
  811. DialyzerBatchNumber: dialyzer_batch_number,
  812. NeedleBatchNumber: needle_batch_number,
  813. }
  814. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  815. if check.ID == 0 { //新增
  816. doubleCheck.FirstCheckTime = firstCheckDate
  817. doubleCheck.CheckTime = checkDate
  818. doubleCheck.Creater = creater
  819. doubleCheck.Modifier = modifier
  820. if adminUserInfo.Org.Id == 10340 {
  821. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  822. doubleCheck.Creater = order.StartNurse
  823. }
  824. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  825. //查询未核对的医嘱
  826. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  827. for _, advice := range doctorList {
  828. if advice.ExecutionStaff == modifier {
  829. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  830. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  831. return
  832. }
  833. }
  834. }
  835. // 查询信息规挡的设置天数
  836. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  837. if infor.ID > 0 && infor.WeekDay > 0 {
  838. var cha_time int64
  839. timeNowStr := time.Now().Format("2006-01-02")
  840. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  841. //今日的日期减去设置的日期
  842. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  843. if cha_time >= recordDate.Unix() {
  844. //查询审核是否允许
  845. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  846. //申请状态不允许的情况 拒绝修改
  847. if infor.ApplicationStatus != 1 {
  848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  849. return
  850. }
  851. }
  852. }
  853. err := service.AddSigleDoubleCheck(&doubleCheck)
  854. finish := models.XtDialysisFinish{
  855. IsFinish: 1,
  856. UserOrgId: adminUserInfo.Org.Id,
  857. Status: 1,
  858. Ctime: time.Now().Unix(),
  859. Mtime: 0,
  860. Module: 5,
  861. RecordDate: recordDate.Unix(),
  862. Sourse: 1,
  863. PatientId: id,
  864. }
  865. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  866. if dialysisFinish.ID == 0 {
  867. service.CreateDialysisFinish(finish)
  868. }
  869. //针对长沙南雅
  870. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  871. //查询未核对的医嘱
  872. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  873. if len(doctorList) > 0 && modifier > 0 {
  874. for _, advice := range doctorList {
  875. service.UpdateDoctorAdviceList(advice.ID, modifier)
  876. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  877. redis := service.RedisClient()
  878. //清空key 值
  879. redis.Set(key, "", time.Second)
  880. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  881. redis.Set(keyTwo, "", time.Second)
  882. theTime := time.Now()
  883. recordDate := theTime.Format("2006-01-02")
  884. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  885. redis.Set(keyFour, "", time.Second)
  886. defer redis.Close()
  887. }
  888. }
  889. }
  890. //针对溪康
  891. if adminUserInfo.Org.Id == 10721 {
  892. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  893. if len(adviceInfoList) > 0 {
  894. for _, item := range adviceInfoList {
  895. service.UpdateHisAdviceList(item.ID, creater)
  896. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  897. redis := service.RedisClient()
  898. //清空key 值
  899. redis.Set(key, "", time.Second)
  900. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  901. redis.Set(keyTwo, "", time.Second)
  902. theTime := time.Now()
  903. recordDate := theTime.Format("2006-01-02")
  904. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  905. redis.Set(keyFour, "", time.Second)
  906. defer redis.Close()
  907. }
  908. }
  909. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  910. if len(adviceList) > 0 {
  911. for _, item := range adviceList {
  912. service.UpdateAdviceList(item.ID, creater)
  913. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  914. redis := service.RedisClient()
  915. //清空key 值
  916. redis.Set(key, "", time.Second)
  917. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  918. redis.Set(keyTwo, "", time.Second)
  919. theTime := time.Now()
  920. recordDate := theTime.Format("2006-01-02")
  921. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  922. redis.Set(keyFour, "", time.Second)
  923. defer redis.Close()
  924. }
  925. }
  926. }
  927. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  928. redis := service.RedisClient()
  929. //清空key 值
  930. redis.Set(key, "", time.Second)
  931. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  932. redis.Set(keyOne, "", time.Second)
  933. defer redis.Close()
  934. if err == nil {
  935. c.ServeSuccessJSON(map[string]interface{}{
  936. "doubleCheck": &doubleCheck,
  937. })
  938. }
  939. } else { //修改
  940. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  941. if infor.ID > 0 {
  942. var cha_time int64
  943. timeNowStr := time.Now().Format("2006-01-02")
  944. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  945. //今日的日期减去设置的日期
  946. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  947. if cha_time >= recordDate.Unix() {
  948. //查询审核是否允许
  949. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  950. //申请状态不允许的情况 拒绝修改
  951. if infor.ApplicationStatus != 1 {
  952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  953. return
  954. }
  955. }
  956. }
  957. doubleCheck.FirstCheckTime = firstCheckDate
  958. doubleCheck.CheckTime = checkDate
  959. doubleCheck.Creater = creater
  960. doubleCheck.Modifier = modifier
  961. doubleCheck.CreatedTime = check.CreatedTime
  962. doubleCheck.ID = check.ID
  963. doubleCheck.EmployeeNumber = employee_number
  964. doubleCheck.NeedleBatchNumber = needle_batch_number
  965. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  966. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  967. //查询未核对的医嘱
  968. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  969. for _, advice := range doctorList {
  970. if advice.ExecutionStaff == modifier {
  971. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  972. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  973. return
  974. }
  975. }
  976. }
  977. //针对溪康
  978. if adminUserInfo.Org.Id == 10721 {
  979. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  980. if len(adviceInfoList) > 0 {
  981. for _, item := range adviceInfoList {
  982. service.UpdateHisAdviceList(item.ID, creater)
  983. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  984. redis := service.RedisClient()
  985. //清空key 值
  986. redis.Set(key, "", time.Second)
  987. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  988. redis.Set(keyTwo, "", time.Second)
  989. theTime := time.Now()
  990. recordDate := theTime.Format("2006-01-02")
  991. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  992. redis.Set(keyFour, "", time.Second)
  993. defer redis.Close()
  994. }
  995. }
  996. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  997. if len(adviceList) > 0 {
  998. for _, item := range adviceList {
  999. service.UpdateAdviceList(item.ID, creater)
  1000. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1001. redis := service.RedisClient()
  1002. //清空key 值
  1003. redis.Set(key, "", time.Second)
  1004. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1005. redis.Set(keyTwo, "", time.Second)
  1006. theTime := time.Now()
  1007. recordDate := theTime.Format("2006-01-02")
  1008. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1009. redis.Set(keyFour, "", time.Second)
  1010. defer redis.Close()
  1011. }
  1012. }
  1013. }
  1014. err := service.UpdateDoubleCheck(&doubleCheck)
  1015. //针对长沙南雅
  1016. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  1017. //查询未核对的医嘱
  1018. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1019. if len(doctorList) > 0 && modifier > 0 {
  1020. for _, advice := range doctorList {
  1021. service.UpdateDoctorAdviceList(advice.ID, modifier)
  1022. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1023. redis := service.RedisClient()
  1024. //清空key 值
  1025. redis.Set(key, "", time.Second)
  1026. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1027. redis.Set(keyTwo, "", time.Second)
  1028. theTime := time.Now()
  1029. recordDate := theTime.Format("2006-01-02")
  1030. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1031. redis.Set(keyFour, "", time.Second)
  1032. defer redis.Close()
  1033. }
  1034. }
  1035. }
  1036. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1037. redis := service.RedisClient()
  1038. //清空key 值
  1039. redis.Set(key, "", time.Second)
  1040. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1041. redis.Set(keyOne, "", time.Second)
  1042. defer redis.Close()
  1043. if err == nil {
  1044. c.ServeSuccessJSON(map[string]interface{}{
  1045. "doubleCheck": &doubleCheck,
  1046. "msg": "1",
  1047. })
  1048. }
  1049. }
  1050. }
  1051. func (c *DialysisAPIController) PostAcceptsAssessment() {
  1052. id, _ := c.GetInt64("patient", 0)
  1053. recordDateStr := c.GetString("record_date")
  1054. way, _ := c.GetInt64("way", 0)
  1055. consciousness, _ := c.GetInt64("consciousness", 0)
  1056. appetite, _ := c.GetInt64("appetite", 0)
  1057. condition, _ := c.GetInt64("condition", 0)
  1058. posture, _ := c.GetInt64("posture")
  1059. sick_condition, _ := c.GetInt64("sick_condition", 0)
  1060. danger_level, _ := c.GetInt64("danger_level", 0)
  1061. intake, _ := c.GetInt64("intake", 0)
  1062. nutrition, _ := c.GetInt64("nutrition", 0)
  1063. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  1064. psychological_assessment_other := c.GetString("psychological_assessment_other")
  1065. score := c.GetString("score")
  1066. sick_condition_other := c.GetString("sick_condition_other")
  1067. //precaution, _ := c.GetInt64("precaution", 0)
  1068. precaution := c.GetString("precaution")
  1069. precaution_other := c.GetString("precaution_other")
  1070. psychological_other := c.GetString("psychological_other")
  1071. admission_number := c.GetString("admission_number")
  1072. tumble, _ := c.GetInt64("tumble")
  1073. diacrisis := c.GetString("diacrisis")
  1074. his_department := c.GetString("his_department")
  1075. his_bed := c.GetString("his_bed")
  1076. if id <= 0 {
  1077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1078. return
  1079. }
  1080. adminUserInfo := c.GetMobileAdminUserInfo()
  1081. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1082. if patient.ID == 0 {
  1083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1084. return
  1085. }
  1086. //now := time.Now()
  1087. //year, month, day := now.Date()
  1088. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1089. //todayTimeStamp := today_time.Unix()
  1090. if len(recordDateStr) == 0 {
  1091. recordDateStr = time.Now().Format("2006-01-02")
  1092. }
  1093. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1094. if parseDateErr != nil {
  1095. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. // 查询信息规挡的设置天数
  1100. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1101. if infor.ID > 0 && infor.WeekDay > 0 {
  1102. var cha_time int64
  1103. timeNowStr := time.Now().Format("2006-01-02")
  1104. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1105. //今日的日期减去设置的日期
  1106. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1107. if cha_time >= recordDate.Unix() {
  1108. //查询审核是否允许
  1109. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1110. //申请状态不允许的情况 拒绝修改
  1111. if infor.ApplicationStatus != 1 {
  1112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1113. return
  1114. }
  1115. }
  1116. }
  1117. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1118. if adminUserInfo.Org.Id == 10340 {
  1119. if condition == 1 {
  1120. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1121. if admission_number == "" {
  1122. admission_number = lastAcceptTreatment.AdmissionNumber
  1123. }
  1124. }
  1125. }
  1126. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1127. UserOrgId: adminUserInfo.Org.Id,
  1128. PatientId: id,
  1129. RecordDate: recordDate.Unix(),
  1130. Way: way,
  1131. Consciousness: consciousness,
  1132. Appetite: appetite,
  1133. Condition: condition,
  1134. SickCondition: sick_condition,
  1135. DangerLevel: danger_level,
  1136. Intake: intake,
  1137. Nutrition: nutrition,
  1138. PsychologicalAssessment: psychological_assessment,
  1139. PsychologicalAssessmentOther: psychological_assessment_other,
  1140. SickConditionOther: sick_condition_other,
  1141. Posture: posture,
  1142. CreatedTime: time.Now().Unix(),
  1143. UpdateTime: time.Now().Unix(),
  1144. Status: 1,
  1145. Score: score,
  1146. Precaution: precaution,
  1147. PrecautionOther: precaution_other,
  1148. PsychologicalOther: psychological_other,
  1149. AdmissionNumber: admission_number,
  1150. Tumble: tumble,
  1151. Diacrisis: diacrisis,
  1152. HisBed: his_bed,
  1153. HisDepartment: his_department,
  1154. }
  1155. if receiveTreatment.ID == 0 { //新增
  1156. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1157. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1158. finish := models.XtDialysisFinish{
  1159. IsFinish: 1,
  1160. UserOrgId: adminUserInfo.Org.Id,
  1161. Status: 1,
  1162. Ctime: time.Now().Unix(),
  1163. Mtime: 0,
  1164. Module: 2,
  1165. RecordDate: recordDate.Unix(),
  1166. Sourse: 1,
  1167. PatientId: id,
  1168. }
  1169. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1170. if dialysisFinish.ID == 0 {
  1171. service.CreateDialysisFinish(finish)
  1172. }
  1173. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1174. redis := service.RedisClient()
  1175. defer redis.Close()
  1176. //清空key 值
  1177. redis.Set(key, "", time.Second)
  1178. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1179. redis.Set(keyOne, "", time.Second)
  1180. if err == nil {
  1181. c.ServeSuccessJSON(map[string]interface{}{
  1182. "receiveTreatmentAsses": receiveTreatmentAsses,
  1183. })
  1184. }
  1185. } else { //修改
  1186. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1187. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1188. // if getPermissionErr != nil {
  1189. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1190. // return
  1191. // } else if headNursePermission == nil {
  1192. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1193. // return
  1194. // }
  1195. //}
  1196. // 查询信息规挡的设置天数
  1197. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1198. if infor.ID > 0 && infor.WeekDay > 0 {
  1199. var cha_time int64
  1200. timeNowStr := time.Now().Format("2006-01-02")
  1201. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1202. //今日的日期减去设置的日期
  1203. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1204. if cha_time >= recordDate.Unix() {
  1205. //查询审核是否允许
  1206. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1207. //申请状态不允许的情况 拒绝修改
  1208. if infor.ApplicationStatus != 1 {
  1209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1210. return
  1211. }
  1212. }
  1213. }
  1214. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1215. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1216. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1217. receiveTreatmentAsses.ID = receiveTreatment.ID
  1218. if adminUserInfo.Org.Id == 10340 {
  1219. if condition == 1 {
  1220. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1221. if receiveTreatmentAsses.AdmissionNumber == "" {
  1222. receiveTreatmentAsses.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  1223. }
  1224. }
  1225. }
  1226. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1227. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1228. redis := service.RedisClient()
  1229. defer redis.Close()
  1230. //清空key 值
  1231. redis.Set(key, "", time.Second)
  1232. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1233. redis.Set(keyOne, "", time.Second)
  1234. if err == nil {
  1235. c.ServeSuccessJSON(map[string]interface{}{
  1236. "receiveTreatmentAsses": receiveTreatmentAsses,
  1237. })
  1238. }
  1239. }
  1240. }
  1241. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1242. id, _ := c.GetInt64("patient", 0)
  1243. recordDateStr := c.GetString("record_date")
  1244. weightAfter, _ := c.GetFloat("weight_after", 0)
  1245. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1246. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1247. fmt.Println("weight_loss", weightReduce)
  1248. temperature, _ := c.GetFloat("temperature", 0)
  1249. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1250. breathing_rate := c.GetString("breathing_rate")
  1251. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1252. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1253. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1254. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1255. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1256. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1257. cruor := c.GetString("cruor")
  1258. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1259. internalFistula := c.GetString("internal_fistula")
  1260. catheter := c.GetString("catheter")
  1261. complications := c.GetString("complication")
  1262. remark := c.GetString("remark")
  1263. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1264. dialysis_intakes := c.GetString("dialysis_intakes")
  1265. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1266. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1267. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1268. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1269. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1270. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1271. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1272. patientGose, _ := c.GetInt64("patient_gose", 0)
  1273. inpatientDepartment := c.GetString("inpatient_department")
  1274. observationContent := c.GetString("observation_content")
  1275. observationContentOther := c.GetString("observation_content_other")
  1276. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1277. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1278. in_advance_reason := c.GetString("in_advance_reason")
  1279. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1280. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1281. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1282. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1283. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1284. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1285. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1286. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1287. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1288. is_eat, _ := c.GetInt64("is_eat", 0)
  1289. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1290. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1291. channels, _ := c.GetInt64("channel", 0)
  1292. return_blood, _ := c.GetInt64("return_blood", 0)
  1293. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1294. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1295. dialysis_during, _ := c.GetFloat("dialysis_during")
  1296. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1297. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1298. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1299. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1300. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1301. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1302. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1303. setting_pressure := c.GetString("setting_pressure")
  1304. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1305. diastolic_pressure := c.GetString("diastolic_pressure")
  1306. other_complication := c.GetString("other_complication")
  1307. ktv := c.GetString("ktv")
  1308. urr := c.GetString("urr")
  1309. hypertenison, _ := c.GetInt64("hypertenison")
  1310. hypopiesia, _ := c.GetInt64("hypopiesia")
  1311. leave_office_method, _ := c.GetInt64("leave_office_method")
  1312. lapse, _ := c.GetInt64("lapse")
  1313. consciousness, _ := c.GetInt64("consciousness")
  1314. fallrisk, _ := c.GetInt64("fallrisk")
  1315. machine_run := c.GetString("machine_run")
  1316. after_urea := c.GetString("after_urea")
  1317. pip_coagulation := c.GetString("pip_coagulation")
  1318. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1319. transfusion_volume := c.GetString("transfusion_volume")
  1320. last_after_weight := c.GetString("last_after_weight")
  1321. displace_liqui_value := c.GetString("displace_liqui_value")
  1322. if id <= 0 {
  1323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1324. return
  1325. }
  1326. adminUserInfo := c.GetMobileAdminUserInfo()
  1327. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1328. if patient.ID == 0 {
  1329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1330. return
  1331. }
  1332. if len(recordDateStr) == 0 {
  1333. recordDateStr = time.Now().Format("2006-01-02")
  1334. }
  1335. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1336. fmt.Println("parseDateErr", parseDateErr)
  1337. if parseDateErr != nil {
  1338. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1340. return
  1341. }
  1342. //now := time.Now()
  1343. //year, month, day := now.Date()
  1344. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1345. //todayTimeStamp := today_time.Unix()
  1346. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1347. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1348. UserOrgId: adminUserInfo.Org.Id,
  1349. PatientId: id,
  1350. AssessmentDate: recordDate.Unix(),
  1351. Temperature: temperature,
  1352. PulseFrequency: pulse_frequency,
  1353. BreathingRate: breathing_rate,
  1354. SystolicBloodPressure: systolic_blood_pressure,
  1355. DiastolicBloodPressure: diastolic_blood_pressure,
  1356. ActualUltrafiltration: actual_ultrafiltration,
  1357. ActualDisplacement: actual_displacement,
  1358. ActualTreatmentHour: actualtreatHour,
  1359. ActualTreatmentMinute: actualtreatmin,
  1360. WeightAfter: weightAfter,
  1361. AdditionalWeight: additionalWeight,
  1362. WeightLoss: weightReduce,
  1363. Cruor: cruor,
  1364. SymptomAfterDialysis: symptomsAfterDialysi,
  1365. InternalFistula: internalFistula,
  1366. Catheter: catheter,
  1367. Complication: complications,
  1368. DialysisIntakes: dialysateVolume,
  1369. CreatedTime: time.Now().Unix(),
  1370. UpdatedTime: time.Now().Unix(),
  1371. Status: 1,
  1372. Remark: remark,
  1373. BloodAccessPartId: blood_access_part_id,
  1374. BloodAccessPartOperaId: blood_access_part_opera_id,
  1375. DialysisIntakesUnit: dialysis_intakes_unit,
  1376. PuncturePointOozingBlood: puncturePointOozingBlood,
  1377. PuncturePointHaematoma: puncturePointHaematoma,
  1378. InternalFistulaTremorAc: internalFistulaTremorAc,
  1379. PatientGose: patientGose,
  1380. InpatientDepartment: inpatientDepartment,
  1381. ObservationContent: observationContent,
  1382. ObservationContentOther: observationContentOther,
  1383. DialysisProcess: dialysis_process,
  1384. InAdvanceMinute: in_advance_minute,
  1385. InAdvanceReason: in_advance_reason,
  1386. HemostasisMinute: hemostasis_minute,
  1387. HemostasisOpera: hemostasis_opera,
  1388. TremorNoise: tremor_noise,
  1389. DisequilibriumSyndrome: disequilibrium_syndrome,
  1390. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1391. ArterialTube: arterial_tube,
  1392. IntravenousTube: intravenous_tube,
  1393. Dialyzer: dialyzer,
  1394. InAdvanceReasonOther: in_advance_reason_other,
  1395. IsEat: is_eat,
  1396. CvcA: cvc_a,
  1397. CvcV: cvc_v,
  1398. Channel: channels,
  1399. ReturnBlood: return_blood,
  1400. RehydrationVolume: rehydration_volume,
  1401. DialysisDuring: dialysis_during,
  1402. StrokeVolume: stroke_volume,
  1403. BloodFlow: blood_flow,
  1404. SealingFluidDispose: sealing_fluid_dispose,
  1405. SealingFluidSpecial: sealing_fluid_special,
  1406. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1407. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1408. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1409. SettingPressure: setting_pressure,
  1410. DiastolicPressure: diastolic_pressure,
  1411. OtherComplication: other_complication,
  1412. Ktv: ktv,
  1413. Urr: urr,
  1414. Hypopiesia: hypopiesia,
  1415. Hypertenison: hypertenison,
  1416. Lapse: lapse,
  1417. LeaveOfficeMethod: leave_office_method,
  1418. Consciousness: consciousness,
  1419. Fallrisk: fallrisk,
  1420. MachineRun: machine_run,
  1421. AfterUrea: after_urea,
  1422. PipCoagulation: pip_coagulation,
  1423. AccumulatedBloodVolume: accumulated_blood_volume,
  1424. TransfusionVolume: transfusion_volume,
  1425. LastAfterWeight: last_after_weight,
  1426. DisplaceLiquiValue: displace_liqui_value,
  1427. }
  1428. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1429. // 查询信息规挡的设置天数
  1430. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1431. if infor.ID > 0 && infor.WeekDay > 0 {
  1432. var cha_time int64
  1433. timeNowStr := time.Now().Format("2006-01-02")
  1434. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1435. //今日的日期减去设置的日期
  1436. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1437. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1438. if cha_time >= recordDate.Unix() {
  1439. //查询审核是否允许
  1440. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1441. //申请状态不允许的情况 拒绝修改
  1442. if infor.ApplicationStatus != 1 {
  1443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1444. return
  1445. }
  1446. }
  1447. }
  1448. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1449. if assessmentAfter.ID == 0 { //新增
  1450. if appRole.UserType == 2 || appRole.UserType == 1 {
  1451. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1452. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1453. } else {
  1454. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1455. }
  1456. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1457. if assessmentAfterDislysis.UserOrgId != 10340 {
  1458. if assessmentAfterDislysis.WeightAfter == 0 {
  1459. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1460. }
  1461. }
  1462. if adminUserInfo.Org.Id == 10693 {
  1463. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1464. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1465. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1466. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1467. }
  1468. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1469. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1470. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1471. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1472. }
  1473. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1474. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1475. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1476. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1477. }
  1478. if assessmentAfterDislysis.PulseFrequency == 0 {
  1479. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1480. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1481. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1482. }
  1483. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1484. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1485. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1486. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1487. }
  1488. }
  1489. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1490. //记录日志
  1491. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1492. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1493. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1494. PatientId: assessmentAfterDislysis.PatientId,
  1495. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1496. Status: 1,
  1497. ErrLog: string(byterequest),
  1498. AdminUserId: adminUserInfo.AdminUser.Id,
  1499. Ctime: 0,
  1500. Mtime: 0,
  1501. Source: "手机端保存透后评估",
  1502. }
  1503. service.CreateAfterDialysisLog(afterDialysisLog)
  1504. finish := models.XtDialysisFinish{
  1505. IsFinish: 1,
  1506. UserOrgId: adminUserInfo.Org.Id,
  1507. Status: 1,
  1508. Ctime: time.Now().Unix(),
  1509. Mtime: 0,
  1510. Module: 9,
  1511. RecordDate: recordDate.Unix(),
  1512. Sourse: 1,
  1513. PatientId: id,
  1514. }
  1515. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1516. if dialysisFinish.ID == 0 {
  1517. service.CreateDialysisFinish(finish)
  1518. }
  1519. redis := service.RedisClient()
  1520. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1521. redis.Set(keyTwo, "", time.Second)
  1522. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1523. //清空key 值
  1524. redis.Set(key, "", time.Second)
  1525. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1526. redis.Set(keyOne, "", time.Second)
  1527. defer redis.Close()
  1528. if err == nil {
  1529. c.ServeSuccessJSON(map[string]interface{}{
  1530. "assessmentAfterDislysis": assessmentAfterDislysis,
  1531. })
  1532. }
  1533. return
  1534. } else { //修改
  1535. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1536. if infor.ID > 0 && infor.WeekDay > 0 {
  1537. var cha_time int64
  1538. timeNowStr := time.Now().Format("2006-01-02")
  1539. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1540. //今日的日期减去设置的日期
  1541. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1542. if cha_time >= recordDate.Unix() {
  1543. //查询审核是否允许
  1544. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1545. //申请状态不允许的情况 拒绝修改
  1546. if infor.ApplicationStatus != 1 {
  1547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1548. return
  1549. }
  1550. }
  1551. }
  1552. if appRole.UserType == 2 || appRole.UserType == 1 {
  1553. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1554. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1555. } else {
  1556. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1557. if assessmentAfterDislysis.Creater == 0 {
  1558. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1559. }
  1560. }
  1561. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1562. assessmentAfterDislysis.ID = assessmentAfter.ID
  1563. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1564. if assessmentAfterDislysis.UserOrgId != 10340 {
  1565. if assessmentAfterDislysis.WeightAfter == 0 {
  1566. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1567. }
  1568. }
  1569. if adminUserInfo.Org.Id == 10693 {
  1570. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1571. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1572. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1573. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1574. }
  1575. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1576. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1577. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1578. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1579. }
  1580. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1581. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1582. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1583. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1584. }
  1585. if assessmentAfterDislysis.PulseFrequency == 0 {
  1586. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1587. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1588. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1589. }
  1590. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1591. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1592. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1593. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1594. }
  1595. }
  1596. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1597. //记录日志
  1598. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1599. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1600. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1601. PatientId: assessmentAfterDislysis.PatientId,
  1602. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1603. Status: 1,
  1604. ErrLog: string(byterequest),
  1605. AdminUserId: adminUserInfo.AdminUser.Id,
  1606. Ctime: time.Now().Unix(),
  1607. Mtime: 0,
  1608. Source: "手机端修改保存透后评估",
  1609. }
  1610. service.CreateAfterDialysisLog(afterDialysisLog)
  1611. redis := service.RedisClient()
  1612. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1613. redis.Set(keyTwo, "", time.Second)
  1614. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1615. //清空key 值
  1616. redis.Set(key, "", time.Second)
  1617. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1618. redis.Set(keyOne, "", time.Second)
  1619. if err == nil {
  1620. c.ServeSuccessJSON(map[string]interface{}{
  1621. "assessmentAfterDislysis": assessmentAfterDislysis,
  1622. })
  1623. return
  1624. }
  1625. }
  1626. return
  1627. }
  1628. func (c *DialysisAPIController) PostDialysisPrescription() {
  1629. id, _ := c.GetInt64("patient", 0)
  1630. recordDateStr := c.GetString("record_date")
  1631. if id <= 0 {
  1632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1633. return
  1634. }
  1635. adminUserInfo := c.GetMobileAdminUserInfo()
  1636. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1637. if patient.ID == 0 {
  1638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1639. return
  1640. }
  1641. if len(recordDateStr) == 0 {
  1642. recordDateStr = time.Now().Format("2006-01-02")
  1643. }
  1644. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1645. if parseDateErr != nil {
  1646. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1648. return
  1649. }
  1650. mode_id, _ := c.GetInt64("mode_id", 0)
  1651. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1652. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1653. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1654. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1655. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1656. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1657. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1658. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1659. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1660. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1661. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1662. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1663. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1664. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1665. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1666. kalium, _ := c.GetFloat("kalium", 0)
  1667. sodium, _ := c.GetFloat("sodium", 0)
  1668. calcium, _ := c.GetFloat("calcium", 0)
  1669. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1670. glucose, _ := c.GetFloat("glucose", 0)
  1671. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1672. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1673. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1674. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1675. conductivity, _ := c.GetFloat("conductivity", 0)
  1676. remark := c.GetString("remark")
  1677. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1678. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1679. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1680. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1681. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1682. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1683. special_medicine_other := c.GetString("special_medicine_other")
  1684. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1685. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1686. blood_access, _ := c.GetInt64("blood_access", 0)
  1687. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1688. body_fluid_other := c.GetString("body_fluid_other")
  1689. niprocart, _ := c.GetInt64("niprocart", 0)
  1690. jms, _ := c.GetInt64("jms", 0)
  1691. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1692. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1693. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1694. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1695. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1696. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1697. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1698. injector, _ := c.GetInt64("injector", 0)
  1699. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1700. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1701. safe_package, _ := c.GetInt64("package", 0)
  1702. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1703. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1704. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1705. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1706. blood := c.GetString("blood")
  1707. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1708. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1709. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1710. displace_speed := c.GetString("displace_speed")
  1711. illness, _ := c.GetInt64("illness")
  1712. amylaceum := c.GetString("amylaceum")
  1713. single_time := c.GetString("single_time")
  1714. single_water := c.GetString("single_water")
  1715. replacement_flow := c.GetString("replacement_flow")
  1716. plasma_separator := c.GetString("plasma_separator")
  1717. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1718. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1719. oxygen_flow := c.GetString("oxygen_flow")
  1720. oxygen_time := c.GetString("oxygen_time")
  1721. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1722. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1723. puncture_needle := c.GetString("puncture_needle")
  1724. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1725. epo := c.GetString("epo")
  1726. epo_count, _ := c.GetFloat("epo_count", 0)
  1727. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1728. admin_user_id, _ := c.GetInt64("admin_user_id")
  1729. is_water := c.GetString("is_water")
  1730. var is_war int64
  1731. if is_water == "是" {
  1732. is_war = 1
  1733. }
  1734. if is_water == "否" {
  1735. is_war = 2
  1736. }
  1737. if is_water == "请选择" {
  1738. is_war = 0
  1739. }
  1740. drhy_water := c.GetString("drhy_water")
  1741. dry_water_hour := c.GetString("dry_water_hour")
  1742. water_machine := c.GetString("water_machine")
  1743. add_amount, _ := c.GetFloat("add_amount")
  1744. reduce_amount, _ := c.GetFloat("reduce_amount")
  1745. dialysis_remark := c.GetString("dialysis_remark")
  1746. prescribing_number, _ := c.GetFloat("prescribing_number")
  1747. prescription_sodium := c.GetString("prescription_sodium")
  1748. start_sodium := c.GetString("start_sodium")
  1749. sodium_curve := c.GetString("sodium_curve")
  1750. treatment_remark := c.GetString("treatment_remark")
  1751. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1752. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1753. prescription_water, _ := c.GetFloat("prescription_water")
  1754. dialysis_strainer := c.GetString("dialysis_strainer")
  1755. chaptalization := c.GetString("chaptalization")
  1756. washing_time := c.GetString("washing_time")
  1757. warsh_count := c.GetString("warsh_count")
  1758. blood_access_part_id := c.GetString("blood_access_part_id")
  1759. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1760. dialyzate := c.GetString("dialyzate")
  1761. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1762. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1763. //
  1764. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1765. // if appRole.UserType == 3 {
  1766. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1767. // if getPermissionErr != nil {
  1768. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1769. // return
  1770. // } else if headNursePermission == nil {
  1771. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1772. // return
  1773. // }
  1774. // }
  1775. //}
  1776. // 查询信息规挡的设置天数
  1777. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1778. if infor.ID > 0 && infor.WeekDay > 0 {
  1779. var cha_time int64
  1780. timeNowStr := time.Now().Format("2006-01-02")
  1781. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1782. //今日的日期减去设置的日期
  1783. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1784. if cha_time >= recordDate.Unix() {
  1785. //查询审核是否允许
  1786. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1787. //申请状态不允许的情况 拒绝修改
  1788. if infor.ApplicationStatus != 1 {
  1789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1790. return
  1791. }
  1792. }
  1793. }
  1794. if mode_id > 0 {
  1795. var str string
  1796. //查找该机构用的是什么透析器
  1797. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1798. if filedConfig.ID > 0 {
  1799. str = dialyzerPerfusionApparatus
  1800. } else {
  1801. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1802. }
  1803. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1804. }
  1805. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  1806. var dialysis_dialyszers_id int64
  1807. var dialysis_strainer_id int64
  1808. var dialysis_irrigation_id int64
  1809. if len(goodList) > 0 {
  1810. for _, item := range goodList {
  1811. if item.SpecificationName == dialysis_dialyszers {
  1812. dialysis_dialyszers_id = item.ID
  1813. }
  1814. if item.SpecificationName == dialysis_irrigation {
  1815. dialysis_irrigation_id = item.ID
  1816. }
  1817. if item.SpecificationName == dialysis_strainer {
  1818. dialysis_strainer_id = item.ID
  1819. }
  1820. }
  1821. }
  1822. //TODO 需要根据角色去判断
  1823. prescription := models.DialysisPrescription{
  1824. UserOrgId: adminUserInfo.Org.Id,
  1825. PatientId: id,
  1826. RecordDate: recordDate.Unix(),
  1827. ModeId: mode_id,
  1828. DialysisDuration: dialysis_duration,
  1829. Dialyzer: dialyzer,
  1830. PerfusionApparatus: perfusion_apparatus,
  1831. BloodFlowVolume: blood_flow_volume,
  1832. DewaterAmount: dewater_amount,
  1833. DisplaceLiqui: displace_liqui,
  1834. ReplacementWay: replacement_way,
  1835. Anticoagulant: anticoagulant,
  1836. AnticoagulantShouji: anticoagulant_shouji,
  1837. AnticoagulantWeichi: anticoagulant_weichi,
  1838. AnticoagulantZongliang: anticoagulant_zongliang,
  1839. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1840. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1841. Kalium: kalium,
  1842. Sodium: sodium,
  1843. Calcium: calcium,
  1844. Bicarbonate: bicarbonate,
  1845. Glucose: glucose,
  1846. // DryWeight: dry_weight,
  1847. DialysateFlow: dialysate_flow,
  1848. DialysateTemperature: dialysate_temperature,
  1849. // PrescriptionDoctor: prescription_doctor,
  1850. ReplacementTotal: replacement_total,
  1851. Conductivity: conductivity,
  1852. Remark: remark,
  1853. Status: 1,
  1854. CreatedTime: time.Now().Unix(),
  1855. UpdatedTime: time.Now().Unix(),
  1856. DialysisDurationMinute: dialysisDurationMinute,
  1857. DialysisDurationHour: dialysisDurationHour,
  1858. TargetUltrafiltration: targetUltrafiltration,
  1859. DialysateFormulation: dialysateFormulation,
  1860. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1861. BodyFluid: body_fluid,
  1862. SpecialMedicine: special_medicine,
  1863. SpecialMedicineOther: special_medicine_other,
  1864. DisplaceLiquiPart: displace_liqui_part,
  1865. DisplaceLiquiValue: displace_liqui_value,
  1866. BloodAccess: blood_access,
  1867. Ultrafiltration: ultrafiltration,
  1868. BodyFluidOther: body_fluid_other,
  1869. Niprocart: niprocart,
  1870. Jms: jms,
  1871. FistulaNeedleSet: fistula_needle_set,
  1872. FistulaNeedleSet16: fistula_needle_set_16,
  1873. Hemoperfusion: hemoperfusion,
  1874. DialyserSterilised: dialyser_sterilised,
  1875. Filtryzer: filtryzer,
  1876. Dialyzers: dialyzers,
  1877. Injector: injector,
  1878. Bloodlines: bloodlines,
  1879. TubingHemodialysis: tubing_hemodialysis,
  1880. Package: safe_package,
  1881. ALiquid: a_liquid,
  1882. TargetKtv: target_ktv,
  1883. PreImpulse: pre_impulse,
  1884. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1885. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1886. Blood: blood,
  1887. DialysisDialyszers: dialysis_dialyszers,
  1888. DialysisIrrigation: dialysis_irrigation,
  1889. AntioxidantCommodityName: antioxidant_commodity_name,
  1890. DisplaceSpeed: displace_speed,
  1891. Illness: illness,
  1892. Amylaceum: amylaceum,
  1893. SingleTime: single_time,
  1894. SingleWater: single_water,
  1895. ReplacementFlow: replacement_flow,
  1896. PlasmaSeparator: plasma_separator,
  1897. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1898. OxygenUptake: oxygen_uptake,
  1899. OxygenFlow: oxygen_flow,
  1900. OxygenTime: oxygen_time,
  1901. HemodialysisPipelines: hemodialysis_pipelines,
  1902. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1903. PunctureNeedle: puncture_needle,
  1904. PunctureNeedleCount: puncture_needle_count,
  1905. Epo: epo,
  1906. EpoCount: epo_count,
  1907. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1908. AdminUserId: admin_user_id,
  1909. IsWater: is_war,
  1910. DrhyWater: drhy_water,
  1911. DryWaterHour: dry_water_hour,
  1912. WaterMachine: water_machine,
  1913. AddAmount: add_amount,
  1914. ReduceAmount: reduce_amount,
  1915. DialysisRemark: dialysis_remark,
  1916. PrescribingNumber: prescribing_number,
  1917. StartSodium: start_sodium,
  1918. SodiumCurve: sodium_curve,
  1919. TreatmentRemark: treatment_remark,
  1920. PrescriptionSodium: prescription_sodium,
  1921. DialysisFluidFlow: dialysis_fluid_flow,
  1922. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1923. PrescriptionWater: prescription_water,
  1924. DialysisStrainer: dialysis_strainer,
  1925. Chaptalization: chaptalization,
  1926. WashingTime: washing_time,
  1927. WarshCount: warsh_count,
  1928. BloodAccessPartId: blood_access_part_id,
  1929. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1930. Dialyzate: dialyzate,
  1931. DialysisDialyszersId: dialysis_dialyszers_id,
  1932. DialysisIrrigationId: dialysis_irrigation_id,
  1933. DialysisStrainerId: dialysis_strainer_id,
  1934. }
  1935. if adminUserInfo.Org.Id == 10721 {
  1936. if prescription.ModeId == 2 {
  1937. if prescription.ReplacementTotal == 0 {
  1938. prescription.ReplacementTotal = 15
  1939. }
  1940. }
  1941. }
  1942. //查询最近透析准备表里是否存在 透析器 灌流器
  1943. //
  1944. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1945. //
  1946. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1947. //
  1948. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1949. //if len(mation)>0{
  1950. // for _, item := range splitStr {
  1951. // for _,it := range mation{
  1952. // if(item == it.SpecificationName){
  1953. //
  1954. // //查询最近一次的透析器
  1955. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1956. //
  1957. // if errcode == gorm.ErrRecordNotFound{
  1958. // //插入数据
  1959. // prepare := models.DialysisBeforePrepare{
  1960. // UserOrgId: adminUserInfo.Org.Id,
  1961. // PatientId: id,
  1962. // RecordDate: recordDate.Unix(),
  1963. // GoodTypeId: it.GoodTypeId,
  1964. // GoodId: it.ID,
  1965. // Count: 1,
  1966. // Ctime: time.Now().Unix(),
  1967. // Creater: adminUserInfo.AdminUser.Id,
  1968. // Status:1,
  1969. //
  1970. // }
  1971. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1972. // fmt.Println("",errcode)
  1973. // }
  1974. // }
  1975. // }
  1976. //
  1977. // }
  1978. //
  1979. // for _, item := range splitIrrigation {
  1980. // for _,it := range mation{
  1981. // if(item == it.SpecificationName){
  1982. // //查询最近一次的透析器
  1983. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1984. // if errcode == gorm.ErrRecordNotFound{
  1985. // //插入数据
  1986. // prepare := models.DialysisBeforePrepare{
  1987. // UserOrgId: adminUserInfo.Org.Id,
  1988. // PatientId: id,
  1989. // RecordDate: recordDate.Unix(),
  1990. // GoodTypeId: it.GoodTypeId,
  1991. // GoodId: it.ID,
  1992. // Count: 1,
  1993. // Ctime: time.Now().Unix(),
  1994. // Creater: adminUserInfo.AdminUser.Id,
  1995. // Status:1,
  1996. //
  1997. // }
  1998. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1999. // fmt.Println(errcode)
  2000. // }
  2001. // }
  2002. // }
  2003. // }
  2004. //}
  2005. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2006. if dialysisPrescription.ID == 0 { //新增
  2007. if appRole.UserType == 2 || appRole.UserType == 1 {
  2008. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2009. }
  2010. prescription.Creater = adminUserInfo.AdminUser.Id
  2011. //针对河间咸得
  2012. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  2013. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  2014. prescription.DisplaceLiquiPart = 0
  2015. prescription.DisplaceLiquiValue = 0
  2016. }
  2017. }
  2018. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  2019. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  2020. }
  2021. err := service.AddSigleRecord(&prescription)
  2022. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2023. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  2024. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2025. if len(monitorList) > 0 {
  2026. var ultrafiltration_rate float64
  2027. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2028. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2029. var replacement_rate float64
  2030. //乘10 除10是为了保留一位小数
  2031. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2032. var firstOpeateTime = monitorList[0].OperateTime
  2033. for _, item := range monitorList {
  2034. //超滤率
  2035. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2036. //置换率
  2037. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2038. //超滤量
  2039. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2040. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2041. //置换量
  2042. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2043. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2044. }
  2045. }
  2046. }
  2047. //记录日志
  2048. byterequest, _ := json.Marshal(prescription)
  2049. prescriptionLog := models.XtDialysisPrescriptionLog{
  2050. UserOrgId: prescription.UserOrgId,
  2051. Ctime: time.Now().Unix(),
  2052. Mtime: 0,
  2053. ErrLog: string(byterequest),
  2054. AdminUserId: adminUserInfo.AdminUser.Id,
  2055. RecordDate: prescription.RecordDate,
  2056. PatientId: prescription.PatientId,
  2057. Source: "手机端新增保存处方",
  2058. Status: 1,
  2059. }
  2060. service.CreatePrescriptionLog(prescriptionLog)
  2061. finish := models.XtDialysisFinish{
  2062. IsFinish: 1,
  2063. UserOrgId: adminUserInfo.Org.Id,
  2064. Status: 1,
  2065. Ctime: time.Now().Unix(),
  2066. Mtime: 0,
  2067. Module: 1,
  2068. RecordDate: recordDate.Unix(),
  2069. Sourse: 1,
  2070. PatientId: id,
  2071. }
  2072. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2073. if dialysisFinish.ID == 0 {
  2074. service.CreateDialysisFinish(finish)
  2075. }
  2076. //长沙南雅医院,自动生成抗凝剂的临时处方
  2077. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2078. if prescribing_number == 0 {
  2079. prescribing_number = 1
  2080. }
  2081. if prescribing_number == 0 && id == 14682 {
  2082. prescribing_number = 2
  2083. }
  2084. if prescribing_number == 0 && id == 18560 {
  2085. prescribing_number = 2
  2086. }
  2087. advice := models.DoctorAdvice{
  2088. UserOrgId: adminUserInfo.Org.Id,
  2089. PatientId: id,
  2090. GroupNo: 0,
  2091. AdviceType: 2,
  2092. RecordDate: recordDate.Unix(),
  2093. AdviceDate: recordDate.Unix(),
  2094. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  2095. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  2096. AdviceDesc: "",
  2097. ReminderDate: 0,
  2098. SingleDose: anticoagulant_zongliang,
  2099. SingleDoseUnit: "iu",
  2100. DrugSpec: 0,
  2101. DrugSpecUnit: "",
  2102. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  2103. PrescribingNumberUnit: "支",
  2104. DeliveryWay: "静脉注射",
  2105. ExecutionFrequency: "上机前",
  2106. AdviceDoctor: 0,
  2107. Status: 1,
  2108. CreatedTime: time.Now().Unix(),
  2109. UpdatedTime: time.Now().Unix(),
  2110. IsPrescription: 1,
  2111. ExecutionState: 2,
  2112. StopState: 2,
  2113. IsSettle: 2,
  2114. }
  2115. // 查询排班信息
  2116. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2117. if schedulePatient.ID > 0 {
  2118. if schedulePatient.ScheduleType == 1 {
  2119. advice.StartTime = recordDate.Unix() + 6.5*60*60
  2120. }
  2121. if schedulePatient.ScheduleType == 2 {
  2122. advice.StartTime = recordDate.Unix() + 9*60*60
  2123. }
  2124. }
  2125. // 抗凝剂名称
  2126. switch anticoagulant {
  2127. case 1:
  2128. advice.AdviceName = "无肝素"
  2129. break
  2130. case 2:
  2131. advice.AdviceName = "普通肝素"
  2132. break
  2133. case 3:
  2134. advice.AdviceName = "低分子肝素"
  2135. break
  2136. case 4:
  2137. advice.AdviceName = "阿加曲班"
  2138. break
  2139. case 5:
  2140. advice.AdviceName = "枸橼酸钠"
  2141. break
  2142. case 6:
  2143. advice.AdviceName = "低分子肝素钙"
  2144. break
  2145. case 7:
  2146. advice.AdviceName = "低分子肝素钠"
  2147. break
  2148. case 8:
  2149. advice.AdviceName = "依诺肝素"
  2150. break
  2151. case 9:
  2152. advice.AdviceName = "达肝素"
  2153. break
  2154. case 10:
  2155. advice.AdviceName = "体外抗凝"
  2156. break
  2157. case 11:
  2158. advice.AdviceName = "那曲肝素"
  2159. break
  2160. case 12:
  2161. advice.AdviceName = "无抗凝剂"
  2162. break
  2163. }
  2164. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2165. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2166. advice.AdviceDoctor = appRole.AdminUserId
  2167. }
  2168. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2169. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2170. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2171. advice.AdviceName = "低分子肝素钠注射液"
  2172. // 修改患者临时医嘱里的抗凝剂医嘱
  2173. advice.ID = advicePrescription.ID
  2174. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2175. } else {
  2176. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2177. advice.AdviceName = "低分子肝素钠注射液"
  2178. // 新增患者临时医嘱里的抗凝剂医嘱
  2179. service.CreateDoctorAdvice(&advice)
  2180. }
  2181. }
  2182. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2183. redis := service.RedisClient()
  2184. defer redis.Close()
  2185. //清空key 值
  2186. redis.Set(key, "", time.Second)
  2187. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2188. redis.Set(keyOne, "", time.Second)
  2189. }
  2190. //获取key,清空redis
  2191. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2192. redis := service.RedisClient()
  2193. //清空key 值
  2194. redis.Set(key, "", time.Second)
  2195. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2196. //清空key 值
  2197. redis.Set(keyOne, "", time.Second)
  2198. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2199. //清空key 值
  2200. redis.Set(keyTwo, "", time.Second)
  2201. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2202. redis.Set(keySix, "", time.Second)
  2203. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2204. redis.Set(keySeven, "", time.Second)
  2205. if err == nil {
  2206. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2207. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2208. //清空key 值
  2209. redis.Set(keyThree, "", time.Second)
  2210. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2211. //清空key 值
  2212. redis.Set(keyFour, "", time.Second)
  2213. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2214. redis.Set(keyFive, "", time.Second)
  2215. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2216. redis.Set(keySix, "", time.Second)
  2217. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2218. redis.Set(keySeven, "", time.Second)
  2219. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2220. //清空key 值
  2221. redis.Set(keyOne, "", time.Second)
  2222. if updateErr != nil {
  2223. utils.ErrorLog("%v", updateErr)
  2224. }
  2225. defer redis.Close()
  2226. c.ServeSuccessJSON(map[string]interface{}{
  2227. "prescription": prescription,
  2228. })
  2229. }
  2230. } else { //修改
  2231. //if mode_id > 0 {
  2232. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2233. //}
  2234. //if template.TemplateId == 1 {
  2235. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2236. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2237. // if getPermissionErr != nil {
  2238. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2239. // return
  2240. // } else if headNursePermission == nil {
  2241. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2242. // return
  2243. // }
  2244. // }
  2245. //}
  2246. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2247. prescription.Modifier = adminUserInfo.AdminUser.Id
  2248. if appRole.UserType == 2 || appRole.UserType == 1 {
  2249. prescription_doctor := adminUserInfo.AdminUser.Id
  2250. prescription.PrescriptionDoctor = prescription_doctor
  2251. } else {
  2252. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2253. }
  2254. if dialysisPrescription.Creater == 0 { //体重称
  2255. prescription.Creater = adminUserInfo.AdminUser.Id
  2256. } else {
  2257. prescription.Creater = dialysisPrescription.Creater
  2258. if adminUserInfo.Org.Id == 9882 {
  2259. if appRole.UserType == 2 || appRole.UserType == 1 {
  2260. prescription_doctor := adminUserInfo.AdminUser.Id
  2261. prescription.PrescriptionDoctor = prescription_doctor
  2262. prescription.Creater = prescription_doctor
  2263. }
  2264. }
  2265. }
  2266. prescription.ID = dialysisPrescription.ID
  2267. if adminUserInfo.Org.Id == 10721 {
  2268. if prescription.ModeId == 2 {
  2269. if prescription.ReplacementTotal == 0 {
  2270. prescription.ReplacementTotal = 15
  2271. }
  2272. }
  2273. }
  2274. service.UpDateDialysisPrescription(&prescription)
  2275. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2276. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  2277. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2278. if len(monitorList) > 0 {
  2279. var ultrafiltration_rate float64
  2280. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2281. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2282. var replacement_rate float64
  2283. //乘10 除10是为了保留一位小数
  2284. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2285. var firstOpeateTime = monitorList[0].OperateTime
  2286. for _, item := range monitorList {
  2287. //超滤率
  2288. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2289. //置换率
  2290. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2291. //超滤量
  2292. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2293. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2294. //置换量
  2295. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2296. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2297. }
  2298. }
  2299. }
  2300. //记录日志
  2301. byterequest, _ := json.Marshal(prescription)
  2302. prescriptionLog := models.XtDialysisPrescriptionLog{
  2303. UserOrgId: prescription.UserOrgId,
  2304. Ctime: time.Now().Unix(),
  2305. Mtime: 0,
  2306. ErrLog: string(byterequest),
  2307. AdminUserId: adminUserInfo.AdminUser.Id,
  2308. RecordDate: prescription.RecordDate,
  2309. PatientId: prescription.PatientId,
  2310. Source: "手机端修改处方",
  2311. Status: 1,
  2312. }
  2313. service.CreatePrescriptionLog(prescriptionLog)
  2314. finish := models.XtDialysisFinish{
  2315. IsFinish: 1,
  2316. UserOrgId: adminUserInfo.Org.Id,
  2317. Status: 1,
  2318. Ctime: time.Now().Unix(),
  2319. Mtime: 0,
  2320. Module: 1,
  2321. RecordDate: recordDate.Unix(),
  2322. Sourse: 1,
  2323. PatientId: id,
  2324. }
  2325. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2326. if dialysisFinish.ID == 0 {
  2327. service.CreateDialysisFinish(finish)
  2328. }
  2329. //修改处方
  2330. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2331. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2332. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2333. if advicePrescription.ID > 0 {
  2334. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2335. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2336. redis := service.RedisClient()
  2337. defer redis.Close()
  2338. //清空key 值
  2339. redis.Set(key, "", time.Second)
  2340. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2341. redis.Set(keyOne, "", time.Second)
  2342. }
  2343. }
  2344. //获取key,清空redis
  2345. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2346. redis := service.RedisClient()
  2347. //清空key 值
  2348. redis.Set(key, "", time.Second)
  2349. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2350. //清空key 值
  2351. redis.Set(keyOne, "", time.Second)
  2352. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2353. redis.Set(keySix, "", time.Second)
  2354. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2355. redis.Set(keySeven, "", time.Second)
  2356. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2357. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2358. //清空key 值
  2359. redis.Set(keyTwoOne, "", time.Second)
  2360. defer redis.Close()
  2361. if updateErr != nil {
  2362. utils.ErrorLog("%v", updateErr)
  2363. }
  2364. c.ServeSuccessJSON(map[string]interface{}{
  2365. "prescription": prescription,
  2366. })
  2367. }
  2368. }
  2369. func (c *DialysisAPIController) Finish() {
  2370. id, _ := c.GetInt64("patient", 0)
  2371. recordDateStr := c.GetString("record_date")
  2372. nurseID, _ := c.GetInt64("nurse")
  2373. end_time := c.GetString("end_time")
  2374. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2375. internal_fistula := c.GetString("blood_access_internal_fistula")
  2376. catheter := c.GetString("catheter")
  2377. cruor := c.GetString("cruor")
  2378. mission := c.GetString("mission")
  2379. condenser := c.GetString("condenser")
  2380. if id <= 0 || nurseID <= 0 {
  2381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2382. return
  2383. }
  2384. adminUserInfo := c.GetMobileAdminUserInfo()
  2385. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2386. if patient.ID == 0 {
  2387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2388. return
  2389. }
  2390. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2391. if getNurseErr != nil {
  2392. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2394. return
  2395. } else if nurse == nil {
  2396. c.ErrorLog("护士不存在")
  2397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2398. return
  2399. }
  2400. if len(recordDateStr) == 0 {
  2401. recordDateStr = time.Now().Format("2006-01-02")
  2402. }
  2403. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2404. if parseDateErr != nil {
  2405. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2407. return
  2408. }
  2409. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2410. if parseEndDateErr != nil {
  2411. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2413. return
  2414. }
  2415. // 查询信息规挡的设置天数
  2416. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2417. if infor.ID > 0 && infor.WeekDay > 0 {
  2418. var cha_time int64
  2419. timeNowStr := time.Now().Format("2006-01-02")
  2420. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2421. //今日的日期减去设置的日期
  2422. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2423. if cha_time >= recordDate.Unix() {
  2424. //查询审核是否允许
  2425. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2426. //申请状态不允许的情况 拒绝修改
  2427. if infor.ApplicationStatus != 1 {
  2428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2429. return
  2430. }
  2431. }
  2432. }
  2433. //now := time.Now()
  2434. //year, month, day := now.Date()
  2435. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2436. //todayTimeStamp := today_time.Unix()
  2437. // 获取当天的第一条透析纪录
  2438. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2439. if getMonitorRecordsErr != nil {
  2440. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2442. return
  2443. }
  2444. // 获取当前的最后一条透析纪录
  2445. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2446. if getMonitorRecordsErr != nil {
  2447. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2449. return
  2450. }
  2451. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2452. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2453. if getAADErr != nil {
  2454. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2456. return
  2457. }
  2458. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2459. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2460. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2461. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2462. if assessmentAfterDislysis != nil {
  2463. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2464. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2465. } else {
  2466. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2467. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2468. tempassessmentAfterDislysis.Status = 1
  2469. tempassessmentAfterDislysis.PatientId = id
  2470. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2471. }
  2472. //长沙南雅
  2473. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2474. //获取最后一条透析处方数据
  2475. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2476. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2477. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2478. }
  2479. if dialysisOrder.Stage == 1 {
  2480. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2481. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2482. fmt.Println(value)
  2483. a, b := math.Modf(value)
  2484. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2485. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2486. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2487. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2488. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2489. }
  2490. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2491. //var num1 int64
  2492. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2493. //fmt.Println(num1)
  2494. //sub := float64(num1 / 3600)
  2495. //fmt.Println(sub)
  2496. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2497. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2498. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2499. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2500. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2501. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2502. if adminUserInfo.Org.Id != 10375 {
  2503. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2504. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2505. }
  2506. if adminUserInfo.Org.Id != 10445 {
  2507. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2508. }
  2509. //北方营口医院
  2510. if adminUserInfo.Org.Id == 10445 {
  2511. //获取最后一条透析处方数据
  2512. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2513. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2514. } else {
  2515. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2516. }
  2517. //新化博翔
  2518. if adminUserInfo.Org.Id == 10447 {
  2519. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2520. }
  2521. //阳春
  2522. if adminUserInfo.Org.Id == 10485 {
  2523. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2524. }
  2525. if adminUserInfo.Org.Id == 10551 {
  2526. //获取最后一条透析处方数据
  2527. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2528. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2529. }
  2530. if adminUserInfo.Org.Id == 10580 {
  2531. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2532. }
  2533. if adminUserInfo.Org.Id == 10612 {
  2534. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2535. }
  2536. //孝康
  2537. if adminUserInfo.Org.Id == 10693 {
  2538. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2539. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2540. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2541. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2542. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2543. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2544. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2545. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2546. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2547. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2548. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2549. }
  2550. if adminUserInfo.Org.Id == 10721 {
  2551. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2552. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2553. }
  2554. if adminUserInfo.Org.Id == 10697 {
  2555. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2556. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2557. lastWeightAfter.LastAfterWeight = floatAfeter
  2558. }
  2559. }
  2560. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 10243 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10414 || adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10693 || adminUserInfo.Org.Id == 10702 {
  2561. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2562. if adminUserInfo.Org.Id != 10702 {
  2563. if evaluation.SystolicBloodPressure == 0 {
  2564. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2565. if adminUserInfo.Org.Id == 10693 {
  2566. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2567. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2568. }
  2569. pre := models.PredialysisEvaluation{
  2570. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2571. }
  2572. fmt.Println("prew", pre)
  2573. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2574. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2575. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2576. redis := service.RedisClient()
  2577. redis.Set(key, "", time.Second)
  2578. redis.Set(keyOne, "", time.Second)
  2579. defer redis.Close()
  2580. fmt.Println(getNurseErr)
  2581. }
  2582. }
  2583. if adminUserInfo.Org.Id != 10702 {
  2584. if evaluation.DiastolicBloodPressure == 0 {
  2585. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2586. if adminUserInfo.Org.Id == 10693 {
  2587. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2588. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2589. }
  2590. pres := models.PredialysisEvaluation{
  2591. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2592. }
  2593. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2594. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2595. redis := service.RedisClient()
  2596. redis.Set(key, "", time.Second)
  2597. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2598. redis.Set(keyOne, "", time.Second)
  2599. defer redis.Close()
  2600. fmt.Println(getNurseErr)
  2601. }
  2602. }
  2603. if adminUserInfo.Org.Id != 10702 {
  2604. if evaluation.PulseFrequency == 0 {
  2605. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2606. if adminUserInfo.Org.Id == 10693 {
  2607. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2608. evaluation.PulseFrequency = pulseFrequency
  2609. }
  2610. press := models.PredialysisEvaluation{
  2611. PulseFrequency: evaluation.PulseFrequency,
  2612. }
  2613. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2614. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2615. redis := service.RedisClient()
  2616. redis.Set(key, "", time.Second)
  2617. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2618. redis.Set(keyOne, "", time.Second)
  2619. defer redis.Close()
  2620. fmt.Println(getNurseErr)
  2621. }
  2622. }
  2623. if evaluation.Temperature == 0 {
  2624. evaluation.Temperature = fmonitorRecords.Temperature
  2625. press := models.PredialysisEvaluation{
  2626. Temperature: evaluation.Temperature,
  2627. }
  2628. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2629. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2630. redis := service.RedisClient()
  2631. redis.Set(key, "", time.Second)
  2632. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2633. redis.Set(keyOne, "", time.Second)
  2634. defer redis.Close()
  2635. fmt.Println(getNurseErr)
  2636. }
  2637. }
  2638. if adminUserInfo.Org.Id == 9583 {
  2639. //获取透析处方的最后一条数据
  2640. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2641. if diaerr != nil {
  2642. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2644. return
  2645. }
  2646. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2647. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2648. }
  2649. }
  2650. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2651. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2652. }
  2653. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2654. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2655. }
  2656. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2657. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2658. }
  2659. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2660. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2661. }
  2662. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2663. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2664. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2665. }
  2666. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2667. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2668. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2669. }
  2670. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2671. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2672. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2673. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2674. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2675. }
  2676. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2677. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2678. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2679. }
  2680. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2681. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2682. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2683. }
  2684. if lastAssessmentAfterDislysis != nil {
  2685. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2686. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2687. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2688. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2689. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2690. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2691. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2692. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2693. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2694. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2695. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2696. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2697. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2698. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2699. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2700. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2701. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2702. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2703. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2704. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2705. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2706. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2707. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2708. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2709. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2710. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2711. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2712. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2713. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2714. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2715. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2716. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2717. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2718. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2719. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2720. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2721. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2722. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2723. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2724. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2725. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2726. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2727. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2728. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2729. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2730. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2731. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2732. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2733. if tempassessmentAfterDislysis.PatientId == 18695 {
  2734. tempassessmentAfterDislysis.ActualDisplacement = 0
  2735. }
  2736. if adminUserInfo.Org.Id != 10375 {
  2737. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2738. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2739. }
  2740. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2741. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2742. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2743. }
  2744. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2745. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2746. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2747. }
  2748. }
  2749. finish := models.XtDialysisFinish{
  2750. IsFinish: 1,
  2751. UserOrgId: adminUserInfo.Org.Id,
  2752. Status: 1,
  2753. Ctime: time.Now().Unix(),
  2754. Mtime: 0,
  2755. Module: 9,
  2756. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2757. Sourse: 1,
  2758. PatientId: tempassessmentAfterDislysis.PatientId,
  2759. }
  2760. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2761. if dialysisFinish.ID == 0 {
  2762. service.CreateDialysisFinish(finish)
  2763. }
  2764. //孝康
  2765. if adminUserInfo.Org.Id == 10693 {
  2766. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2767. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2768. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2769. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2770. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2771. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2772. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2773. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2774. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2775. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2776. }
  2777. if adminUserInfo.Org.Id == 10697 {
  2778. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2779. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2780. lastWeightAfter.LastAfterWeight = floatAfeter
  2781. }
  2782. if adminUserInfo.Org.Id == 10721 {
  2783. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2784. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2785. }
  2786. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2787. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2788. redis := service.RedisClient()
  2789. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2790. redis.Set(keyOne, "", time.Second)
  2791. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2792. redis.Set(keyTwo, "", time.Second)
  2793. defer redis.Close()
  2794. //清空key 值
  2795. redis.Set(key, "", time.Second)
  2796. if err != nil {
  2797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2798. return
  2799. }
  2800. if dialysisOrder == nil {
  2801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2802. return
  2803. }
  2804. if dialysisOrder.Stage == 2 {
  2805. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2806. return
  2807. }
  2808. if dialysisOrder.Stage == 1 {
  2809. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2810. finish := models.XtDialysisFinish{
  2811. IsFinish: 1,
  2812. UserOrgId: adminUserInfo.Org.Id,
  2813. Status: 1,
  2814. Ctime: time.Now().Unix(),
  2815. Mtime: 0,
  2816. Module: 8,
  2817. RecordDate: recordDate.Unix(),
  2818. Sourse: 1,
  2819. PatientId: id,
  2820. }
  2821. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2822. if dialysisFinish.ID == 0 {
  2823. service.CreateDialysisFinish(finish)
  2824. }
  2825. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2826. redis := service.RedisClient()
  2827. defer redis.Close()
  2828. //清空key 值
  2829. redis.Set(key, "", time.Second)
  2830. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2831. redis.Set(keyOne, "", time.Second)
  2832. //结束时候透析次数加1
  2833. service.UpdateSolutionByPatientId(id)
  2834. //下机完自动消毒,针对长沙南雅
  2835. if dialysisOrder.Stage == 1 {
  2836. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9538 || adminUserInfo.Org.Id == 10121 || adminUserInfo.Org.Id == 10612 {
  2837. //根据床位号获取设备型号
  2838. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2839. //查询使用消毒最后一条消毒记录
  2840. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2841. fmt.Println("err", err)
  2842. if err == gorm.ErrRecordNotFound {
  2843. //查找排班
  2844. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2845. //查询改设备是否有消毒计划
  2846. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2847. //根据床位号获取设备id
  2848. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2849. //查询病人信息
  2850. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2851. var con = ""
  2852. if patients.IsInfectious == 0 {
  2853. con = ""
  2854. }
  2855. if patients.IsInfectious == 1 {
  2856. con = "无"
  2857. }
  2858. if patients.IsInfectious == 2 {
  2859. con = "有"
  2860. }
  2861. if errcode == nil {
  2862. var end_time int64
  2863. end_time = endDate.Unix() + plan.DisinfecTime*60
  2864. //新增消毒
  2865. information := models.DeviceInformation{
  2866. Date: dialysisOrder.DialysisDate,
  2867. Zone: dialysisOrder.ZoneId,
  2868. Class: dialysisOrder.SchedualType,
  2869. BedNumber: dialysisOrder.BedID,
  2870. PatientId: dialysisOrder.PatientId,
  2871. DialysisMode: scheduleByPatient.ModeId,
  2872. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2873. Disinfection: 1,
  2874. DialysisConcentration: 1,
  2875. DisinfectionStatus: 1,
  2876. Move: 1,
  2877. UserOrgId: dialysisOrder.UserOrgId,
  2878. DisinfectType: plan.Way,
  2879. DisinfectantType: plan.MachineDisinfectant,
  2880. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2881. Disinfectant: plan.Disinfectant,
  2882. Ctime: time.Now().Unix(),
  2883. Status: 1,
  2884. SignName: nurseID,
  2885. EquimentId: addmacher.ID,
  2886. DisinfectionResidue: 2,
  2887. Bed: addmacher.BedNumber,
  2888. StartTime: dialysisOrder.StartTime,
  2889. EndTime: dialysisOrder.EndTime,
  2890. Contagion: con,
  2891. WeightLoss: 0,
  2892. Hyperfiltratio: 0,
  2893. DialysisHour: "",
  2894. MachineRun: 1,
  2895. DisinfecStartime: endDate.Unix(),
  2896. DisinfecEndtime: end_time,
  2897. }
  2898. err := service.CreateInformationTwo(&information)
  2899. fmt.Println("报错", err)
  2900. }
  2901. }
  2902. }
  2903. }
  2904. dialysisOrder.Stage = 2
  2905. dialysisOrder.FinishNurse = nurseID
  2906. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2907. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2908. dialysisOrder.EndTime = endDate.Unix()
  2909. // 长沙南雅需求
  2910. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2911. //获取最后1条监测的数据
  2912. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2913. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2914. var accumulatedBloodVolume float64
  2915. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2916. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2917. fmt.Println(err)
  2918. // 查询未执行的医嘱
  2919. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2920. for _, item := range doctorAdvice {
  2921. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2922. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2923. redis := service.RedisClient()
  2924. //清空key 值
  2925. redis.Set(key, "", time.Second)
  2926. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2927. redis.Set(keyTwo, "", time.Second)
  2928. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2929. redis.Set(keyThree, "", time.Second)
  2930. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2931. theTime := toTime.Format("2006-01-02")
  2932. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2933. redis.Set(keyFour, "", time.Second)
  2934. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2935. redis.Set(keyFive, "", time.Second)
  2936. defer redis.Close()
  2937. }
  2938. }
  2939. go func() {
  2940. ssoDomain := beego.AppConfig.String("call_domain")
  2941. api := ssoDomain + "/index/downpatient"
  2942. values := make(url.Values)
  2943. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2944. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2945. values.Set("patient_id", strconv.FormatInt(id, 10))
  2946. http.PostForm(api, values)
  2947. }()
  2948. if err == nil {
  2949. c.ServeSuccessJSON(map[string]interface{}{
  2950. "dialysisOrder": dialysisOrder,
  2951. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2952. })
  2953. } else {
  2954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2955. }
  2956. }
  2957. }
  2958. func (c *DialysisAPIController) GetAllZone() {
  2959. adminUserInfo := c.GetMobileAdminUserInfo()
  2960. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2961. if err == nil {
  2962. c.ServeSuccessJSON(map[string]interface{}{
  2963. "zone": zone,
  2964. })
  2965. }
  2966. }
  2967. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2968. adminUserInfo := c.GetMobileAdminUserInfo()
  2969. page, _ := c.GetInt64("page", 1)
  2970. limit, _ := c.GetInt64("limit", 10)
  2971. schedulType, _ := c.GetInt64("schedul_type", 0)
  2972. startTime, _ := c.GetInt64("schedul_time", 0)
  2973. partitionType, _ := c.GetInt64("partition_type", 0)
  2974. keywords := c.GetString("keywords")
  2975. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2976. if err == nil {
  2977. c.ServeSuccessJSON(map[string]interface{}{
  2978. "schedule": dialysisSchedule,
  2979. })
  2980. }
  2981. return
  2982. }
  2983. // /m/api/dialysis/start [post]
  2984. // @param patient_id:int
  2985. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2986. // @param nurse:int 上机护士
  2987. // @param bed:int 床位号
  2988. func (this *DialysisAPIController) StartDialysis() {
  2989. patientID, _ := this.GetInt64("patient_id")
  2990. recordDateStr := this.GetString("record_date")
  2991. nurseID, _ := this.GetInt64("start_nurse")
  2992. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2993. blood_drawing, _ := this.GetInt64("blood_drawing")
  2994. schedual_type, _ := this.GetInt64("schedual_type")
  2995. bedID, _ := this.GetInt64("bed")
  2996. start_time := this.GetString("start_time")
  2997. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2998. change_nurse, _ := this.GetInt64("change_nurse")
  2999. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3000. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3001. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3002. puncture_needle := this.GetString("puncture_needle")
  3003. puncture_way := this.GetString("puncture_way")
  3004. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3005. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3006. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3007. zone_id, _ := this.GetInt64("zone_id")
  3008. elecsign := this.GetString("url")
  3009. nuclein_date_str := this.GetString("nuclein_date_str")
  3010. schedule_remark := this.GetString("schedule_remark")
  3011. order_remark := this.GetString("order_remark")
  3012. catheter_operation := this.GetString("catheter_operation")
  3013. blood_flow_volume := this.GetString("blood_flow_volume")
  3014. dialysis_strainer := this.GetString("dialysis_strainer")
  3015. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  3016. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3017. return
  3018. }
  3019. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3020. if parseStartDateErr != nil {
  3021. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3022. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3023. return
  3024. }
  3025. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3026. if parseErr != nil {
  3027. this.ErrorLog("时间解析失败:%v", parseErr)
  3028. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3029. return
  3030. }
  3031. adminUserInfo := this.GetMobileAdminUserInfo()
  3032. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  3033. if getPatientErr != nil {
  3034. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3035. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3036. return
  3037. } else if patient == nil {
  3038. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3039. return
  3040. }
  3041. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3042. if getNurseErr != nil {
  3043. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3044. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3045. return
  3046. } else if nurse == nil {
  3047. this.ErrorLog("护士不存在")
  3048. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3049. return
  3050. }
  3051. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3052. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3053. if getDeviceNumberErr != nil {
  3054. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3055. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3056. return
  3057. } else if deviceNumber == nil {
  3058. this.ErrorLog("床位号不存在")
  3059. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3060. return
  3061. }
  3062. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3063. if getRecordErr != nil {
  3064. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  3065. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3066. return
  3067. } else if dialysisRecord != nil {
  3068. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  3069. return
  3070. }
  3071. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  3072. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  3073. timeLayout := "2006-01-02 15:04:05"
  3074. loc, _ := time.LoadLocation("Local")
  3075. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3076. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  3077. schedulestartTime := theStartTime.Unix()
  3078. scheduleendTime := theEndTime.Unix()
  3079. var theNucleinDate int64
  3080. timeLayoutOne := "2006-01-02"
  3081. if len(nuclein_date_str) > 0 {
  3082. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  3083. if err != nil {
  3084. utils.ErrorLog(err.Error())
  3085. }
  3086. theNucleinDate = theTime.Unix()
  3087. }
  3088. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3089. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  3090. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  3091. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3092. //查询该床位是否有人用了
  3093. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3094. if err == gorm.ErrRecordNotFound { //空床位
  3095. // 修改了床位逻辑
  3096. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3097. if daySchedule.ID > 0 {
  3098. daySchedule.PartitionId = deviceNumber.ZoneID
  3099. daySchedule.BedId = bedID
  3100. daySchedule.ScheduleType = schedual_type
  3101. daySchedule.UpdatedTime = time.Now().Unix()
  3102. xtSchedule := models.Schedule{
  3103. PartitionId: deviceNumber.ZoneID,
  3104. BedId: bedID,
  3105. ScheduleType: schedual_type,
  3106. UpdatedTime: time.Now().Unix(),
  3107. }
  3108. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3109. if err != nil {
  3110. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3111. return
  3112. }
  3113. }
  3114. } else if err == nil {
  3115. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  3116. if order.ID > 0 { //该机位被其他人占用了
  3117. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3118. return
  3119. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  3120. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3121. if daySchedule.ID > 0 {
  3122. err := service.UpdateScheduleTwo(daySchedule, schedule)
  3123. if err != nil {
  3124. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3125. return
  3126. }
  3127. }
  3128. }
  3129. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  3130. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3131. return
  3132. }
  3133. //else if order.ID == 0 { //该床位没被占用
  3134. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3135. // if daySchedule.ID > 0 {
  3136. // //daySchedule.PartitionId = deviceNumber.ZoneID
  3137. // //daySchedule.BedId = bedID
  3138. // //daySchedule.ScheduleType = schedual_type
  3139. // //daySchedule.UpdatedTime = time.Now().Unix()
  3140. // //err := service.UpdateSchedule(&daySchedule)
  3141. // xtSchedule := models.Schedule{
  3142. // PartitionId: deviceNumber.ZoneID,
  3143. // BedId: bedID,
  3144. // ScheduleType: schedual_type,
  3145. // UpdatedTime: time.Now().Unix(),
  3146. // }
  3147. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3148. // if err != nil {
  3149. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3150. // return
  3151. // }
  3152. // }
  3153. //}
  3154. //}
  3155. } else if err != nil {
  3156. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3157. return
  3158. }
  3159. // 查询信息规挡的设置天数
  3160. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3161. if infor.ID > 0 && infor.WeekDay > 0 {
  3162. var cha_time int64
  3163. timeNowStr := time.Now().Format("2006-01-02")
  3164. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3165. //今日的日期减去设置的日期
  3166. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3167. if cha_time >= recordDate.Unix() {
  3168. //查询审核是否允许
  3169. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  3170. //申请状态不允许的情况 拒绝修改
  3171. if infor.ApplicationStatus != 1 {
  3172. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3173. return
  3174. }
  3175. }
  3176. }
  3177. dialysisRecord = &models.DialysisOrder{
  3178. DialysisDate: recordDate.Unix(),
  3179. UserOrgId: adminUserInfo.Org.Id,
  3180. PatientId: patientID,
  3181. Stage: 1,
  3182. BedID: bedID,
  3183. StartNurse: nurseID,
  3184. Status: 1,
  3185. StartTime: startDate.Unix(),
  3186. CreatedTime: time.Now().Unix(),
  3187. UpdatedTime: time.Now().Unix(),
  3188. PunctureNurse: puncture_nurse,
  3189. Creator: adminUserInfo.AdminUser.Id,
  3190. Modifier: adminUserInfo.AdminUser.Id,
  3191. SchedualType: schedual_type,
  3192. WashpipeNurse: washpipe_nurse,
  3193. ChangeNurse: change_nurse,
  3194. DifficultPunctureNurse: difficult_puncture_nurse,
  3195. NewFistulaNurse: new_fistula_nurse,
  3196. ZoneId: zone_id,
  3197. QualityNurseId: quality_nurse_id,
  3198. PunctureNeedle: puncture_needle,
  3199. PunctureWay: puncture_way,
  3200. DialysisIrrigation: dialysis_irrigation,
  3201. DialysisDialyszers: dialysis_dialyszers,
  3202. BloodAccessId: blood_access_id,
  3203. Url: elecsign,
  3204. NucleinDate: theNucleinDate,
  3205. ScheduleRemark: schedule_remark,
  3206. OrderRemark: order_remark,
  3207. CatheterOperation: catheter_operation,
  3208. BloodFlowVolume: blood_flow_volume,
  3209. BloodDrawing: blood_drawing,
  3210. DialysisStrainer: dialysis_strainer,
  3211. }
  3212. //查询该床位是否有人用了
  3213. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3214. if errorscode == gorm.ErrRecordNotFound {
  3215. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3216. finish := models.XtDialysisFinish{
  3217. IsFinish: 1,
  3218. UserOrgId: adminUserInfo.Org.Id,
  3219. Status: 1,
  3220. Ctime: time.Now().Unix(),
  3221. Mtime: 0,
  3222. Module: 6,
  3223. RecordDate: schedulestartTime,
  3224. Sourse: 1,
  3225. PatientId: patientID,
  3226. }
  3227. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3228. if dialysisFinish.ID == 0 {
  3229. service.CreateDialysisFinish(finish)
  3230. }
  3231. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3232. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3233. //统计该患者总次数
  3234. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3235. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3236. }
  3237. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3238. //统计该患者总次数
  3239. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3240. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3241. }
  3242. redis := service.RedisClient()
  3243. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3244. redis.Set(key, "", time.Second)
  3245. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3246. //清空key 值
  3247. redis.Set(keyOne, "", time.Second)
  3248. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3249. //清空key 值
  3250. redis.Set(keyTwo, "", time.Second)
  3251. if createErr != nil {
  3252. this.ErrorLog("上机失败:%v", createErr)
  3253. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3254. return
  3255. }
  3256. }
  3257. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3258. var tempdispose string
  3259. // 只针对中能建
  3260. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3261. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3262. }
  3263. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3264. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3265. }
  3266. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3267. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3268. //}
  3269. var ultrafiltration_rate float64
  3270. var ultrafiltration_rate_one string
  3271. var replacement_rate float64
  3272. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3273. //后期预增脱水量
  3274. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3275. if prescription.ID > 0 {
  3276. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3277. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3278. if (template.TemplateId == 6 || template.TemplateId == 32 || template.TemplateId == 65 || adminUserInfo.Org.Id == 10375 || adminUserInfo.Org.Id == 10599) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  3279. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3280. }
  3281. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3282. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3283. }
  3284. //针对医师汇
  3285. if adminUserInfo.Org.Id == 10121 {
  3286. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3287. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3288. }
  3289. //针对通道
  3290. if adminUserInfo.Org.Id == 10234 {
  3291. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3292. }
  3293. //针对监利大垸医院
  3294. if template.TemplateId == 41 {
  3295. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3296. }
  3297. //针对肇庆三鹤血液透析中心
  3298. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3299. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3300. }
  3301. if adminUserInfo.Org.Id == 10469 {
  3302. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3303. }
  3304. if adminUserInfo.Org.Id == 10667 {
  3305. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3306. }
  3307. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3308. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3309. }
  3310. // 只针对方济医院
  3311. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3312. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3313. ultrafiltration_rate = value
  3314. }
  3315. //针对
  3316. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3317. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3318. ultrafiltration_rate = ultrafiltration_rate / 1000
  3319. }
  3320. if adminUserInfo.Org.Id == 10551 {
  3321. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3322. ultrafiltration_rate = ultrafiltration_rate / 1000
  3323. }
  3324. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3325. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3326. ultrafiltration_rate = ultrafiltration_rate / 1000
  3327. }
  3328. if adminUserInfo.Org.Id == 10580 {
  3329. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3330. ultrafiltration_rate = ultrafiltration_rate / 1000
  3331. }
  3332. if adminUserInfo.Org.Id == 10629 {
  3333. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3334. ultrafiltration_rate = ultrafiltration_rate / 1000
  3335. }
  3336. if adminUserInfo.Org.Id == 10644 {
  3337. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3338. ultrafiltration_rate = ultrafiltration_rate / 1000
  3339. }
  3340. if adminUserInfo.Org.Id == 10667 {
  3341. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3342. ultrafiltration_rate = ultrafiltration_rate / 1000
  3343. }
  3344. if adminUserInfo.Org.Id == 10693 {
  3345. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3346. ultrafiltration_rate = ultrafiltration_rate
  3347. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3348. }
  3349. if adminUserInfo.Org.Id == 10727 || adminUserInfo.Org.Id == 10731 {
  3350. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3351. ultrafiltration_rate = ultrafiltration_rate
  3352. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3353. }
  3354. if adminUserInfo.Org.Id == 10206 {
  3355. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60)
  3356. ultrafiltration_rate = ultrafiltration_rate
  3357. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3358. }
  3359. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3360. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3361. ultrafiltration_rate = ultrafiltration_rate
  3362. }
  3363. if adminUserInfo.Org.Id == 10702 {
  3364. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3365. ultrafiltration_rate = ultrafiltration_rate / 1000
  3366. }
  3367. if adminUserInfo.Org.Id == 10723 {
  3368. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3369. ultrafiltration_rate = ultrafiltration_rate / 1000
  3370. }
  3371. if adminUserInfo.Org.Id == 10721 {
  3372. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3373. ultrafiltration_rate = ultrafiltration_rate / 1000
  3374. }
  3375. if adminUserInfo.Org.Id == 10721 {
  3376. if prescription.ModeId == 2 {
  3377. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3378. if totalMin == 0 {
  3379. totalMin = 240
  3380. }
  3381. if prescription.ReplacementTotal == 0 {
  3382. prescription.ReplacementTotal = 15
  3383. }
  3384. //乘10 除10是为了保留一位小数
  3385. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3386. }
  3387. }
  3388. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10731 || adminUserInfo.Org.Id == 10727 {
  3389. if prescription.ModeId == 2 {
  3390. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3391. if totalMin == 0 {
  3392. totalMin = 240
  3393. }
  3394. if prescription.DisplaceLiquiValue == 0 {
  3395. prescription.ReplacementTotal = 32
  3396. }
  3397. //乘10 除10是为了保留一位小数
  3398. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3399. }
  3400. }
  3401. }
  3402. }
  3403. if adminUserInfo.Org.Id == 10172 {
  3404. if prescription.ID == 0 {
  3405. if prescription.ModeId == 2 {
  3406. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3407. if totalMin == 0 {
  3408. totalMin = 240
  3409. }
  3410. if prescription.ReplacementTotal == 0 {
  3411. prescription.ReplacementTotal = 15
  3412. }
  3413. //乘10 除10是为了保留一位小数
  3414. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3415. }
  3416. }
  3417. }
  3418. record := models.MonitoringRecord{
  3419. UserOrgId: adminUserInfo.Org.Id,
  3420. PatientId: patientID,
  3421. DialysisOrderId: dialysisRecord.ID,
  3422. MonitoringDate: schedulestartTime,
  3423. OperateTime: startDate.Unix(),
  3424. // MonitoringTime: recordTime,
  3425. MonitoringNurse: nurseID,
  3426. Dispose: tempdispose,
  3427. UltrafiltrationRate: ultrafiltration_rate,
  3428. UltrafiltrationVolume: 0,
  3429. Status: 1,
  3430. CreatedTime: time.Now().Unix(),
  3431. UpdatedTime: time.Now().Unix(),
  3432. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3433. ReplacementRate: replacement_rate,
  3434. }
  3435. //只针对广慈医院
  3436. if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.Org.Id == 9987 || adminUserInfo.Org.Id == 9526 || template.TemplateId == 32 || adminUserInfo.Org.Id == 9918 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 4 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10517 || adminUserInfo.Org.Id == 10679 {
  3437. // 查询病人是否有透前评估数据
  3438. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3439. //如果有数据就插入
  3440. if errcode == nil {
  3441. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3442. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3443. record.BreathingRate = befor.BreathingRate
  3444. record.PulseFrequency = befor.PulseFrequency
  3445. record.Temperature = befor.Temperature
  3446. }
  3447. }
  3448. //孝昌
  3449. if adminUserInfo.Org.Id == 10693 {
  3450. // 查询病人是否有透前评估数据
  3451. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3452. //如果有数据就插入
  3453. if errcode == nil {
  3454. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3455. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3456. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3457. record.BreathingRate = befor.BreathingRate
  3458. }
  3459. }
  3460. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3461. if newdialysisRecord.ID > 0 {
  3462. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3463. record.Temperature = 36.5
  3464. record.ArterialPressure = -100
  3465. record.DialysateTemperature = 36.5
  3466. record.Conductivity = 14
  3467. record.BreathingRate = "20"
  3468. record.VenousPressure = 80
  3469. record.TransmembranePressure = 60
  3470. record.Dispose = catheter_operation
  3471. }
  3472. //针对新化博翔
  3473. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3474. record.BloodOxygenSaturation = "99"
  3475. record.Conductivity = 14
  3476. record.DialysateTemperature = 36.5
  3477. record.BreathingRate = "20"
  3478. }
  3479. //针对兰溪人民医院的需求
  3480. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3481. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3482. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3483. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3484. record.Temperature = befor.Temperature
  3485. record.PulseFrequency = befor.PulseFrequency
  3486. record.BreathingRate = befor.BreathingRate
  3487. }
  3488. //针对乐山友谊医院的需求
  3489. if adminUserInfo.Org.Id == 10677 {
  3490. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3491. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3492. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3493. record.Temperature = befor.Temperature
  3494. record.PulseFrequency = befor.PulseFrequency
  3495. record.BreathingRate = befor.BreathingRate
  3496. }
  3497. //新化博翔
  3498. if adminUserInfo.Org.Id == 10447 {
  3499. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3500. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3501. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3502. record.BreathingRate = befor.BreathingRate
  3503. }
  3504. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3505. record.PulseFrequency = 80
  3506. record.Temperature = 36.5
  3507. }
  3508. //诊断灵山圣康
  3509. if adminUserInfo.Org.Id == 10375 {
  3510. record.Conductivity = 13.8
  3511. record.DialysateTemperature = 37
  3512. record.DialysateFlow = 500
  3513. record.BloodFlowVolume = 200
  3514. record.BreathingRate = "18"
  3515. record.SodiumConcentration = 140
  3516. }
  3517. //江成肾病医院
  3518. if adminUserInfo.Org.Id == 10517 {
  3519. record.SodiumConcentration = 138
  3520. record.DialysateTemperature = 36.5
  3521. }
  3522. //濉溪杏康血液透析中心
  3523. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3524. record.BloodFlowVolume = prescription.BloodFlowVolume
  3525. }
  3526. if adminUserInfo.Org.Id != 10683 {
  3527. err = service.CreateMonitor(&record)
  3528. }
  3529. //记录日志
  3530. byterequest, _ := json.Marshal(record)
  3531. monitorRecordLog := models.XtMonitorRecordLog{
  3532. RecordDate: record.MonitoringDate,
  3533. PatientId: record.PatientId,
  3534. Module: 1,
  3535. AdminUserId: adminUserInfo.AdminUser.Id,
  3536. Ctime: time.Now().Unix(),
  3537. Mtime: 0,
  3538. Status: 1,
  3539. UserOrgId: record.UserOrgId,
  3540. ErrLog: string(byterequest),
  3541. Source: "执行上机时新增监测",
  3542. }
  3543. service.CreateMonitorRecordLog(monitorRecordLog)
  3544. finish := models.XtDialysisFinish{
  3545. IsFinish: 1,
  3546. UserOrgId: adminUserInfo.Org.Id,
  3547. Status: 1,
  3548. Ctime: time.Now().Unix(),
  3549. Mtime: 0,
  3550. Module: 7,
  3551. RecordDate: schedulestartTime,
  3552. Sourse: 1,
  3553. PatientId: patientID,
  3554. }
  3555. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3556. if dialysisFinish.ID == 0 {
  3557. service.CreateDialysisFinish(finish)
  3558. }
  3559. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3560. redis := service.RedisClient()
  3561. //清空key 值
  3562. redis.Set(key, "", time.Second)
  3563. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3564. redis.Set(keyOne, "", time.Second)
  3565. defer redis.Close()
  3566. if err != nil {
  3567. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3568. return
  3569. }
  3570. }
  3571. go func() {
  3572. ssoDomain := beego.AppConfig.String("call_domain")
  3573. api := ssoDomain + "/index/uppatient"
  3574. values := make(url.Values)
  3575. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3576. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3577. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3578. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3579. http.PostForm(api, values)
  3580. }()
  3581. this.ServeSuccessJSON(map[string]interface{}{
  3582. "dialysis_order": newdialysisRecord,
  3583. "monitor": record,
  3584. })
  3585. return
  3586. }
  3587. func (c *DialysisAPIController) PostSolution() {
  3588. id, _ := c.GetInt64("patient", 0)
  3589. recordDateStr := c.GetString("record_date")
  3590. if id <= 0 {
  3591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3592. return
  3593. }
  3594. adminUserInfo := c.GetMobileAdminUserInfo()
  3595. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3596. if patient.ID == 0 {
  3597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3598. return
  3599. }
  3600. if len(recordDateStr) == 0 {
  3601. recordDateStr = time.Now().Format("2006-01-02")
  3602. }
  3603. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3604. if parseDateErr != nil {
  3605. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3607. return
  3608. }
  3609. mode_id, _ := c.GetInt64("mode_id", 0)
  3610. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3611. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3612. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3613. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3614. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3615. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3616. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3617. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3618. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3619. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3620. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3621. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3622. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3623. kalium, _ := c.GetFloat("kalium", 0)
  3624. sodium, _ := c.GetFloat("sodium", 0)
  3625. calcium, _ := c.GetFloat("calcium", 0)
  3626. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3627. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3628. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3629. glucose, _ := c.GetFloat("glucose", 0)
  3630. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3631. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3632. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3633. conductivity, _ := c.GetFloat("conductivity", 0)
  3634. remark := c.GetString("remark")
  3635. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3636. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3637. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3638. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3639. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3640. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3641. special_medicine_other := c.GetString("special_medicine_other")
  3642. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3643. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3644. blood_access, _ := c.GetInt64("blood_access", 0)
  3645. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3646. body_fluid_other := c.GetString("body_fluid_other")
  3647. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3648. niprocart, _ := c.GetInt64("niprocart", 0)
  3649. jms, _ := c.GetInt64("jms", 0)
  3650. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3651. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3652. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3653. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3654. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3655. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3656. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3657. injector, _ := c.GetInt64("injector", 0)
  3658. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3659. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3660. safe_package, _ := c.GetInt64("package", 0)
  3661. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3662. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3663. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3664. blood := c.GetString("blood")
  3665. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3666. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3667. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3668. displace_speed := c.GetString("displace_speed")
  3669. illness, _ := c.GetInt64("illness")
  3670. amylaceum := c.GetString("amylaceum")
  3671. single_time := c.GetString("single_time")
  3672. single_water := c.GetString("single_water")
  3673. replacement_flow := c.GetString("replacement_flow")
  3674. plasma_separator := c.GetString("plasma_separator")
  3675. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3676. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3677. oxygen_flow := c.GetString("oxygen_flow")
  3678. oxygen_time := c.GetString("oxygen_time")
  3679. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3680. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3681. puncture_needle := c.GetString("puncture_needle")
  3682. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3683. epo := c.GetString("epo")
  3684. epo_count, _ := c.GetFloat("epo_count", 0)
  3685. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3686. pre_impulse := c.GetString("pre_impulse")
  3687. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3688. admin_user_id, _ := c.GetInt64("admin_user_id")
  3689. is_water := c.GetString("is_water")
  3690. add_amount, _ := c.GetFloat("add_amount")
  3691. reduce_amount, _ := c.GetFloat("reduce_amount")
  3692. prescribing_number, _ := c.GetFloat("prescribing_number")
  3693. treatment_remark := c.GetString("treatment_remark")
  3694. prescription_sodium := c.GetString("prescription_sodium")
  3695. start_sodium := c.GetString("start_sodium")
  3696. sodium_curve := c.GetString("sodium_curve")
  3697. var is_war int64
  3698. if is_water == "是" {
  3699. is_war = 1
  3700. }
  3701. if is_water == "否" {
  3702. is_war = 2
  3703. }
  3704. if is_water == "请选择" {
  3705. is_war = 0
  3706. }
  3707. drhy_water := c.GetString("drhy_water")
  3708. dry_water_hour := c.GetString("dry_water_hour")
  3709. water_machine := c.GetString("water_machine")
  3710. dialysis_remark := c.GetString("dialysis_remark")
  3711. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3712. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3713. prescription_water, _ := c.GetFloat("prescription_water")
  3714. dialysis_strainer := c.GetString("dialysis_strainer")
  3715. chaptalization := c.GetString("chaptalization")
  3716. washing_time := c.GetString("washing_time")
  3717. warsh_count := c.GetString("warsh_count")
  3718. blood_access_part_id := c.GetString("blood_access_part_id")
  3719. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3720. dialyzate := c.GetString("dialyzate")
  3721. if mode_id > 0 {
  3722. var str string
  3723. //查找该机构用的是什么透析器
  3724. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3725. if filedConfig.ID > 0 {
  3726. str = dialyzerPerfusionApparatus
  3727. } else {
  3728. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3729. }
  3730. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3731. }
  3732. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3733. //
  3734. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3735. // if appRole.UserType == 3 {
  3736. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3737. // if getPermissionErr != nil {
  3738. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3739. // return
  3740. // } else if headNursePermission == nil {
  3741. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3742. // return
  3743. // }
  3744. // }
  3745. //}
  3746. // 查询信息规挡的设置天数
  3747. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3748. if infor.ID > 0 && infor.WeekDay > 0 {
  3749. var cha_time int64
  3750. timeNowStr := time.Now().Format("2006-01-02")
  3751. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3752. //今日的日期减去设置的日期
  3753. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3754. if cha_time >= recordDate.Unix() {
  3755. //查询审核是否允许
  3756. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3757. //申请状态不允许的情况 拒绝修改
  3758. if infor.ApplicationStatus != 1 {
  3759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3760. return
  3761. }
  3762. }
  3763. }
  3764. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  3765. var dialysis_dialyszers_id int64
  3766. var dialysis_strainer_id int64
  3767. var dialysis_irrigation_id int64
  3768. if len(goodList) > 0 {
  3769. for _, item := range goodList {
  3770. if item.SpecificationName == dialysis_dialyszers {
  3771. dialysis_dialyszers_id = item.ID
  3772. }
  3773. if item.SpecificationName == dialysis_irrigation {
  3774. dialysis_irrigation_id = item.ID
  3775. }
  3776. if item.SpecificationName == dialysis_strainer {
  3777. dialysis_strainer_id = item.ID
  3778. }
  3779. }
  3780. }
  3781. prescription := models.DialysisPrescription{
  3782. UserOrgId: adminUserInfo.Org.Id,
  3783. PatientId: id,
  3784. RecordDate: recordDate.Unix(),
  3785. ModeId: mode_id,
  3786. DialysisDuration: dialysis_duration,
  3787. Dialyzer: dialyzer,
  3788. PerfusionApparatus: perfusion_apparatus,
  3789. BloodFlowVolume: blood_flow_volume,
  3790. DewaterAmount: dewater_amount,
  3791. DisplaceLiqui: displace_liqui,
  3792. ReplacementWay: replacement_way,
  3793. Anticoagulant: anticoagulant,
  3794. AnticoagulantShouji: anticoagulant_shouji,
  3795. AnticoagulantWeichi: anticoagulant_weichi,
  3796. AnticoagulantZongliang: anticoagulant_zongliang,
  3797. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3798. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3799. Kalium: kalium,
  3800. Sodium: sodium,
  3801. Calcium: calcium,
  3802. Bicarbonate: bicarbonate,
  3803. Glucose: glucose,
  3804. // DryWeight: dry_weight,
  3805. DialysateFlow: dialysate_flow,
  3806. DialysateTemperature: dialysate_temperature,
  3807. Conductivity: conductivity,
  3808. Remark: remark,
  3809. Status: 1,
  3810. CreatedTime: time.Now().Unix(),
  3811. UpdatedTime: time.Now().Unix(),
  3812. DialysisDurationMinute: dialysisDurationMinute,
  3813. DialysisDurationHour: dialysisDurationHour,
  3814. TargetUltrafiltration: targetUltrafiltration,
  3815. DialysateFormulation: dialysateFormulation,
  3816. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3817. BodyFluid: body_fluid,
  3818. SpecialMedicine: special_medicine,
  3819. SpecialMedicineOther: special_medicine_other,
  3820. DisplaceLiquiPart: displace_liqui_part,
  3821. DisplaceLiquiValue: displace_liqui_value,
  3822. BloodAccess: blood_access,
  3823. Ultrafiltration: ultrafiltration,
  3824. BodyFluidOther: body_fluid_other,
  3825. ReplacementTotal: replacement_total,
  3826. Niprocart: niprocart,
  3827. Jms: jms,
  3828. FistulaNeedleSet: fistula_needle_set,
  3829. FistulaNeedleSet16: fistula_needle_set_16,
  3830. Hemoperfusion: hemoperfusion,
  3831. DialyserSterilised: dialyser_sterilised,
  3832. Filtryzer: filtryzer,
  3833. TargetKtv: target_ktv,
  3834. Dialyzers: dialyzers,
  3835. Injector: injector,
  3836. Bloodlines: bloodlines,
  3837. TubingHemodialysis: tubing_hemodialysis,
  3838. Package: safe_package,
  3839. ALiquid: a_liquid,
  3840. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3841. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3842. Blood: blood,
  3843. DialysisDialyszers: dialysis_dialyszers,
  3844. DialysisIrrigation: dialysis_irrigation,
  3845. AntioxidantCommodityName: antioxidant_commodity_name,
  3846. DisplaceSpeed: displace_speed,
  3847. Illness: illness,
  3848. Amylaceum: amylaceum,
  3849. SingleWater: single_water,
  3850. SingleTime: single_time,
  3851. ReplacementFlow: replacement_flow,
  3852. PlasmaSeparator: plasma_separator,
  3853. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3854. OxygenUptake: oxygen_uptake,
  3855. OxygenTime: oxygen_time,
  3856. OxygenFlow: oxygen_flow,
  3857. HemodialysisPipelines: hemodialysis_pipelines,
  3858. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3859. PunctureNeedle: puncture_needle,
  3860. PunctureNeedleCount: puncture_needle_count,
  3861. Epo: epo,
  3862. EpoCount: epo_count,
  3863. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3864. PreImpulse: impulse,
  3865. AdminUserId: admin_user_id,
  3866. IsWater: is_war,
  3867. DrhyWater: drhy_water,
  3868. DryWaterHour: dry_water_hour,
  3869. WaterMachine: water_machine,
  3870. AddAmount: add_amount,
  3871. ReduceAmount: reduce_amount,
  3872. DialysisRemark: dialysis_remark,
  3873. PrescribingNumber: prescribing_number,
  3874. PrescriptionSodium: prescription_sodium,
  3875. StartSodium: start_sodium,
  3876. SodiumCurve: sodium_curve,
  3877. TreatmentRemark: treatment_remark,
  3878. DialysisFluidFlow: dialysis_fluid_flow,
  3879. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3880. PrescriptionWater: prescription_water,
  3881. DialysisStrainer: dialysis_strainer,
  3882. Chaptalization: chaptalization,
  3883. WashingTime: washing_time,
  3884. WarshCount: warsh_count,
  3885. BloodAccessPartId: blood_access_part_id,
  3886. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3887. Dialyzate: dialyzate,
  3888. DialysisDialyszersId: dialysis_dialyszers_id,
  3889. DialysisIrrigationId: dialysis_irrigation_id,
  3890. DialysisStrainerId: dialysis_strainer_id,
  3891. }
  3892. if adminUserInfo.Org.Id == 10721 {
  3893. if prescription.ModeId == 2 {
  3894. if prescription.ReplacementTotal == 0 {
  3895. prescription.ReplacementTotal = 15
  3896. }
  3897. }
  3898. }
  3899. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3900. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3901. //
  3902. if appRole.UserType == 2 || appRole.UserType == 1 {
  3903. prescription_doctor = adminUserInfo.AdminUser.Id
  3904. prescription.PrescriptionDoctor = prescription_doctor
  3905. }
  3906. if dialysisPrescription.ID == 0 { //新增
  3907. prescription.Creater = adminUserInfo.AdminUser.Id
  3908. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3909. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3910. }
  3911. } else { //修改
  3912. if dialysisPrescription.Creater == 0 {
  3913. prescription.Creater = adminUserInfo.AdminUser.Id
  3914. } else {
  3915. prescription.Creater = dialysisPrescription.Creater
  3916. if adminUserInfo.Org.Id == 9882 {
  3917. if appRole.UserType == 2 || appRole.UserType == 1 {
  3918. prescription.Creater = adminUserInfo.AdminUser.Id
  3919. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3920. }
  3921. }
  3922. }
  3923. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3924. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3925. }
  3926. //if/**/
  3927. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3928. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3929. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3930. // if getPermissionErr != nil {
  3931. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3932. // return
  3933. // } else if headNursePermission == nil {
  3934. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3935. // return
  3936. // }
  3937. //}
  3938. //prescription.Creater = dialysisPrescription.Creater
  3939. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3940. prescription.Modifier = adminUserInfo.AdminUser.Id
  3941. prescription.ID = dialysisPrescription.ID
  3942. }
  3943. solution := models.DialysisSolution{
  3944. RegistrarsId: adminUserInfo.AdminUser.Id,
  3945. UserOrgId: adminUserInfo.Org.Id,
  3946. Doctor: prescription_doctor,
  3947. PatientId: id,
  3948. ModeId: mode_id,
  3949. DialysisDuration: dialysis_duration,
  3950. PerfusionApparatus: perfusion_apparatus,
  3951. BloodFlowVolume: blood_flow_volume,
  3952. Dewater: dewater_amount,
  3953. DisplaceLiqui: displace_liqui,
  3954. ReplacementWay: replacement_way,
  3955. Anticoagulant: anticoagulant,
  3956. AnticoagulantShouji: anticoagulant_shouji,
  3957. AnticoagulantWeichi: anticoagulant_weichi,
  3958. AnticoagulantZongliang: anticoagulant_zongliang,
  3959. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3960. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3961. Kalium: kalium,
  3962. Sodium: sodium,
  3963. Calcium: calcium,
  3964. Bicarbonate: bicarbonate,
  3965. Glucose: glucose,
  3966. // DryWeight: dry_weight,
  3967. DialysateFlow: dialysate_flow,
  3968. DialysateTemperature: dialysate_temperature,
  3969. Conductivity: conductivity,
  3970. Remark: remark,
  3971. Status: 1,
  3972. CreatedTime: time.Now().Unix(),
  3973. UpdatedTime: time.Now().Unix(),
  3974. DialysisDurationMinute: dialysisDurationMinute,
  3975. DialysisDurationHour: dialysisDurationHour,
  3976. TargetUltrafiltration: targetUltrafiltration,
  3977. DialysateFormulation: dialysateFormulation,
  3978. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3979. BodyFluid: body_fluid,
  3980. SpecialMedicine: special_medicine,
  3981. SpecialMedicineOther: special_medicine_other,
  3982. DisplaceLiquiPart: displace_liqui_part,
  3983. DisplaceLiquiValue: displace_liqui_value,
  3984. BloodAccess: blood_access,
  3985. Ultrafiltration: ultrafiltration,
  3986. BodyFluidOther: body_fluid_other,
  3987. ReplacementTotal: replacement_total,
  3988. TargetKtv: target_ktv,
  3989. DialysisDialyszers: dialysis_dialyszers,
  3990. DialysisIrrigation: dialysis_irrigation,
  3991. HemodialysisPipelines: hemodialysis_pipelines,
  3992. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3993. PunctureNeedle: puncture_needle,
  3994. PunctureNeedleCount: puncture_needle_count,
  3995. Epo: epo,
  3996. EpoCount: epo_count,
  3997. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3998. PreImpulse: impulse,
  3999. SolutionStatus: 1,
  4000. DialysisRemark: dialysis_remark,
  4001. PrescribingNumber: prescribing_number,
  4002. PrescriptionSodium: prescription_sodium,
  4003. StartSodium: start_sodium,
  4004. SodiumCurve: sodium_curve,
  4005. TreatmentRemark: treatment_remark,
  4006. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  4007. DialysisFluidFlow: dialysis_fluid_flow,
  4008. PrescriptionWater: prescription_water,
  4009. DialysisStrainer: dialysis_strainer,
  4010. Chaptalization: chaptalization,
  4011. WashingTime: washing_time,
  4012. WarshCount: warsh_count,
  4013. BloodAccessPartId: blood_access_part_id,
  4014. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  4015. Dialyzate: dialyzate,
  4016. DialysisDialyszersId: dialysis_dialyszers_id,
  4017. DialysisIrrigationId: dialysis_irrigation_id,
  4018. DialysisStrainerId: dialysis_strainer_id,
  4019. }
  4020. //针对河间咸的
  4021. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  4022. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  4023. solution.DisplaceLiquiPart = 0
  4024. solution.DisplaceLiquiValue = 0
  4025. }
  4026. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  4027. prescription.DisplaceLiquiPart = 0
  4028. prescription.DisplaceLiquiValue = 0
  4029. }
  4030. }
  4031. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  4032. if solution.PrescribingNumber == 0 {
  4033. solution.PrescribingNumber = 1
  4034. }
  4035. if prescription.PrescribingNumber == 0 {
  4036. prescription.PrescribingNumber = 1
  4037. }
  4038. if solution.PrescribingNumber == 0 && id == 14682 {
  4039. solution.PrescribingNumber = 2
  4040. }
  4041. if solution.PrescribingNumber == 0 && id == 18560 {
  4042. solution.PrescribingNumber = 2
  4043. }
  4044. if prescription.PrescribingNumber == 0 && id == 14682 {
  4045. prescription.PrescribingNumber = 2
  4046. }
  4047. if prescription.PrescribingNumber == 0 && id == 18560 {
  4048. prescription.PrescribingNumber = 2
  4049. }
  4050. }
  4051. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  4052. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  4053. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  4054. if len(monitorList) > 0 {
  4055. var ultrafiltration_rate float64
  4056. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4057. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  4058. var replacement_rate float64
  4059. //乘10 除10是为了保留一位小数
  4060. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  4061. var firstOpeateTime = monitorList[0].OperateTime
  4062. for _, item := range monitorList {
  4063. //超滤率
  4064. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  4065. //置换率
  4066. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  4067. //超滤量
  4068. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  4069. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  4070. //置换量
  4071. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  4072. fmt.Println("displacement_quantity----------------------", displacement_quantity)
  4073. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  4074. }
  4075. }
  4076. }
  4077. //记录日志
  4078. byterequest, _ := json.Marshal(prescription)
  4079. prescriptionLog := models.XtDialysisPrescriptionLog{
  4080. UserOrgId: prescription.UserOrgId,
  4081. Ctime: time.Now().Unix(),
  4082. Mtime: 0,
  4083. ErrLog: string(byterequest),
  4084. AdminUserId: adminUserInfo.AdminUser.Id,
  4085. RecordDate: prescription.RecordDate,
  4086. PatientId: prescription.PatientId,
  4087. Source: "手机端新增长期处方",
  4088. Status: 1,
  4089. }
  4090. service.CreatePrescriptionLog(prescriptionLog)
  4091. finish := models.XtDialysisFinish{
  4092. IsFinish: 1,
  4093. UserOrgId: adminUserInfo.Org.Id,
  4094. Status: 1,
  4095. Ctime: time.Now().Unix(),
  4096. Mtime: 0,
  4097. Module: 1,
  4098. RecordDate: recordDate.Unix(),
  4099. Sourse: 1,
  4100. PatientId: id,
  4101. }
  4102. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  4103. if dialysisFinish.ID == 0 {
  4104. service.CreateDialysisFinish(finish)
  4105. }
  4106. //获取最新1条
  4107. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  4108. //更新状态
  4109. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  4110. //长沙南雅医院,自动生成抗凝剂的临时处方
  4111. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  4112. if prescribing_number == 0 {
  4113. prescribing_number = 1
  4114. }
  4115. advice := models.DoctorAdvice{
  4116. UserOrgId: adminUserInfo.Org.Id,
  4117. PatientId: id,
  4118. GroupNo: 0,
  4119. AdviceType: 2,
  4120. RecordDate: recordDate.Unix(),
  4121. AdviceDate: recordDate.Unix(),
  4122. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  4123. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  4124. AdviceDesc: "",
  4125. ReminderDate: 0,
  4126. SingleDose: prescription.AnticoagulantZongliang,
  4127. SingleDoseUnit: "iu",
  4128. DrugSpec: 0,
  4129. DrugSpecUnit: "",
  4130. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  4131. PrescribingNumberUnit: "支",
  4132. DeliveryWay: "静脉注射",
  4133. ExecutionFrequency: "上机前",
  4134. AdviceDoctor: 0,
  4135. Status: 1,
  4136. CreatedTime: time.Now().Unix(),
  4137. UpdatedTime: time.Now().Unix(),
  4138. IsPrescription: 1,
  4139. ExecutionState: 2,
  4140. StopState: 2,
  4141. IsSettle: 2,
  4142. }
  4143. // 查询排班信息
  4144. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4145. if schedulePatient.ID > 0 {
  4146. if schedulePatient.ScheduleType == 1 {
  4147. advice.StartTime = recordDate.Unix() + 6.5*60*60
  4148. }
  4149. if schedulePatient.ScheduleType == 2 {
  4150. advice.StartTime = recordDate.Unix() + 9*60*60
  4151. }
  4152. }
  4153. // 抗凝剂名称
  4154. switch anticoagulant {
  4155. case 1:
  4156. advice.AdviceName = "无肝素"
  4157. break
  4158. case 2:
  4159. advice.AdviceName = "普通肝素"
  4160. break
  4161. case 3:
  4162. advice.AdviceName = "低分子肝素"
  4163. break
  4164. case 4:
  4165. advice.AdviceName = "阿加曲班"
  4166. break
  4167. case 5:
  4168. advice.AdviceName = "枸橼酸钠"
  4169. break
  4170. case 6:
  4171. advice.AdviceName = "低分子肝素钙"
  4172. break
  4173. case 7:
  4174. advice.AdviceName = "低分子肝素钠"
  4175. break
  4176. case 8:
  4177. advice.AdviceName = "依诺肝素"
  4178. break
  4179. case 9:
  4180. advice.AdviceName = "达肝素"
  4181. break
  4182. case 10:
  4183. advice.AdviceName = "体外抗凝"
  4184. break
  4185. case 11:
  4186. advice.AdviceName = "那曲肝素"
  4187. break
  4188. case 12:
  4189. advice.AdviceName = "无抗凝剂"
  4190. break
  4191. }
  4192. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  4193. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  4194. advice.AdviceDoctor = appRole.AdminUserId
  4195. }
  4196. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  4197. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  4198. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  4199. advice.AdviceName = "低分子肝素钠注射液"
  4200. // 修改患者临时医嘱里的抗凝剂医嘱
  4201. advice.ID = advicePrescription.ID
  4202. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  4203. } else {
  4204. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  4205. advice.AdviceName = "低分子肝素钠注射液"
  4206. service.CreateDoctorAdvice(&advice)
  4207. }
  4208. }
  4209. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  4210. redis := service.RedisClient()
  4211. defer redis.Close()
  4212. //清空key 值
  4213. redis.Set(key, "", time.Second)
  4214. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  4215. redis.Set(keyOne, "", time.Second)
  4216. }
  4217. //获取key,清空redis
  4218. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  4219. redis := service.RedisClient()
  4220. defer redis.Close()
  4221. //清空key 值
  4222. redis.Set(key, "", time.Second)
  4223. //清空长期医嘱的key
  4224. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  4225. redis.Set(soulution_key, "", time.Second)
  4226. //查询最近透析准备表里是否存在 透析器 灌流器
  4227. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4228. redis.Set(keyOne, "", time.Second)
  4229. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  4230. redis.Set(keyTwo, "", time.Second)
  4231. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  4232. redis.Set(keyThree, "", time.Second)
  4233. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  4234. redis.Set(keyFour, "", time.Second)
  4235. //splitStr := strings.Split(dialysis_dialyszers, ",")
  4236. //
  4237. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  4238. //
  4239. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  4240. //if len(mation)>0{
  4241. // for _, item := range splitStr {
  4242. // for _,it := range mation{
  4243. // if(item == it.SpecificationName){
  4244. //
  4245. // //查询最近一次的透析器
  4246. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4247. //
  4248. // if errcode == gorm.ErrRecordNotFound{
  4249. // //插入数据
  4250. // prepare := models.DialysisBeforePrepare{
  4251. // UserOrgId: adminUserInfo.Org.Id,
  4252. // PatientId: id,
  4253. // RecordDate: recordDate.Unix(),
  4254. // GoodTypeId: it.GoodTypeId,
  4255. // GoodId: it.ID,
  4256. // Count: 1,
  4257. // Ctime: time.Now().Unix(),
  4258. // Creater: adminUserInfo.AdminUser.Id,
  4259. // Status:1,
  4260. //
  4261. // }
  4262. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4263. // fmt.Println("",errcode)
  4264. // }
  4265. // }
  4266. // }
  4267. //
  4268. // }
  4269. //
  4270. // for _, item := range splitIrrigation {
  4271. // for _,it := range mation{
  4272. // if(item == it.SpecificationName){
  4273. // //查询最近一次的透析器
  4274. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4275. // if errcode == gorm.ErrRecordNotFound{
  4276. // //插入数据
  4277. // prepare := models.DialysisBeforePrepare{
  4278. // UserOrgId: adminUserInfo.Org.Id,
  4279. // PatientId: id,
  4280. // RecordDate: recordDate.Unix(),
  4281. // GoodTypeId: it.GoodTypeId,
  4282. // GoodId: it.ID,
  4283. // Count: 1,
  4284. // Ctime: time.Now().Unix(),
  4285. // Creater: adminUserInfo.AdminUser.Id,
  4286. // Status:1,
  4287. //
  4288. // }
  4289. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4290. // fmt.Println(errcode)
  4291. // }
  4292. // }
  4293. // }
  4294. // }
  4295. //}
  4296. c.ServeSuccessJSON(map[string]interface{}{
  4297. "solution": &solution,
  4298. "prescription": &prescription,
  4299. })
  4300. }
  4301. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4302. patient, _ := c.GetInt64("patient", 0)
  4303. adminUserInfo := c.GetMobileAdminUserInfo()
  4304. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4305. c.ServeSuccessJSON(map[string]interface{}{
  4306. "receiveTreatmentAsses": receiveTreatmentAsses,
  4307. })
  4308. }
  4309. func (this *DialysisAPIController) PostSignInfo() {
  4310. patientID, _ := this.GetInt64("patient_id")
  4311. recordDateStr := this.GetString("date")
  4312. if patientID <= 0 {
  4313. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4314. return
  4315. }
  4316. if len(recordDateStr) == 0 {
  4317. recordDateStr = time.Now().Format("2006-01-02")
  4318. }
  4319. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4320. if parseDateErr != nil {
  4321. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4322. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4323. return
  4324. }
  4325. adminInfo := this.GetMobileAdminUserInfo()
  4326. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4327. if err != nil {
  4328. this.ErrorLog("签名失败:%v", err)
  4329. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4330. return
  4331. }
  4332. this.ServeSuccessJSON(map[string]interface{}{
  4333. "doctor_id": adminInfo.AdminUser.Id,
  4334. })
  4335. }
  4336. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4337. patientID, _ := this.GetInt64("patient_id")
  4338. adminInfo := this.GetMobileAdminUserInfo()
  4339. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4340. this.ServeSuccessJSON(map[string]interface{}{
  4341. "monitor": record,
  4342. })
  4343. }
  4344. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4345. thisTime := time.Now()
  4346. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4347. timeLayout := "2006-01-02 15:04:05"
  4348. loc, _ := time.LoadLocation("Local")
  4349. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4350. theAssessmentDateTime := theStartTime.Unix()
  4351. patientID, _ := this.GetInt64("patient_id")
  4352. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4353. adminInfo := this.GetMobileAdminUserInfo()
  4354. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4355. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4356. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4357. var ultrafiltration_rate float64
  4358. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4359. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4360. fmt.Println(evaluation)
  4361. fmt.Println("prescription.ID", prescription.ID)
  4362. if prescription.ID > 0 {
  4363. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4364. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4365. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4366. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4367. record.UltrafiltrationRate = ultrafiltration_rate
  4368. }
  4369. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4370. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4371. record.UltrafiltrationRate = ultrafiltration_rate
  4372. }
  4373. if adminInfo.Org.Id == 10510 {
  4374. record.UltrafiltrationRate = 0
  4375. }
  4376. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4377. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4378. record.UltrafiltrationRate = ultrafiltration_rate
  4379. }
  4380. if template.TemplateId == 20 || template.TemplateId == 22 || adminInfo.Org.Id == 10731 {
  4381. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4382. record.UltrafiltrationRate = ultrafiltration_rate
  4383. }
  4384. // 只针对方济医院
  4385. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4386. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4387. ultrafiltration_rate = value
  4388. record.UltrafiltrationRate = ultrafiltration_rate
  4389. }
  4390. if template.TemplateId == 41 || template.TemplateId == 47 {
  4391. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4392. record.UltrafiltrationRate = ultrafiltration_rate
  4393. }
  4394. if template.TemplateId == 43 {
  4395. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4396. record.UltrafiltrationRate = ultrafiltration_rate
  4397. }
  4398. if template.TemplateId == 46 || template.TemplateId == 54 {
  4399. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4400. record.UltrafiltrationRate = ultrafiltration_rate
  4401. }
  4402. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 9829 || adminInfo.Org.Id == 10440 || adminInfo.Org.Id == 10610 || adminInfo.Org.Id == 10537 {
  4403. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4404. record.UltrafiltrationRate = ultrafiltration_rate
  4405. }
  4406. if adminInfo.Org.Id == 10469 {
  4407. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4408. record.UltrafiltrationRate = ultrafiltration_rate
  4409. }
  4410. if adminInfo.Org.Id == 10667 {
  4411. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4412. record.UltrafiltrationRate = ultrafiltration_rate
  4413. }
  4414. if adminInfo.Org.Id == 10471 {
  4415. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4416. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4417. }
  4418. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4419. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4420. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4421. }
  4422. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4423. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4424. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4425. }
  4426. if adminInfo.Org.Id == 10721 {
  4427. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4428. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4429. }
  4430. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4431. record.UltrafiltrationRate = 0
  4432. }
  4433. if adminInfo.Org.Id == 10727 || adminInfo.Org.Id == 10731 {
  4434. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4435. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4436. }
  4437. if adminInfo.Org.Id == 10206 {
  4438. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4439. fmt.Println("ultrafiltration_rate------------------", ultrafiltration_rate)
  4440. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4441. }
  4442. //if template.TemplateId == 47 {
  4443. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4444. // record.UltrafiltrationRate = ultrafiltration_rate
  4445. //}
  4446. }
  4447. }
  4448. // record.UltrafiltrationRate = ultrafiltration_rate
  4449. record.UltrafiltrationVolume = 0
  4450. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 { //adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535
  4451. if ultrafiltration_rate > 0 {
  4452. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4453. record.UltrafiltrationVolume = value
  4454. }
  4455. }
  4456. if template.TemplateId == 6 || template.TemplateId == 65 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 || template.TemplateId == 41 || template.TemplateId == 43 || template.TemplateId == 47 || template.TemplateId == 54 || adminInfo.Org.Id == 10599 { //adminInfo.Org.Id == 9538
  4457. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4458. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4459. record.UltrafiltrationVolume = ultrafiltration_volume
  4460. }
  4461. }
  4462. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4463. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4464. record.UltrafiltrationVolume = ultrafiltration_volume
  4465. }
  4466. //长沙南雅
  4467. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 10469 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10610 || adminInfo.Org.Id == 10537 || adminInfo.Org.Id == 10667 {
  4468. if ultrafiltration_rate > 0 {
  4469. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4470. record.UltrafiltrationVolume = ultrafiltration_volume
  4471. }
  4472. }
  4473. if adminInfo.Org.Id == 10471 {
  4474. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4475. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4476. }
  4477. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4478. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4479. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4480. }
  4481. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4482. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4483. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4484. }
  4485. //长沙南雅累计血容量自动计算
  4486. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4487. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4488. //}
  4489. if template.TemplateId == 47 || template.TemplateId == 54 {
  4490. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4491. }
  4492. if adminInfo.Org.Id == 10510 {
  4493. record.UltrafiltrationVolume = 0
  4494. }
  4495. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10164 || adminInfo.Org.Id == 10731 {
  4496. if ultrafiltration_rate > 0 {
  4497. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4498. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4499. }
  4500. }
  4501. //古镇乐生
  4502. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  4503. if ultrafiltration_rate > 0 {
  4504. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4505. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4506. }
  4507. }
  4508. if adminInfo.Org.Id == 10206 {
  4509. if ultrafiltration_rate > 0 {
  4510. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4511. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4512. }
  4513. }
  4514. if adminInfo.Org.Id == 10721 {
  4515. var replacement_rate float64
  4516. var displacement_quantity float64
  4517. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4518. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*60) / 1000
  4519. record.ReplacementRate = replacement_rate
  4520. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4521. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4522. record.DisplacementQuantity = displacement_quantity
  4523. }
  4524. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  4525. var replacement_rate float64
  4526. var displacement_quantity float64
  4527. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4528. if totalMin == 0 {
  4529. totalMin = 240
  4530. }
  4531. if prescription.DisplaceLiquiValue == 0 {
  4532. prescription.ReplacementTotal = 32
  4533. }
  4534. //乘10 除10是为了保留一位小数
  4535. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  4536. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4537. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4538. record.DisplacementQuantity = displacement_quantity
  4539. }
  4540. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4541. this.ServeSuccessJSON(map[string]interface{}{
  4542. "monitor": record,
  4543. "lastMonitorRecordList": lastMonitorRecordList,
  4544. })
  4545. }
  4546. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4547. record_id, _ := this.GetInt64("id")
  4548. nurseID, _ := this.GetInt64("start_nurse")
  4549. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4550. bedID, _ := this.GetInt64("bed")
  4551. start_time := this.GetString("start_time")
  4552. schedual_type, _ := this.GetInt64("schedual_type")
  4553. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4554. change_nurse, _ := this.GetInt64("change_nurse")
  4555. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4556. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4557. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4558. patient_id, _ := this.GetInt64("patient_id")
  4559. record_date, _ := this.GetInt64("record_date")
  4560. puncture_needle := this.GetString("puncture_needle")
  4561. puncture_way := this.GetString("puncture_way")
  4562. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4563. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4564. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4565. nuclein_date_str := this.GetString("nuclein_date_str")
  4566. order_remark := this.GetString("order_remark")
  4567. schedule_remark := this.GetString("schedule_remark")
  4568. catheter_operation := this.GetString("catheter_operation")
  4569. blood_flow_volume := this.GetString("blood_flow_volume")
  4570. blood_drawing, _ := this.GetInt64("blood_drawing")
  4571. dialysis_strainer := this.GetString("dialysis_strainer")
  4572. if record_id == 0 {
  4573. this.ErrorLog("id:%v", record_id)
  4574. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4575. return
  4576. }
  4577. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4578. if parseStartDateErr != nil {
  4579. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4580. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4581. return
  4582. }
  4583. adminUserInfo := this.GetMobileAdminUserInfo()
  4584. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4585. if getNurseErr != nil {
  4586. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4587. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4588. return
  4589. } else if nurse == nil {
  4590. this.ErrorLog("护士不存在")
  4591. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4592. return
  4593. }
  4594. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4595. //if getNurseErr != nil {
  4596. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4597. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4598. // return
  4599. //} else if nurse == nil {
  4600. // this.ErrorLog("护士不存在")
  4601. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4602. // return
  4603. //}
  4604. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4605. if getDeviceNumberErr != nil {
  4606. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4607. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4608. return
  4609. } else if deviceNumber == nil {
  4610. this.ErrorLog("床位号不存在")
  4611. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4612. return
  4613. }
  4614. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4615. //
  4616. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4617. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4618. // if getPermissionErr != nil {
  4619. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4620. // return
  4621. // } else if headNursePermission == nil {
  4622. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4623. // return
  4624. // }
  4625. //}
  4626. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4627. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4628. timeLayout := "2006-01-02 15:04:05"
  4629. loc, _ := time.LoadLocation("Local")
  4630. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4631. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4632. schedulestartTime := theStartTime.Unix()
  4633. scheduleendTime := theEndTime.Unix()
  4634. var theNucleinDate int64
  4635. timeLayoutOne := "2006-01-02"
  4636. if len(nuclein_date_str) > 0 {
  4637. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4638. if err != nil {
  4639. utils.ErrorLog(err.Error())
  4640. }
  4641. theNucleinDate = theTime.Unix()
  4642. }
  4643. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4644. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4645. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4646. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4647. if err == gorm.ErrRecordNotFound { //空床位
  4648. // 修改了床位逻辑
  4649. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4650. if daySchedule.ID > 0 {
  4651. //daySchedule.BedId = bedID
  4652. //daySchedule.PartitionId = deviceNumber.ZoneID
  4653. //daySchedule.ScheduleType = schedual_type
  4654. //daySchedule.UpdatedTime = time.Now().Unix()
  4655. //err := service.UpdateSchedule(&daySchedule)
  4656. xtSchedule := models.Schedule{
  4657. PartitionId: deviceNumber.ZoneID,
  4658. BedId: bedID,
  4659. ScheduleType: schedual_type,
  4660. UpdatedTime: time.Now().Unix(),
  4661. }
  4662. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4663. if err != nil {
  4664. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4665. return
  4666. }
  4667. }
  4668. } else if err == nil {
  4669. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4670. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4671. if daySchedule.ID > 0 {
  4672. //daySchedule.BedId = bedID
  4673. //daySchedule.PartitionId = deviceNumber.ZoneID
  4674. //
  4675. //daySchedule.ScheduleType = schedual_type
  4676. //daySchedule.UpdatedTime = time.Now().Unix()
  4677. //err := service.UpdateSchedule(&daySchedule)
  4678. xtSchedule := models.Schedule{
  4679. PartitionId: deviceNumber.ZoneID,
  4680. BedId: bedID,
  4681. ScheduleType: schedual_type,
  4682. UpdatedTime: time.Now().Unix(),
  4683. }
  4684. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4685. if err != nil {
  4686. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4687. return
  4688. }
  4689. }
  4690. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4691. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4692. return
  4693. }
  4694. } else if err != nil {
  4695. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4696. return
  4697. }
  4698. }
  4699. dialysisRecord := &models.DialysisOrder{
  4700. ID: record_id,
  4701. UserOrgId: adminUserInfo.Org.Id,
  4702. BedID: bedID,
  4703. StartNurse: nurseID,
  4704. StartTime: startDate.Unix(),
  4705. PunctureNurse: puncture_nurse,
  4706. Creator: adminUserInfo.AdminUser.Id,
  4707. Modifier: adminUserInfo.AdminUser.Id,
  4708. WashpipeNurse: washpipe_nurse,
  4709. SchedualType: schedual_type,
  4710. ChangeNurse: change_nurse,
  4711. DifficultPunctureNurse: difficult_puncture_nurse,
  4712. NewFistulaNurse: new_fistula_nurse,
  4713. QualityNurseId: quality_nurse_id,
  4714. PunctureNeedle: puncture_needle,
  4715. PunctureWay: puncture_way,
  4716. DialysisDialyszers: dialysis_dialyszers,
  4717. DialysisIrrigation: dialysis_irrigation,
  4718. BloodAccessId: blood_access_id,
  4719. NucleinDate: theNucleinDate,
  4720. OrderRemark: order_remark,
  4721. ScheduleRemark: schedule_remark,
  4722. CatheterOperation: catheter_operation,
  4723. BloodFlowVolume: blood_flow_volume,
  4724. BloodDrawing: blood_drawing,
  4725. DialysisStrainer: dialysis_strainer,
  4726. }
  4727. //修改床位号需要重新消毒
  4728. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4729. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4730. //查询第一条监测
  4731. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4732. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4733. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4734. redis := service.RedisClient()
  4735. //清空key 值
  4736. redis.Set(key, "", time.Second)
  4737. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4738. redis.Set(keyOne, "", time.Second)
  4739. defer redis.Close()
  4740. }
  4741. // 查询信息规挡的设置天数
  4742. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4743. if infor.ID > 0 && infor.WeekDay > 0 {
  4744. var cha_time int64
  4745. timeNowStr := time.Now().Format("2006-01-02")
  4746. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4747. //今日的日期减去设置的日期
  4748. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4749. if cha_time >= record_date {
  4750. //查询审核是否允许
  4751. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4752. //申请状态不允许的情况 拒绝修改
  4753. if infor.ApplicationStatus != 1 {
  4754. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4755. return
  4756. }
  4757. }
  4758. }
  4759. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4760. //修改床位后重新生成消毒计划
  4761. if adminUserInfo.Org.Id == 10340 {
  4762. //根据床位号获取设备型号
  4763. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4764. //查询使用消毒最后一条消毒记录
  4765. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  4766. fmt.Println("err", err)
  4767. if err == gorm.ErrRecordNotFound {
  4768. //查找排班
  4769. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  4770. //查询改设备是否有消毒计划
  4771. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  4772. //根据床位号获取设备id
  4773. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4774. //查询病人信息
  4775. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  4776. var con = ""
  4777. if patients.IsInfectious == 0 {
  4778. con = ""
  4779. }
  4780. if patients.IsInfectious == 1 {
  4781. con = "无"
  4782. }
  4783. if patients.IsInfectious == 2 {
  4784. con = "有"
  4785. }
  4786. if errcode == nil {
  4787. var end_time int64
  4788. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  4789. //新增消毒
  4790. information := models.DeviceInformation{
  4791. Date: dialysisRecord.DialysisDate,
  4792. Zone: dialysisRecord.ZoneId,
  4793. Class: dialysisRecord.SchedualType,
  4794. BedNumber: dialysisRecord.BedID,
  4795. PatientId: dialysisRecord.PatientId,
  4796. DialysisMode: scheduleByPatient.ModeId,
  4797. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  4798. Disinfection: 1,
  4799. DialysisConcentration: 1,
  4800. DisinfectionStatus: 1,
  4801. Move: 1,
  4802. UserOrgId: dialysisRecord.UserOrgId,
  4803. DisinfectType: plan.Way,
  4804. DisinfectantType: plan.MachineDisinfectant,
  4805. FluidPath: plan.DisinfectanWay, //液路消毒方式
  4806. Disinfectant: plan.Disinfectant,
  4807. Ctime: time.Now().Unix(),
  4808. Status: 1,
  4809. SignName: nurseID,
  4810. EquimentId: addmacher.ID,
  4811. DisinfectionResidue: 2,
  4812. Bed: addmacher.BedNumber,
  4813. StartTime: dialysisRecord.StartTime,
  4814. EndTime: dialysisRecord.EndTime,
  4815. Contagion: con,
  4816. WeightLoss: 0,
  4817. Hyperfiltratio: 0,
  4818. DialysisHour: "",
  4819. MachineRun: 1,
  4820. DisinfecStartime: dialysisRecord.EndTime,
  4821. DisinfecEndtime: end_time,
  4822. }
  4823. err := service.CreateInformationTwo(&information)
  4824. fmt.Println("报错", err)
  4825. }
  4826. }
  4827. }
  4828. order, _ := service.GetLastPatientOrder(record_id)
  4829. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4830. redis := service.RedisClient()
  4831. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4832. redis.Set(key, "", time.Second)
  4833. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4834. //清空key 值
  4835. redis.Set(keyOne, "", time.Second)
  4836. scheduleDateStartOne := startDate.Format("2006-01-02")
  4837. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4838. redis.Set(keyTwo, "", time.Second)
  4839. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4840. redis.Set(keyThree, "", time.Second)
  4841. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4842. redis.Set(keyFour, "", time.Second)
  4843. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4844. redis.Set(keyFive, "", time.Second)
  4845. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4846. redis.Set(keySix, "", time.Second)
  4847. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4848. redis.Set(keySeven, "", time.Second)
  4849. if updateErr != nil {
  4850. this.ErrorLog("修改上机失败:%v", updateErr)
  4851. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4852. return
  4853. }
  4854. if updateErr == nil {
  4855. if tempDialysisRecord.Stage == 2 {
  4856. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4857. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4858. fmt.Println(value)
  4859. a, b := math.Modf(value)
  4860. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4861. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4862. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4863. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4864. redis := service.RedisClient()
  4865. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4866. redis.Set(key, "", time.Second)
  4867. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4868. redis.Set(keyOne, "", time.Second)
  4869. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4870. //清空key 值
  4871. redis.Set(keySix, "", time.Second)
  4872. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4873. redis.Set(keySeven, "", time.Second)
  4874. redis.Close()
  4875. if updateAssessmentErr != nil {
  4876. utils.ErrorLog("%v", updateAssessmentErr)
  4877. }
  4878. }
  4879. }
  4880. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4881. this.ServeSuccessJSON(map[string]interface{}{
  4882. "dialysis_order": dialysisRecords,
  4883. })
  4884. }
  4885. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4886. record_id, _ := c.GetInt64("id")
  4887. nurseID, _ := c.GetInt64("nurse")
  4888. end_time := c.GetString("end_time")
  4889. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4890. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4891. catheter := c.GetString("catheter")
  4892. cruor := c.GetString("cruor")
  4893. mission := c.GetString("mission")
  4894. condenser := c.GetString("condenser")
  4895. if record_id <= 0 || nurseID <= 0 {
  4896. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4897. return
  4898. }
  4899. adminUserInfo := c.GetMobileAdminUserInfo()
  4900. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4901. if getNurseErr != nil {
  4902. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4904. return
  4905. } else if nurse == nil {
  4906. c.ErrorLog("护士不存在")
  4907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4908. return
  4909. }
  4910. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4911. if parseEndDateErr != nil {
  4912. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4914. return
  4915. }
  4916. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4917. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4918. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4919. // if getPermissionErr != nil {
  4920. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4921. // return
  4922. // } else if headNursePermission == nil {
  4923. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4924. // return
  4925. // }
  4926. //}
  4927. // 查询信息规挡的设置天数
  4928. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4929. if infor.ID > 0 {
  4930. var cha_time int64
  4931. timeNowStr := time.Now().Format("2006-01-02")
  4932. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4933. //今日的日期减去设置的日期
  4934. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4935. if cha_time >= tempDialysisRecords.DialysisDate {
  4936. //查询审核是否允许
  4937. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  4938. //申请状态不允许的情况 拒绝修改
  4939. if infor.ApplicationStatus != 1 {
  4940. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4941. return
  4942. }
  4943. }
  4944. }
  4945. dialysisRecord := &models.DialysisOrder{
  4946. ID: record_id,
  4947. UserOrgId: adminUserInfo.Org.Id,
  4948. EndTime: endDate.Unix(),
  4949. FinishNurse: nurseID,
  4950. FinishModifier: adminUserInfo.AdminUser.Id,
  4951. PuncturePointHaematoma: puncture_point_haematoma,
  4952. BloodAccessInternalFistula: blood_access_internal_fistula,
  4953. Catheter: catheter,
  4954. Cruor: cruor,
  4955. Mission: mission,
  4956. Condenser: condenser,
  4957. }
  4958. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4959. redis := service.RedisClient()
  4960. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4961. //清空key 值
  4962. redis.Set(key, "", time.Second)
  4963. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4964. //清空key 值
  4965. redis.Set(keyOne, "", time.Second)
  4966. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4967. redis.Set(keySeven, "", time.Second)
  4968. redis.Close()
  4969. if updateErr != nil {
  4970. c.ErrorLog("修改下机失败:%v", updateErr)
  4971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4972. return
  4973. }
  4974. if updateErr == nil {
  4975. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4976. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4977. a, b := math.Modf(value)
  4978. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4979. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4980. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4981. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4982. redis := service.RedisClient()
  4983. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4984. redis.Set(keyTen, "", time.Second)
  4985. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4986. redis.Set(keyTwo, "", time.Second)
  4987. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4988. redis.Set(key, "", time.Second)
  4989. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4990. redis.Set(keyThree, "", time.Second)
  4991. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4992. redis.Set(keySeven, "", time.Second)
  4993. defer redis.Close()
  4994. if updateAssessmentErr != nil {
  4995. utils.ErrorLog("%v", updateAssessmentErr)
  4996. }
  4997. }
  4998. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4999. c.ServeSuccessJSON(map[string]interface{}{
  5000. "dialysis_order": dialysisRecords,
  5001. })
  5002. }
  5003. func (c *DialysisAPIController) GetLongAdvice() {
  5004. patient_id, _ := c.GetInt64("id")
  5005. adminUserInfo := c.GetMobileAdminUserInfo()
  5006. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5007. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5008. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5009. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5010. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5011. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5012. c.ServeSuccessJSON(map[string]interface{}{
  5013. "status": "1",
  5014. })
  5015. return
  5016. } else { //开启推送提醒
  5017. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5018. var advice_three []*models.DoctorAdvice
  5019. recordDateStr := time.Now().Format("2006-01-02")
  5020. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5021. nowtime := recordDate.Unix()
  5022. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  5023. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  5024. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  5025. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  5026. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  5027. for _, advice := range advices {
  5028. if advice.FrequencyType == 3 {
  5029. t := time.Now()
  5030. week := int(t.Weekday())
  5031. fmt.Println(t.Weekday())
  5032. fmt.Println(week)
  5033. switch week {
  5034. case 1:
  5035. if strings.Index(advice.WeekDay, "周一") == -1 {
  5036. advice_three = append(advice_three, advice)
  5037. }
  5038. break
  5039. case 2:
  5040. if strings.Index(advice.WeekDay, "周二") == -1 {
  5041. advice_three = append(advice_three, advice)
  5042. }
  5043. break
  5044. case 3:
  5045. if strings.Index(advice.WeekDay, "周三") == -1 {
  5046. advice_three = append(advice_three, advice)
  5047. }
  5048. break
  5049. case 4:
  5050. if strings.Index(advice.WeekDay, "周四") == -1 {
  5051. advice_three = append(advice_three, advice)
  5052. }
  5053. break
  5054. case 5:
  5055. if strings.Index(advice.WeekDay, "周五") == -1 {
  5056. advice_three = append(advice_three, advice)
  5057. }
  5058. break
  5059. case 6:
  5060. if strings.Index(advice.WeekDay, "周六") == -1 {
  5061. advice_three = append(advice_three, advice)
  5062. }
  5063. break
  5064. case 0:
  5065. if strings.Index(advice.WeekDay, "周日") == -1 {
  5066. advice_three = append(advice_three, advice)
  5067. }
  5068. break
  5069. }
  5070. }
  5071. }
  5072. for _, advice := range advices_two {
  5073. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5074. now := p.Unix()
  5075. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5076. dayStr2 := "-" + dayStr
  5077. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5078. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5079. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5080. for _, ad := range advices {
  5081. advice_three = append(advice_three, ad)
  5082. }
  5083. }
  5084. if err == nil {
  5085. c.ServeSuccessJSON(map[string]interface{}{
  5086. "status": "2",
  5087. "advices": advices,
  5088. "advices_two": RemoveRepeatedElement(advice_three),
  5089. "is_open_remind": config.IsOpenRemind,
  5090. "his_config_open": hisConfig.IsOpen,
  5091. "is_advice_open": is_advice_open.IsAdviceOpen,
  5092. "prescription_open": prescription_open.IsOpen,
  5093. })
  5094. }
  5095. }
  5096. }
  5097. func (c *DialysisAPIController) GetLongAdviceOne() {
  5098. patient_id, _ := c.GetInt64("id")
  5099. startTime := c.GetString("schedule_date")
  5100. timeLayout := "2006-01-02"
  5101. loc, _ := time.LoadLocation("Local")
  5102. var theStartTime int64
  5103. if len(startTime) > 0 {
  5104. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  5105. if err != nil {
  5106. utils.ErrorLog(err.Error())
  5107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5108. return
  5109. }
  5110. theStartTime = theTime.Unix()
  5111. }
  5112. adminUserInfo := c.GetMobileAdminUserInfo()
  5113. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5114. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5115. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5116. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5117. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5118. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5119. c.ServeSuccessJSON(map[string]interface{}{
  5120. "status": "1",
  5121. })
  5122. return
  5123. } else { //开启推送提醒
  5124. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5125. var advice_three []*models.DoctorAdvice
  5126. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  5127. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  5128. for _, advice := range advices {
  5129. if advice.FrequencyType == 3 {
  5130. t := time.Now()
  5131. week := int(t.Weekday())
  5132. fmt.Println(t.Weekday())
  5133. fmt.Println(week)
  5134. switch week {
  5135. case 1:
  5136. if strings.Index(advice.WeekDay, "周一") == -1 {
  5137. advice_three = append(advice_three, advice)
  5138. }
  5139. break
  5140. case 2:
  5141. if strings.Index(advice.WeekDay, "周二") == -1 {
  5142. advice_three = append(advice_three, advice)
  5143. }
  5144. break
  5145. case 3:
  5146. if strings.Index(advice.WeekDay, "周三") == -1 {
  5147. advice_three = append(advice_three, advice)
  5148. }
  5149. break
  5150. case 4:
  5151. if strings.Index(advice.WeekDay, "周四") == -1 {
  5152. advice_three = append(advice_three, advice)
  5153. }
  5154. break
  5155. case 5:
  5156. if strings.Index(advice.WeekDay, "周五") == -1 {
  5157. advice_three = append(advice_three, advice)
  5158. }
  5159. break
  5160. case 6:
  5161. if strings.Index(advice.WeekDay, "周六") == -1 {
  5162. advice_three = append(advice_three, advice)
  5163. }
  5164. break
  5165. case 0:
  5166. if strings.Index(advice.WeekDay, "周日") == -1 {
  5167. advice_three = append(advice_three, advice)
  5168. }
  5169. break
  5170. }
  5171. }
  5172. }
  5173. for _, advice := range advices_two {
  5174. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5175. now := p.Unix()
  5176. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5177. dayStr2 := "-" + dayStr
  5178. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5179. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5180. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5181. for _, ad := range advices {
  5182. advice_three = append(advice_three, ad)
  5183. }
  5184. }
  5185. if err == nil {
  5186. c.ServeSuccessJSON(map[string]interface{}{
  5187. "status": "2",
  5188. "advices": advices,
  5189. "advices_two": RemoveRepeatedElement(advice_three),
  5190. "is_open_remind": config.IsOpenRemind,
  5191. "his_config_open": hisConfig.IsOpen,
  5192. "is_advice_open": is_advice_open.IsAdviceOpen,
  5193. "prescription_open": prescription_open.IsOpen,
  5194. })
  5195. }
  5196. }
  5197. }
  5198. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5199. newArr = make([]*models.DoctorAdvice, 0)
  5200. for i := 0; i < len(arr); i++ {
  5201. repeat := false
  5202. for j := i + 1; j < len(arr); j++ {
  5203. if arr[i].ID == arr[j].ID {
  5204. repeat = true
  5205. break
  5206. }
  5207. }
  5208. if !repeat {
  5209. newArr = append(newArr, arr[i])
  5210. }
  5211. }
  5212. return
  5213. }
  5214. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5215. patient, _ := c.GetInt64("id", 0)
  5216. groupNo, _ := c.GetInt64("groupno", 0)
  5217. if patient <= 0 {
  5218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5219. return
  5220. }
  5221. adminUserInfo := c.GetMobileAdminUserInfo()
  5222. dataBody := make(map[string]interface{}, 0)
  5223. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5224. if err != nil {
  5225. utils.ErrorLog(err.Error())
  5226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5227. return
  5228. }
  5229. utils.ErrorLog("%v", dataBody)
  5230. timeLayout := "2006-01-02 15:04"
  5231. loc, _ := time.LoadLocation("Local")
  5232. timeLayout2 := "2006-01-02"
  5233. loc2, _ := time.LoadLocation("Local")
  5234. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5235. utils.ErrorLog("advice_type")
  5236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5237. return
  5238. }
  5239. adviceType := int64(2)
  5240. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5241. utils.ErrorLog("advice_date")
  5242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5243. return
  5244. }
  5245. adviceDate, _ := dataBody["advice_date"].(string)
  5246. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5247. AdviceDate := theTime.Unix()
  5248. RecordDate := theTime.Unix()
  5249. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5250. utils.ErrorLog("start_time")
  5251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5252. return
  5253. }
  5254. startTime, _ := dataBody["start_time"].(string)
  5255. if len(startTime) == 0 {
  5256. utils.ErrorLog("len(start_time) == 0")
  5257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5258. return
  5259. }
  5260. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5261. if err != nil {
  5262. utils.ErrorLog(err.Error())
  5263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5264. return
  5265. }
  5266. StartTime := theTime.Unix()
  5267. Remark := ""
  5268. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5269. remark, _ := dataBody["remark"].(string)
  5270. Remark = remark
  5271. }
  5272. var advices []*models.GroupAdvice
  5273. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5274. utils.ErrorLog("advices")
  5275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5276. return
  5277. }
  5278. adviceNames := dataBody["advices"].([]interface{})
  5279. for _, adviceNameMap := range adviceNames {
  5280. adviceNameM := adviceNameMap.(map[string]interface{})
  5281. var advice models.GroupAdvice
  5282. advice.Remark = Remark
  5283. advice.AdviceType = adviceType
  5284. advice.StartTime = StartTime
  5285. advice.AdviceDate = AdviceDate
  5286. advice.RecordDate = RecordDate
  5287. advice.Status = 1
  5288. advice.CreatedTime = time.Now().Unix()
  5289. advice.UpdatedTime = time.Now().Unix()
  5290. advice.StopState = 2
  5291. advice.ExecutionState = 2
  5292. advice.UserOrgId = adminUserInfo.Org.Id
  5293. advice.PatientId = patient
  5294. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5295. advice.IsSettle = 2
  5296. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5297. utils.ErrorLog("advice_name")
  5298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5299. return
  5300. }
  5301. adviceName, _ := adviceNameM["advice_name"].(string)
  5302. if len(adviceName) == 0 {
  5303. utils.ErrorLog("len(advice_name) == 0")
  5304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5305. return
  5306. }
  5307. advice.AdviceName = adviceName
  5308. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5309. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5310. advice.DrugSpec = drugSpec
  5311. }
  5312. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5313. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5314. advice.AdviceDesc = adviceDesc
  5315. }
  5316. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5317. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5318. advice.DrugSpecUnit = drugSpecUnit
  5319. }
  5320. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5321. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5322. // advice.SingleDose = singleDose
  5323. //}
  5324. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5325. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5326. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5327. }
  5328. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5329. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5330. advice.SingleDoseUnit = singleDoseUnit
  5331. }
  5332. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5333. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5334. // advice.PrescribingNumber = prescribingNumber
  5335. //}
  5336. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5337. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5338. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5339. }
  5340. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5341. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5342. advice.PrescribingNumberUnit = prescribingNumberUnit
  5343. }
  5344. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5345. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5346. advice.DeliveryWay = deliveryWay
  5347. }
  5348. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5349. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5350. advice.ExecutionFrequency = executionFrequency
  5351. }
  5352. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5353. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5354. advice.FrequencyType = frequency_type
  5355. }
  5356. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5357. day_count := int64(adviceNameM["day_count"].(float64))
  5358. advice.DayCount = day_count
  5359. }
  5360. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5361. week_day, _ := adviceNameM["week_day"].(string)
  5362. advice.WeekDay = week_day
  5363. }
  5364. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5365. way := int64(adviceNameM["way"].(float64))
  5366. advice.Way = way
  5367. }
  5368. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5369. drug_id := int64(adviceNameM["drug_id"].(float64))
  5370. advice.DrugId = drug_id
  5371. }
  5372. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5373. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5374. advice.DrugNameId = drug_name_id
  5375. }
  5376. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  5377. remark, _ := adviceNameM["remark"].(string)
  5378. advice.Remark = remark
  5379. }
  5380. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  5381. groupno := int64(adviceNameM["groupno"].(float64))
  5382. advice.GroupNo = groupno
  5383. }
  5384. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5385. template_id, _ := adviceNameM["template_id"].(string)
  5386. advice.TemplateId = template_id
  5387. }
  5388. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5389. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5390. advice.ExecutionFrequency = executionFrequency
  5391. }
  5392. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5393. children := adviceNameM["child"].([]interface{})
  5394. if len(children) > 0 {
  5395. for _, childrenMap := range children {
  5396. childMap := childrenMap.(map[string]interface{})
  5397. var child models.GroupAdvice
  5398. child.Remark = Remark
  5399. child.AdviceType = adviceType
  5400. child.StartTime = StartTime
  5401. child.AdviceDate = AdviceDate
  5402. child.RecordDate = RecordDate
  5403. child.Status = 1
  5404. child.CreatedTime = time.Now().Unix()
  5405. child.UpdatedTime = time.Now().Unix()
  5406. child.StopState = 2
  5407. child.ExecutionState = 2
  5408. child.UserOrgId = adminUserInfo.Org.Id
  5409. child.PatientId = patient
  5410. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5411. child.IsSettle = 1
  5412. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5413. utils.ErrorLog("child advice_name")
  5414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5415. return
  5416. }
  5417. childAdviceName, _ := childMap["advice_name"].(string)
  5418. if len(childAdviceName) == 0 {
  5419. utils.ErrorLog("len(child advice_name) == 0")
  5420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5421. return
  5422. }
  5423. child.AdviceName = childAdviceName
  5424. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5425. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5426. child.AdviceDesc = childAdviceDesc
  5427. }
  5428. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5429. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5430. child.DrugSpec = childDrugSpec
  5431. }
  5432. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5433. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5434. child.DrugSpecUnit = childDrugSpecUnit
  5435. }
  5436. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5437. child.SingleDose = childMap["single_dose"].(float64)
  5438. }
  5439. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5440. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5441. child.SingleDoseUnit = childSingleDoseUnit
  5442. }
  5443. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5444. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5445. }
  5446. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5447. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5448. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5449. }
  5450. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  5451. groupno := int64(childMap["groupno"].(float64))
  5452. advice.GroupNo = groupno
  5453. }
  5454. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5455. remark, _ := childMap["remark"].(string)
  5456. child.Remark = remark
  5457. }
  5458. child.DeliveryWay = advice.DeliveryWay
  5459. child.ExecutionFrequency = advice.ExecutionFrequency
  5460. advice.Children = append(advice.Children, &child)
  5461. }
  5462. }
  5463. }
  5464. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  5465. if temp_advice.ID == 0 {
  5466. advices = append(advices, &advice)
  5467. }
  5468. }
  5469. if len(advices) > 0 {
  5470. finish := models.XtDialysisFinish{
  5471. IsFinish: 1,
  5472. UserOrgId: adminUserInfo.Org.Id,
  5473. Status: 1,
  5474. Ctime: time.Now().Unix(),
  5475. Mtime: 0,
  5476. Module: 4,
  5477. RecordDate: AdviceDate,
  5478. Sourse: 1,
  5479. PatientId: patient,
  5480. }
  5481. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  5482. if dialysisFinish.ID == 0 {
  5483. service.CreateDialysisFinish(finish)
  5484. }
  5485. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  5486. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5487. for _, item := range advices {
  5488. byterequest, _ := json.Marshal(item)
  5489. adviceLog := models.XtDoctorAdviceLog{
  5490. UserOrgId: adminUserInfo.Org.Id,
  5491. PatientId: patient,
  5492. AdminUserId: adminUserInfo.AdminUser.Id,
  5493. Module: 1,
  5494. ErrLog: string(byterequest),
  5495. Status: 1,
  5496. Ctime: time.Now().Unix(),
  5497. Mtime: 0,
  5498. Source: "手机端医嘱推送",
  5499. RecordDate: item.AdviceDate,
  5500. }
  5501. service.CreateDoctorAdviceLog(adviceLog)
  5502. }
  5503. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5504. redis := service.RedisClient()
  5505. //清空key 值
  5506. redis.Set(key, "", time.Second)
  5507. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5508. redis.Set(keyOne, "", time.Second)
  5509. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5510. defer redis.Close()
  5511. redis.Set(keyThree, "", time.Second)
  5512. if err != nil {
  5513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5514. return
  5515. }
  5516. c.ServeSuccessJSON(map[string]interface{}{
  5517. "msg": "ok",
  5518. "advices": list,
  5519. })
  5520. } else {
  5521. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5522. for _, item := range advices {
  5523. byterequest, _ := json.Marshal(item)
  5524. adviceLog := models.XtDoctorAdviceLog{
  5525. UserOrgId: adminUserInfo.Org.Id,
  5526. PatientId: patient,
  5527. AdminUserId: adminUserInfo.AdminUser.Id,
  5528. Module: 1,
  5529. ErrLog: string(byterequest),
  5530. Status: 1,
  5531. Ctime: time.Now().Unix(),
  5532. Mtime: 0,
  5533. Source: "手机端医嘱推送",
  5534. RecordDate: item.AdviceDate,
  5535. }
  5536. service.CreateDoctorAdviceLog(adviceLog)
  5537. }
  5538. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5539. redis := service.RedisClient()
  5540. //清空key 值
  5541. redis.Set(key, "", time.Second)
  5542. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5543. redis.Set(keyOne, "", time.Second)
  5544. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5545. defer redis.Close()
  5546. redis.Set(keyThree, "", time.Second)
  5547. if err != nil {
  5548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5549. return
  5550. }
  5551. c.ServeSuccessJSON(map[string]interface{}{
  5552. "msg": "ok",
  5553. "advices": list,
  5554. })
  5555. }
  5556. } else {
  5557. c.ServeSuccessJSON(map[string]interface{}{
  5558. "msg": "ok",
  5559. })
  5560. }
  5561. return
  5562. }
  5563. func (c *DialysisAPIController) UploadDryWeight() {
  5564. patient_id, _ := c.GetInt64("id")
  5565. dry_weight, _ := c.GetFloat("dry_weight")
  5566. doctor_id, _ := c.GetInt64("doctor_id")
  5567. remark := c.GetString("remark")
  5568. adminUserInfo := c.GetMobileAdminUserInfo()
  5569. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5570. if err == gorm.ErrRecordNotFound {
  5571. dryWeight := &models.SgjPatientDryweight{
  5572. PatientId: patient_id,
  5573. DryWeight: dry_weight,
  5574. Remakes: remark,
  5575. Ctime: time.Now().Unix(),
  5576. Mtime: time.Now().Unix(),
  5577. Creator: doctor_id,
  5578. Status: 1,
  5579. UserOrgId: adminUserInfo.Org.Id,
  5580. AdjustedValue: "/",
  5581. UserId: adminUserInfo.AdminUser.Id,
  5582. }
  5583. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5584. redis := service.RedisClient()
  5585. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  5586. redis.Set(keyOne, "", time.Second)
  5587. loc, _ := time.LoadLocation("Local")
  5588. nowTime := time.Now()
  5589. nowDay := nowTime.Format("2006-01-02")
  5590. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5591. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5592. redis.Set(key, "", time.Second)
  5593. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5594. redis.Set(keyTwo, "", time.Second)
  5595. redis.Close()
  5596. if createErr == nil {
  5597. c.ServeSuccessJSON(map[string]interface{}{
  5598. "msg": "提交成功",
  5599. "weight": dryWeight,
  5600. })
  5601. }
  5602. } else {
  5603. dryWeight := &models.SgjPatientDryweight{
  5604. PatientId: patient_id,
  5605. DryWeight: dry_weight,
  5606. Remakes: remark,
  5607. Ctime: time.Now().Unix(),
  5608. Mtime: time.Now().Unix(),
  5609. Creator: doctor_id,
  5610. Status: 1,
  5611. UserOrgId: adminUserInfo.Org.Id,
  5612. AdjustedValue: "/",
  5613. UserId: adminUserInfo.AdminUser.Id,
  5614. }
  5615. var value float64
  5616. value = dry_weight - weightAdjust.DryWeight
  5617. if value < 0 {
  5618. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5619. } else if value == 0 {
  5620. dryWeight.AdjustedValue = "/"
  5621. } else if value > 0 {
  5622. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5623. }
  5624. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5625. //康桥
  5626. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10721 {
  5627. timeNowStr := time.Now().Format("2006-01-02")
  5628. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5629. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5630. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5631. if beforAssesment.ID > 0 {
  5632. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  5633. var dewater_amount float64
  5634. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  5635. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  5636. //获取key,清空redis
  5637. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  5638. redis := service.RedisClient()
  5639. //清空key 值
  5640. redis.Set(key, "", time.Second)
  5641. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5642. //清空key 值
  5643. redis.Set(keyOne, "", time.Second)
  5644. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  5645. //清空key 值
  5646. redis.Set(keyTwo, "", time.Second)
  5647. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  5648. redis.Set(keySix, "", time.Second)
  5649. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  5650. redis.Set(keySeven, "", time.Second)
  5651. }
  5652. }
  5653. redis := service.RedisClient()
  5654. loc, _ := time.LoadLocation("Local")
  5655. nowTime := time.Now()
  5656. nowDay := nowTime.Format("2006-01-02")
  5657. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5658. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5659. redis.Set(keyOne, "", time.Second)
  5660. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5661. redis.Set(key, "", time.Second)
  5662. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5663. redis.Set(keyTwo, "", time.Second)
  5664. redis.Close()
  5665. if createErr == nil {
  5666. c.ServeSuccessJSON(map[string]interface{}{
  5667. "msg": "提交成功",
  5668. "weight": dryWeight,
  5669. })
  5670. }
  5671. }
  5672. }
  5673. func (c *DialysisAPIController) GetSolution() {
  5674. patient_id, _ := c.GetInt64("patient_id")
  5675. mode_id, _ := c.GetInt64("mode_id")
  5676. adminUserInfo := c.GetMobileAdminUserInfo()
  5677. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5678. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5679. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5680. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5681. if err != nil {
  5682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5683. return
  5684. }
  5685. c.ServeSuccessJSON(map[string]interface{}{
  5686. "solution": solution,
  5687. "prescription": prescription,
  5688. "system_prescription": system_prescription,
  5689. "dialysisPrescription": dialysisPrescription,
  5690. })
  5691. }
  5692. func (c *DialysisAPIController) GetSchedule() {
  5693. schedual_type, _ := c.GetInt64("schedual_type")
  5694. adminUserInfo := c.GetMobileAdminUserInfo()
  5695. scheduleTime, _ := c.GetInt64("record_date")
  5696. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5697. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5698. c.ServeSuccessJSON(map[string]interface{}{
  5699. "number": deviceNumber,
  5700. "list": list,
  5701. })
  5702. }
  5703. func (c *DialysisAPIController) GetPatientId() {
  5704. id, _ := c.GetInt64("id")
  5705. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5706. patientId, _ := service.GetPatientId(id)
  5707. //获取该患者的所有传染病
  5708. list, _ := service.GetPatientInfectious(id)
  5709. c.ServeSuccessJSON(map[string]interface{}{
  5710. "patient": patientId,
  5711. "infectioulist": list,
  5712. })
  5713. }
  5714. func (this *DialysisAPIController) GetDialysisSchedule() {
  5715. schedualDate := this.GetString("date")
  5716. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5717. if parseDateErr != nil {
  5718. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5719. return
  5720. }
  5721. adminInfo := this.GetMobileAdminUserInfo()
  5722. orgID := adminInfo.Org.Id
  5723. redis := service.RedisClient()
  5724. defer redis.Close()
  5725. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5726. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5727. if len(scheduals) > 0 {
  5728. //缓存数据
  5729. scheduals_json, err := json.Marshal(scheduals)
  5730. if err == nil {
  5731. redis.Set(key, scheduals_json, time.Second*30)
  5732. }
  5733. }
  5734. this.ServeSuccessJSON(map[string]interface{}{
  5735. "scheduals": scheduals,
  5736. })
  5737. }
  5738. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5739. change_type, _ := this.GetInt64("type", 0)
  5740. record_date := this.GetString("record_time")
  5741. patient_id, _ := this.GetInt64("patient_id", 0)
  5742. timeLayout := "2006-01-02"
  5743. loc, _ := time.LoadLocation("Local")
  5744. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5745. record_time := theAdviceRecordTime.Unix()
  5746. adminUserInfo := this.GetMobileAdminUserInfo()
  5747. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5748. if err == nil {
  5749. if len(advices) == 0 {
  5750. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5751. return
  5752. } else {
  5753. this.ServeSuccessJSON(map[string]interface{}{
  5754. "advices": advices,
  5755. "schedule": sch,
  5756. })
  5757. return
  5758. }
  5759. } else {
  5760. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5761. return
  5762. }
  5763. }
  5764. func (c *DialysisAPIController) CreateConsumables() {
  5765. record_date := c.GetString("record_time")
  5766. patient_id, _ := c.GetInt64("patient_id", 0)
  5767. active, _ := c.GetInt64("active")
  5768. adminUser := c.GetMobileAdminUserInfo()
  5769. timeLayout := "2006-01-02"
  5770. loc, _ := time.LoadLocation("Local")
  5771. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5772. record_time := theRecordTime.Unix()
  5773. // 查询信息规挡的设置天数
  5774. orgid := c.GetMobileAdminUserInfo().Org.Id
  5775. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5776. if infor.ID > 0 {
  5777. var cha_time int64
  5778. timeNowStr := time.Now().Format("2006-01-02")
  5779. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5780. //今日的日期减去设置的日期
  5781. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5782. if cha_time >= record_time {
  5783. //查询审核是否允许
  5784. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5785. //申请状态不允许的情况 拒绝修改
  5786. if infor.ApplicationStatus != 1 {
  5787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5788. return
  5789. }
  5790. }
  5791. }
  5792. dataBody := make(map[string]interface{}, 0)
  5793. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5794. if err != nil {
  5795. utils.ErrorLog(err.Error())
  5796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5797. return
  5798. }
  5799. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5800. var beforePrepares []*models.DialysisBeforePrepareGoods
  5801. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5802. var dialysisBefor []*models.DialysisBeforePrepare
  5803. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5804. goods, _ := dataBody["goods"].([]interface{})
  5805. if len(goods) > 0 {
  5806. for _, item := range goods {
  5807. items := item.(map[string]interface{})
  5808. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5809. utils.ErrorLog("good_id")
  5810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5811. return
  5812. }
  5813. good_id := int64(items["good_id"].(float64))
  5814. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5815. utils.ErrorLog("good_type_id")
  5816. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5817. return
  5818. }
  5819. good_type_id := int64(items["good_type_id"].(float64))
  5820. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5821. utils.ErrorLog("count")
  5822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5823. return
  5824. }
  5825. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5826. commdity_code := items["commdity_code"].(string)
  5827. fmt.Println("commdity", commdity_code)
  5828. prepareGoods := &models.DialysisBeforePrepareGoods{
  5829. GoodTypeId: good_type_id,
  5830. GoodId: good_id,
  5831. Count: count,
  5832. StorehouseId: houseConfig.StorehouseOutInfo,
  5833. }
  5834. beforePrepares = append(beforePrepares, prepareGoods)
  5835. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5836. GoodTypeId: good_type_id,
  5837. GoodId: good_id,
  5838. Count: count,
  5839. StorehouseId: houseConfig.StorehouseOutInfo,
  5840. }
  5841. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5842. prepare := &models.DialysisBeforePrepare{
  5843. GoodTypeId: good_type_id,
  5844. GoodId: good_id,
  5845. Count: count,
  5846. PatientId: patient_id,
  5847. RecordDate: record_time,
  5848. UserOrgId: adminUser.Org.Id,
  5849. Status: 1,
  5850. Ctime: time.Now().Unix(),
  5851. Creater: adminUser.AdminUser.Id,
  5852. CommdityCode: commdity_code,
  5853. StorehouseId: houseConfig.StorehouseOutInfo,
  5854. }
  5855. dialysisBefor = append(dialysisBefor, prepare)
  5856. }
  5857. }
  5858. //查询是否有库存
  5859. for _, item := range dialysisBefor {
  5860. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5861. if err == gorm.ErrRecordNotFound {
  5862. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5863. c.ServeSuccessJSON(map[string]interface{}{
  5864. "message": "1",
  5865. "good_name": goodObj.GoodName,
  5866. "specification_name": goodObj.SpecificationName,
  5867. })
  5868. return
  5869. }
  5870. if err != nil {
  5871. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5872. c.ServeSuccessJSON(map[string]interface{}{
  5873. "message": "1",
  5874. "good_name": goodObj.GoodName,
  5875. "specification_name": goodObj.SpecificationName,
  5876. })
  5877. return
  5878. }
  5879. }
  5880. fmt.Println("active-----------------------", active)
  5881. fmt.Println("len(goods)-----------------------", len(goods))
  5882. //新增
  5883. if active == 1 && len(goods) > 0 {
  5884. for _, item := range dialysisBefor {
  5885. dialyPrepareOne := models.DialysisBeforePrepare{
  5886. GoodTypeId: item.GoodTypeId,
  5887. GoodId: item.GoodId,
  5888. PatientId: item.PatientId,
  5889. RecordDate: item.RecordDate,
  5890. UserOrgId: item.UserOrgId,
  5891. Count: item.Count,
  5892. Ctime: time.Now().Unix(),
  5893. Creater: item.Creater,
  5894. CommdityCode: item.CommdityCode,
  5895. Status: 1,
  5896. StorehouseId: houseConfig.StorehouseOutInfo,
  5897. }
  5898. //先清除再插入
  5899. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5900. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5901. //查询默认仓库
  5902. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5903. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5904. var total_count int64
  5905. for _, it := range stockList {
  5906. total_count += it.StockCount
  5907. }
  5908. //基础库插入数据
  5909. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5910. //更新库存
  5911. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5912. var flush_count int64
  5913. for _, it := range goodList {
  5914. flush_count += it.StockCount
  5915. }
  5916. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5917. }
  5918. if err == nil {
  5919. c.ServeSuccessJSON(map[string]interface{}{
  5920. "msg": "保存成功",
  5921. "message": "2",
  5922. })
  5923. return
  5924. } else {
  5925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5926. return
  5927. }
  5928. }
  5929. if len(beforePrepares) > 0 && active == 2 {
  5930. for _, item := range beforePrepares {
  5931. //1.查看该患者该耗材型号最后一次出库数量
  5932. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5933. //判断当前出库数量和最后一次出库数量的大小
  5934. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  5935. if item.Count <= goodInfo.Count {
  5936. //退库
  5937. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  5938. //查询今日出库数据
  5939. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5940. for _, it := range list {
  5941. prepare := models.DialysisBeforePrepare{
  5942. UserOrgId: it.OrgId,
  5943. PatientId: patient_id,
  5944. RecordDate: it.RecordTime,
  5945. GoodId: it.GoodId,
  5946. GoodTypeId: it.GoodTypeId,
  5947. Count: it.Count,
  5948. Ctime: time.Now().Unix(),
  5949. Creater: adminUser.AdminUser.Id,
  5950. Status: 1,
  5951. StorehouseId: houseConfig.StorehouseOutInfo,
  5952. }
  5953. //删除准备表数据
  5954. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5955. service.CreateDialysisBeforePrepareOne(&prepare)
  5956. }
  5957. }
  5958. var last_total int64
  5959. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5960. if item.Count >= goodInfo.Count {
  5961. //查询当前批次当前耗材最后一条出库数据
  5962. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5963. //计算当前出库和最后一次出库数据相差数据
  5964. last_total = item.Count - lastOutInfo.Count
  5965. //查询该批次剩余库存
  5966. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  5967. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  5968. if lastInfo.StockCount >= last_total {
  5969. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5970. //查询今日出库数据
  5971. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5972. for _, it := range list {
  5973. prepare := models.DialysisBeforePrepare{
  5974. UserOrgId: it.OrgId,
  5975. PatientId: patient_id,
  5976. RecordDate: it.RecordTime,
  5977. GoodId: it.GoodId,
  5978. GoodTypeId: it.GoodTypeId,
  5979. Count: it.Count,
  5980. Ctime: time.Now().Unix(),
  5981. Creater: adminUser.AdminUser.Id,
  5982. Status: 1,
  5983. StorehouseId: houseConfig.StorehouseOutInfo,
  5984. }
  5985. //删除准备表数据
  5986. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5987. service.CreateDialysisBeforePrepareOne(&prepare)
  5988. //查询默认仓库
  5989. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5990. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5991. var total_count int64
  5992. for _, it := range stockList {
  5993. total_count += it.StockCount
  5994. }
  5995. //基础库插入数据
  5996. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5997. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5998. var flush_count int64
  5999. for _, it := range goodList {
  6000. flush_count += it.StockCount
  6001. }
  6002. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6003. }
  6004. }
  6005. //如果库存不够,则出库到下一个批次
  6006. if lastInfo.StockCount < last_total {
  6007. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6008. //查询今日出库数据
  6009. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6010. for _, it := range list {
  6011. prepare := models.DialysisBeforePrepare{
  6012. UserOrgId: it.OrgId,
  6013. PatientId: patient_id,
  6014. RecordDate: it.RecordTime,
  6015. GoodId: it.GoodId,
  6016. GoodTypeId: it.GoodTypeId,
  6017. Count: it.Count,
  6018. Ctime: time.Now().Unix(),
  6019. Creater: adminUser.AdminUser.Id,
  6020. Status: 1,
  6021. StorehouseId: houseConfig.StorehouseOutInfo,
  6022. }
  6023. //删除准备表数据
  6024. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6025. service.CreateDialysisBeforePrepareOne(&prepare)
  6026. //查询默认仓库
  6027. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6028. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6029. var total_count int64
  6030. for _, it := range stockList {
  6031. total_count += it.StockCount
  6032. }
  6033. //基础库插入数据
  6034. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6035. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6036. var flush_count int64
  6037. for _, it := range goodList {
  6038. flush_count += it.StockCount
  6039. }
  6040. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6041. }
  6042. if err != nil {
  6043. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6044. c.ServeSuccessJSON(map[string]interface{}{
  6045. "message": "1",
  6046. "good_name": goodObj.GoodName,
  6047. "specification_name": goodObj.SpecificationName,
  6048. })
  6049. return
  6050. }
  6051. }
  6052. }
  6053. if err != nil {
  6054. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6055. c.ServeSuccessJSON(map[string]interface{}{
  6056. "message": "1",
  6057. "good_name": goodObj.GoodName,
  6058. "specification_name": goodObj.SpecificationName,
  6059. })
  6060. return
  6061. }
  6062. }
  6063. }
  6064. }
  6065. var errs error
  6066. if errs == nil {
  6067. c.ServeSuccessJSON(map[string]interface{}{
  6068. "msg": "提交成功",
  6069. "message": "2",
  6070. "good_name": "",
  6071. "specification_name": "",
  6072. })
  6073. return
  6074. } else {
  6075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6076. return
  6077. }
  6078. }
  6079. func (c *DialysisAPIController) CreateStockOutInfo() {
  6080. patient_id, _ := c.GetInt64("patient_id", 0)
  6081. record_date := c.GetString("record_time")
  6082. if patient_id <= 0 {
  6083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6084. return
  6085. }
  6086. adminInfo := c.GetMobileAdminUserInfo()
  6087. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  6088. timeLayout := "2006-01-02"
  6089. loc, _ := time.LoadLocation("Local")
  6090. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6091. record_time := theRecordTime.Unix()
  6092. // 查询信息规挡的设置天数
  6093. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6094. if infor.ID > 0 && infor.WeekDay > 0 {
  6095. var cha_time int64
  6096. timeNowStr := time.Now().Format("2006-01-02")
  6097. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6098. //今日的日期减去设置的日期
  6099. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6100. if cha_time >= record_time {
  6101. //查询审核是否允许
  6102. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6103. //申请状态不允许的情况 拒绝修改
  6104. if infor.ApplicationStatus != 1 {
  6105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6106. return
  6107. }
  6108. }
  6109. }
  6110. //创建步骤表
  6111. finish := models.XtDialysisFinish{
  6112. IsFinish: 1,
  6113. UserOrgId: adminInfo.Org.Id,
  6114. Status: 1,
  6115. Ctime: time.Now().Unix(),
  6116. Mtime: 0,
  6117. Module: 11,
  6118. RecordDate: record_time,
  6119. Sourse: 1,
  6120. PatientId: patient_id,
  6121. }
  6122. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6123. if dialysisFinish.ID == 0 {
  6124. service.CreateDialysisFinish(finish)
  6125. }
  6126. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  6127. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6128. //去重
  6129. consumables = RemoveRepeatedGood(consumables)
  6130. if adminInfo.Org.Id == 9919 {
  6131. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6132. //查询是否有库存
  6133. for _, item := range consumables {
  6134. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6135. if item.Count > warehouse.Count {
  6136. goodErrcode := models.XtGoodErrcode{
  6137. UserOrgId: item.UserOrgId,
  6138. Errcode: "自动出库库存不足",
  6139. GoodId: item.GoodId,
  6140. Status: 1,
  6141. Ctime: time.Now().Unix(),
  6142. Mtime: 0,
  6143. Count: 0,
  6144. StockCount: 0,
  6145. Creater: creator,
  6146. BatchNumberId: warehouse.ID,
  6147. WarehouseOutId: 0,
  6148. }
  6149. service.CreateGoodErrcode(goodErrcode)
  6150. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6151. c.ServeSuccessJSON(map[string]interface{}{
  6152. "message": "1",
  6153. "good_name": goodObj.GoodName,
  6154. "specification_name": goodObj.SpecificationName,
  6155. })
  6156. return
  6157. }
  6158. }
  6159. //查询是否有出库单
  6160. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6161. if err == gorm.ErrRecordNotFound {
  6162. //没有记录,则创建出库单
  6163. timeStr := time.Now().Format("2006-01-02")
  6164. timeArr := strings.Split(timeStr, "-")
  6165. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6166. total = total + 1
  6167. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6168. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6169. number = number + total
  6170. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6171. creater := adminInfo.AdminUser.Id
  6172. warehouseOut := models.WarehouseOut{
  6173. WarehouseOutOrderNumber: warehousing_out_order,
  6174. OperationTime: time.Now().Unix(),
  6175. OrgId: adminInfo.Org.Id,
  6176. Creater: creater,
  6177. Ctime: time.Now().Unix(),
  6178. Status: 1,
  6179. WarehouseOutTime: record_time,
  6180. Dealer: 0,
  6181. Manufacturer: 0,
  6182. Type: 1,
  6183. IsSys: 1,
  6184. StorehouseId: houseConfig.StorehouseOutInfo,
  6185. IsCheck: 1,
  6186. }
  6187. err := service.AddSigleWarehouseOut(&warehouseOut)
  6188. if err != nil {
  6189. goodErrcode := models.XtGoodErrcode{
  6190. UserOrgId: adminInfo.Org.Id,
  6191. Errcode: "创建出库单失败",
  6192. GoodId: 0,
  6193. Status: 1,
  6194. Ctime: time.Now().Unix(),
  6195. Mtime: 0,
  6196. Count: 0,
  6197. StockCount: 0,
  6198. Creater: creator,
  6199. BatchNumberId: 0,
  6200. WarehouseOutId: 0,
  6201. }
  6202. service.CreateGoodErrcode(goodErrcode)
  6203. utils.TraceLog("创建出库单失败 err = %v", err)
  6204. } else {
  6205. for _, item := range consumables {
  6206. //出库
  6207. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6208. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6209. if err == nil {
  6210. goodErrcode := models.XtGoodErrcode{
  6211. UserOrgId: adminInfo.Org.Id,
  6212. Errcode: "自动出库接口报错",
  6213. GoodId: 0,
  6214. Status: 1,
  6215. Ctime: time.Now().Unix(),
  6216. Mtime: 0,
  6217. Count: 0,
  6218. StockCount: 0,
  6219. Creater: creator,
  6220. BatchNumberId: 0,
  6221. WarehouseOutId: 0,
  6222. }
  6223. service.CreateGoodErrcode(goodErrcode)
  6224. utils.TraceLog("创建出库单失败 err = %v", err)
  6225. }
  6226. //查询
  6227. //出库数量相加
  6228. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6229. if errs != nil {
  6230. goodErrcode := models.XtGoodErrcode{
  6231. UserOrgId: item.UserOrgId,
  6232. Errcode: "创建剩余库存字段报错",
  6233. GoodId: item.GoodId,
  6234. Status: 1,
  6235. Ctime: time.Now().Unix(),
  6236. Mtime: 0,
  6237. Count: 0,
  6238. StockCount: 0,
  6239. Creater: creater,
  6240. BatchNumberId: 0,
  6241. WarehouseOutId: 0,
  6242. }
  6243. service.CreateGoodErrcode(goodErrcode)
  6244. }
  6245. }
  6246. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6247. if len(list) == 0 {
  6248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6249. return
  6250. }
  6251. for _, item := range list {
  6252. prepare := models.DialysisBeforePrepare{
  6253. UserOrgId: adminInfo.Org.Id,
  6254. PatientId: patient_id,
  6255. RecordDate: record_time,
  6256. GoodId: item.GoodId,
  6257. GoodTypeId: item.GoodTypeId,
  6258. Count: item.Count,
  6259. Creater: adminInfo.AdminUser.Id,
  6260. Status: 1,
  6261. Ctime: time.Now().Unix(),
  6262. StorehouseId: houseConfig.StorehouseOutInfo,
  6263. }
  6264. //清空准备表数据
  6265. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6266. if err != nil {
  6267. goodErrcode := models.XtGoodErrcode{
  6268. UserOrgId: item.OrgId,
  6269. Errcode: "自动出库清空准备表数据报错",
  6270. GoodId: item.GoodId,
  6271. Status: 1,
  6272. Ctime: time.Now().Unix(),
  6273. Mtime: 0,
  6274. Count: 0,
  6275. StockCount: 0,
  6276. Creater: creater,
  6277. BatchNumberId: 0,
  6278. WarehouseOutId: 0,
  6279. }
  6280. service.CreateGoodErrcode(goodErrcode)
  6281. }
  6282. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6283. if errs != nil {
  6284. goodErrcode := models.XtGoodErrcode{
  6285. UserOrgId: item.OrgId,
  6286. Errcode: "自动出库创建准备表数据报错",
  6287. GoodId: item.GoodId,
  6288. Status: 1,
  6289. Ctime: time.Now().Unix(),
  6290. Mtime: 0,
  6291. Count: 0,
  6292. StockCount: 0,
  6293. Creater: creater,
  6294. BatchNumberId: 0,
  6295. WarehouseOutId: 0,
  6296. }
  6297. service.CreateGoodErrcode(goodErrcode)
  6298. }
  6299. //查询默认仓库
  6300. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6301. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6302. var total_count int64
  6303. for _, it := range stockList {
  6304. total_count += it.StockCount
  6305. }
  6306. //基础库插入数据
  6307. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6308. if errcodes != nil {
  6309. goodErrcode := models.XtGoodErrcode{
  6310. UserOrgId: item.OrgId,
  6311. Errcode: "自动出库基础库插入数据",
  6312. GoodId: item.GoodId,
  6313. Status: 1,
  6314. Ctime: time.Now().Unix(),
  6315. Mtime: 0,
  6316. Count: 0,
  6317. StockCount: 0,
  6318. Creater: creater,
  6319. BatchNumberId: 0,
  6320. WarehouseOutId: 0,
  6321. }
  6322. service.CreateGoodErrcode(goodErrcode)
  6323. }
  6324. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6325. var flush_count int64
  6326. for _, it := range goodList {
  6327. flush_count += it.StockCount
  6328. }
  6329. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6330. if errsss != nil {
  6331. goodErrcode := models.XtGoodErrcode{
  6332. UserOrgId: item.OrgId,
  6333. Errcode: "自动出库剩余库存更新数据",
  6334. GoodId: item.GoodId,
  6335. Status: 1,
  6336. Ctime: time.Now().Unix(),
  6337. Mtime: 0,
  6338. Count: 0,
  6339. StockCount: 0,
  6340. Creater: creater,
  6341. BatchNumberId: 0,
  6342. WarehouseOutId: 0,
  6343. }
  6344. service.CreateGoodErrcode(goodErrcode)
  6345. }
  6346. }
  6347. }
  6348. //
  6349. } else if err == nil {
  6350. for _, item := range consumables {
  6351. //出库
  6352. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6353. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6354. if err != nil {
  6355. goodErrcode := models.XtGoodErrcode{
  6356. UserOrgId: adminInfo.Org.Id,
  6357. Errcode: "自动出库接口报错",
  6358. GoodId: 0,
  6359. Status: 1,
  6360. Ctime: time.Now().Unix(),
  6361. Mtime: 0,
  6362. Count: 0,
  6363. StockCount: 0,
  6364. Creater: creator,
  6365. BatchNumberId: 0,
  6366. WarehouseOutId: 0,
  6367. }
  6368. service.CreateGoodErrcode(goodErrcode)
  6369. }
  6370. //出库数量相加
  6371. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6372. if errss != nil {
  6373. goodErrcode := models.XtGoodErrcode{
  6374. UserOrgId: item.UserOrgId,
  6375. Errcode: "创建剩余库存字段报错",
  6376. GoodId: item.GoodId,
  6377. Status: 1,
  6378. Ctime: time.Now().Unix(),
  6379. Mtime: time.Now().Unix(),
  6380. Count: 0,
  6381. StockCount: 0,
  6382. Creater: item.Creater,
  6383. BatchNumberId: 0,
  6384. WarehouseOutId: 0,
  6385. }
  6386. service.CreateGoodErrcode(goodErrcode)
  6387. }
  6388. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6389. if len(list) == 0 {
  6390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6391. return
  6392. }
  6393. for _, item := range list {
  6394. prepare := models.DialysisBeforePrepare{
  6395. UserOrgId: adminInfo.Org.Id,
  6396. PatientId: patient_id,
  6397. RecordDate: record_time,
  6398. GoodId: item.GoodId,
  6399. GoodTypeId: item.GoodTypeId,
  6400. Count: item.Count,
  6401. Creater: adminInfo.AdminUser.Id,
  6402. Status: 1,
  6403. Ctime: time.Now().Unix(),
  6404. StorehouseId: houseConfig.StorehouseOutInfo,
  6405. }
  6406. //清空准备表数据
  6407. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6408. if errs != nil {
  6409. goodErrcode := models.XtGoodErrcode{
  6410. UserOrgId: adminInfo.Org.Id,
  6411. Errcode: "自动出库清空准备表数据报错",
  6412. GoodId: 0,
  6413. Status: 1,
  6414. Ctime: time.Now().Unix(),
  6415. Mtime: 0,
  6416. Count: 0,
  6417. StockCount: 0,
  6418. Creater: creator,
  6419. BatchNumberId: 0,
  6420. WarehouseOutId: 0,
  6421. }
  6422. service.CreateGoodErrcode(goodErrcode)
  6423. }
  6424. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6425. if errcodes != nil {
  6426. goodErrcode := models.XtGoodErrcode{
  6427. UserOrgId: adminInfo.Org.Id,
  6428. Errcode: "自动出库创建准备表数据报错",
  6429. GoodId: 0,
  6430. Status: 1,
  6431. Ctime: time.Now().Unix(),
  6432. Mtime: 0,
  6433. Count: 0,
  6434. StockCount: 0,
  6435. Creater: creator,
  6436. BatchNumberId: 0,
  6437. WarehouseOutId: 0,
  6438. }
  6439. service.CreateGoodErrcode(goodErrcode)
  6440. }
  6441. //查询默认仓库
  6442. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6443. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6444. var total_count int64
  6445. for _, it := range stockList {
  6446. total_count += it.StockCount
  6447. }
  6448. //基础库插入数据
  6449. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6450. if errcodes != nil {
  6451. goodErrcode := models.XtGoodErrcode{
  6452. UserOrgId: adminInfo.Org.Id,
  6453. Errcode: "自动出库基础库插入数据报错",
  6454. GoodId: 0,
  6455. Status: 1,
  6456. Ctime: time.Now().Unix(),
  6457. Mtime: 0,
  6458. Count: 0,
  6459. StockCount: 0,
  6460. Creater: creator,
  6461. BatchNumberId: 0,
  6462. WarehouseOutId: 0,
  6463. }
  6464. service.CreateGoodErrcode(goodErrcode)
  6465. }
  6466. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6467. var flush_count int64
  6468. for _, it := range goodList {
  6469. flush_count += it.StockCount
  6470. }
  6471. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6472. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6473. if errss != nil {
  6474. goodErrcode := models.XtGoodErrcode{
  6475. UserOrgId: item.OrgId,
  6476. Errcode: "自动出库剩余库存更新数据",
  6477. GoodId: item.GoodId,
  6478. Status: 1,
  6479. Ctime: time.Now().Unix(),
  6480. Mtime: 0,
  6481. Count: 0,
  6482. StockCount: 0,
  6483. Creater: creater,
  6484. BatchNumberId: 0,
  6485. WarehouseOutId: 0,
  6486. }
  6487. service.CreateGoodErrcode(goodErrcode)
  6488. }
  6489. }
  6490. }
  6491. }
  6492. c.ServeSuccessJSON(map[string]interface{}{
  6493. "msg": "提交成功",
  6494. "message": "2",
  6495. "good_name": "",
  6496. "specification_name": "",
  6497. })
  6498. return
  6499. }
  6500. if record.IsOpen == 1 {
  6501. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6502. //查询是否有库存
  6503. for _, item := range consumables {
  6504. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6505. if item.Count > warehouse.Count {
  6506. goodErrcode := models.XtGoodErrcode{
  6507. UserOrgId: item.UserOrgId,
  6508. Errcode: "自动出库库存不足",
  6509. GoodId: item.GoodId,
  6510. Status: 1,
  6511. Ctime: time.Now().Unix(),
  6512. Mtime: 0,
  6513. Count: 0,
  6514. StockCount: 0,
  6515. Creater: creator,
  6516. BatchNumberId: warehouse.ID,
  6517. WarehouseOutId: 0,
  6518. }
  6519. service.CreateGoodErrcode(goodErrcode)
  6520. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6521. c.ServeSuccessJSON(map[string]interface{}{
  6522. "message": "1",
  6523. "good_name": goodObj.GoodName,
  6524. "specification_name": goodObj.SpecificationName,
  6525. })
  6526. return
  6527. }
  6528. }
  6529. //查询是否有出库单
  6530. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6531. if err == gorm.ErrRecordNotFound {
  6532. //没有记录,则创建出库单
  6533. timeStr := time.Now().Format("2006-01-02")
  6534. timeArr := strings.Split(timeStr, "-")
  6535. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6536. total = total + 1
  6537. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6538. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6539. number = number + total
  6540. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6541. creater := adminInfo.AdminUser.Id
  6542. warehouseOut := models.WarehouseOut{
  6543. WarehouseOutOrderNumber: warehousing_out_order,
  6544. OperationTime: time.Now().Unix(),
  6545. OrgId: adminInfo.Org.Id,
  6546. Creater: creater,
  6547. Ctime: time.Now().Unix(),
  6548. Status: 1,
  6549. WarehouseOutTime: record_time,
  6550. Dealer: 0,
  6551. Manufacturer: 0,
  6552. Type: 1,
  6553. IsSys: 1,
  6554. StorehouseId: houseConfig.StorehouseOutInfo,
  6555. IsCheck: 1,
  6556. }
  6557. err := service.AddSigleWarehouseOut(&warehouseOut)
  6558. if err != nil {
  6559. goodErrcode := models.XtGoodErrcode{
  6560. UserOrgId: adminInfo.Org.Id,
  6561. Errcode: "创建出库单失败",
  6562. GoodId: 0,
  6563. Status: 1,
  6564. Ctime: time.Now().Unix(),
  6565. Mtime: 0,
  6566. Count: 0,
  6567. StockCount: 0,
  6568. Creater: creator,
  6569. BatchNumberId: 0,
  6570. WarehouseOutId: 0,
  6571. }
  6572. service.CreateGoodErrcode(goodErrcode)
  6573. utils.TraceLog("创建出库单失败 err = %v", err)
  6574. } else {
  6575. for _, item := range consumables {
  6576. //出库
  6577. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6578. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6579. if err == nil {
  6580. goodErrcode := models.XtGoodErrcode{
  6581. UserOrgId: adminInfo.Org.Id,
  6582. Errcode: "自动出库接口报错",
  6583. GoodId: 0,
  6584. Status: 1,
  6585. Ctime: time.Now().Unix(),
  6586. Mtime: 0,
  6587. Count: 0,
  6588. StockCount: 0,
  6589. Creater: creator,
  6590. BatchNumberId: 0,
  6591. WarehouseOutId: 0,
  6592. }
  6593. service.CreateGoodErrcode(goodErrcode)
  6594. utils.TraceLog("创建出库单失败 err = %v", err)
  6595. }
  6596. //查询
  6597. //出库数量相加
  6598. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6599. if errs != nil {
  6600. goodErrcode := models.XtGoodErrcode{
  6601. UserOrgId: item.UserOrgId,
  6602. Errcode: "创建剩余库存字段报错",
  6603. GoodId: item.GoodId,
  6604. Status: 1,
  6605. Ctime: time.Now().Unix(),
  6606. Mtime: 0,
  6607. Count: 0,
  6608. StockCount: 0,
  6609. Creater: creater,
  6610. BatchNumberId: 0,
  6611. WarehouseOutId: 0,
  6612. }
  6613. service.CreateGoodErrcode(goodErrcode)
  6614. }
  6615. }
  6616. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6617. if len(list) == 0 {
  6618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6619. return
  6620. }
  6621. for _, item := range list {
  6622. prepare := models.DialysisBeforePrepare{
  6623. UserOrgId: adminInfo.Org.Id,
  6624. PatientId: patient_id,
  6625. RecordDate: record_time,
  6626. GoodId: item.GoodId,
  6627. GoodTypeId: item.GoodTypeId,
  6628. Count: item.Count,
  6629. Creater: adminInfo.AdminUser.Id,
  6630. Status: 1,
  6631. Ctime: time.Now().Unix(),
  6632. StorehouseId: houseConfig.StorehouseOutInfo,
  6633. }
  6634. //清空准备表数据
  6635. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6636. if err != nil {
  6637. goodErrcode := models.XtGoodErrcode{
  6638. UserOrgId: item.OrgId,
  6639. Errcode: "自动出库清空准备表数据报错",
  6640. GoodId: item.GoodId,
  6641. Status: 1,
  6642. Ctime: time.Now().Unix(),
  6643. Mtime: 0,
  6644. Count: 0,
  6645. StockCount: 0,
  6646. Creater: creater,
  6647. BatchNumberId: 0,
  6648. WarehouseOutId: 0,
  6649. }
  6650. service.CreateGoodErrcode(goodErrcode)
  6651. }
  6652. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6653. if errs != nil {
  6654. goodErrcode := models.XtGoodErrcode{
  6655. UserOrgId: item.OrgId,
  6656. Errcode: "自动出库创建准备表数据报错",
  6657. GoodId: item.GoodId,
  6658. Status: 1,
  6659. Ctime: time.Now().Unix(),
  6660. Mtime: 0,
  6661. Count: 0,
  6662. StockCount: 0,
  6663. Creater: creater,
  6664. BatchNumberId: 0,
  6665. WarehouseOutId: 0,
  6666. }
  6667. service.CreateGoodErrcode(goodErrcode)
  6668. }
  6669. //查询默认仓库
  6670. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6671. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6672. var total_count int64
  6673. for _, it := range stockList {
  6674. total_count += it.StockCount
  6675. }
  6676. //基础库插入数据
  6677. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6678. if errcodes != nil {
  6679. goodErrcode := models.XtGoodErrcode{
  6680. UserOrgId: item.OrgId,
  6681. Errcode: "自动出库基础库插入数据",
  6682. GoodId: item.GoodId,
  6683. Status: 1,
  6684. Ctime: time.Now().Unix(),
  6685. Mtime: 0,
  6686. Count: 0,
  6687. StockCount: 0,
  6688. Creater: creater,
  6689. BatchNumberId: 0,
  6690. WarehouseOutId: 0,
  6691. }
  6692. service.CreateGoodErrcode(goodErrcode)
  6693. }
  6694. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6695. var flush_count int64
  6696. for _, it := range goodList {
  6697. flush_count += it.StockCount
  6698. }
  6699. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6700. if errsss != nil {
  6701. goodErrcode := models.XtGoodErrcode{
  6702. UserOrgId: item.OrgId,
  6703. Errcode: "自动出库剩余库存更新数据",
  6704. GoodId: item.GoodId,
  6705. Status: 1,
  6706. Ctime: time.Now().Unix(),
  6707. Mtime: 0,
  6708. Count: 0,
  6709. StockCount: 0,
  6710. Creater: creater,
  6711. BatchNumberId: 0,
  6712. WarehouseOutId: 0,
  6713. }
  6714. service.CreateGoodErrcode(goodErrcode)
  6715. }
  6716. }
  6717. }
  6718. //
  6719. } else if err == nil {
  6720. for _, item := range consumables {
  6721. //出库
  6722. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6723. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6724. if err != nil {
  6725. goodErrcode := models.XtGoodErrcode{
  6726. UserOrgId: adminInfo.Org.Id,
  6727. Errcode: "自动出库接口报错",
  6728. GoodId: 0,
  6729. Status: 1,
  6730. Ctime: time.Now().Unix(),
  6731. Mtime: 0,
  6732. Count: 0,
  6733. StockCount: 0,
  6734. Creater: creator,
  6735. BatchNumberId: 0,
  6736. WarehouseOutId: 0,
  6737. }
  6738. service.CreateGoodErrcode(goodErrcode)
  6739. }
  6740. //出库数量相加
  6741. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6742. if errss != nil {
  6743. goodErrcode := models.XtGoodErrcode{
  6744. UserOrgId: item.UserOrgId,
  6745. Errcode: "创建剩余库存字段报错",
  6746. GoodId: item.GoodId,
  6747. Status: 1,
  6748. Ctime: time.Now().Unix(),
  6749. Mtime: time.Now().Unix(),
  6750. Count: 0,
  6751. StockCount: 0,
  6752. Creater: item.Creater,
  6753. BatchNumberId: 0,
  6754. WarehouseOutId: 0,
  6755. }
  6756. service.CreateGoodErrcode(goodErrcode)
  6757. }
  6758. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6759. if len(list) == 0 {
  6760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6761. return
  6762. }
  6763. for _, item := range list {
  6764. prepare := models.DialysisBeforePrepare{
  6765. UserOrgId: adminInfo.Org.Id,
  6766. PatientId: patient_id,
  6767. RecordDate: record_time,
  6768. GoodId: item.GoodId,
  6769. GoodTypeId: item.GoodTypeId,
  6770. Count: item.Count,
  6771. Creater: adminInfo.AdminUser.Id,
  6772. Status: 1,
  6773. Ctime: time.Now().Unix(),
  6774. StorehouseId: houseConfig.StorehouseOutInfo,
  6775. }
  6776. //清空准备表数据
  6777. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6778. if errs != nil {
  6779. goodErrcode := models.XtGoodErrcode{
  6780. UserOrgId: adminInfo.Org.Id,
  6781. Errcode: "自动出库清空准备表数据报错",
  6782. GoodId: 0,
  6783. Status: 1,
  6784. Ctime: time.Now().Unix(),
  6785. Mtime: 0,
  6786. Count: 0,
  6787. StockCount: 0,
  6788. Creater: creator,
  6789. BatchNumberId: 0,
  6790. WarehouseOutId: 0,
  6791. }
  6792. service.CreateGoodErrcode(goodErrcode)
  6793. }
  6794. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6795. if errcodes != nil {
  6796. goodErrcode := models.XtGoodErrcode{
  6797. UserOrgId: adminInfo.Org.Id,
  6798. Errcode: "自动出库创建准备表数据报错",
  6799. GoodId: 0,
  6800. Status: 1,
  6801. Ctime: time.Now().Unix(),
  6802. Mtime: 0,
  6803. Count: 0,
  6804. StockCount: 0,
  6805. Creater: creator,
  6806. BatchNumberId: 0,
  6807. WarehouseOutId: 0,
  6808. }
  6809. service.CreateGoodErrcode(goodErrcode)
  6810. }
  6811. //查询默认仓库
  6812. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6813. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6814. var total_count int64
  6815. for _, it := range stockList {
  6816. total_count += it.StockCount
  6817. }
  6818. //基础库插入数据
  6819. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6820. if errcodes != nil {
  6821. goodErrcode := models.XtGoodErrcode{
  6822. UserOrgId: adminInfo.Org.Id,
  6823. Errcode: "自动出库基础库插入数据报错",
  6824. GoodId: 0,
  6825. Status: 1,
  6826. Ctime: time.Now().Unix(),
  6827. Mtime: 0,
  6828. Count: 0,
  6829. StockCount: 0,
  6830. Creater: creator,
  6831. BatchNumberId: 0,
  6832. WarehouseOutId: 0,
  6833. }
  6834. service.CreateGoodErrcode(goodErrcode)
  6835. }
  6836. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6837. var flush_count int64
  6838. for _, it := range goodList {
  6839. flush_count += it.StockCount
  6840. }
  6841. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6842. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6843. if errss != nil {
  6844. goodErrcode := models.XtGoodErrcode{
  6845. UserOrgId: item.OrgId,
  6846. Errcode: "自动出库剩余库存更新数据",
  6847. GoodId: item.GoodId,
  6848. Status: 1,
  6849. Ctime: time.Now().Unix(),
  6850. Mtime: 0,
  6851. Count: 0,
  6852. StockCount: 0,
  6853. Creater: creater,
  6854. BatchNumberId: 0,
  6855. WarehouseOutId: 0,
  6856. }
  6857. service.CreateGoodErrcode(goodErrcode)
  6858. }
  6859. }
  6860. }
  6861. }
  6862. c.ServeSuccessJSON(map[string]interface{}{
  6863. "msg": "提交成功",
  6864. "message": "2",
  6865. "good_name": "",
  6866. "specification_name": "",
  6867. })
  6868. return
  6869. } else {
  6870. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6871. return
  6872. }
  6873. }
  6874. func (c *DialysisAPIController) EditConsumables() {
  6875. patient_id, _ := c.GetInt64("patient_id", 0)
  6876. record_date := c.GetString("record_time")
  6877. if patient_id <= 0 {
  6878. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6879. return
  6880. }
  6881. adminInfo := c.GetMobileAdminUserInfo()
  6882. timeLayout := "2006-01-02"
  6883. loc, _ := time.LoadLocation("Local")
  6884. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6885. record_time := theRecordTime.Unix()
  6886. // 查询信息规挡的设置天数
  6887. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6888. if infor.ID > 0 && infor.WeekDay > 0 {
  6889. var cha_time int64
  6890. timeNowStr := time.Now().Format("2006-01-02")
  6891. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6892. //今日的日期减去设置的日期
  6893. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6894. if cha_time >= record_time {
  6895. //查询审核是否允许
  6896. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6897. //申请状态不允许的情况 拒绝修改
  6898. if infor.ApplicationStatus != 1 {
  6899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6900. return
  6901. }
  6902. }
  6903. }
  6904. dataBody := make(map[string]interface{}, 0)
  6905. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6906. if err != nil {
  6907. utils.ErrorLog(err.Error())
  6908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6909. return
  6910. }
  6911. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6912. var beforePrepares []*models.DialysisBeforePrepareGoods
  6913. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6914. var cancelbefor []*models.DialysisBeforePrepareGoods
  6915. var outbefor []*models.DialysisBeforePrepareGoods
  6916. //判断是否开启自动出库
  6917. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6918. if record.IsOpen == 1 {
  6919. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6920. goods, _ := dataBody["goods"].([]interface{})
  6921. if len(goods) > 0 {
  6922. for _, item := range goods {
  6923. items := item.(map[string]interface{})
  6924. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6925. utils.ErrorLog("good_id")
  6926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6927. return
  6928. }
  6929. good_id := int64(items["good_id"].(float64))
  6930. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6931. utils.ErrorLog("good_type_id")
  6932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6933. return
  6934. }
  6935. good_type_id := int64(items["good_type_id"].(float64))
  6936. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6937. utils.ErrorLog("count")
  6938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6939. return
  6940. }
  6941. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6942. commdity_code := items["commdity_code"].(string)
  6943. fmt.Println(commdity_code)
  6944. prepareGoods := &models.DialysisBeforePrepareGoods{
  6945. GoodTypeId: good_type_id,
  6946. GoodId: good_id,
  6947. Count: count,
  6948. StorehouseId: houseConfig.StorehouseOutInfo,
  6949. }
  6950. beforePrepares = append(beforePrepares, prepareGoods)
  6951. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6952. GoodTypeId: good_type_id,
  6953. GoodId: good_id,
  6954. Count: count,
  6955. StorehouseId: houseConfig.StorehouseOutInfo,
  6956. }
  6957. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6958. }
  6959. for _, item := range beforePrepares {
  6960. //1.查看该患者该耗材型号最后一次出库数量
  6961. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6962. //判断当前出库数量和最后一次出库数量的大小
  6963. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  6964. if item.Count < goodInfo.Count {
  6965. cancelbefor = append(cancelbefor, item)
  6966. }
  6967. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6968. if item.Count > goodInfo.Count {
  6969. outbefor = append(outbefor, item)
  6970. }
  6971. //处理编辑耗材新增不了的问题
  6972. if goodInfo.Count == item.Count {
  6973. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  6974. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  6975. }
  6976. }
  6977. if len(cancelbefor) > 0 {
  6978. //退库
  6979. for _, item := range cancelbefor {
  6980. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6981. creater := adminInfo.AdminUser.Id
  6982. //查询该患者当天已经出库的耗材信息
  6983. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  6984. var delete_count int64 = 0
  6985. delete_count = warehouseOutInfos.Count - item.Count
  6986. //增加库存数量
  6987. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  6988. //减少实际出库库存数量
  6989. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  6990. // 删除出库完成后,要增加对应批次的库存数量
  6991. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  6992. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6993. //更新剩余库存
  6994. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6995. var flush_count int64
  6996. for _, it := range goodListOne {
  6997. flush_count += it.StockCount
  6998. }
  6999. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7000. //查询剩余库存
  7001. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7002. var sum_count int64
  7003. for _, item := range goodList {
  7004. sum_count += item.StockCount
  7005. }
  7006. // 在出库记录表里记录退库详情
  7007. warehouseOutInfo := &models.WarehouseOutInfo{
  7008. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7009. WarehouseOutId: warehouseOut.ID,
  7010. Status: 1,
  7011. Ctime: time.Now().Unix(),
  7012. OrgId: adminInfo.Org.Id,
  7013. Type: 1,
  7014. IsSys: 1,
  7015. SysRecordTime: record_time,
  7016. GoodTypeId: item.GoodTypeId,
  7017. GoodId: item.GoodId,
  7018. PatientId: patient_id,
  7019. ConsumableType: 2,
  7020. StorehouseId: houseConfig.StorehouseOutInfo,
  7021. IsCheck: 1,
  7022. OverCount: sum_count,
  7023. }
  7024. warehouseOutInfo.Count = item.Count
  7025. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  7026. warehouseOutInfo.Price = stockInInfo.Price
  7027. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7028. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7029. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7030. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7031. warehouseOutInfo.Number = warehouseOutInfos.Number
  7032. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7033. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7034. //查找当天是否存在出库记录
  7035. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  7036. if errcod == gorm.ErrRecordNotFound {
  7037. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7038. //插入详情明细表
  7039. stockFlow := models.VmStockFlow{
  7040. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7041. WarehouseOutId: warehouseOut.ID,
  7042. GoodId: item.GoodId,
  7043. Number: warehouseOutInfos.Number,
  7044. ProductDate: stockInInfo.ProductDate,
  7045. ExpireDate: stockInInfo.ExpiryDate,
  7046. Count: item.Count,
  7047. Price: stockInInfo.Price,
  7048. Status: 1,
  7049. Ctime: record_time,
  7050. UserOrgId: adminInfo.Org.Id,
  7051. Manufacturer: stockInInfo.Manufacturer,
  7052. Dealer: stockInInfo.Dealer,
  7053. LicenseNumber: stockInInfo.LicenseNumber,
  7054. IsEdit: 2,
  7055. Creator: creater,
  7056. SystemTime: record_time,
  7057. ConsumableType: 3,
  7058. WarehousingDetailId: 0,
  7059. IsSys: 1,
  7060. UpdateCreator: creater,
  7061. PatientId: patient_id,
  7062. StorehouseId: houseConfig.StorehouseOutInfo,
  7063. }
  7064. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  7065. if errflow == gorm.ErrRecordNotFound {
  7066. //创建流水表
  7067. err := service.CreateStockFlowOne(stockFlow)
  7068. fmt.Println("err", err)
  7069. } else if errflow == nil {
  7070. //插入详情明细表
  7071. stockFlow := models.VmStockFlow{
  7072. ID: exsit.ID,
  7073. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7074. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7075. WarehouseOutId: warehouseOut.ID,
  7076. GoodId: item.GoodId,
  7077. Number: warehouseOutInfos.Number,
  7078. ProductDate: stockInInfo.ProductDate,
  7079. ExpireDate: stockInInfo.ExpiryDate,
  7080. Count: exsit.Count - delete_count,
  7081. Price: stockInInfo.Price,
  7082. Status: 1,
  7083. Ctime: record_time,
  7084. UserOrgId: adminInfo.Org.Id,
  7085. Manufacturer: stockInInfo.Manufacturer,
  7086. Dealer: stockInInfo.Dealer,
  7087. LicenseNumber: stockInInfo.LicenseNumber,
  7088. IsEdit: 2,
  7089. Creator: creater,
  7090. SystemTime: record_time,
  7091. ConsumableType: 3,
  7092. WarehousingDetailId: 0,
  7093. IsSys: 1,
  7094. UpdateCreator: creater,
  7095. PatientId: patient_id,
  7096. StorehouseId: houseConfig.StorehouseOutInfo,
  7097. }
  7098. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  7099. }
  7100. } else if errcod == nil {
  7101. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  7102. //查询剩余库存
  7103. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7104. var sum_count int64
  7105. for _, item := range goodList {
  7106. sum_count += item.StockCount
  7107. }
  7108. //创建退库单,生成退库数据
  7109. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7110. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  7111. operation_time := time.Now().Unix()
  7112. creater := adminInfo.AdminUser.Id
  7113. //创建退库单
  7114. timeStr := time.Now().Format("2006-01-02")
  7115. timeArr := strings.Split(timeStr, "-")
  7116. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  7117. total = total + 1
  7118. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7119. cancelStock := models.CancelStock{
  7120. OrderNumber: orderNumber,
  7121. OperaTime: operation_time,
  7122. OrgId: adminInfo.Org.Id,
  7123. Creater: creater,
  7124. Ctime: time.Now().Unix(),
  7125. Status: 1,
  7126. ReturnTime: record_time,
  7127. Type: 1,
  7128. StorehouseId: houseConfig.StorehouseOutInfo,
  7129. IsCheck: 1,
  7130. }
  7131. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  7132. if msgerrkonde == gorm.ErrRecordNotFound {
  7133. service.AddSigleCancelStock(&cancelStock)
  7134. }
  7135. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  7136. //查询是否有出库
  7137. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  7138. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7139. deaerler, _ := service.GetDealerById(info.Dealer)
  7140. if info.ID > 0 {
  7141. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  7142. cancelStockInfo := models.CancelStockInfo{
  7143. GoodId: item.GoodId,
  7144. CancelStockId: cancel.ID,
  7145. GoodTypeId: good.GoodTypeId,
  7146. Count: delete_count,
  7147. Price: info.Price,
  7148. Total: 0,
  7149. ProductDate: info.ProductDate,
  7150. ExpiryDate: info.ExpiryDate,
  7151. Ctime: time.Now().Unix(),
  7152. Status: 1,
  7153. OrgId: adminInfo.Org.Id,
  7154. OrderNumber: cancel.OrderNumber,
  7155. Type: 0,
  7156. Dealer: deaerler.DealerName,
  7157. Manufacturer: manufacturer.ManufacturerName,
  7158. Number: info.Number,
  7159. RegisterAccount: "",
  7160. Remark: "",
  7161. WarehouseInfoId: info.WarehouseInfotId,
  7162. PatientId: info.PatientId,
  7163. RecordDate: info.SysRecordTime,
  7164. StorehouseId: houseConfig.StorehouseOutInfo,
  7165. IsCheck: 1,
  7166. }
  7167. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7168. //退库数量增加
  7169. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7170. //查询剩余库存
  7171. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7172. var over_count int64
  7173. for _, it := range goodList {
  7174. over_count += it.StockCount
  7175. }
  7176. flow := models.VmStockFlow{
  7177. WarehousingId: info.WarehouseInfotId,
  7178. GoodId: item.GoodId,
  7179. Number: info.Number,
  7180. LicenseNumber: info.LicenseNumber,
  7181. Count: delete_count,
  7182. UserOrgId: adminInfo.Org.Id,
  7183. PatientId: patient_id,
  7184. SystemTime: info.SysRecordTime,
  7185. ConsumableType: 7,
  7186. IsSys: 0,
  7187. WarehousingOrder: "",
  7188. WarehouseOutId: info.WarehouseOutId,
  7189. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7190. IsEdit: 0,
  7191. CancelStockId: cancel.ID,
  7192. CancelOrderNumber: cancel.OrderNumber,
  7193. Manufacturer: manufacturer.ID,
  7194. Dealer: 0,
  7195. Creator: adminInfo.AdminUser.Id,
  7196. UpdateCreator: 0,
  7197. Status: 1,
  7198. Ctime: record_time,
  7199. Mtime: 0,
  7200. Price: info.Price,
  7201. WarehousingDetailId: info.WarehouseInfotId,
  7202. WarehouseOutDetailId: info.ID,
  7203. CancelOutDetailId: cancelInfo.ID,
  7204. ProductDate: info.ProductDate,
  7205. ExpireDate: info.ExpiryDate,
  7206. StorehouseId: houseConfig.StorehouseOutInfo,
  7207. OverCount: over_count,
  7208. }
  7209. service.CreateStockFlowOne(flow)
  7210. }
  7211. }
  7212. //更改自动出库的表格
  7213. details := models.BloodAutomaticReduceDetail{
  7214. WarehouseOutId: warehouseOutInfo.ID,
  7215. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7216. PatientId: patient_id,
  7217. Ctime: time.Now().Unix(),
  7218. Mtime: time.Now().Unix(),
  7219. Status: 1,
  7220. RecordTime: record_time,
  7221. OrgId: adminInfo.Org.Id,
  7222. GoodId: item.GoodId,
  7223. GoodTypeId: item.GoodTypeId,
  7224. Count: item.Count,
  7225. StorehouseId: houseConfig.StorehouseOutInfo,
  7226. }
  7227. //查询当天耗材是否已经存在数据
  7228. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7229. if errcode == gorm.ErrRecordNotFound {
  7230. service.CreateAutoReduceRecord(&details)
  7231. } else if errcode == nil {
  7232. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7233. service.CreateAutoReduceRecord(&details)
  7234. }
  7235. //查询默认仓库
  7236. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7237. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7238. var total_count int64
  7239. for _, it := range stockList {
  7240. total_count += it.StockCount
  7241. }
  7242. //基础库插入数据
  7243. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7244. }
  7245. }
  7246. if len(outbefor) > 0 {
  7247. //出库
  7248. for _, item := range outbefor {
  7249. var last_total int64
  7250. //1.查看该患者该耗材型号最后一次出库数量
  7251. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7252. //计算当前出库和最后一次出库数据相差数据
  7253. last_total = item.Count - goodInfoOne.Count
  7254. //查询该耗材的总库存
  7255. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  7256. // 如果库存差大于剩余库存则提示库存不足
  7257. if last_total > wareinfo.StockCount {
  7258. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7259. c.ServeSuccessJSON(map[string]interface{}{
  7260. "message": "1",
  7261. "good_name": goodObj.GoodName,
  7262. "specification_name": goodObj.SpecificationName,
  7263. })
  7264. return
  7265. } else {
  7266. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7267. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7268. if err == gorm.ErrRecordNotFound {
  7269. //没有记录,则创建出库单
  7270. timeStr := time.Now().Format("2006-01-02")
  7271. timeArr := strings.Split(timeStr, "-")
  7272. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7273. total = total + 1
  7274. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7275. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7276. number = number + total
  7277. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7278. warehouseOut := models.WarehouseOut{
  7279. WarehouseOutOrderNumber: warehousing_out_order,
  7280. OperationTime: time.Now().Unix(),
  7281. OrgId: adminInfo.Org.Id,
  7282. Creater: adminInfo.AdminUser.Id,
  7283. Ctime: time.Now().Unix(),
  7284. Status: 1,
  7285. WarehouseOutTime: record_time,
  7286. Dealer: 0,
  7287. Manufacturer: 0,
  7288. Type: 1,
  7289. IsSys: 1,
  7290. StorehouseId: houseConfig.StorehouseOutInfo,
  7291. IsCheck: 1,
  7292. }
  7293. service.AddSigleWarehouseOut(&warehouseOut)
  7294. }
  7295. //出库
  7296. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  7297. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7298. //1.查看该患者该耗材型号最后一次出库数量
  7299. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7300. prepare := models.DialysisBeforePrepare{
  7301. UserOrgId: adminInfo.Org.Id,
  7302. PatientId: patient_id,
  7303. RecordDate: record_time,
  7304. GoodId: item.GoodId,
  7305. GoodTypeId: item.GoodTypeId,
  7306. Count: item.Count - goodInfoTwo.Count,
  7307. Ctime: time.Now().Unix(),
  7308. Mtime: 0,
  7309. Creater: adminInfo.AdminUser.Id,
  7310. Modifier: adminInfo.AdminUser.Id,
  7311. Status: 1,
  7312. CommdityCode: "",
  7313. NewCount: 0,
  7314. ProjectId: 0,
  7315. StorehouseId: houseConfig.StorehouseOutInfo,
  7316. }
  7317. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  7318. //增加出库数量
  7319. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  7320. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7321. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7322. var total_count int64
  7323. for _, it := range stockList {
  7324. total_count += it.StockCount
  7325. }
  7326. //基础库插入数据
  7327. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7328. //剩余库存
  7329. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7330. var flush_count int64
  7331. for _, it := range goodList {
  7332. flush_count += it.StockCount
  7333. }
  7334. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7335. }
  7336. }
  7337. }
  7338. //查询今日出库数据
  7339. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7340. for _, it := range list {
  7341. prepare := models.DialysisBeforePrepare{
  7342. UserOrgId: it.OrgId,
  7343. PatientId: patient_id,
  7344. RecordDate: it.RecordTime,
  7345. GoodId: it.GoodId,
  7346. GoodTypeId: it.GoodTypeId,
  7347. Count: it.Count,
  7348. Ctime: time.Now().Unix(),
  7349. Creater: adminInfo.AdminUser.Id,
  7350. Status: 1,
  7351. StorehouseId: houseConfig.StorehouseOutInfo,
  7352. ProjectId: it.ProjectId,
  7353. }
  7354. //删除准备表数据
  7355. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  7356. service.CreateDialysisBeforePrepareOne(&prepare)
  7357. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7358. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7359. var total_count int64
  7360. for _, it := range stockList {
  7361. total_count += it.StockCount
  7362. }
  7363. //基础库插入数据
  7364. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  7365. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  7366. var flush_count int64
  7367. for _, it := range goodList {
  7368. flush_count += it.StockCount
  7369. }
  7370. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  7371. }
  7372. }
  7373. }
  7374. //更新自动出库的地方
  7375. var errs error
  7376. if errs == nil {
  7377. c.ServeSuccessJSON(map[string]interface{}{
  7378. "msg": "修改成功",
  7379. "message": "2",
  7380. "good_name": "",
  7381. "specification_name": "",
  7382. })
  7383. return
  7384. } else {
  7385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7386. return
  7387. }
  7388. }
  7389. }
  7390. func (c *DialysisAPIController) GetDialysisGoods() {
  7391. schedualDate := c.GetString("schedule_date")
  7392. schedule_type, _ := c.GetInt64("schedule_type")
  7393. partition_id, _ := c.GetInt64("partition_id")
  7394. page, _ := c.GetInt("page")
  7395. patient_id, _ := c.GetInt64("patient_id")
  7396. schedualEndDate := int64(0)
  7397. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  7398. if parseDateErr != nil && len(schedualDate) != 0 {
  7399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7400. return
  7401. }
  7402. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  7403. if parseDateErr != nil && len(schedualDate) != 0 {
  7404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7405. return
  7406. }
  7407. schedualEndDate = endDate.Unix()
  7408. adminUser := c.GetMobileAdminUserInfo()
  7409. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  7410. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  7411. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7412. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7413. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  7414. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  7415. //获取当天该病人的透析处方
  7416. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7417. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7418. if err == gorm.ErrRecordNotFound {
  7419. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7420. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7421. if patient_id != 0 {
  7422. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7423. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7424. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7425. //获取患者总的出库数据
  7426. item.LastAutomaticReduceDetail = goodUser
  7427. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7428. item.Project = project
  7429. for _, it := range item.AutomaticReduceDetail {
  7430. var total int64
  7431. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7432. for _, its := range auto {
  7433. total += its.Count
  7434. }
  7435. it.Count = total
  7436. }
  7437. }
  7438. }
  7439. c.ServeSuccessJSON(map[string]interface{}{
  7440. "dialysis_goods": dialysisGoods,
  7441. "good_type": goodTypes,
  7442. "total": total,
  7443. "prescribe": prescribe,
  7444. "good_info": good_info,
  7445. "warehouseOutList": warehouseOutList,
  7446. "config": config,
  7447. "outConfig": outConfig,
  7448. "settleConfig": settleConfig,
  7449. })
  7450. return
  7451. } else if err == nil {
  7452. //获取当天排班的每个患者的库存使用情况
  7453. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7454. //获取患者总的出库数据
  7455. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7456. if patient_id != 0 {
  7457. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7458. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7459. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7460. item.Project = project
  7461. item.LastAutomaticReduceDetail = goodUser
  7462. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7463. for _, it := range item.AutomaticReduceDetail {
  7464. var total int64
  7465. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7466. for _, its := range auto {
  7467. total += its.Count
  7468. }
  7469. it.Count = total
  7470. }
  7471. }
  7472. }
  7473. if err == nil {
  7474. c.ServeSuccessJSON(map[string]interface{}{
  7475. "dialysis_goods": dialysisGoods,
  7476. "good_type": goodTypes,
  7477. "total": total,
  7478. "prescribe": prescribe,
  7479. "good_info": good_info,
  7480. "project": project,
  7481. "warehouseOutList": warehouseOutList,
  7482. "config": config,
  7483. "outConfig": outConfig,
  7484. "settleConfig": settleConfig,
  7485. })
  7486. return
  7487. } else {
  7488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7489. return
  7490. }
  7491. } else if err != nil {
  7492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7493. return
  7494. }
  7495. }
  7496. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  7497. start_time := c.GetString("start_time")
  7498. end_time := c.GetString("end_time")
  7499. timeLayout := "2006-01-02"
  7500. loc, _ := time.LoadLocation("Local")
  7501. var theStartTime int64
  7502. if len(start_time) > 0 {
  7503. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7504. if err != nil {
  7505. utils.ErrorLog(err.Error())
  7506. }
  7507. theStartTime = theTime.Unix()
  7508. }
  7509. var theEndtTime int64
  7510. if len(end_time) > 0 {
  7511. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7512. if err != nil {
  7513. utils.ErrorLog(err.Error())
  7514. }
  7515. theEndtTime = theTime.Unix()
  7516. }
  7517. adminUser := c.GetMobileAdminUserInfo()
  7518. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  7519. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  7520. if err == nil {
  7521. c.ServeSuccessJSON(map[string]interface{}{
  7522. "stock_out": outInfo,
  7523. "stockCount": stockCount,
  7524. })
  7525. return
  7526. } else {
  7527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7528. return
  7529. }
  7530. }
  7531. func (c *DialysisAPIController) GetStockInGoodInfo() {
  7532. patient_id, _ := c.GetInt64("patient_id", 0)
  7533. record_time := c.GetString("record_time")
  7534. adminUser := c.GetMobileAdminUserInfo()
  7535. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  7536. if parseDateErr != nil && len(record_time) != 0 {
  7537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7538. return
  7539. }
  7540. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  7541. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7542. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  7543. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  7544. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7545. //获取今日患者的透析处方参数
  7546. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7547. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  7548. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7549. c.ServeSuccessJSON(map[string]interface{}{
  7550. "good_type": goodTypes,
  7551. "good_user": goodUser,
  7552. "good_info": good_info,
  7553. "last_good_user": lastGoodUserDetial,
  7554. "project": project,
  7555. "prescription": prescribe,
  7556. "outInfo": outInfo,
  7557. "configs": configs,
  7558. })
  7559. return
  7560. }
  7561. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  7562. patient_id, _ := c.GetInt64("patient_id", 0)
  7563. record_date := c.GetString("record_time")
  7564. timeLayout := "2006-01-02"
  7565. loc, _ := time.LoadLocation("Local")
  7566. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7567. record_time := theRecordTime.Unix()
  7568. adminInfo := c.GetMobileAdminUserInfo()
  7569. dataBody := make(map[string]interface{}, 0)
  7570. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7571. if err != nil {
  7572. utils.ErrorLog(err.Error())
  7573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7574. return
  7575. }
  7576. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7577. var beforePrepares []*models.DialysisBeforePrepareGoods
  7578. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7579. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7580. goods, _ := dataBody["goods"].([]interface{})
  7581. if len(goods) > 0 {
  7582. for _, item := range goods {
  7583. items := item.(map[string]interface{})
  7584. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7585. utils.ErrorLog("good_id")
  7586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7587. return
  7588. }
  7589. good_id := int64(items["good_id"].(float64))
  7590. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7591. utils.ErrorLog("good_type_id")
  7592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7593. return
  7594. }
  7595. good_type_id := int64(items["good_type_id"].(float64))
  7596. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7597. utils.ErrorLog("count")
  7598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7599. return
  7600. }
  7601. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7602. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  7603. utils.ErrorLog("project_id")
  7604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7605. return
  7606. }
  7607. project_id := int64(items["project_id"].(float64))
  7608. new_count := int64(items["new_count"].(float64))
  7609. old_count := int64(items["old_count"].(float64))
  7610. prepare := &models.DialysisBeforePrepareGoods{
  7611. GoodId: good_id,
  7612. GoodTypeId: good_type_id,
  7613. Count: count,
  7614. ProjectId: project_id,
  7615. StorehouseId: houseConfig.StorehouseOutInfo,
  7616. NewCount: new_count,
  7617. OldCount: old_count,
  7618. }
  7619. beforePrepares = append(beforePrepares, prepare)
  7620. newPrepare := &models.NewDialysisBeforePrepareGoods{
  7621. GoodId: good_id,
  7622. GoodTypeId: good_type_id,
  7623. Count: count,
  7624. ProjectId: project_id,
  7625. StorehouseId: houseConfig.StorehouseOutInfo,
  7626. NewCount: new_count,
  7627. OldCount: old_count,
  7628. }
  7629. newBeforePrepares = append(newBeforePrepares, newPrepare)
  7630. }
  7631. }
  7632. }
  7633. //查询是否有库存
  7634. for _, item := range beforePrepares {
  7635. if item.NewCount > 0 {
  7636. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7637. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  7638. if item.Count > warehouse.Count {
  7639. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7640. c.ServeSuccessJSON(map[string]interface{}{
  7641. "message": "1",
  7642. "good_name": goodObj.GoodName,
  7643. "specification_name": goodObj.SpecificationName,
  7644. })
  7645. return
  7646. }
  7647. }
  7648. }
  7649. // 查询信息规挡的设置天数
  7650. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7651. if infor.ID > 0 && infor.WeekDay > 0 {
  7652. var cha_time int64
  7653. timeNowStr := time.Now().Format("2006-01-02")
  7654. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7655. //今日的日期减去设置的日期
  7656. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7657. if cha_time >= record_time {
  7658. //查询审核是否允许
  7659. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7660. //申请状态不允许的情况 拒绝修改
  7661. if infor.ApplicationStatus != 1 {
  7662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7663. return
  7664. }
  7665. }
  7666. }
  7667. //出库逻辑
  7668. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  7669. if err != nil {
  7670. utils.ErrorLog(err.Error())
  7671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7672. return
  7673. }
  7674. finish := models.XtDialysisFinish{
  7675. IsFinish: 1,
  7676. UserOrgId: adminInfo.Org.Id,
  7677. Status: 1,
  7678. Ctime: time.Now().Unix(),
  7679. Mtime: 0,
  7680. Module: 11,
  7681. RecordDate: record_time,
  7682. Sourse: 1,
  7683. PatientId: patient_id,
  7684. }
  7685. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  7686. if dialysisFinish.ID == 0 {
  7687. service.CreateDialysisFinish(finish)
  7688. }
  7689. //查询当天出库的数据
  7690. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7691. for _, item := range list {
  7692. prepare := models.DialysisBeforePrepare{
  7693. UserOrgId: item.OrgId,
  7694. PatientId: item.PatientId,
  7695. RecordDate: item.RecordTime,
  7696. GoodId: item.GoodId,
  7697. GoodTypeId: item.GoodTypeId,
  7698. Count: item.Count,
  7699. Creater: adminInfo.AdminUser.Id,
  7700. Status: 1,
  7701. Ctime: time.Now().Unix(),
  7702. ProjectId: item.ProjectId,
  7703. StorehouseId: houseConfig.StorehouseOutInfo,
  7704. }
  7705. //清空准备表的数据
  7706. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7707. //插入准备表数据
  7708. service.CreateDialysisBeforePrepareOne(&prepare)
  7709. //查询默认仓库
  7710. //查询默认仓库
  7711. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7712. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7713. var total_count int64
  7714. for _, it := range stockList {
  7715. total_count += it.StockCount
  7716. }
  7717. //基础库插入数据
  7718. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7719. ////更新剩余库存
  7720. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7721. var flush_count int64
  7722. for _, it := range goodList {
  7723. flush_count += it.StockCount
  7724. }
  7725. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7726. if errs != nil {
  7727. goodErrcode := models.XtGoodErrcode{
  7728. UserOrgId: item.OrgId,
  7729. Errcode: "手动出库更新剩余出库失败",
  7730. GoodId: item.GoodId,
  7731. Status: 1,
  7732. Ctime: time.Now().Unix(),
  7733. Mtime: 0,
  7734. Count: 0,
  7735. StockCount: 0,
  7736. Creater: adminInfo.AdminUser.Id,
  7737. BatchNumberId: 0,
  7738. WarehouseOutId: 0,
  7739. }
  7740. service.CreateGoodErrcode(goodErrcode)
  7741. }
  7742. }
  7743. //更新自动出库的地方
  7744. var errs error
  7745. if errs == nil {
  7746. c.ServeSuccessJSON(map[string]interface{}{
  7747. "msg": "修改成功",
  7748. "message": "2",
  7749. "good_name": "",
  7750. "specification_name": "",
  7751. })
  7752. return
  7753. } else {
  7754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7755. return
  7756. }
  7757. }
  7758. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7759. newArr = make([]*models.DialysisBeforePrepare, 0)
  7760. for i := 0; i < len(arr); i++ {
  7761. repeat := false
  7762. for j := i + 1; j < len(arr); j++ {
  7763. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7764. repeat = true
  7765. break
  7766. }
  7767. }
  7768. if !repeat {
  7769. newArr = append(newArr, arr[i])
  7770. }
  7771. }
  7772. return
  7773. }
  7774. func (c *DialysisAPIController) GetAllDrug() {
  7775. patient_id, _ := c.GetInt64("patient_id", 0)
  7776. adminInfo := c.GetMobileAdminUserInfo()
  7777. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7778. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7779. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7780. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7781. c.ServeSuccessJSON(map[string]interface{}{
  7782. "base_drug_config": drugStockConfig,
  7783. "private_drug_config": privateDrugConfig,
  7784. "base_drug_list": drugList,
  7785. "private_drug_list": privateDrugList,
  7786. })
  7787. }
  7788. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7789. newArr = make([]*models.DialysisBeforePrepare, 0)
  7790. for i := 0; i < len(arr); i++ {
  7791. repeat := false
  7792. for j := i + 1; j < len(arr); j++ {
  7793. if arr[i].GoodId == arr[j].GoodId {
  7794. repeat = true
  7795. break
  7796. }
  7797. }
  7798. if !repeat {
  7799. newArr = append(newArr, arr[i])
  7800. }
  7801. }
  7802. return
  7803. }
  7804. func (c *DialysisAPIController) GetDepartment() {
  7805. adminInfo := c.GetMobileAdminUserInfo()
  7806. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7807. if err == nil {
  7808. c.ServeSuccessJSON(map[string]interface{}{
  7809. "departments": departments,
  7810. })
  7811. } else {
  7812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7813. return
  7814. }
  7815. }
  7816. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7817. types, _ := c.GetInt("type", 0)
  7818. start_time := c.GetString("start_time")
  7819. end_time := c.GetString("end_time")
  7820. orgId := c.GetMobileAdminUserInfo().Org.Id
  7821. timeLayout := "2006-01-02"
  7822. loc, _ := time.LoadLocation("Local")
  7823. var startTime int64
  7824. if len(start_time) > 0 {
  7825. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7826. if err != nil {
  7827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7828. return
  7829. }
  7830. startTime = theTime.Unix()
  7831. }
  7832. var endTime int64
  7833. if len(end_time) > 0 {
  7834. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7835. if err != nil {
  7836. utils.ErrorLog(err.Error())
  7837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7838. return
  7839. }
  7840. endTime = theTime.Unix()
  7841. }
  7842. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7843. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7844. if err != nil {
  7845. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7846. } else {
  7847. c.ServeSuccessJSON(map[string]interface{}{
  7848. "list": list,
  7849. "type": types,
  7850. "stockTotal": stockTotal,
  7851. })
  7852. }
  7853. }
  7854. func (c *DialysisAPIController) GetPrescriptionList() {
  7855. start_time := c.GetString("start_time")
  7856. end_time := c.GetString("end_time")
  7857. schedule_type, _ := c.GetInt64("schedule_type")
  7858. partion_id, _ := c.GetInt64("partion_id")
  7859. orgId := c.GetMobileAdminUserInfo().Org.Id
  7860. timeLayout := "2006-01-02"
  7861. loc, _ := time.LoadLocation("Local")
  7862. var startTime int64
  7863. if len(start_time) > 0 {
  7864. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7865. if err != nil {
  7866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7867. return
  7868. }
  7869. startTime = theTime.Unix()
  7870. }
  7871. var endTime int64
  7872. if len(end_time) > 0 {
  7873. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7874. if err != nil {
  7875. utils.ErrorLog(err.Error())
  7876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7877. return
  7878. }
  7879. endTime = theTime.Unix()
  7880. }
  7881. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7882. fmt.Println("schedulelist22222222", schedulelist)
  7883. c.ServeSuccessJSON(map[string]interface{}{
  7884. "list": schedulelist,
  7885. })
  7886. return
  7887. }
  7888. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7889. ids := c.GetString("ids")
  7890. //patient_id, _ := c.GetInt64("patient_id")
  7891. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7892. idArray := strings.Split(ids, ",")
  7893. err := service.BatchDeleteMonitor(idArray)
  7894. fmt.Print("err", err)
  7895. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7896. //redis := service.RedisClient()
  7897. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7898. //redis.Set(key, "", time.Second)
  7899. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7900. //redis.Set(keyOne, "", time.Second)
  7901. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7902. //redis.Close()
  7903. c.ServeSuccessJSON(map[string]interface{}{
  7904. "msg": "批量删除成功",
  7905. })
  7906. return
  7907. }
  7908. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7909. id, _ := c.GetInt64("id")
  7910. timeLayout := "2006-01-02"
  7911. loc, _ := time.LoadLocation("Local")
  7912. //start_time := time.Now().Format("2006-01-02")
  7913. start_time := c.GetString("start_time")
  7914. end_time := c.GetString("end_time")
  7915. var startdateunix int64
  7916. if len(start_time) > 0 {
  7917. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7918. if err != nil {
  7919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7920. return
  7921. }
  7922. startdateunix = theTime.Unix()
  7923. }
  7924. var enddateunix int64
  7925. if len(end_time) > 0 {
  7926. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7927. if err != nil {
  7928. utils.ErrorLog(err.Error())
  7929. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7930. return
  7931. }
  7932. enddateunix = theTime.Unix()
  7933. }
  7934. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7935. //nowTime := time.Now()
  7936. //endTime := nowTime.AddDate(-30, 0, 0)
  7937. //endTimes := endTime.Format("2006-01-02")
  7938. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7939. org_id := c.GetMobileAdminUserInfo().Org.Id
  7940. //if org_id == 10579 {
  7941. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7942. // c.ServeSuccessJSON(map[string]interface{}{
  7943. // "list": list,
  7944. // })
  7945. // return
  7946. //} else {
  7947. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7948. // c.ServeSuccessJSON(map[string]interface{}{
  7949. // "list": list,
  7950. // })
  7951. // return
  7952. //}
  7953. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  7954. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7955. c.ServeSuccessJSON(map[string]interface{}{
  7956. "list": list,
  7957. })
  7958. return
  7959. } else {
  7960. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7961. c.ServeSuccessJSON(map[string]interface{}{
  7962. "list": list,
  7963. })
  7964. }
  7965. return
  7966. }
  7967. func (c *DialysisAPIController) BathDeleteAdviceList() {
  7968. dataBody := make(map[string]interface{}, 0)
  7969. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7970. ids := c.GetString("ids")
  7971. idArray := strings.Split(ids, ",")
  7972. origin, _ := c.GetInt64("origin")
  7973. if origin == 1 {
  7974. err = service.BatchDeleteAdvice(idArray)
  7975. fmt.Print("err", err)
  7976. c.ServeSuccessJSON(map[string]interface{}{
  7977. "msg": "批量删除成功",
  7978. })
  7979. return
  7980. }
  7981. if origin == 2 {
  7982. service.BatchDeleteHisAdvice(idArray)
  7983. }
  7984. }
  7985. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  7986. good_id, _ := c.GetInt64("good_id")
  7987. count, _ := c.GetInt64("count")
  7988. record_time, _ := c.GetInt64("record_time")
  7989. patient_id, _ := c.GetInt64("patient_id")
  7990. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  7991. c.ServeSuccessJSON(map[string]interface{}{
  7992. "detail": detail,
  7993. })
  7994. return
  7995. }
  7996. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  7997. good_id, _ := c.GetInt64("good_id")
  7998. record_time, _ := c.GetInt64("record_time")
  7999. patient_id, _ := c.GetInt64("patient_id")
  8000. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  8001. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  8002. fmt.Print("err", err)
  8003. c.ServeSuccessJSON(map[string]interface{}{
  8004. "msg": "批量删除成功",
  8005. })
  8006. return
  8007. }
  8008. func (c *DialysisAPIController) BatchAdviceCheck() {
  8009. ids := c.GetString("ids")
  8010. idArray := strings.Split(ids, ",")
  8011. creator, _ := c.GetInt64("creator")
  8012. origin, _ := c.GetInt64("origin")
  8013. if origin == 1 {
  8014. err := service.BatchAdviceCheck(idArray, creator)
  8015. fmt.Println(err)
  8016. list, _ := service.GetAdviceExecutionById(idArray)
  8017. c.ServeSuccessJSON(map[string]interface{}{
  8018. "list": list,
  8019. })
  8020. return
  8021. }
  8022. if origin == 2 {
  8023. service.BatchHisAdviceCheck(idArray, creator)
  8024. list, _ := service.GetHisAdviceExecutionById(idArray)
  8025. c.ServeSuccessJSON(map[string]interface{}{
  8026. "list": list,
  8027. })
  8028. return
  8029. }
  8030. }
  8031. func (c *DialysisAPIController) BatchAdviceExecution() {
  8032. ids := c.GetString("ids")
  8033. idArray := strings.Split(ids, ",")
  8034. executionTime := c.GetString("execution_time")
  8035. creator, _ := c.GetInt64("creator")
  8036. timeLayout := "2006-01-02 15:04:05"
  8037. loc, _ := time.LoadLocation("Local")
  8038. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  8039. orgin, _ := c.GetInt64("origin")
  8040. if orgin == 1 {
  8041. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  8042. list, _ := service.GetAdviceExecutionById(idArray)
  8043. fmt.Println(err)
  8044. c.ServeSuccessJSON(map[string]interface{}{
  8045. "list": list,
  8046. })
  8047. return
  8048. }
  8049. if orgin == 2 {
  8050. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  8051. list, _ := service.GetHisAdviceExecutionById(idArray)
  8052. fmt.Println(err)
  8053. c.ServeSuccessJSON(map[string]interface{}{
  8054. "list": list,
  8055. })
  8056. return
  8057. }
  8058. }
  8059. func (c *DialysisAPIController) UpdateStockGoods() {
  8060. good_id, _ := c.GetInt64("good_id")
  8061. record_time, _ := c.GetInt64("record_time")
  8062. patient_id, _ := c.GetInt64("patient_id")
  8063. count, _ := c.GetInt64("count")
  8064. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  8065. fmt.Print("err", err)
  8066. c.ServeSuccessJSON(map[string]interface{}{
  8067. "msg": "更新成功",
  8068. })
  8069. return
  8070. }
  8071. // 当前数据比上一次出库数据少
  8072. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  8073. //查询该患者当天已经出库的耗材信息
  8074. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8075. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8076. for i := len(goods_yc) - 1; i >= 0; i-- {
  8077. goods_yc_temp := goods_yc[i]
  8078. for j := len(goods) - 1; j >= 0; j-- {
  8079. goods_temp := goods[j]
  8080. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8081. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8082. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8083. if goods_yc_temp.Count == goods_temp.Count {
  8084. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8085. goods = append(goods[:j], goods[j+1:]...)
  8086. break
  8087. }
  8088. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8089. if goods_yc_temp.Count > goods_temp.Count {
  8090. temp_count := goods_yc_temp.Count - goods_temp.Count
  8091. goods_yc[i].Count = temp_count
  8092. goods = append(goods[:j], goods[j+1:]...)
  8093. break
  8094. }
  8095. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8096. if goods_yc_temp.Count < goods_temp.Count {
  8097. temp_count := goods_temp.Count - goods_yc_temp.Count
  8098. goods[j].Count = temp_count
  8099. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8100. break
  8101. }
  8102. }
  8103. }
  8104. }
  8105. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8106. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8107. //退库
  8108. if len(goods_yc) > 0 {
  8109. for _, good_yc := range goods_yc {
  8110. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8111. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  8112. }
  8113. }
  8114. return nil
  8115. }
  8116. // 耗材出库删除
  8117. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8118. // 先根据相关信息查询当天该耗材的出库信息
  8119. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8120. if err != nil {
  8121. return err
  8122. }
  8123. var delete_count int64 = 0
  8124. delete_count = warehouseOutInfos.Count - count
  8125. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8126. // 在出库记录表里记录退库详情
  8127. warehouseOutInfo := &models.WarehouseOutInfo{
  8128. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8129. WarehouseOutId: warehouseOut.ID,
  8130. Status: 1,
  8131. Ctime: time.Now().Unix(),
  8132. OrgId: orgID,
  8133. Type: 1,
  8134. IsSys: 1,
  8135. SysRecordTime: record_time,
  8136. GoodTypeId: good_yc.GoodTypeId,
  8137. GoodId: good_yc.GoodId,
  8138. PatientId: good_yc.PatientId,
  8139. ConsumableType: 2,
  8140. StorehouseId: houseConfig.StorehouseOutInfo,
  8141. IsCheck: 1,
  8142. }
  8143. warehouseOutInfo.Count = count
  8144. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8145. warehouseOutInfo.Price = stockInInfo.Price
  8146. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8147. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8148. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8149. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8150. warehouseOutInfo.Number = warehouseOutInfos.Number
  8151. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8152. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8153. //查找当天是否存在出库记录
  8154. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8155. if errcod == gorm.ErrRecordNotFound {
  8156. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8157. //插入详情明细表
  8158. stockFlow := models.VmStockFlow{
  8159. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8160. WarehouseOutId: warehouseOut.ID,
  8161. GoodId: good_yc.GoodId,
  8162. Number: warehouseOutInfos.Number,
  8163. ProductDate: stockInInfo.ProductDate,
  8164. ExpireDate: stockInInfo.ExpiryDate,
  8165. Count: count,
  8166. Price: stockInInfo.Price,
  8167. Status: 1,
  8168. Ctime: time.Now().Unix(),
  8169. UserOrgId: good_yc.OrgId,
  8170. Manufacturer: stockInInfo.Manufacturer,
  8171. Dealer: stockInInfo.Dealer,
  8172. LicenseNumber: stockInInfo.LicenseNumber,
  8173. IsEdit: 2,
  8174. Creator: creater,
  8175. SystemTime: record_time,
  8176. ConsumableType: 3,
  8177. WarehousingDetailId: 0,
  8178. IsSys: 1,
  8179. UpdateCreator: creater,
  8180. PatientId: patient_id,
  8181. StorehouseId: houseConfig.StorehouseOutInfo,
  8182. }
  8183. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8184. if errflow == gorm.ErrRecordNotFound {
  8185. //创建流水表
  8186. err := service.CreateStockFlowOne(stockFlow)
  8187. fmt.Println("err", err)
  8188. } else if errflow == nil {
  8189. //插入详情明细表
  8190. stockFlow := models.VmStockFlow{
  8191. ID: exsit.ID,
  8192. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8193. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8194. WarehouseOutId: warehouseOut.ID,
  8195. GoodId: good_yc.GoodId,
  8196. Number: warehouseOutInfos.Number,
  8197. ProductDate: stockInInfo.ProductDate,
  8198. ExpireDate: stockInInfo.ExpiryDate,
  8199. Count: exsit.Count - delete_count,
  8200. Price: stockInInfo.Price,
  8201. Status: 1,
  8202. Ctime: time.Now().Unix(),
  8203. UserOrgId: good_yc.OrgId,
  8204. Manufacturer: stockInInfo.Manufacturer,
  8205. Dealer: stockInInfo.Dealer,
  8206. LicenseNumber: stockInInfo.LicenseNumber,
  8207. IsEdit: 2,
  8208. Creator: creater,
  8209. SystemTime: record_time,
  8210. ConsumableType: 3,
  8211. WarehousingDetailId: 0,
  8212. IsSys: 1,
  8213. UpdateCreator: creater,
  8214. PatientId: patient_id,
  8215. StorehouseId: houseConfig.StorehouseOutInfo,
  8216. }
  8217. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8218. }
  8219. if errOne != nil {
  8220. return errOne
  8221. }
  8222. } else if errcod == nil {
  8223. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8224. //插入详情明细表
  8225. stockFlow := models.VmStockFlow{
  8226. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8227. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8228. WarehouseOutId: warehouseOut.ID,
  8229. GoodId: good_yc.GoodId,
  8230. Number: warehouseOutInfos.Number,
  8231. ProductDate: stockInInfo.ProductDate,
  8232. ExpireDate: stockInInfo.ExpiryDate,
  8233. Count: count,
  8234. Price: stockInInfo.Price,
  8235. Status: 1,
  8236. Ctime: time.Now().Unix(),
  8237. UserOrgId: good_yc.OrgId,
  8238. Manufacturer: stockInInfo.Manufacturer,
  8239. Dealer: stockInInfo.Dealer,
  8240. LicenseNumber: stockInInfo.LicenseNumber,
  8241. IsEdit: 2,
  8242. Creator: creater,
  8243. SystemTime: record_time,
  8244. ConsumableType: 3,
  8245. WarehousingDetailId: 0,
  8246. IsSys: 1,
  8247. UpdateCreator: creater,
  8248. PatientId: patient_id,
  8249. ReturnCount: delete_count,
  8250. StorehouseId: houseConfig.StorehouseOutInfo,
  8251. }
  8252. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8253. if errflows == gorm.ErrRecordNotFound {
  8254. //创建流水表
  8255. service.CreateStockFlowOne(stockFlow)
  8256. } else if errflows == nil {
  8257. stockFlow := models.VmStockFlow{
  8258. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8259. ID: exsit.ID,
  8260. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8261. WarehouseOutId: warehouseOut.ID,
  8262. GoodId: good_yc.GoodId,
  8263. Number: warehouseOutInfos.Number,
  8264. ProductDate: stockInInfo.ProductDate,
  8265. ExpireDate: stockInInfo.ExpiryDate,
  8266. Count: exsit.Count - delete_count,
  8267. Price: stockInInfo.Price,
  8268. Status: 1,
  8269. Ctime: time.Now().Unix(),
  8270. UserOrgId: good_yc.OrgId,
  8271. Manufacturer: stockInInfo.Manufacturer,
  8272. Dealer: stockInInfo.Dealer,
  8273. LicenseNumber: stockInInfo.LicenseNumber,
  8274. IsEdit: 2,
  8275. Creator: creater,
  8276. SystemTime: record_time,
  8277. ConsumableType: 3,
  8278. WarehousingDetailId: 0,
  8279. IsSys: 1,
  8280. UpdateCreator: creater,
  8281. PatientId: patient_id,
  8282. ReturnCount: delete_count,
  8283. StorehouseId: houseConfig.StorehouseOutInfo,
  8284. }
  8285. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8286. }
  8287. }
  8288. //更改自动出库的表格
  8289. details := models.BloodAutomaticReduceDetail{
  8290. WarehouseOutId: warehouseOutInfo.ID,
  8291. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8292. PatientId: patient_id,
  8293. Ctime: time.Now().Unix(),
  8294. Mtime: time.Now().Unix(),
  8295. Status: 1,
  8296. RecordTime: record_time,
  8297. OrgId: orgID,
  8298. GoodId: good_yc.GoodId,
  8299. GoodTypeId: good_yc.GoodTypeId,
  8300. Count: count,
  8301. StorehouseId: houseConfig.StorehouseOutInfo,
  8302. }
  8303. //查询当天耗材是否已经存在数据
  8304. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8305. if errcode == gorm.ErrRecordNotFound {
  8306. errTwo := service.CreateAutoReduceRecord(&details)
  8307. if errTwo != nil {
  8308. return errTwo
  8309. }
  8310. } else if errcode == nil {
  8311. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8312. service.CreateAutoReduceRecord(&details)
  8313. }
  8314. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8315. //增加出库库存数量
  8316. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  8317. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8318. fmt.Println("errOne", errOne)
  8319. // 删除出库完成后,要增加对应批次的库存数量
  8320. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8321. if errThree != nil {
  8322. return errThree
  8323. }
  8324. if good_yc.Count == 0 {
  8325. return nil
  8326. } else {
  8327. return errors.New("退库和出库数据不匹配")
  8328. }
  8329. }
  8330. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  8331. //查询该患者当天已经出库的耗材信息
  8332. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8333. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8334. for i := len(goods_yc) - 1; i >= 0; i-- {
  8335. goods_yc_temp := goods_yc[i]
  8336. for j := len(goods) - 1; j >= 0; j-- {
  8337. goods_temp := goods[j]
  8338. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8339. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8340. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8341. if goods_yc_temp.Count == goods_temp.Count {
  8342. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8343. goods = append(goods[:j], goods[j+1:]...)
  8344. break
  8345. }
  8346. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8347. if goods_yc_temp.Count > goods_temp.Count {
  8348. temp_count := goods_yc_temp.Count - goods_temp.Count
  8349. goods_yc[i].Count = temp_count
  8350. goods = append(goods[:j], goods[j+1:]...)
  8351. break
  8352. }
  8353. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8354. if goods_yc_temp.Count < goods_temp.Count {
  8355. temp_count := goods_temp.Count - goods_yc_temp.Count
  8356. goods[j].Count = temp_count
  8357. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8358. break
  8359. }
  8360. }
  8361. }
  8362. }
  8363. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8364. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8365. fmt.Println("剩余需要出库的", len(goods))
  8366. if len(goods) > 0 {
  8367. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  8368. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8369. if err == gorm.ErrRecordNotFound {
  8370. //没有记录,则创建出库单
  8371. timeStr := time.Now().Format("2006-01-02")
  8372. timeArr := strings.Split(timeStr, "-")
  8373. total, _ := service.FindAllWarehouseOut(orgID)
  8374. total = total + 1
  8375. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8376. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8377. number = number + total
  8378. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8379. warehouseOut := models.WarehouseOut{
  8380. WarehouseOutOrderNumber: warehousing_out_order,
  8381. OperationTime: time.Now().Unix(),
  8382. OrgId: orgID,
  8383. Creater: creater,
  8384. Ctime: time.Now().Unix(),
  8385. Status: 1,
  8386. WarehouseOutTime: record_time,
  8387. Dealer: 0,
  8388. Manufacturer: 0,
  8389. Type: 1,
  8390. IsSys: 1,
  8391. StorehouseId: houseConfig.StorehouseOutInfo,
  8392. IsCheck: 1,
  8393. }
  8394. err := service.AddSigleWarehouseOut(&warehouseOut)
  8395. if err != nil {
  8396. utils.TraceLog("创建出库单失败 err = %v", err)
  8397. return err
  8398. } else {
  8399. out = warehouseOut
  8400. }
  8401. }
  8402. for _, item := range goods {
  8403. var newCount int64 = 0
  8404. for _, it := range goodOne {
  8405. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  8406. newCount = it.Count
  8407. }
  8408. }
  8409. prepare := models.DialysisBeforePrepare{
  8410. GoodTypeId: item.GoodTypeId,
  8411. GoodId: item.GoodId,
  8412. Count: item.Count,
  8413. StorehouseId: houseConfig.StorehouseOutInfo,
  8414. }
  8415. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  8416. //增加出库数量
  8417. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  8418. }
  8419. }
  8420. if len(goods_yc) > 0 {
  8421. for _, good_yc := range goods_yc {
  8422. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8423. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  8424. }
  8425. }
  8426. return nil
  8427. }
  8428. // 耗材出库删除
  8429. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  8430. // 先根据相关信息查询当天该耗材的出库信息
  8431. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  8432. if err != nil {
  8433. return err
  8434. }
  8435. var delete_count int64 = 0
  8436. for _, ware := range warehouseOutInfos {
  8437. // 判断当前出库的数据和删除出库数量
  8438. if good_yc.Count <= ware.Count {
  8439. delete_count = good_yc.Count
  8440. } else {
  8441. delete_count = ware.Count
  8442. }
  8443. warehouseOutInfo := &models.WarehouseOutInfo{
  8444. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8445. WarehouseOutId: warehouseOut.ID,
  8446. Status: 1,
  8447. Ctime: time.Now().Unix(),
  8448. Remark: "",
  8449. OrgId: orgID,
  8450. Type: 1,
  8451. Manufacturer: 0,
  8452. Dealer: 0,
  8453. IsSys: 0,
  8454. SysRecordTime: record_time,
  8455. GoodTypeId: good_yc.GoodTypeId,
  8456. GoodId: good_yc.GoodId,
  8457. StorehouseId: warehouseOut.StorehouseId,
  8458. IsCheck: 1,
  8459. }
  8460. warehouseOutInfo.Count = delete_count
  8461. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8462. warehouseOutInfo.Price = stockInInfo.Price
  8463. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8464. if errOne != nil {
  8465. return errOne
  8466. }
  8467. // 删除出库完成后,要改变流水库存(有疑问)
  8468. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8469. fmt.Println("errOne", errOne)
  8470. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  8471. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8472. //扣减出库数量
  8473. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  8474. if errThree != nil {
  8475. return errThree
  8476. }
  8477. }
  8478. if good_yc.Count == 0 {
  8479. return nil
  8480. } else {
  8481. return errors.New("退库和出库数据不匹配")
  8482. }
  8483. }
  8484. func (this *DialysisAPIController) GetMobileScheduleList() {
  8485. limit, _ := this.GetInt64("limit")
  8486. page, _ := this.GetInt64("page")
  8487. type_options_visible, _ := this.GetInt64("type_options_visible")
  8488. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  8489. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  8490. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  8491. }
  8492. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  8493. newArr = make([]*models.HisPrescriptionProject, 0)
  8494. for i := 0; i < len(arr); i++ {
  8495. repeat := false
  8496. for j := i + 1; j < len(arr); j++ {
  8497. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  8498. repeat = true
  8499. break
  8500. }
  8501. }
  8502. if !repeat {
  8503. newArr = append(newArr, arr[i])
  8504. }
  8505. }
  8506. return
  8507. }
  8508. func (this *DialysisAPIController) GetRoleList() {
  8509. admin_user_id, _ := this.GetInt64("admin_user_id")
  8510. orgid := this.GetMobileAdminUserInfo().Org.Id
  8511. list, err := service.GetRoleList(orgid, admin_user_id)
  8512. fmt.Println(err)
  8513. this.ServeSuccessJSON(map[string]interface{}{
  8514. "list": list,
  8515. })
  8516. return
  8517. }
  8518. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8519. // 先根据相关信息查询当天该耗材的出库信息
  8520. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8521. if err != nil {
  8522. return err
  8523. }
  8524. var delete_count int64 = 0
  8525. delete_count = warehouseOutInfos.Count - count
  8526. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8527. // 删除出库完成后,要增加对应批次的库存数量
  8528. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8529. if errThree != nil {
  8530. return errThree
  8531. }
  8532. //增加退库数量
  8533. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  8534. //扣减出库数量
  8535. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  8536. //查询剩余库存
  8537. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  8538. var sum_count int64
  8539. for _, item := range goodList {
  8540. sum_count += item.StockCount
  8541. }
  8542. // 在出库记录表里记录退库详情
  8543. warehouseOutInfo := &models.WarehouseOutInfo{
  8544. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8545. WarehouseOutId: warehouseOut.ID,
  8546. Status: 1,
  8547. Ctime: time.Now().Unix(),
  8548. OrgId: orgID,
  8549. Type: 1,
  8550. IsSys: 1,
  8551. SysRecordTime: record_time,
  8552. GoodTypeId: good_yc.GoodTypeId,
  8553. GoodId: good_yc.GoodId,
  8554. PatientId: good_yc.PatientId,
  8555. ConsumableType: 2,
  8556. StorehouseId: houseConfig.StorehouseOutInfo,
  8557. IsCheck: 1,
  8558. OverCount: sum_count,
  8559. }
  8560. warehouseOutInfo.Count = count
  8561. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8562. warehouseOutInfo.Price = stockInInfo.Price
  8563. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8564. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8565. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8566. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8567. warehouseOutInfo.Number = warehouseOutInfos.Number
  8568. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8569. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8570. //查找当天是否存在出库记录
  8571. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8572. if errcod == gorm.ErrRecordNotFound {
  8573. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8574. //插入详情明细表
  8575. if errOne != nil {
  8576. return errOne
  8577. }
  8578. //插入详情明细表
  8579. stockFlow := models.VmStockFlow{
  8580. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8581. WarehouseOutId: warehouseOut.ID,
  8582. GoodId: good_yc.GoodId,
  8583. Number: warehouseOutInfos.Number,
  8584. ProductDate: stockInInfo.ProductDate,
  8585. ExpireDate: stockInInfo.ExpiryDate,
  8586. Count: count,
  8587. Price: stockInInfo.Price,
  8588. Status: 1,
  8589. Ctime: record_time,
  8590. UserOrgId: good_yc.OrgId,
  8591. Manufacturer: stockInInfo.Manufacturer,
  8592. Dealer: stockInInfo.Dealer,
  8593. LicenseNumber: stockInInfo.LicenseNumber,
  8594. IsEdit: 2,
  8595. Creator: creater,
  8596. SystemTime: record_time,
  8597. ConsumableType: 3,
  8598. WarehousingDetailId: 0,
  8599. IsSys: 1,
  8600. UpdateCreator: creater,
  8601. PatientId: patient_id,
  8602. StorehouseId: houseConfig.StorehouseOutInfo,
  8603. OverCount: sum_count,
  8604. ProjectId: good_yc.ProjectId,
  8605. }
  8606. err := service.CreateStockFlowOne(stockFlow)
  8607. fmt.Println("err", err)
  8608. } else if errcod == nil {
  8609. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8610. }
  8611. //创建退库单
  8612. operation_time := time.Now().Unix()
  8613. //创建退库单
  8614. timeStr := time.Now().Format("2006-01-02")
  8615. timeArr := strings.Split(timeStr, "-")
  8616. total, _ := service.FindAllCancelStockTotal(orgID)
  8617. total = total + 1
  8618. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8619. cancelStock := models.CancelStock{
  8620. OrderNumber: orderNumber,
  8621. OperaTime: operation_time,
  8622. OrgId: orgID,
  8623. Creater: warehouseOut.Creater,
  8624. Ctime: time.Now().Unix(),
  8625. Status: 1,
  8626. ReturnTime: record_time,
  8627. Type: 1,
  8628. StorehouseId: stockInInfo.StorehouseId,
  8629. IsCheck: 1,
  8630. }
  8631. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  8632. if msgerrkonde == gorm.ErrRecordNotFound {
  8633. service.AddSigleCancelStock(&cancelStock)
  8634. }
  8635. cancel, _ := service.GetLastCancelStockById(orgID)
  8636. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  8637. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  8638. cancelStockInfo := models.CancelStockInfo{
  8639. GoodId: stockInInfo.GoodId,
  8640. CancelStockId: cancel.ID,
  8641. GoodTypeId: stockInInfo.GoodTypeId,
  8642. Count: delete_count,
  8643. Price: stockInInfo.PackingPrice,
  8644. Total: 0,
  8645. ProductDate: stockInInfo.ProductDate,
  8646. ExpiryDate: stockInInfo.ExpiryDate,
  8647. Ctime: record_time,
  8648. Status: 1,
  8649. OrgId: orgID,
  8650. OrderNumber: cancel.OrderNumber,
  8651. Type: 0,
  8652. Dealer: deaerler.DealerName,
  8653. Manufacturer: manufacturer.ManufacturerName,
  8654. Number: stockInInfo.Number,
  8655. RegisterAccount: "",
  8656. Remark: "",
  8657. WarehouseInfoId: stockInInfo.ID,
  8658. PatientId: patient_id,
  8659. RecordDate: record_time,
  8660. StorehouseId: stockInInfo.StorehouseId,
  8661. IsCheck: 1,
  8662. }
  8663. service.CreateCancelStockInfoOne(&cancelStockInfo)
  8664. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  8665. flow := models.VmStockFlow{
  8666. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  8667. GoodId: good_yc.GoodId,
  8668. Number: warehouseOutInfos.Number,
  8669. LicenseNumber: stockInInfo.LicenseNumber,
  8670. Count: delete_count,
  8671. UserOrgId: orgID,
  8672. PatientId: patient_id,
  8673. SystemTime: record_time,
  8674. ConsumableType: 7,
  8675. IsSys: 0,
  8676. WarehousingOrder: "",
  8677. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  8678. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8679. IsEdit: 0,
  8680. CancelStockId: cancel.ID,
  8681. CancelOrderNumber: cancel.OrderNumber,
  8682. Manufacturer: manufacturer.ID,
  8683. Dealer: 0,
  8684. Creator: warehouseOut.Creater,
  8685. UpdateCreator: 0,
  8686. Status: 1,
  8687. Ctime: record_time,
  8688. Mtime: 0,
  8689. Price: stockInInfo.Price,
  8690. WarehousingDetailId: stockInInfo.ID,
  8691. WarehouseOutDetailId: warehouseOutInfos.ID,
  8692. CancelOutDetailId: cancelInfo.ID,
  8693. ProductDate: stockInInfo.ProductDate,
  8694. ExpireDate: stockInInfo.ExpiryDate,
  8695. StorehouseId: houseConfig.StorehouseOutInfo,
  8696. OverCount: sum_count,
  8697. }
  8698. service.CreateStockFlowOne(flow)
  8699. //更改自动出库的表格
  8700. details := models.BloodAutomaticReduceDetail{
  8701. WarehouseOutId: warehouseOutInfo.ID,
  8702. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8703. PatientId: patient_id,
  8704. Ctime: time.Now().Unix(),
  8705. Mtime: time.Now().Unix(),
  8706. Status: 1,
  8707. RecordTime: record_time,
  8708. OrgId: orgID,
  8709. GoodId: good_yc.GoodId,
  8710. GoodTypeId: good_yc.GoodTypeId,
  8711. Count: count,
  8712. StorehouseId: houseConfig.StorehouseOutInfo,
  8713. }
  8714. //查询当天耗材是否已经存在数据
  8715. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8716. if errcode == gorm.ErrRecordNotFound {
  8717. errTwo := service.CreateAutoReduceRecord(&details)
  8718. if errTwo != nil {
  8719. return errTwo
  8720. }
  8721. } else if errcode == nil {
  8722. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8723. service.CreateAutoReduceRecord(&details)
  8724. }
  8725. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8726. //增加出库库存数量
  8727. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8728. if good_yc.Count == 0 {
  8729. return nil
  8730. } else {
  8731. return errors.New("退库和出库数据不匹配")
  8732. }
  8733. }
  8734. func (this *DialysisAPIController) SavePatientSign() {
  8735. adminUserInfo := this.GetMobileAdminUserInfo()
  8736. patient_id, _ := this.GetInt64("patient_id")
  8737. dialysis_date, _ := this.GetInt64("dialysis_date")
  8738. orgid := adminUserInfo.Org.Id
  8739. var esdata models.DialysisOrder
  8740. var err error
  8741. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8742. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8743. return
  8744. }
  8745. esdata.Hash = esdata.Hash
  8746. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8747. order := models.DialysisOrder{
  8748. Hash: esdata.Hash,
  8749. Url: esdata.Url,
  8750. }
  8751. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8752. redis := service.RedisClient()
  8753. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8754. redis.Set(key, "", time.Second)
  8755. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8756. //清空key 值
  8757. redis.Set(keyOne, "", time.Second)
  8758. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8759. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8760. //redis.Set(keyTwo, "", time.Second)
  8761. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8762. redis.Set(keyThree, "", time.Second)
  8763. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8764. redis.Set(keyFour, "", time.Second)
  8765. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8766. redis.Set(keyFive, "", time.Second)
  8767. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8768. redis.Set(keySix, "", time.Second)
  8769. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8770. redis.Set(keySeven, "", time.Second)
  8771. if err != nil {
  8772. fmt.Println(err)
  8773. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8774. return
  8775. }
  8776. this.ServeSuccessJSON(map[string]interface{}{
  8777. "electronic_signature": esdata,
  8778. })
  8779. }
  8780. func (this *DialysisAPIController) GetPatientSign() {
  8781. patient_id, _ := this.GetInt64("patient_id")
  8782. dialysis_date, _ := this.GetInt64("dialysis_date")
  8783. adminUserInfo := this.GetMobileAdminUserInfo()
  8784. orgId := adminUserInfo.Org.Id
  8785. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8786. if err != nil {
  8787. fmt.Println(err)
  8788. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8789. return
  8790. }
  8791. this.ServeSuccessJSON(map[string]interface{}{
  8792. "dialysisOrder": dialysisOrder,
  8793. })
  8794. }
  8795. func (this *DialysisAPIController) GetScheduleByPatient() {
  8796. patient_id, _ := this.GetInt64("patient_id")
  8797. schedule_date, _ := this.GetInt64("schedule_date")
  8798. orgid := this.GetMobileAdminUserInfo().Org.Id
  8799. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8800. this.ServeSuccessJSON(map[string]interface{}{
  8801. "schedule": schedule,
  8802. })
  8803. }
  8804. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8805. org_id := this.GetMobileAdminUserInfo().Org.Id
  8806. patient_id, _ := this.GetInt64("patient_id")
  8807. schedule_date, _ := this.GetInt64("schedule_date")
  8808. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8809. this.ServeSuccessJSON(map[string]interface{}{
  8810. "order": order,
  8811. })
  8812. }
  8813. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8814. org_id := this.GetMobileAdminUserInfo().Org.Id
  8815. schedule_date := this.GetString("schedule_date")
  8816. schedule_type, _ := this.GetInt64("schedule_type")
  8817. timeLayout := "2006-01-02"
  8818. loc, _ := time.LoadLocation("Local")
  8819. var startdateunix int64
  8820. if len(schedule_date) > 0 {
  8821. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8822. if err != nil {
  8823. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8824. return
  8825. }
  8826. startdateunix = theTime.Unix()
  8827. }
  8828. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8829. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8830. devices, _ := service.GetAllDevicetByListSix(org_id)
  8831. for key, item := range scheduals {
  8832. // 床位信息
  8833. for _, device := range devices {
  8834. if item.BedId == device.ID {
  8835. scheduals[key].DeviceNumber = device
  8836. break
  8837. }
  8838. }
  8839. }
  8840. this.ServeSuccessJSON(map[string]interface{}{
  8841. "list": list,
  8842. "scheduals": scheduals,
  8843. })
  8844. }
  8845. func (this *DialysisAPIController) SavePatientPicture() {
  8846. patient_id, _ := this.GetInt64("patient_id")
  8847. dialysis_date, _ := this.GetInt64("schedule_date")
  8848. avatar := this.GetString("avatar")
  8849. fmt.Println("patient_id", patient_id)
  8850. orgId := this.GetMobileAdminUserInfo().Org.Id
  8851. order := models.DialysisOrder{
  8852. Url: avatar,
  8853. }
  8854. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8855. redis := service.RedisClient()
  8856. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8857. redis.Set(key, "", time.Second)
  8858. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8859. //清空key 值
  8860. redis.Set(keyOne, "", time.Second)
  8861. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8862. redis.Set(keyThree, "", time.Second)
  8863. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8864. redis.Set(keyFour, "", time.Second)
  8865. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8866. redis.Set(keyFive, "", time.Second)
  8867. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8868. redis.Set(keySix, "", time.Second)
  8869. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8870. redis.Set(keySeven, "", time.Second)
  8871. if err != nil {
  8872. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8873. return
  8874. }
  8875. this.ServeSuccessJSON(map[string]interface{}{
  8876. "order": order,
  8877. })
  8878. }
  8879. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8880. ids := this.GetString("ids")
  8881. idSplit := strings.Split(ids, ",")
  8882. orgId := this.GetMobileAdminUserInfo().Org.Id
  8883. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8884. execution_time := this.GetString("exce_time")
  8885. timeLayout2 := "2006-01-02 15:04:05"
  8886. loc, _ := time.LoadLocation("Local")
  8887. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8888. if errs != nil {
  8889. utils.ErrorLog(errs.Error())
  8890. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8891. return
  8892. }
  8893. //his客户
  8894. if config.IsOpen == 1 {
  8895. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8896. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8897. for _, item := range list {
  8898. for _, it := range adviceList {
  8899. if item.DrugId == it.DrugId {
  8900. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8901. }
  8902. }
  8903. }
  8904. for _, item := range list {
  8905. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8906. var sum_out_count int64
  8907. for _, itemThree := range item.ChildDoctorAdvice {
  8908. var prescribing_number int64
  8909. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8910. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8911. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8912. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8913. }
  8914. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8915. prescribing_number = parseIntPrescribingNumber
  8916. }
  8917. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8918. prescribing_number = parseIntPrescribingNumber
  8919. }
  8920. sum_out_count += prescribing_number
  8921. }
  8922. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8923. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8924. //库存不足
  8925. if sum_out_count > drugStockOut.FlushCount {
  8926. this.ServeSuccessJSON(map[string]interface{}{
  8927. "msg": "2",
  8928. "drug": medical,
  8929. "ids": ids,
  8930. })
  8931. return
  8932. }
  8933. }
  8934. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8935. //执行医嘱
  8936. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8937. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  8938. for _, item := range advices {
  8939. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8940. redis := service.RedisClient()
  8941. //清空key 值
  8942. redis.Set(key, "", time.Second)
  8943. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8944. redis.Set(keyTwo, "", time.Second)
  8945. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8946. redis.Set(keyThree, "", time.Second)
  8947. recordDate := theTime.Format("2006-01-02")
  8948. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8949. redis.Set(keyFour, "", time.Second)
  8950. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8951. redis.Set(keyFive, "", time.Second)
  8952. defer redis.Close()
  8953. }
  8954. if errs == nil {
  8955. //药品管理信息
  8956. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8957. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8958. if drugStockConfig.IsOpen == 1 {
  8959. for _, item := range advices {
  8960. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  8961. config, _ := service.GetDrugOpenConfigOne(orgId)
  8962. if config.IsOpen != 1 {
  8963. //查询该药品是否有库存
  8964. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8965. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  8966. if medical.IsUse == 2 {
  8967. if config.IsOpen != 1 {
  8968. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8969. service.HisDrugsDelivery(orgId, creater, &advice)
  8970. if orgId == 3877 || orgId == 10265 {
  8971. //查询该药品是否有出库记录
  8972. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8973. if len(flowMap) == 0 {
  8974. errs := service.UpdateHisAdviceById(advice.ID)
  8975. if errs != nil {
  8976. drugError := models.XtDrugError{
  8977. UserOrgId: orgId,
  8978. DrugId: item.DrugId,
  8979. RecordDate: item.AdviceDate,
  8980. PatientId: item.PatientId,
  8981. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8982. Status: 1,
  8983. Ctime: time.Now().Unix(),
  8984. Mtime: 0,
  8985. SumCount: 0,
  8986. Prescribingnumber: advice.PrescribingNumber,
  8987. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8988. }
  8989. service.CreateDrugError(drugError)
  8990. }
  8991. this.ServeSuccessJSON(map[string]interface{}{
  8992. "msg": "2",
  8993. "drug": medical,
  8994. "ids": ids,
  8995. })
  8996. return
  8997. }
  8998. }
  8999. }
  9000. if pharmacyConfig.IsOpen != 1 {
  9001. service.HisDrugsDelivery(orgId, creater, &advice)
  9002. if orgId == 3877 || orgId == 10265 {
  9003. //查询该药品是否有出库记录
  9004. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9005. if len(flowMap) == 0 {
  9006. errs := service.UpdateHisAdviceById(advice.ID)
  9007. if errs != nil {
  9008. drugError := models.XtDrugError{
  9009. UserOrgId: orgId,
  9010. DrugId: item.DrugId,
  9011. RecordDate: item.AdviceDate,
  9012. PatientId: item.PatientId,
  9013. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9014. Status: 1,
  9015. Ctime: time.Now().Unix(),
  9016. Mtime: 0,
  9017. SumCount: 0,
  9018. Prescribingnumber: advice.PrescribingNumber,
  9019. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9020. }
  9021. service.CreateDrugError(drugError)
  9022. }
  9023. this.ServeSuccessJSON(map[string]interface{}{
  9024. "msg": "2",
  9025. "drug": medical,
  9026. "ids": ids,
  9027. })
  9028. return
  9029. }
  9030. }
  9031. }
  9032. //更新字典里面的库存
  9033. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9034. var sum_count int64
  9035. for _, its := range stockInfo {
  9036. if its.MaxUnit == medical.MaxUnit {
  9037. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9038. }
  9039. sum_count += its.StockMaxNumber + its.StockMinNumber
  9040. }
  9041. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9042. //剩余库存
  9043. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9044. }
  9045. }
  9046. }
  9047. }
  9048. }
  9049. this.ServeSuccessJSON(map[string]interface{}{
  9050. "msg": "1",
  9051. "ids": ids,
  9052. })
  9053. return
  9054. } else {
  9055. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9056. }
  9057. }
  9058. //血透客户
  9059. if config.IsOpen == 2 || config.IsOpen == 0 {
  9060. //药品管理信息
  9061. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9062. if drugStockConfig.IsOpen == 1 {
  9063. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  9064. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  9065. for _, item := range list {
  9066. for _, it := range adviceList {
  9067. if item.DrugId == it.DrugId {
  9068. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9069. }
  9070. }
  9071. }
  9072. for _, item := range list {
  9073. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9074. var sum_out_count int64
  9075. for _, itemThree := range item.ChildDoctorAdvice {
  9076. var prescribing_number int64
  9077. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9078. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9079. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9080. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9081. }
  9082. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9083. prescribing_number = parseIntPrescribingNumber
  9084. }
  9085. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9086. prescribing_number = parseIntPrescribingNumber
  9087. }
  9088. sum_out_count += prescribing_number
  9089. }
  9090. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9091. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9092. //库存不足
  9093. if sum_out_count > drugStockOut.FlushCount {
  9094. this.ServeSuccessJSON(map[string]interface{}{
  9095. "msg": "2",
  9096. "drug": medical,
  9097. "ids": ids,
  9098. })
  9099. return
  9100. }
  9101. }
  9102. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9103. //执行医嘱
  9104. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9105. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9106. for _, item := range advices {
  9107. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9108. redis := service.RedisClient()
  9109. //清空key 值
  9110. redis.Set(key, "", time.Second)
  9111. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9112. redis.Set(keyTwo, "", time.Second)
  9113. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9114. redis.Set(keyThree, "", time.Second)
  9115. recordDate := theTime.Format("2006-01-02")
  9116. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9117. redis.Set(keyFour, "", time.Second)
  9118. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9119. redis.Set(keyFive, "", time.Second)
  9120. defer redis.Close()
  9121. }
  9122. if errs == nil {
  9123. for _, item := range advices {
  9124. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9125. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9126. //查询是否出库按钮开启
  9127. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  9128. if adviceSetting.IsAdviceOpen == 1 {
  9129. //查询是否出库按钮开启
  9130. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  9131. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9132. if prescriptionConfig.IsOpen == 1 {
  9133. if medical.IsUse == 2 {
  9134. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9135. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9136. }
  9137. if pharmacyConfig.IsOpen != 1 {
  9138. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9139. }
  9140. //更新字典里面的库存
  9141. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9142. var sum_count int64
  9143. for _, its := range stockInfo {
  9144. if its.MaxUnit == medical.MaxUnit {
  9145. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9146. }
  9147. sum_count += its.StockMaxNumber + its.StockMinNumber
  9148. }
  9149. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9150. //剩余库存
  9151. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9152. }
  9153. }
  9154. } else {
  9155. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9156. if medical.IsUse == 2 {
  9157. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9158. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9159. }
  9160. if pharmacyConfig.IsOpen != 1 {
  9161. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9162. }
  9163. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9164. var sum_count int64
  9165. for _, its := range stockInfo {
  9166. if its.MaxUnit == medical.MaxUnit {
  9167. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9168. }
  9169. sum_count += its.StockMaxNumber + its.StockMinNumber
  9170. }
  9171. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9172. //剩余库存
  9173. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9174. }
  9175. }
  9176. }
  9177. }
  9178. this.ServeSuccessJSON(map[string]interface{}{
  9179. "msg": "1",
  9180. "ids": ids,
  9181. })
  9182. return
  9183. } else {
  9184. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9185. //执行医嘱
  9186. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9187. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9188. for _, item := range advices {
  9189. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9190. redis := service.RedisClient()
  9191. //清空key 值
  9192. redis.Set(key, "", time.Second)
  9193. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9194. redis.Set(keyTwo, "", time.Second)
  9195. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9196. redis.Set(keyThree, "", time.Second)
  9197. recordDate := theTime.Format("2006-01-02")
  9198. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9199. redis.Set(keyFour, "", time.Second)
  9200. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9201. redis.Set(keyFive, "", time.Second)
  9202. defer redis.Close()
  9203. }
  9204. this.ServeSuccessJSON(map[string]interface{}{
  9205. "msg": "1",
  9206. "ids": ids,
  9207. })
  9208. return
  9209. }
  9210. }
  9211. }
  9212. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  9213. ids := this.GetString("ids")
  9214. idSplit := strings.Split(ids, ",")
  9215. orgId := this.GetMobileAdminUserInfo().Org.Id
  9216. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9217. if config.IsOpen == 1 {
  9218. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  9219. this.ServeSuccessJSON(map[string]interface{}{
  9220. "msg": "1",
  9221. "ids": ids,
  9222. })
  9223. return
  9224. }
  9225. if config.IsOpen == 0 || config.IsOpen == 2 {
  9226. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  9227. this.ServeSuccessJSON(map[string]interface{}{
  9228. "msg": "1",
  9229. "ids": ids,
  9230. })
  9231. return
  9232. }
  9233. }
  9234. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  9235. ids := this.GetString("ids")
  9236. idSplit := strings.Split(ids, ",")
  9237. orgId := this.GetMobileAdminUserInfo().Org.Id
  9238. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9239. //his
  9240. if config.IsOpen == 1 {
  9241. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9242. theTime := time.Now()
  9243. advices := models.HisDoctorAdviceThirty{
  9244. CheckTime: theTime.Unix(),
  9245. Checker: checker,
  9246. UpdatedTime: time.Now().Unix(),
  9247. }
  9248. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  9249. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9250. for _, item := range list {
  9251. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9252. redis := service.RedisClient()
  9253. //清空key 值
  9254. redis.Set(key, "", time.Second)
  9255. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9256. redis.Set(keyTwo, "", time.Second)
  9257. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9258. redis.Set(keyThree, "", time.Second)
  9259. recordDate := theTime.Format("2006-01-02")
  9260. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9261. redis.Set(keyFour, "", time.Second)
  9262. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9263. redis.Set(keyFive, "", time.Second)
  9264. defer redis.Close()
  9265. }
  9266. this.ServeSuccessJSON(map[string]interface{}{
  9267. "msg": "1",
  9268. "ids": ids,
  9269. })
  9270. return
  9271. }
  9272. //血透
  9273. if config.IsOpen == 0 || config.IsOpen == 2 {
  9274. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9275. theTime := time.Now()
  9276. advices := models.DoctorAdvice{
  9277. CheckTime: theTime.Unix(),
  9278. Checker: checker,
  9279. UpdatedTime: time.Now().Unix(),
  9280. }
  9281. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  9282. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9283. for _, item := range list {
  9284. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9285. redis := service.RedisClient()
  9286. //清空key 值
  9287. redis.Set(key, "", time.Second)
  9288. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9289. redis.Set(keyTwo, "", time.Second)
  9290. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9291. redis.Set(keyThree, "", time.Second)
  9292. recordDate := theTime.Format("2006-01-02")
  9293. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9294. redis.Set(keyFour, "", time.Second)
  9295. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9296. redis.Set(keyFive, "", time.Second)
  9297. defer redis.Close()
  9298. }
  9299. this.ServeSuccessJSON(map[string]interface{}{
  9300. "msg": "1",
  9301. "ids": ids,
  9302. })
  9303. return
  9304. }
  9305. }
  9306. func (this *DialysisAPIController) CheckSchedule() {
  9307. patientID, _ := this.GetInt64("patient_id")
  9308. recordDateStr := this.GetString("record_date")
  9309. nurseID, _ := this.GetInt64("start_nurse")
  9310. schedual_type, _ := this.GetInt64("schedual_type")
  9311. bedID, _ := this.GetInt64("bed")
  9312. start_time := this.GetString("start_time")
  9313. fmt.Println("patientID", patientID)
  9314. fmt.Println("recordDateStr", recordDateStr)
  9315. fmt.Println("nurseID", nurseID)
  9316. fmt.Println("schedual_type------", schedual_type)
  9317. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  9318. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9319. return
  9320. }
  9321. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  9322. if parseStartDateErr != nil {
  9323. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  9324. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9325. return
  9326. }
  9327. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9328. if parseErr != nil {
  9329. this.ErrorLog("时间解析失败:%v", parseErr)
  9330. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9331. return
  9332. }
  9333. adminUserInfo := this.GetMobileAdminUserInfo()
  9334. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  9335. if getPatientErr != nil {
  9336. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  9337. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9338. return
  9339. } else if patient == nil {
  9340. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9341. return
  9342. }
  9343. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  9344. if getNurseErr != nil {
  9345. this.ErrorLog("获取护士失败:%v", getNurseErr)
  9346. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9347. return
  9348. } else if nurse == nil {
  9349. this.ErrorLog("护士不存在")
  9350. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9351. return
  9352. }
  9353. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  9354. if getDeviceNumberErr != nil {
  9355. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  9356. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9357. return
  9358. } else if deviceNumber == nil {
  9359. this.ErrorLog("床位号不存在")
  9360. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9361. return
  9362. }
  9363. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  9364. if getRecordErr != nil {
  9365. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  9366. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9367. return
  9368. } else if dialysisRecord != nil {
  9369. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  9370. return
  9371. }
  9372. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  9373. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  9374. timeLayout := "2006-01-02 15:04:05"
  9375. loc, _ := time.LoadLocation("Local")
  9376. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  9377. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  9378. schedulestartTime := theStartTime.Unix()
  9379. scheduleendTime := theEndTime.Unix()
  9380. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  9381. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  9382. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9383. //查询该床位是否有人用了
  9384. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9385. if err == nil {
  9386. if schedule.ID == 0 {
  9387. this.ServeSuccessJSON(map[string]interface{}{
  9388. "status": 0,
  9389. "msg": "请求失败",
  9390. })
  9391. } else {
  9392. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  9393. if order.ID > 0 { //该机位被其他人占用了
  9394. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  9395. return
  9396. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  9397. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  9398. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  9399. this.ServeSuccessJSON(map[string]interface{}{
  9400. "status": 1,
  9401. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  9402. })
  9403. return
  9404. } else {
  9405. this.ServeSuccessJSON(map[string]interface{}{
  9406. "status": 0,
  9407. "msg": "",
  9408. })
  9409. }
  9410. }
  9411. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  9412. this.ServeSuccessJSON(map[string]interface{}{
  9413. "status": 2,
  9414. "msg": "当前机位已有患者在使用,请重新选择!",
  9415. })
  9416. }
  9417. }
  9418. } else {
  9419. this.ServeSuccessJSON(map[string]interface{}{
  9420. "status": 0,
  9421. "msg": "",
  9422. })
  9423. }
  9424. }
  9425. func (this *DialysisAPIController) GetNewDoctorListToday() {
  9426. orgId := this.GetMobileAdminUserInfo().Org.Id
  9427. schedule_type, _ := this.GetInt64("schedule_type")
  9428. partion_type, _ := this.GetInt64("partion_type")
  9429. start_time := this.GetString("start_time")
  9430. timeLayout := "2006-01-02"
  9431. loc, _ := time.LoadLocation("Local")
  9432. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9433. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  9434. _, config := service.FindXTHisRecordByOrgId(orgId)
  9435. appId := this.GetMobileAdminUserInfo().App.Id
  9436. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  9437. if err == nil {
  9438. this.ServeSuccessJSON(map[string]interface{}{
  9439. "list": list,
  9440. "config": config,
  9441. "doctorList": doctorList,
  9442. })
  9443. return
  9444. } else {
  9445. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9446. return
  9447. }
  9448. }
  9449. func (this *DialysisAPIController) SaveMobileInformation() {
  9450. patient_id, _ := this.GetInt64("patient_id")
  9451. record_date, _ := this.GetInt64("record_date")
  9452. startTime := this.GetString("start_time")
  9453. module, _ := this.GetInt64("module")
  9454. remark := this.GetString("remark")
  9455. timeLayout := "2006-01-02 15:04"
  9456. loc, _ := time.LoadLocation("Local")
  9457. if len(startTime) == 0 {
  9458. utils.ErrorLog("len(start_time) == 0")
  9459. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9460. return
  9461. }
  9462. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  9463. if err != nil {
  9464. utils.ErrorLog(err.Error())
  9465. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9466. return
  9467. }
  9468. StartTime := theTime.Unix()
  9469. fmt.Println("startime-------------", StartTime)
  9470. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9471. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  9472. information := models.XtDialysisInformation{
  9473. Module: module,
  9474. PatientId: patient_id,
  9475. RecordDate: record_date,
  9476. ApplicationDate: StartTime,
  9477. Creater: creater,
  9478. ApplicationStatus: 2,
  9479. Checker: 0,
  9480. CheckTime: 0,
  9481. Remark: remark,
  9482. UserOrgId: user_org_id,
  9483. Ctime: time.Now().Unix(),
  9484. Status: 1,
  9485. Mtime: 0,
  9486. }
  9487. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  9488. if infor.ID == 0 {
  9489. service.SaveDialysisInformation(information)
  9490. }
  9491. if infor.ID > 0 {
  9492. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  9493. }
  9494. this.ServeSuccessJSON(map[string]interface{}{
  9495. "information": information,
  9496. })
  9497. return
  9498. }
  9499. func (this *DialysisAPIController) GetMobileInformation() {
  9500. limit, _ := this.GetInt64("limit")
  9501. page, _ := this.GetInt64("page")
  9502. orgid := this.GetMobileAdminUserInfo().Org.Id
  9503. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  9504. appid := this.GetMobileAdminUserInfo().App.Id
  9505. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9506. patients, _ := service.GetAllpatientThirty(orgid)
  9507. this.ServeSuccessJSON(map[string]interface{}{
  9508. "information": information,
  9509. "total": total,
  9510. "doclist": doclist,
  9511. "patients": patients,
  9512. })
  9513. return
  9514. }
  9515. func (this *DialysisAPIController) GetMobileInformationOne() {
  9516. limit, _ := this.GetInt64("limit")
  9517. page, _ := this.GetInt64("page")
  9518. orgid := this.GetMobileAdminUserInfo().Org.Id
  9519. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  9520. appid := this.GetMobileAdminUserInfo().App.Id
  9521. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9522. patients, _ := service.GetAllpatientThirty(orgid)
  9523. this.ServeSuccessJSON(map[string]interface{}{
  9524. "information": information,
  9525. "total": total,
  9526. "doclist": doclist,
  9527. "patients": patients,
  9528. })
  9529. return
  9530. }
  9531. func (this *DialysisAPIController) CheckMobileInformation() {
  9532. id, _ := this.GetInt64("id")
  9533. application_status, _ := this.GetInt64("application_status")
  9534. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9535. checktime := time.Now().Unix()
  9536. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  9537. if err == nil {
  9538. this.ServeSuccessJSON(map[string]interface{}{
  9539. "msg": "ok",
  9540. })
  9541. return
  9542. }
  9543. }
  9544. func (c *DialysisAPIController) GetControlMonitorList() {
  9545. partition, _ := c.GetInt64("partition")
  9546. monitorDate := c.GetString("date")
  9547. patient_id, _ := c.GetInt64("patient_id")
  9548. pat_type, _ := c.GetInt64("pat_type")
  9549. timeLayout := "2006-01-02"
  9550. loc, _ := time.LoadLocation("Local")
  9551. var theStartTime int64
  9552. if len(monitorDate) > 0 {
  9553. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  9554. if err != nil {
  9555. theStartTime = 0
  9556. }
  9557. theStartTime = theTime.Unix()
  9558. }
  9559. adminInfo := c.GetMobileAdminUserInfo()
  9560. orgID := adminInfo.Org.Id
  9561. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  9562. if err != nil {
  9563. c.ErrorLog("获取排班信息失败:%v", err)
  9564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9565. } else {
  9566. if len(monitor) > 0 {
  9567. //获取所有床位
  9568. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  9569. //获取所有分区
  9570. zoneList, _ := service.GetAllZoneByList(orgID)
  9571. //获取透析处方
  9572. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  9573. //获取透前评估
  9574. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  9575. //获取上机
  9576. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  9577. //获取透后
  9578. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  9579. //获取透后监测
  9580. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  9581. //获取所有的患者
  9582. patients, _ := service.GetAllPatientListByListOne(orgID)
  9583. //获取所有透析模式
  9584. treatments, _ := service.GetAllTreatModeByList(orgID)
  9585. //获取所有医嘱
  9586. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  9587. //获取双人核对
  9588. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  9589. //治疗小结
  9590. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  9591. //待消毒
  9592. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  9593. for key, item := range monitor {
  9594. // 获取床位信息
  9595. for _, it := range numberList {
  9596. if item.BedId == it.ID {
  9597. monitor[key].DeviceNumber = it
  9598. break
  9599. }
  9600. }
  9601. //获取分区信息
  9602. for _, it := range zoneList {
  9603. if item.PartitionId == it.ID {
  9604. monitor[key].DeviceZone = it
  9605. }
  9606. }
  9607. for _, prescription := range prescriptions {
  9608. if item.PatientId == prescription.PatientId {
  9609. monitor[key].Prescription = prescription
  9610. break
  9611. }
  9612. }
  9613. for _, it := range checkList {
  9614. if item.PatientId == it.PatientId {
  9615. monitor[key].DoubleCheck = it
  9616. break
  9617. }
  9618. }
  9619. for _, it := range summaryList {
  9620. if item.PatientId == it.PatientId {
  9621. monitor[key].TreatmentSummaryForList = it
  9622. break
  9623. }
  9624. }
  9625. // 透前评估
  9626. for _, assessmentBefore := range assessmentBefores {
  9627. if item.PatientId == assessmentBefore.PatientId {
  9628. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  9629. break
  9630. }
  9631. }
  9632. // 透析上下机
  9633. for _, dialysisOrder := range dialysisOrders {
  9634. if item.PatientId == dialysisOrder.PatientId {
  9635. monitor[key].DialysisOrder = dialysisOrder
  9636. break
  9637. }
  9638. }
  9639. // 治疗小节
  9640. for _, afterDislysis := range AssessmentAfterDislysis {
  9641. if item.PatientId == afterDislysis.PatientId {
  9642. monitor[key].AssessmentAfterDislysis = afterDislysis
  9643. break
  9644. }
  9645. }
  9646. for _, it := range monitorlist {
  9647. if item.PatientId == it.PatientId {
  9648. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  9649. }
  9650. }
  9651. for _, it := range adviceList {
  9652. if item.PatientId == it.PatientId {
  9653. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  9654. }
  9655. }
  9656. for _, patient := range patients {
  9657. if item.PatientId == patient.ID {
  9658. monitor[key].MonitorPatients = patient
  9659. break
  9660. }
  9661. }
  9662. for _, treatment := range treatments {
  9663. if item.ModeId == treatment.ID {
  9664. monitor[key].TreatmentMode = treatment
  9665. break
  9666. }
  9667. }
  9668. for _, infor := range informationList {
  9669. if item.PatientId == infor.PatientId {
  9670. monitor[key].NewDeviceInformation = infor
  9671. break
  9672. }
  9673. }
  9674. }
  9675. }
  9676. }
  9677. patients, err := service.GetAllpatientFourty(orgID)
  9678. var mds []*models.NewMonitorDialysisScheduleList
  9679. if pat_type == 0 {
  9680. for _, item := range monitor {
  9681. mds = append(mds, item)
  9682. }
  9683. }
  9684. //待医嘱核对
  9685. if pat_type == 1 {
  9686. for _, item := range monitor {
  9687. if len(item.AdviceList) > 0 {
  9688. mds = append(mds, item)
  9689. }
  9690. }
  9691. }
  9692. //待开小结
  9693. if pat_type == 2 {
  9694. for _, item := range monitor {
  9695. if item.TreatmentSummaryForList == nil {
  9696. mds = append(mds, item)
  9697. }
  9698. }
  9699. }
  9700. //待下机
  9701. if pat_type == 3 {
  9702. for _, item := range monitor {
  9703. if item.DialysisOrder != nil {
  9704. if item.DialysisOrder.ID > 0 {
  9705. mds = append(mds, item)
  9706. }
  9707. }
  9708. }
  9709. }
  9710. //待消毒
  9711. if pat_type == 4 {
  9712. for _, item := range monitor {
  9713. if item.NewDeviceInformation == nil {
  9714. mds = append(mds, item)
  9715. }
  9716. }
  9717. }
  9718. //待双人核对
  9719. if pat_type == 5 {
  9720. for _, item := range monitor {
  9721. if item.DoubleCheck == nil {
  9722. mds = append(mds, item)
  9723. }
  9724. }
  9725. }
  9726. //医嘱未执行
  9727. if pat_type == 6 {
  9728. for _, item := range monitor {
  9729. if len(item.AdviceList) > 0 {
  9730. mds = append(mds, item)
  9731. }
  9732. }
  9733. }
  9734. //患者未签名
  9735. if pat_type == 7 {
  9736. for _, item := range monitor {
  9737. if item.DialysisOrder != nil {
  9738. if item.DialysisOrder.ID > 0 {
  9739. mds = append(mds, item)
  9740. }
  9741. }
  9742. }
  9743. }
  9744. //目标超滤于实际超滤不同
  9745. if pat_type == 8 {
  9746. for _, item := range monitor {
  9747. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9748. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9749. mds = append(mds, item)
  9750. }
  9751. }
  9752. }
  9753. }
  9754. //血压少于5次
  9755. if pat_type == 9 {
  9756. for _, item := range monitor {
  9757. if len(item.MonitoringRecord) < 5 {
  9758. mds = append(mds, item)
  9759. }
  9760. }
  9761. }
  9762. if pat_type == 10 {
  9763. for _, item := range monitor {
  9764. if len(item.MonitoringRecord) == 0 {
  9765. mds = append(mds, item)
  9766. }
  9767. }
  9768. }
  9769. if pat_type == 11 {
  9770. for _, item := range monitor {
  9771. if len(item.MonitoringRecord) > 0 {
  9772. mds = append(mds, item)
  9773. }
  9774. }
  9775. }
  9776. if pat_type == 12 {
  9777. for _, item := range monitor {
  9778. if len(item.MonitoringRecord) > 0 {
  9779. mds = append(mds, item)
  9780. }
  9781. }
  9782. }
  9783. if err == nil {
  9784. c.ServeSuccessJSON(map[string]interface{}{
  9785. "monitor": mds,
  9786. "patients": patients,
  9787. })
  9788. } else {
  9789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9790. }
  9791. }
  9792. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9793. admin_user_id, _ := c.GetInt64("admin_user_id")
  9794. timeStr := time.Now().Format("2006-01-02")
  9795. timeLayout := "2006-01-02 15:04:05"
  9796. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9797. timenow := timeStringToTime.Unix()
  9798. orgId := c.GetMobileAdminUserInfo().Org.Id
  9799. //查询当前护士的患者
  9800. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9801. var patientIds []int64
  9802. for _, item := range orderList {
  9803. patientIds = append(patientIds, item.PatientId)
  9804. }
  9805. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9806. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9807. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9808. //药品管理信息
  9809. _, drugStockConfig := service.FindHisConfig(orgId)
  9810. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9811. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9812. c.ServeSuccessJSON(map[string]interface{}{
  9813. "adviceList": adviceList,
  9814. "hisAdviceList": hisAdviceList,
  9815. "projectList": projectList,
  9816. "drugStockConfig": drugStockConfig,
  9817. "patientList": patientList,
  9818. "projectConfig": projectConfig,
  9819. })
  9820. }
  9821. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9822. patient_id, _ := c.GetInt64("patient_id")
  9823. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9824. c.ServeSuccessJSON(map[string]interface{}{
  9825. "recrods": recrods,
  9826. })
  9827. }
  9828. func (c *DialysisAPIController) ExMobileChangeSch() {
  9829. id_one, _ := c.GetInt64("id_one")
  9830. id_two, _ := c.GetInt64("id_two")
  9831. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9832. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9833. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9834. //if order2.ID > 0 {
  9835. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9836. // return
  9837. //}
  9838. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9839. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9840. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9841. if count > 0 {
  9842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9843. return
  9844. }
  9845. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9846. if count1 > 0 {
  9847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9848. return
  9849. }
  9850. }
  9851. err := service.UpdateScheduleThree(sch, sch_two)
  9852. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  9853. if order.ID > 0 {
  9854. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  9855. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9856. redis := service.RedisClient()
  9857. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  9858. redis.Set(key, "", time.Second)
  9859. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9860. //清空key 值
  9861. redis.Set(keyOne, "", time.Second)
  9862. }
  9863. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  9864. if orderOne.ID > 0 {
  9865. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  9866. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9867. redis := service.RedisClient()
  9868. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9869. redis.Set(key, "", time.Second)
  9870. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9871. //清空key 值
  9872. redis.Set(keyOne, "", time.Second)
  9873. }
  9874. if err == nil {
  9875. //去除当天患者排班中重复数据,保留最后一条数据
  9876. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9877. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9878. c.ServeSuccessJSON(map[string]interface{}{
  9879. "msg": "交换成功",
  9880. })
  9881. } else {
  9882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9883. return
  9884. }
  9885. }
  9886. func (c *DialysisAPIController) MobileCoverSch() {
  9887. id_one, _ := c.GetInt64("id_one")
  9888. id_two, _ := c.GetInt64("id_two")
  9889. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9890. //针对凤凰医院
  9891. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  9892. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9893. if len(advice) > 0 {
  9894. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9895. }
  9896. }
  9897. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  9898. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9899. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9900. if len(hisAdvice) > 0 {
  9901. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9902. }
  9903. if len(project) > 0 {
  9904. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9905. }
  9906. }
  9907. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9908. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9909. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9910. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9911. if count > 0 {
  9912. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9913. return
  9914. }
  9915. }
  9916. var new_sch models.Schedule
  9917. new_sch = sch
  9918. new_sch.BedId = sch_two.BedId
  9919. new_sch.ScheduleDate = sch_two.ScheduleDate
  9920. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  9921. new_sch.PartitionId = sch_two.PartitionId
  9922. new_sch.ScheduleType = sch_two.ScheduleType
  9923. new_sch.ID = 0
  9924. //删除原来的排班
  9925. err := service.SaveSchTwo(sch, sch_two)
  9926. //生成新的排班
  9927. if err == nil {
  9928. err2 := service.SaveSch(&new_sch)
  9929. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  9930. if order.ID > 0 {
  9931. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  9932. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9933. redis := service.RedisClient()
  9934. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  9935. redis.Set(key, "", time.Second)
  9936. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9937. //清空key 值
  9938. redis.Set(keyOne, "", time.Second)
  9939. }
  9940. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  9941. if orderOne.ID > 0 {
  9942. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  9943. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9944. redis := service.RedisClient()
  9945. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9946. redis.Set(key, "", time.Second)
  9947. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9948. //清空key 值
  9949. redis.Set(keyOne, "", time.Second)
  9950. }
  9951. if err2 == nil {
  9952. //去除当天患者排班中重复数据,保留最后一条数据
  9953. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9954. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9955. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  9956. c.ServeSuccessJSON(map[string]interface{}{
  9957. "msg": "覆盖成功",
  9958. "new_sch": new_sch,
  9959. })
  9960. } else {
  9961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9962. return
  9963. }
  9964. } else {
  9965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9966. return
  9967. }
  9968. }
  9969. func (c *DialysisAPIController) BatchCheckAdvice() {
  9970. patient_id, _ := c.GetInt64("patient_id")
  9971. advice_date, _ := c.GetInt64("advice_date")
  9972. org_id := c.GetMobileAdminUserInfo().Org.Id
  9973. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  9974. //查询是his系统还是血透系统
  9975. _, configs := service.FindXTHisRecordByOrgId(org_id)
  9976. //his客户
  9977. if configs.IsOpen == 1 {
  9978. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  9979. for _, item := range adviceList {
  9980. service.BatchCheckHisAdvice(item.ID, creater)
  9981. }
  9982. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9983. for _, item := range projectList {
  9984. service.BatchCheckProject(item.ID, creater)
  9985. }
  9986. c.ServeSuccessJSON(map[string]interface{}{
  9987. "adviceList": adviceList,
  9988. "projectList": projectList,
  9989. })
  9990. }
  9991. if configs.IsOpen != 1 {
  9992. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  9993. for _, item := range adviceList {
  9994. service.BatchAdviceList(item.ID, creater)
  9995. }
  9996. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9997. for _, item := range projectList {
  9998. service.BatchCheckProject(item.ID, creater)
  9999. }
  10000. c.ServeSuccessJSON(map[string]interface{}{
  10001. "adviceList": adviceList,
  10002. "projectList": projectList,
  10003. })
  10004. }
  10005. return
  10006. }
  10007. func (c *DialysisAPIController) GetAllMobileDrugList() {
  10008. org_id := c.GetMobileAdminUserInfo().Org.Id
  10009. drugList, _ := service.GetAllDrugList(org_id)
  10010. c.ServeSuccessJSON(map[string]interface{}{
  10011. "drugList": drugList,
  10012. })
  10013. }
  10014. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  10015. org_id := c.GetMobileAdminUserInfo().Org.Id
  10016. dataBody := make(map[string]interface{}, 0)
  10017. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10018. if err != nil {
  10019. utils.ErrorLog(err.Error())
  10020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10021. return
  10022. }
  10023. timeLayout := "2006-01-02"
  10024. loc, _ := time.LoadLocation("Local")
  10025. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  10026. utils.ErrorLog("advice_type")
  10027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10028. return
  10029. }
  10030. adviceType := int64(dataBody["advice_type"].(float64))
  10031. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10032. utils.ErrorLog("start_time")
  10033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10034. return
  10035. }
  10036. startTime2, _ := dataBody["start_time"].(string)
  10037. time_arr := strings.Split(startTime2, " ")
  10038. if len(time_arr) > 0 {
  10039. startTime2 = time_arr[0]
  10040. }
  10041. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10042. utils.ErrorLog("advice_date")
  10043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10044. return
  10045. }
  10046. advice_date, _ := dataBody["advice_date"].(string)
  10047. var advicedateunix int64
  10048. if len(advice_date) > 0 {
  10049. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10050. if err != nil {
  10051. fmt.Println(err)
  10052. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10053. return
  10054. }
  10055. advicedateunix = theTime.Unix()
  10056. }
  10057. adviceDate := startTime2
  10058. if len(adviceDate) == 0 {
  10059. utils.ErrorLog("len(adviceDate) == 0")
  10060. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10061. return
  10062. }
  10063. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10064. if err != nil {
  10065. utils.ErrorLog(err.Error())
  10066. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10067. return
  10068. }
  10069. AdviceDate := advicedateunix
  10070. RecordDate := advicedateunix
  10071. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10072. utils.ErrorLog("start_time")
  10073. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10074. return
  10075. }
  10076. startTime, _ := dataBody["start_time"].(string)
  10077. if len(startTime) == 0 {
  10078. utils.ErrorLog("len(start_time) == 0")
  10079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10080. return
  10081. }
  10082. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10083. if err != nil {
  10084. utils.ErrorLog(err.Error())
  10085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10086. return
  10087. }
  10088. StartTime := theTime.Unix()
  10089. advice_name, _ := dataBody["advice_name"].(string)
  10090. advice_desc, _ := dataBody["advice_desc"].(string)
  10091. delivery_way, _ := dataBody["delivery_way"].(string)
  10092. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10093. frequency_type := int64(dataBody["frequency_type"].(float64))
  10094. frequency_week, _ := dataBody["frequency_week"].(string)
  10095. prescribing_number := dataBody["prescribing_number"].(float64)
  10096. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10097. remark := dataBody["remark"].(string)
  10098. single_dose := dataBody["single_dose"].(float64)
  10099. single_dose_unit := dataBody["single_dose_unit"].(string)
  10100. patient_id := int64(dataBody["patient_id"].(float64))
  10101. day_count := int64(dataBody["day_count"].(float64))
  10102. groupNo := int64(dataBody["group_no"].(float64))
  10103. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10104. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  10105. if groupNo <= 0 {
  10106. group := service.GetMaxAdviceGroupID(org_id)
  10107. groupNo = group + 1
  10108. }
  10109. var template_id = ""
  10110. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  10111. template_id = "M" + adviceLastId
  10112. advice := models.DoctorAdvice{
  10113. UserOrgId: org_id,
  10114. PatientId: patient_id,
  10115. AdviceType: adviceType,
  10116. AdviceDate: AdviceDate,
  10117. StartTime: StartTime,
  10118. AdviceName: advice_name,
  10119. AdviceDesc: advice_desc,
  10120. ReminderDate: 0,
  10121. SingleDose: single_dose,
  10122. SingleDoseUnit: single_dose_unit,
  10123. DrugSpec: 0,
  10124. DrugSpecUnit: "",
  10125. PrescribingNumber: prescribing_number,
  10126. PrescribingNumberUnit: prescribing_number_unit,
  10127. DeliveryWay: delivery_way,
  10128. ExecutionFrequency: execution_frequency,
  10129. AdviceDoctor: advice_doctor,
  10130. Status: 1,
  10131. CreatedTime: time.Now().Unix(),
  10132. UpdatedTime: 0,
  10133. AdviceAffirm: "",
  10134. Remark: remark,
  10135. StopTime: 0,
  10136. StopReason: "",
  10137. StopDoctor: 0,
  10138. StopState: 0,
  10139. ParentId: 0,
  10140. ExecutionTime: 0,
  10141. ExecutionStaff: 0,
  10142. ExecutionState: 0,
  10143. Checker: 0,
  10144. RecordDate: RecordDate,
  10145. DialysisOrderId: 0,
  10146. CheckTime: 0,
  10147. CheckState: 0,
  10148. AdviceId: 0,
  10149. RemindType: 0,
  10150. FrequencyType: frequency_type,
  10151. DayCount: day_count,
  10152. WeekDay: frequency_week,
  10153. ChildDoctorAdvice: nil,
  10154. TemplateId: template_id,
  10155. Modifier: 0,
  10156. IsCheck: 0,
  10157. Way: 0,
  10158. DrugId: 0,
  10159. DrugNameId: 0,
  10160. IsMedicine: 0,
  10161. PushStartTime: 0,
  10162. IsSettle: 0,
  10163. IsPrescription: 0,
  10164. GroupNo: groupNo,
  10165. }
  10166. service.CreateMobileAdivce(advice)
  10167. c.ServeSuccessJSON(map[string]interface{}{
  10168. "msg": "保存成功!",
  10169. })
  10170. }
  10171. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  10172. patient_id, _ := c.GetInt64("patient_id")
  10173. org_id := c.GetMobileAdminUserInfo().Org.Id
  10174. app_id := c.GetMobileAdminUserInfo().App.Id
  10175. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  10176. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  10177. c.ServeSuccessJSON(map[string]interface{}{
  10178. "adviceList": adviceList,
  10179. "adminRoles": adminRoles,
  10180. })
  10181. }
  10182. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  10183. org_id := c.GetMobileAdminUserInfo().Org.Id
  10184. dataBody := make(map[string]interface{}, 0)
  10185. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10186. if err != nil {
  10187. utils.ErrorLog(err.Error())
  10188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10189. return
  10190. }
  10191. timeLayout := "2006-01-02"
  10192. loc, _ := time.LoadLocation("Local")
  10193. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10194. utils.ErrorLog("start_time")
  10195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10196. return
  10197. }
  10198. startTime2, _ := dataBody["start_time"].(string)
  10199. time_arr := strings.Split(startTime2, " ")
  10200. if len(time_arr) > 0 {
  10201. startTime2 = time_arr[0]
  10202. }
  10203. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10204. utils.ErrorLog("advice_date")
  10205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10206. return
  10207. }
  10208. advice_date, _ := dataBody["advice_date"].(string)
  10209. var advicedateunix int64
  10210. if len(advice_date) > 0 {
  10211. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10212. if err != nil {
  10213. fmt.Println(err)
  10214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10215. return
  10216. }
  10217. advicedateunix = theTime.Unix()
  10218. }
  10219. adviceDate := startTime2
  10220. if len(adviceDate) == 0 {
  10221. utils.ErrorLog("len(adviceDate) == 0")
  10222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10223. return
  10224. }
  10225. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10226. if err != nil {
  10227. utils.ErrorLog(err.Error())
  10228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10229. return
  10230. }
  10231. AdviceDate := advicedateunix
  10232. RecordDate := advicedateunix
  10233. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10234. utils.ErrorLog("start_time")
  10235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10236. return
  10237. }
  10238. startTime, _ := dataBody["start_time"].(string)
  10239. if len(startTime) == 0 {
  10240. utils.ErrorLog("len(start_time) == 0")
  10241. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10242. return
  10243. }
  10244. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10245. if err != nil {
  10246. utils.ErrorLog(err.Error())
  10247. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10248. return
  10249. }
  10250. StartTime := theTime.Unix()
  10251. advice_name, _ := dataBody["advice_name"].(string)
  10252. advice_desc, _ := dataBody["advice_desc"].(string)
  10253. delivery_way, _ := dataBody["delivery_way"].(string)
  10254. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10255. prescribing_number := dataBody["prescribing_number"].(float64)
  10256. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10257. remark := dataBody["remark"].(string)
  10258. single_dose := dataBody["single_dose"].(float64)
  10259. single_dose_unit := dataBody["single_dose_unit"].(string)
  10260. patient_id := int64(dataBody["patient_id"].(float64))
  10261. groupNo := int64(dataBody["group_no"].(float64))
  10262. parent_id := int64(dataBody["parent_id"].(float64))
  10263. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10264. advice := models.XtDoctorAdviceOne{
  10265. UserOrgId: org_id,
  10266. PatientId: patient_id,
  10267. AdviceType: 1,
  10268. AdviceDate: AdviceDate,
  10269. StartTime: StartTime,
  10270. AdviceName: advice_name,
  10271. AdviceDesc: advice_desc,
  10272. ReminderDate: 0,
  10273. SingleDose: single_dose,
  10274. SingleDoseUnit: single_dose_unit,
  10275. PrescribingNumber: prescribing_number,
  10276. PrescribingNumberUnit: prescribing_number_unit,
  10277. DeliveryWay: delivery_way,
  10278. ExecutionFrequency: execution_frequency,
  10279. AdviceDoctor: advice_doctor,
  10280. Status: 1,
  10281. CreatedTime: time.Now().Unix(),
  10282. UpdatedTime: time.Now().Unix(),
  10283. AdviceAffirm: "",
  10284. Remark: remark,
  10285. StopTime: 0,
  10286. StopReason: "",
  10287. StopDoctor: 0,
  10288. StopState: 0,
  10289. ParentId: parent_id,
  10290. ExecutionTime: 0,
  10291. ExecutionStaff: 0,
  10292. ExecutionState: 0,
  10293. Checker: 0,
  10294. RecordDate: RecordDate,
  10295. DialysisOrderId: 0,
  10296. CheckTime: 0,
  10297. CheckState: 0,
  10298. DrugSpec: 0,
  10299. DrugSpecUnit: "",
  10300. Groupno: groupNo,
  10301. RemindType: 0,
  10302. FrequencyType: 0,
  10303. DayCount: 0,
  10304. WeekDay: "",
  10305. TemplateId: "",
  10306. Modifier: 0,
  10307. }
  10308. service.CreateMobileAdivceOne(advice)
  10309. c.ServeSuccessJSON(map[string]interface{}{
  10310. "msg": "保存成功!",
  10311. })
  10312. }
  10313. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  10314. id, _ := c.GetInt64("id")
  10315. service.DeleteSelfAdviceSubAdvice(id)
  10316. c.ServeSuccessJSON(map[string]interface{}{
  10317. "msg": "保存成功!",
  10318. })
  10319. }
  10320. func (c *DialysisAPIController) GetEditAdviceAction() {
  10321. id, _ := c.GetInt64("id")
  10322. org_id := c.GetMobileAdminUserInfo().Org.Id
  10323. advice, _ := service.GetEditAdviceActionList(id, org_id)
  10324. drugList, _ := service.GetAllDrugList(org_id)
  10325. c.ServeSuccessJSON(map[string]interface{}{
  10326. "advice": advice,
  10327. "drugList": drugList,
  10328. })
  10329. }
  10330. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  10331. dataBody := make(map[string]interface{}, 0)
  10332. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10333. if err != nil {
  10334. utils.ErrorLog(err.Error())
  10335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10336. return
  10337. }
  10338. timeLayout := "2006-01-02"
  10339. loc, _ := time.LoadLocation("Local")
  10340. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10341. utils.ErrorLog("start_time")
  10342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10343. return
  10344. }
  10345. startTime2, _ := dataBody["start_time"].(string)
  10346. time_arr := strings.Split(startTime2, " ")
  10347. if len(time_arr) > 0 {
  10348. startTime2 = time_arr[0]
  10349. }
  10350. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10351. utils.ErrorLog("advice_date")
  10352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10353. return
  10354. }
  10355. advice_date, _ := dataBody["advice_date"].(string)
  10356. var advicedateunix int64
  10357. if len(advice_date) > 0 {
  10358. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10359. if err != nil {
  10360. fmt.Println(err)
  10361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10362. return
  10363. }
  10364. advicedateunix = theTime.Unix()
  10365. }
  10366. adviceDate := startTime2
  10367. if len(adviceDate) == 0 {
  10368. utils.ErrorLog("len(adviceDate) == 0")
  10369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10370. return
  10371. }
  10372. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10373. if err != nil {
  10374. utils.ErrorLog(err.Error())
  10375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10376. return
  10377. }
  10378. AdviceDate := advicedateunix
  10379. RecordDate := advicedateunix
  10380. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10381. utils.ErrorLog("start_time")
  10382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10383. return
  10384. }
  10385. startTime, _ := dataBody["start_time"].(string)
  10386. if len(startTime) == 0 {
  10387. utils.ErrorLog("len(start_time) == 0")
  10388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10389. return
  10390. }
  10391. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10392. if err != nil {
  10393. utils.ErrorLog(err.Error())
  10394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10395. return
  10396. }
  10397. StartTime := theTime.Unix()
  10398. advice_name, _ := dataBody["advice_name"].(string)
  10399. advice_desc, _ := dataBody["advice_desc"].(string)
  10400. delivery_way, _ := dataBody["delivery_way"].(string)
  10401. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10402. prescribing_number := dataBody["prescribing_number"].(float64)
  10403. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10404. remark := dataBody["remark"].(string)
  10405. single_dose := dataBody["single_dose"].(float64)
  10406. single_dose_unit := dataBody["single_dose_unit"].(string)
  10407. id := int64(dataBody["id"].(float64))
  10408. frequency_type := int64(dataBody["frequency_type"].(float64))
  10409. frequency_week, _ := dataBody["frequency_week"].(string)
  10410. day_count := int64(dataBody["day_count"].(float64))
  10411. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10412. advice := models.XtDoctorAdviceOne{
  10413. AdviceDate: AdviceDate,
  10414. StartTime: StartTime,
  10415. AdviceName: advice_name,
  10416. AdviceDesc: advice_desc,
  10417. SingleDose: single_dose,
  10418. SingleDoseUnit: single_dose_unit,
  10419. PrescribingNumber: prescribing_number,
  10420. PrescribingNumberUnit: prescribing_number_unit,
  10421. DeliveryWay: delivery_way,
  10422. ExecutionFrequency: execution_frequency,
  10423. AdviceDoctor: advice_doctor,
  10424. Remark: remark,
  10425. RecordDate: RecordDate,
  10426. FrequencyType: frequency_type,
  10427. DayCount: day_count,
  10428. WeekDay: frequency_week,
  10429. }
  10430. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  10431. c.ServeSuccessJSON(map[string]interface{}{
  10432. "advice": advice,
  10433. })
  10434. }
  10435. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  10436. dataBody := make(map[string]interface{}, 0)
  10437. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10438. if err != nil {
  10439. utils.ErrorLog(err.Error())
  10440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10441. return
  10442. }
  10443. timeLayout := "2006-01-02"
  10444. loc, _ := time.LoadLocation("Local")
  10445. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10446. utils.ErrorLog("start_time")
  10447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10448. return
  10449. }
  10450. startTime2, _ := dataBody["start_time"].(string)
  10451. time_arr := strings.Split(startTime2, " ")
  10452. if len(time_arr) > 0 {
  10453. startTime2 = time_arr[0]
  10454. }
  10455. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10456. utils.ErrorLog("advice_date")
  10457. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10458. return
  10459. }
  10460. advice_date, _ := dataBody["advice_date"].(string)
  10461. var advicedateunix int64
  10462. if len(advice_date) > 0 {
  10463. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10464. if err != nil {
  10465. fmt.Println(err)
  10466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10467. return
  10468. }
  10469. advicedateunix = theTime.Unix()
  10470. }
  10471. adviceDate := startTime2
  10472. if len(adviceDate) == 0 {
  10473. utils.ErrorLog("len(adviceDate) == 0")
  10474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10475. return
  10476. }
  10477. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10478. if err != nil {
  10479. utils.ErrorLog(err.Error())
  10480. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10481. return
  10482. }
  10483. AdviceDate := advicedateunix
  10484. RecordDate := advicedateunix
  10485. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10486. utils.ErrorLog("start_time")
  10487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10488. return
  10489. }
  10490. startTime, _ := dataBody["start_time"].(string)
  10491. if len(startTime) == 0 {
  10492. utils.ErrorLog("len(start_time) == 0")
  10493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10494. return
  10495. }
  10496. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10497. if err != nil {
  10498. utils.ErrorLog(err.Error())
  10499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10500. return
  10501. }
  10502. StartTime := theTime.Unix()
  10503. advice_name, _ := dataBody["advice_name"].(string)
  10504. advice_desc, _ := dataBody["advice_desc"].(string)
  10505. delivery_way, _ := dataBody["delivery_way"].(string)
  10506. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10507. prescribing_number := dataBody["prescribing_number"].(float64)
  10508. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10509. remark := dataBody["remark"].(string)
  10510. single_dose := dataBody["single_dose"].(float64)
  10511. single_dose_unit := dataBody["single_dose_unit"].(string)
  10512. id := int64(dataBody["id"].(float64))
  10513. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10514. advice := models.XtDoctorAdviceOne{
  10515. AdviceDate: AdviceDate,
  10516. StartTime: StartTime,
  10517. AdviceName: advice_name,
  10518. AdviceDesc: advice_desc,
  10519. SingleDose: single_dose,
  10520. SingleDoseUnit: single_dose_unit,
  10521. PrescribingNumber: prescribing_number,
  10522. PrescribingNumberUnit: prescribing_number_unit,
  10523. DeliveryWay: delivery_way,
  10524. ExecutionFrequency: execution_frequency,
  10525. AdviceDoctor: advice_doctor,
  10526. Remark: remark,
  10527. RecordDate: RecordDate,
  10528. }
  10529. service.UpdateMobileDoctorAdviceById(id, advice)
  10530. c.ServeSuccessJSON(map[string]interface{}{
  10531. "advice": advice,
  10532. })
  10533. }
  10534. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  10535. dataBody := make(map[string]interface{}, 0)
  10536. timeLayout := "2006-01-02"
  10537. loc, _ := time.LoadLocation("Local")
  10538. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10539. if err != nil {
  10540. utils.ErrorLog(err.Error())
  10541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10542. return
  10543. }
  10544. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10545. utils.ErrorLog("start_time")
  10546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10547. return
  10548. }
  10549. startTime2, _ := dataBody["start_time"].(string)
  10550. time_arr := strings.Split(startTime2, " ")
  10551. if len(time_arr) > 0 {
  10552. startTime2 = time_arr[0]
  10553. }
  10554. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10555. utils.ErrorLog("advice_date")
  10556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10557. return
  10558. }
  10559. advice_date, _ := dataBody["advice_date"].(string)
  10560. var advicedateunix int64
  10561. if len(advice_date) > 0 {
  10562. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10563. if err != nil {
  10564. fmt.Println(err)
  10565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10566. return
  10567. }
  10568. advicedateunix = theTime.Unix()
  10569. }
  10570. adviceDate := startTime2
  10571. if len(adviceDate) == 0 {
  10572. utils.ErrorLog("len(adviceDate) == 0")
  10573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10574. return
  10575. }
  10576. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10577. if err != nil {
  10578. utils.ErrorLog(err.Error())
  10579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10580. return
  10581. }
  10582. RecordDate := advicedateunix
  10583. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10584. utils.ErrorLog("start_time")
  10585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10586. return
  10587. }
  10588. startTime, _ := dataBody["start_time"].(string)
  10589. if len(startTime) == 0 {
  10590. utils.ErrorLog("len(start_time) == 0")
  10591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10592. return
  10593. }
  10594. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10595. if err != nil {
  10596. utils.ErrorLog(err.Error())
  10597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10598. return
  10599. }
  10600. StartTime := theTime.Unix()
  10601. patient_id := int64(dataBody["patient_id"].(float64))
  10602. group_no := int64(dataBody["group_no"].(float64))
  10603. org_id := c.GetMobileAdminUserInfo().Org.Id
  10604. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10605. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  10606. utils.ErrorLog("advices")
  10607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10608. return
  10609. }
  10610. adviceNames := dataBody["advices"].([]interface{})
  10611. var advices []*models.GroupAdvice
  10612. for _, adviceNameMap := range adviceNames {
  10613. var advice models.GroupAdvice
  10614. adviceNameM := adviceNameMap.(map[string]interface{})
  10615. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  10616. utils.ErrorLog("advice_name")
  10617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10618. return
  10619. }
  10620. adviceName, _ := adviceNameM["advice_name"].(string)
  10621. if len(adviceName) == 0 {
  10622. utils.ErrorLog("len(advice_name) == 0")
  10623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10624. return
  10625. }
  10626. advice.AdviceName = adviceName
  10627. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  10628. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  10629. advice.DrugSpec = drugSpec
  10630. }
  10631. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  10632. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  10633. advice.AdviceDesc = adviceDesc
  10634. }
  10635. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  10636. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  10637. advice.DrugSpecUnit = drugSpecUnit
  10638. }
  10639. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  10640. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  10641. advice.SingleDose = singleDose
  10642. }
  10643. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  10644. singleDose := adviceNameM["single_dose"].(float64)
  10645. advice.SingleDose = singleDose
  10646. }
  10647. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  10648. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  10649. advice.SingleDoseUnit = singleDoseUnit
  10650. }
  10651. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  10652. tmp := adviceNameM["single_dose_unit"].(float64)
  10653. singleDoseUnit := service.TypeConversion(tmp)
  10654. advice.SingleDoseUnit = singleDoseUnit
  10655. }
  10656. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  10657. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  10658. advice.PrescribingNumber = prescribingNumber
  10659. }
  10660. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  10661. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  10662. advice.PrescribingNumber = prescribingNumber
  10663. }
  10664. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  10665. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  10666. advice.PrescribingNumberUnit = prescribingNumberUnit
  10667. }
  10668. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  10669. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  10670. advice.DeliveryWay = deliveryWay
  10671. }
  10672. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  10673. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  10674. advice.ExecutionFrequency = executionFrequency
  10675. }
  10676. remark, _ := adviceNameM["remark"].(string)
  10677. advice.Remark = remark
  10678. advice.AdviceType = 1
  10679. advice.StartTime = StartTime
  10680. advice.RecordDate = RecordDate
  10681. advice.PatientId = patient_id
  10682. advice.UserOrgId = org_id
  10683. advice.AdviceDoctor = advice_doctor
  10684. advices = append(advices, &advice)
  10685. }
  10686. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  10687. c.ServeSuccessJSON(map[string]interface{}{
  10688. "advice": newAdvices,
  10689. })
  10690. }
  10691. func (c *DialysisAPIController) StopLongAdvice() {
  10692. stop_time := c.GetString("execution_time")
  10693. id, _ := c.GetInt64("id")
  10694. if len(stop_time) <= 0 {
  10695. utils.ErrorLog("stop_time")
  10696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10697. return
  10698. }
  10699. timeLayout2 := "2006-01-02 15:04:05"
  10700. loc, _ := time.LoadLocation("Local")
  10701. theTime, errs := time.ParseInLocation(timeLayout2, stop_time, loc)
  10702. if errs != nil {
  10703. utils.ErrorLog(errs.Error())
  10704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10705. return
  10706. }
  10707. advice, _ := service.StopLongAdvice(id, theTime.Unix())
  10708. c.ServeSuccessJSON(map[string]interface{}{
  10709. "advice": advice,
  10710. })
  10711. }